]> granicus.if.org Git - llvm/commitdiff
[CodeGen/Analysis] Intrinsic llvm.assume should not block tail call optimization
authorGuozhi Wei <carrot@google.com>
Fri, 16 Aug 2019 16:26:12 +0000 (16:26 +0000)
committerGuozhi Wei <carrot@google.com>
Fri, 16 Aug 2019 16:26:12 +0000 (16:26 +0000)
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

lib/CodeGen/Analysis.cpp
test/CodeGen/X86/tailcall-assume.ll [new file with mode: 0644]

index e72938ba9bec438207b40d477688973d379b9a8c..f1bbb341df1a263bbd0d6fe1de4788bf60f0e96d 100644 (file)
@@ -536,9 +536,11 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM) {
       // 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))
diff --git a/test/CodeGen/X86/tailcall-assume.ll b/test/CodeGen/X86/tailcall-assume.ll
new file mode 100644 (file)
index 0000000..3baac9c
--- /dev/null
@@ -0,0 +1,15 @@
+; 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)
+