DeadArgElim: arguments affect all returned sub-values by default.

Unless we meet an insertvalue on a path from some value to a return, that value
will be live if *any* of the return's components are live, so all of those
components must be added to the MaybeLiveUses.

Previously we were deleting arguments if sub-value 0 turned out to be dead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228731 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tim Northover 2015-02-10 19:49:18 +00:00
parent 03e1afd8fe
commit b613f8842e
2 changed files with 33 additions and 4 deletions

View File

@ -146,7 +146,7 @@ namespace {
private:
Liveness MarkIfNotLive(RetOrArg Use, UseVector &MaybeLiveUses);
Liveness SurveyUse(const Use *U, UseVector &MaybeLiveUses,
unsigned RetValNum = 0);
unsigned RetValNum = -1U);
Liveness SurveyUses(const Value *V, UseVector &MaybeLiveUses);
void SurveyFunction(const Function &F);
@ -443,9 +443,21 @@ DAE::Liveness DAE::SurveyUse(const Use *U,
// function's return value is live. We use RetValNum here, for the case
// that U is really a use of an insertvalue instruction that uses the
// original Use.
RetOrArg Use = CreateRet(RI->getParent()->getParent(), RetValNum);
// We might be live, depending on the liveness of Use.
return MarkIfNotLive(Use, MaybeLiveUses);
const Function *F = RI->getParent()->getParent();
if (RetValNum != -1U) {
RetOrArg Use = CreateRet(F, RetValNum);
// We might be live, depending on the liveness of Use.
return MarkIfNotLive(Use, MaybeLiveUses);
} else {
DAE::Liveness Result;
for (unsigned i = 0; i < NumRetVals(F); ++i) {
RetOrArg Use = CreateRet(F, i);
// We might be live, depending on the liveness of Use. All Results
// should be the same since they depend only on F.
Result = MarkIfNotLive(Use, MaybeLiveUses);
}
return Result;
}
}
if (const InsertValueInst *IV = dyn_cast<InsertValueInst>(V)) {
if (U->getOperandNo() != InsertValueInst::getAggregateOperandIndex()

View File

@ -113,3 +113,20 @@ define void @test_can_shrink_arrays() {
ret void
}
; Case 5: %in gets passed directly to the return. It should mark be marked as
; used if *any* of the return values are, not just if value 0 is.
; CHECK-LABEL: define internal i32 @ret_applies_to_all({ i32, i32 } %in)
; CHECK: [[RET:%.*]] = extractvalue { i32, i32 } %in, 1
; CHECK: ret i32 [[RET]]
define internal {i32, i32} @ret_applies_to_all({i32, i32} %in) {
ret {i32, i32} %in
}
define i32 @test_ret_applies_to_all() {
%val = call {i32, i32} @ret_applies_to_all({i32, i32} {i32 42, i32 43})
%ret = extractvalue {i32, i32} %val, 1
ret i32 %ret
}