Index: lib/CodeGen/Analysis.cpp =================================================================== --- lib/CodeGen/Analysis.cpp +++ lib/CodeGen/Analysis.cpp @@ -536,9 +536,11 @@ // 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)) 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) +