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) |
From: | Fernando <pronesto@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 7 Aug 2009 05:20:49 -0700 (PDT) |
Organization: | Compilers Central |
References: | 09-08-010 |
Keywords: | analysis |
Posted-Date: | 07 Aug 2009 09:48:08 EDT |
On Aug 6, 3:45 am, rajeshkann...@aol.in wrote:
> Dear all,
>
> 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
>
> (snip end)
>
> 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.
>
> Thanks and regards,
> Kannan
Hi, Kannan,
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.
Going back to your code, notice that once you redefine gsiVarB, it
is like if you had a completely new variable. This issue becomes much
clearer when you have the code in SSA form. In this case, each
variable is define at most once.
Fernando
Return to the
comp.compilers page.
Search the
comp.compilers archives again.