Skip to content

Commit

Permalink
Maintain calling convention when inling calls to llvm.deoptimize
Browse files Browse the repository at this point in the history
The behavior here was buggy -- we'd forget the calling convention after
inlining a callsite calling llvm.deoptimize.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265867 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
sanjoy committed Apr 9, 2016
1 parent 5bb9d06 commit 5ff00d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
continue;
}

auto CallingConv = DeoptCall->getCallingConv();
auto *CurBB = RI->getParent();
RI->eraseFromParent();

Expand All @@ -1856,8 +1857,9 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
"Expected at least the deopt operand bundle");

IRBuilder<> Builder(CurBB);
Value *NewDeoptCall =
CallInst *NewDeoptCall =
Builder.CreateCall(NewDeoptIntrinsic, CallArgs, OpBundles);
NewDeoptCall->setCallingConv(CallingConv);
if (NewDeoptCall->getType()->isVoidTy())
Builder.CreateRetVoid();
else
Expand Down
15 changes: 15 additions & 0 deletions test/Transforms/Inline/deoptimize-intrinsic.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; RUN: opt -S -always-inline < %s | FileCheck %s

declare i8 @llvm.experimental.deoptimize.i8(...)
declare cc42 i32 @llvm.experimental.deoptimize.i32(...)

define i8 @callee(i1* %c) alwaysinline {
%c0 = load volatile i1, i1* %c
Expand Down Expand Up @@ -120,3 +121,17 @@ define void @caller_with_stacksaverestore(i32 %n) {
call i8 @callee_with_dynamic_alloca(i32 %n)
ret void
}

define i32 @callee_with_coldcc() alwaysinline {
%v0 = call cc42 i32(...) @llvm.experimental.deoptimize.i32(i32 1) [ "deopt"() ]
ret i32 %v0
}

define void @caller_with_coldcc() {
; CHECK-LABEL: @caller_with_coldcc(
; CHECK-NEXT: call cc42 void (...) @llvm.experimental.deoptimize.isVoid(i32 1) [ "deopt"() ]
; CHECK-NEXT: ret void

%val = call i32 @callee_with_coldcc()
ret void
}

0 comments on commit 5ff00d9

Please sign in to comment.