<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>8.1.1 Sub-expression Elimination</TITLE> <META NAME="description" CONTENT="8.1.1 Sub-expression Elimination"> <META NAME="keywords" CONTENT="sdccman"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="sdccman.css"> <LINK REL="next" HREF="node171.html"> <LINK REL="previous" HREF="node169.html"> <LINK REL="up" HREF="node169.html"> <LINK REL="next" HREF="node171.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html3371" HREF="node171.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3365" HREF="node169.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3359" HREF="node169.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3367" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3369" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3372" HREF="node171.html">8.1.2 Dead-Code Elimination</A> <B> Up:</B> <A NAME="tex2html3366" HREF="node169.html">8.1 Optimizations</A> <B> Previous:</B> <A NAME="tex2html3360" HREF="node169.html">8.1 Optimizations</A> <B> <A NAME="tex2html3368" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3370" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION00911000000000000000"></A><A NAME="3969"></A> <BR> 8.1.1 Sub-expression Elimination </H2> <P> The compiler does local and <I>g</I>lobal <I>c</I>ommon <I>s</I>ubexpression <I>e</I>limination, e.g.: <BLOCKQUOTE> <TT>i = x + y + 1; </TT> <BR><TT>j = x + y;</TT> </BLOCKQUOTE> will be translated to <BLOCKQUOTE> <TT>iTemp = x + y; </TT> <BR><TT>i = iTemp + 1; </TT> <BR><TT>j = iTemp;</TT> </BLOCKQUOTE> Some subexpressions are not as obvious as the above example, e.g.: <BLOCKQUOTE> <TT>a->b[i].c = 10; </TT> <BR><TT>a->b[i].d = 11;</TT> </BLOCKQUOTE> In this case the address arithmetic a->b[i] will be computed only once; the equivalent code in C would be. <BLOCKQUOTE> <TT>iTemp = a->b[i]; </TT> <BR><TT>iTemp.c = 10; </TT> <BR><TT>iTemp.d = 11;</TT> </BLOCKQUOTE> The compiler will try to keep these temporary variables in registers. <P> <BR><HR> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>