[PATCH] Fix for PR15086

Nick Lewycky nicholas at mxc.ca
Sun Oct 20 17:49:55 PDT 2013


Dimitry Andric wrote:
> On Oct 20, 2013, at 23:48, Nick Lewycky<nicholas at mxc.ca>  wrote:
>> Dimitry Andric wrote:
> ...
>>> Therefore, I propose the attached fix, which changes X86TargetLowering::LowerCall() to skip tail call optimization, if the called function is a global or external symbol.  I have also updated the appropriate test cases.  If most people would also like to have a separate test case just for this specific PR, let me know and I will add one.
>>
>> I agree with Tijl's assessment in the bug. I'd appreciate if you could add a testcase where the caller does have internal linkage and ensure that we do emit a tail call.
>
> There is already such a testcase

Excellent!

>> Also, what does this do to:
>>
>>   extern int i;
>>   int foo(void) { return i; }
>>   int bar(void) { return foo(); }
>>
>> foo is externally visible but this can also be a tail call because we don't permit symbol interposition in cases where inlining would be legal.
>
> There does not seem to be any change in the produced code.  At -O0, the call to foo() in bar() gets done via the PLT, with or without my patch.  With any optimization, clang inlines foo() into bar(), and directly uses i at GOT to access the variable.  Since variables cannot be lazily linked, this is no problem.

Please try harder. :) Does __attribute__((noinline)) help? 
Alternatively, skip C and write it as straight .ll (be sure to include 
the 'tail' marker on the call).

>> Please commit the change to test/ExecutionEngine/MCJIT/test-global-init-nonzero-sm-pic.ll now and pull it out of this patch.
>
> Ah sorry, this was part of my local changes to make the test suite pass successfully.  Since I do not have commit rights, can you please commit it for me?

Done in r193063. Thanks for the patch!

Nick



More information about the llvm-commits mailing list