diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-08-28 16:44:09 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-08-28 16:44:09 +0000 |
commit | a787de32270237059d712108eedbd1c06300ca70 (patch) | |
tree | 74f730fd573323b7278e37afaa7c0cc777236f26 | |
parent | 69e7f6e4365a917b79e1d98238e2c31bcc2ee083 (diff) | |
download | bcm5719-llvm-a787de32270237059d712108eedbd1c06300ca70.tar.gz bcm5719-llvm-a787de32270237059d712108eedbd1c06300ca70.zip |
[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.
llvm-svn: 246304
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/CodeGen/Analysis.cpp | 22 |
2 files changed, 12 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index d3d71182b76..ab6907dcbd9 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -3147,7 +3147,8 @@ bool llvm::isSafeToSpeculativelyExecute(const Value *V, 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. diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index 98d4c8afc7b..33ad88358e5 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -506,18 +506,16 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM) { // 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( |