Skip to content

Commit

Permalink
[DeadArgumentElimination] Propagate operand bundles to promoted call …
Browse files Browse the repository at this point in the history
…sites

We neglected to transfer operand bundles when performing argument
promotion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268008 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Apr 29, 2016
1 parent 7ea09d5 commit 1766d67
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Transforms/IPO/DeadArgumentElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,17 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
PAL = AttributeSet::get(Fn.getContext(), AttributesVec);
}

SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);

Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, "", Call);
Args, OpBundles, "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setAttributes(PAL);
} else {
New = CallInst::Create(NF, Args, "", Call);
New = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setAttributes(PAL);
if (cast<CallInst>(Call)->isTailCall())
Expand Down Expand Up @@ -948,14 +951,17 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// Reconstruct the AttributesList based on the vector we constructed.
AttributeSet NewCallPAL = AttributeSet::get(F->getContext(), AttributesVec);

SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);

Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, "", Call->getParent());
Args, OpBundles, "", Call->getParent());
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setAttributes(NewCallPAL);
} else {
New = CallInst::Create(NF, Args, "", Call);
New = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setAttributes(NewCallPAL);
if (cast<CallInst>(Call)->isTailCall())
Expand Down
29 changes: 29 additions & 0 deletions test/Transforms/DeadArgElim/funclet.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: opt -S -deadargelim < %s | FileCheck %s
target triple = "x86_64-pc-windows-msvc"

define internal void @callee(i8*) {
entry:
call void @thunk()
ret void
}

define void @test1() personality i32 (...)* @__CxxFrameHandler3 {
entry:
invoke void @thunk()
to label %good1 unwind label %bad1

good1: ; preds = %entry-block
ret void

bad1: ; preds = %entry-block
%pad1 = cleanuppad within none []
call void @callee(i8* null) [ "funclet"(token %pad1) ]
cleanupret from %pad1 unwind to caller
}
; CHECK-LABEL: define void @test1(
; CHECK: %[[pad:.*]] = cleanuppad within none []
; CHECK-NEXT: call void @callee() [ "funclet"(token %[[pad]]) ]

declare void @thunk()

declare i32 @__CxxFrameHandler3(...)

0 comments on commit 1766d67

Please sign in to comment.