[PATCH] D66096: [CodeGen/Analysis] Intrinsic llvm.assume should not block tail call optimization
Guozhi Wei via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 10:52:24 PDT 2019
Carrot created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D66096
Files:
lib/CodeGen/Analysis.cpp
test/CodeGen/X86/tailcall-assume.ll
Index: test/CodeGen/X86/tailcall-assume.ll
===================================================================
--- test/CodeGen/X86/tailcall-assume.ll
+++ test/CodeGen/X86/tailcall-assume.ll
@@ -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)
+
Index: lib/CodeGen/Analysis.cpp
===================================================================
--- lib/CodeGen/Analysis.cpp
+++ lib/CodeGen/Analysis.cpp
@@ -538,7 +538,8 @@
continue;
// A lifetime end 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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66096.214663.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190812/92290004/attachment.bin>
More information about the llvm-commits
mailing list