Re: Copy propagation optimization

Giridhar S <thisisgiri@gmail.com>
Thu, 6 Aug 2009 14:33:01 -0400

          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: Giridhar S <thisisgiri@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 6 Aug 2009 14:33:01 -0400
Organization: Compilers Central
References: 09-08-010
Keywords: optimize
Posted-Date: 07 Aug 2009 09:44:53 EDT

What you're describing has nothing to do with copy propagation - but
it's related to register allocation. It is very likely that most
compilers today will do what you're expecting, by default, even
without any optimization turned on. The span of instructions from the
point where gsiVarA is defined to the point where gsiVarA is last used
(let's assume statement B is the last use) defines the live range of
the variable - and the compiler tries very hard to ensure that every
variable lives in a register for the duration of it's live-range, in
order to avoid multiple trips to memory.


Of course, if the register pressure is very high within the live range
of the variable, the compiler maybe forced to spill the register to
memory and reload it upon next use - and this varies based on the
register allocation/spilling algorithm used by the compiler and a
bunch of other related issues.


HTH,


On Thu, Aug 6, 2009 at 2:45 AM, <rajeshkannanb@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.


> Thanks and regards,
> Kannan



Post a followup to this message

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