On 03/25/2010 11:22 PM, Jeff Law wrote:
On 03/25/10 09:14, Bernd Schmidt wrote:
On 03/25/2010 04:03 PM, Jie Zhang wrote:
I just found that the current RTL code hoisting cannot optimize

REG = ...
if (cond)
{
r0 = REG;
....
}
else
{
r0 = REG;
...
}

to


REG = ...
r0 = REG;
if (cond)
{
....
}
else
{
...
}

where REG is a pseudo register and r0 is a physical register. I have
looked at the code of RTL hoisting pass. But I cannot find a simple way
to extend it to deal with this case. And the hoisting pass is only
enabled when -Os. So I'm going to implement another hoisting pass to do
this optimization. Is it a good idea? Does anyone know if there is an
existing pass which should have handled or be able to be easily adapted
to handle this case? Thanks!
Isn't this similar to crossjumping, except done in the other direction?
Yes, though the implementation is completely different. Hoisting
computes which blocks compute specific expressions, then determines if
all paths from a point compute the same expression and if so, moves the
multiple computations to a single location.

cross jumping works by matching RTL bits at the end of blocks.

I never bothered to implement hoisting which touched hard regs -- I
never thought the cost/benefit analysis made much sense. It's quite a
bit more work to implement and code motion of hard regs is much more
restricted than code motion involving just pseudos.

Thanks Bernd and Jeff.

This case is not common. I'm wondering how likely this kind of optimization pass will be accepted into GCC.

Another way to fix it is teaching register allocator to allocate r0 to REG. But I guess it's more difficult.


Jie

Reply via email to