From: Guozhi Wei Date: Fri, 16 Aug 2019 16:26:12 +0000 (+0000) Subject: [CodeGen/Analysis] Intrinsic llvm.assume should not block tail call optimization X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc203b96253af16da46c65588d256579180d428d;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369125 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/Analysis.cpp b/lib/CodeGen/Analysis.cpp index e72938ba9be..f1bbb341df1 100644 --- a/lib/CodeGen/Analysis.cpp +++ b/lib/CodeGen/Analysis.cpp @@ -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(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(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 index 00000000000..3baac9c4121 --- /dev/null +++ b/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) +