Skip to content

Commit e03f6a1

Browse files
committedAug 16, 2019
[CodeGen/Analysis] Intrinsic llvm.assume should not block tail call optimization
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 llvm-svn: 369125
1 parent ac83aab commit e03f6a1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎llvm/lib/CodeGen/Analysis.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,11 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM) {
536536
// Debug info intrinsics do not get in the way of tail call optimization.
537537
if (isa<DbgInfoIntrinsic>(BBI))
538538
continue;
539-
// A lifetime end intrinsic should not stop tail call optimization.
539+
// A lifetime end or assume intrinsic should not stop tail call
540+
// optimization.
540541
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(BBI))
541-
if (II->getIntrinsicID() == Intrinsic::lifetime_end)
542+
if (II->getIntrinsicID() == Intrinsic::lifetime_end ||
543+
II->getIntrinsicID() == Intrinsic::assume)
542544
continue;
543545
if (BBI->mayHaveSideEffects() || BBI->mayReadFromMemory() ||
544546
!isSafeToSpeculativelyExecute(&*BBI))
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
2+
3+
; Intrinsic call to @llvm.assume should not prevent tail call optimization.
4+
; CHECK-LABEL: foo:
5+
; CHECK: jmp bar # TAILCALL
6+
define i8* @foo() {
7+
%1 = tail call i8* @bar()
8+
%2 = icmp ne i8* %1, null
9+
tail call void @llvm.assume(i1 %2)
10+
ret i8* %1
11+
}
12+
13+
declare i8* @bar()
14+
declare void @llvm.assume(i1)
15+

0 commit comments

Comments
 (0)
Please sign in to comment.