[CodeGen] isInTailCallPosition didn't consider readnone tailcalls
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 28 Aug 2015 16:44:09 +0000 (16:44 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 28 Aug 2015 16:44:09 +0000 (16:44 +0000)
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
lib/CodeGen/Analysis.cpp

index d3d71182b762470100d3f822db67f6fd78decdab..ab6907dcbd90aa2dc12f51dede8a01687d0985ea 100644 (file)
@@ -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.
index 98d4c8afc7b98b0c2ce53e390f1b0c1669e0957b..33ad88358e57517593e5d182041545a3c6582a3d 100644 (file)
@@ -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(