Re: Copy propagation optimization

kamal <kamalpr@gmail.com>
Tue, 25 Aug 2009 04:51:36 -0700 (PDT)

          From comp.compilers

Related articles
Copy propagation optimization rajeshkannanb@aol.in (2009-08-06)
Re: Copy propagation optimization thisisgiri@gmail.com (Giridhar S) (2009-08-06)
Re: Copy propagation optimization news@iecc.com (2009-08-07)
Re: Copy propagation optimization pronesto@gmail.com (Fernando) (2009-08-07)
Re: Copy propagation optimization kamalpr@gmail.com (kamal) (2009-08-25)
| List of all articles for this month |

From: kamal <kamalpr@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 25 Aug 2009 04:51:36 -0700 (PDT)
Organization: Compilers Central
References: 09-08-010 09-08-017
Keywords: analysis
Posted-Date: 27 Aug 2009 15:58:43 EDT

On Aug 7, 5:20 pm, Fernando <prone...@gmail.com> wrote:
> On Aug 6, 3:45 am, rajeshkann...@aol.in wrote:
>
> > Please clarify my doubt regarding copy propagation optimization.
>
> > (snip)
>
> > gsiVarA = gsiVarB + gsiVarC;
>
> > gsiVarB = 1 ; // One of expression's operand
> > is
> > redefined
>
> > gsiVarD = gsiVarA ; // Statement-B


this is constant propagation, which is a subset of copy propagation.


> > As shown in the above snip, can the compiler use the result of
> > expression
> > (gsiVarB + gsiVarC) in Statement B instead of gsiVarA.
>
> > I expect the below result
>
> > (snip)
>
> > gsiVarA = gsiVarB + gsiVarC;
>
> > load R1, gsiVarB
> > load R2, gsiVarC
> > Add R1, R2
> > Store R1, R3
>
> > .... // gsiVarB is redefined.
> > ....
>
> > gsiVarD = gsiVarA ; // Statement-B
>
> > Store R1, gsiVarD // Result of expression is used.
>
> > (snip end)
>
> > Please clarify whether the compiler can perform the above optimization.


> the code you wrote looks fine to me. However, I think that is not
> really called copy propagation. You would have copy propagation if,
> for instance, you had:
>
> gsiVarC = ...
> gsiVarB = gsiVarA // this is a copy
> gsiVarD = gsiVarC + gsiVarB
>
> - The optimization would yield:
>
> gsiVarC = ...
> gsiVarD = gsiVarC + gsiVarA // the result of the copy is used instead.


this is copy propagation. The OP wanted to know whether this would be
implemented in a compiler by default. The answer is that it depends on
the compiler and the optimization level one opts for. GNU C implements
this at +O1.


http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Optimize-Options.html#Optimize-Op
tions


regards
-kamal


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.