In function Analysis.cpp:isInTailCallPosition, instructions between call and ret are checked to see if they block tail call optimization. If an instruction is an intrinsic call, only llvm.lifetime_end is allowed and other intrinsic functions block tail call. When compiling tcmalloc, we found llvm.assume between a hot function call and ret, it blocks the optimization. But llvm.assume doesn't generate instructions, it should not block tail call.
Differential Revision: https://reviews.llvm.org/D66096
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369125
91177308-0d34-0410-b5e6-
96231b3b80d8
// Debug info intrinsics do not get in the way of tail call optimization.
if (isa<DbgInfoIntrinsic>(BBI))
continue;
- // A lifetime end intrinsic should not stop tail call optimization.
+ // A lifetime end or assume intrinsic should not stop tail call
+ // optimization.
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(BBI))
- if (II->getIntrinsicID() == Intrinsic::lifetime_end)
+ if (II->getIntrinsicID() == Intrinsic::lifetime_end ||
+ II->getIntrinsicID() == Intrinsic::assume)
continue;
if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
!isSafeToSpeculativelyExecute(&*BBI))
--- /dev/null
+; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
+
+; Intrinsic call to @llvm.assume should not prevent tail call optimization.
+; CHECK-LABEL: foo:
+; CHECK: jmp bar # TAILCALL
+define i8* @foo() {
+ %1 = tail call i8* @bar()
+ %2 = icmp ne i8* %1, null
+ tail call void @llvm.assume(i1 %2)
+ ret i8* %1
+}
+
+declare i8* @bar()
+declare void @llvm.assume(i1)
+