[llvm] r246304 - [CodeGen] isInTailCallPosition didn't consider readnone tailcalls
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 10:24:23 PDT 2015
On Fri, Aug 28, 2015 at 10:16 AM, Reid Kleckner <rnk at google.com> wrote:
> Test case?
>
Forgot to 'git add', added in r246306.
> Also, I think you can do a more precise analysis here. We should be able
> to tail call in this example:
>
> i32* @f() {
> %a = tail call i32* @foo_readnone()
> store i32 0, i32* %b
> ret i32* %a
> }
>
> I think in the readnone case you just need to check that the return value
> is used by nothing more than the ReturnInst.
>
I think that's possible, I'm willing to live with the current state of
things until I'm finished adding a 'pure' attribute to LLVM IR.
>
> On Fri, Aug 28, 2015 at 9:44 AM, David Majnemer via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: majnemer
>> Date: Fri Aug 28 11:44:09 2015
>> New Revision: 246304
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=246304&view=rev
>> Log:
>> [CodeGen] isInTailCallPosition didn't consider readnone tailcalls
>>
>> A readnone tailcall may still have a chain of computation which follows
>> it that would invalidate a tailcall lowering. Don't skip the analysis
>> in such cases.
>>
>> This fixes PR24613.
>>
>> Modified:
>> llvm/trunk/lib/Analysis/ValueTracking.cpp
>> llvm/trunk/lib/CodeGen/Analysis.cpp
>>
>> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=246304&r1=246303&r2=246304&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
>> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Aug 28 11:44:09 2015
>> @@ -3147,7 +3147,8 @@ bool llvm::isSafeToSpeculativelyExecute(
>> LI->getPointerOperand(), LI->getAlignment(), DL, CtxI, DT, TLI);
>> }
>> case Instruction::Call: {
>> - if (cast<CallInst>(Inst)->doesNotAccessMemory())
>> + auto *CI = cast<CallInst>(Inst);
>> + if (CI->doesNotAccessMemory() && !CI->isMustTailCall())
>> return true;
>> return false; // The called function could have undefined behavior or
>> // side-effects.
>>
>> Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=246304&r1=246303&r2=246304&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/Analysis.cpp Fri Aug 28 11:44:09 2015
>> @@ -506,18 +506,16 @@ bool llvm::isInTailCallPosition(Immutabl
>>
>> // If I will have a chain, make sure no other instruction that will
>> have a
>> // chain interposes between I and the return.
>> - if (I->mayHaveSideEffects() || I->mayReadFromMemory() ||
>> - !isSafeToSpeculativelyExecute(I))
>> - for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);;
>> --BBI) {
>> - if (&*BBI == I)
>> - break;
>> - // Debug info intrinsics do not get in the way of tail call
>> optimization.
>> - if (isa<DbgInfoIntrinsic>(BBI))
>> - continue;
>> - if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
>> - !isSafeToSpeculativelyExecute(BBI))
>> - return false;
>> - }
>> + for (BasicBlock::const_iterator BBI = std::prev(ExitBB->end(), 2);;
>> --BBI) {
>> + if (&*BBI == I)
>> + break;
>> + // Debug info intrinsics do not get in the way of tail call
>> optimization.
>> + if (isa<DbgInfoIntrinsic>(BBI))
>> + continue;
>> + if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
>> + !isSafeToSpeculativelyExecute(BBI))
>> + return false;
>> + }
>>
>> const Function *F = ExitBB->getParent();
>> return returnTypeIsEligibleForTailCall(
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150828/c6ed51f9/attachment.html>
More information about the llvm-commits
mailing list