Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > e677bbbdff6d27fe001f15e0ef2bb4cc > files > 158

sdcc-3.0.0-0.fc14.x86_64.rpm

<!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.4 Loop Optimizations</TITLE>
<META NAME="description" CONTENT="8.1.4 Loop Optimizations">
<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="node174.html">
<LINK REL="previous" HREF="node172.html">
<LINK REL="up" HREF="node169.html">
<LINK REL="next" HREF="node174.html">
</HEAD>

<BODY >
<!--Navigation Panel-->
<A NAME="tex2html3413"
  HREF="node174.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html3407"
  HREF="node169.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html3401"
  HREF="node172.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html3409"
  HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html3411"
  HREF="node191.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html3414"
  HREF="node174.html">8.1.5 Loop Reversing</A>
<B> Up:</B> <A NAME="tex2html3408"
  HREF="node169.html">8.1 Optimizations</A>
<B> Previous:</B> <A NAME="tex2html3402"
  HREF="node172.html">8.1.3 Copy-Propagation</A>
 &nbsp; <B>  <A NAME="tex2html3410"
  HREF="node1.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html3412"
  HREF="node191.html">Index</A></B> 
<BR>
<BR>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00914000000000000000"></A><A NAME="4037"></A><A NAME="sub:Loop-Optimizations"></A>
<BR>
8.1.4 Loop Optimizations
</H2>

<P>
Two types of loop optimizations are done by SDCC <I>loop invariant</I>
lifting and <I>strength reduction</I> of loop induction variables.
In addition to the strength reduction the optimizer marks the induction
variables and the register allocator tries to keep the induction variables
in registers for the duration of the loop. Because of this preference
of the register allocator<A NAME="4041"></A>, loop induction
optimization causes an increase in register pressure, which may cause
unwanted spilling of other temporary variables into the stack<A NAME="4042"></A>
/ data space. The compiler will generate a warning message when it
is forced to allocate extra space either on the stack or data space.
If this extra space allocation is undesirable then induction optimization
can be eliminated either for the entire source file (with --noinduction
option) or for a given function only using #pragma&nbsp;noinduction<A NAME="4043"></A>.
<BR>
<BR>
Loop Invariant:
<BLOCKQUOTE>
<TT>for (i = 0 ; i &lt; 100 ; i ++) </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;f += k + l;</TT>

</BLOCKQUOTE>
changed to
<BLOCKQUOTE>
<TT>itemp = k + l; </TT>&nbsp;
<BR><TT>for (i = 0; i &lt; 100; i++) </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;f += itemp;</TT>

</BLOCKQUOTE>
As mentioned previously some loop invariants are not as apparent,
all static address computations are also moved out of the loop.
<BR>
<BR>
Strength Reduction<A NAME="4053"></A>, this optimization
substitutes an expression by a cheaper expression:
<BLOCKQUOTE>
<TT>for (i=0;i &lt; 100; i++)</TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;ar[i*5] = i*3;</TT>

</BLOCKQUOTE>
changed to
<BLOCKQUOTE>
<TT>itemp1 = 0; </TT>&nbsp;
<BR><TT>itemp2 = 0; </TT>&nbsp;
<BR><TT>for (i=0;i&lt; 100;i++) { </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;ar[itemp1] = itemp2; </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;itemp1 += 5; </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;itemp2 += 3; </TT>&nbsp;
<BR><TT>}</TT>

</BLOCKQUOTE>
The more expensive multiplication<A NAME="4071"></A> is changed
to a less expensive addition.

<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html3413"
  HREF="node174.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html3407"
  HREF="node169.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html3401"
  HREF="node172.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html3409"
  HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html3411"
  HREF="node191.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html3414"
  HREF="node174.html">8.1.5 Loop Reversing</A>
<B> Up:</B> <A NAME="tex2html3408"
  HREF="node169.html">8.1 Optimizations</A>
<B> Previous:</B> <A NAME="tex2html3402"
  HREF="node172.html">8.1.3 Copy-Propagation</A>
 &nbsp; <B>  <A NAME="tex2html3410"
  HREF="node1.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html3412"
  HREF="node191.html">Index</A></B> 
<!--End of Navigation Panel-->
<ADDRESS>

2011-03-20
</ADDRESS>
</BODY>
</HTML>