From c03acbca56b21439a306a5f2cbae2e4bf6ce22f9 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 28 Aug 2015 16:44:09 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246304 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ValueTracking.cpp | 3 ++- lib/CodeGen/Analysis.cpp | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index d3d71182b76..ab6907dcbd9 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/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(Inst)->doesNotAccessMemory()) + auto *CI = cast(Inst); + if (CI->doesNotAccessMemory() && !CI->isMustTailCall()) return true; return false; // The called function could have undefined behavior or // side-effects. diff --git a/lib/CodeGen/Analysis.cpp b/lib/CodeGen/Analysis.cpp index 98d4c8afc7b..33ad88358e5 100644 --- a/lib/CodeGen/Analysis.cpp +++ b/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(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(BBI)) + continue; + if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() || + !isSafeToSpeculativelyExecute(BBI)) + return false; + } const Function *F = ExitBB->getParent(); return returnTypeIsEligibleForTailCall( -- 2.34.1