[RFC PATCH] ira: accept loads via argp rtx in validate_equiv_mem

Jeff Law law@redhat.com
Mon May 4 17:37:00 GMT 2015


On 05/04/2015 10:37 AM, Alexander Monakov wrote:
> With this patch at hand, I'd like to discuss a code generation problem, which
> my patch solves only partially.  FWIW, it passes bootstrap/regtest on x86-64.
>
> With other patches in series applied, GCC with -fno-plt can generate tail
> calls in PIC mode more frequently, but sometimes poorer code is generated.
> I've tried to look for possible causes, and found one issue so far.
>
> Consider the following testcase:
>
> void foo1(int a, int b, int c, int d, int e, int f, int g, int h);
> int bar(int x);
> void foo2(int a, int b, int c, int d, int e, int f, int g, int h)
> {
>    bar(a);
>    foo1(a, b, c, d, e, f, g, h);
> }
>
> Comparing x86 code generation with -O2 -m32 and with/without -fPIC, you can
> see that -fPIC happens to produce smaller code.  Without -fPIC, GCC
> saves/restores all arguments before/after call to 'bar'.
>
> The reason for that is without -fPIC, GCC performs tail call optimization on
> 'foo1', and that causes it to drop REG_EQUIV notes for incoming arguments in
> fixup_tail_calls.  After that, code generation diverges at IRA stage, where
> lack of equivalences prevents loads of pseudos to be moved to the point of
> first use.
>
> The patch tries to repair the problem by allowing REG_EQUIV notes to be
> resynthesized at ira init for loads that happen via `argp' rtx.  It helps for
> the simple testcase above, but not for problematic Clang/LLVM functions where
> I noticed the issue.
>
> I hope there's a way around the 'big hammer' approach of fixup_tail_calls.
> Might it be possible instead of dropping REG_EQUIV notes, to copy incoming
> arguments into other pseudos just prior to stack pointer adjustment in
> preparation for tailcall?
Isn't the whole point of dropping the notes to indicate that those 
argument slots are not longer guaranteed to hold the value at all points 
throughout the function?

That can certainly be relaxed, but you'll have to have some kind of code 
to analyze the data in the argument slots to ensure they haven't 
changed.  You can't just blindly put the notes back if I remember this 
stuff correctly.

Jeff



More information about the Gcc-patches mailing list