Skip to content

Commit 90d1786

Browse files
committed
[DSE] Fix invalid removal of store instruction
Fix handling of alloc-like instructions in isGuaranteedLoopInvariant(). It was not valid when the 'KillingDef' was outside of the loop, while the 'CurrentDef' was inside the loop. In that case, the 'KillingDef' only overwrites the definition from the last iteration of the loop, and not the ones of all iterations. Therefor it does not make the 'CurrentDef' to be dead, and must not remove it. Fixing issue : llvm#52774 Reviewed by: Florian Hahn Differential revision: https://reviews.llvm.org/D115965
1 parent 32e8b30 commit 90d1786

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,17 +1209,10 @@ struct DSEState {
12091209
/// loop. In particular, this guarantees that it only references a single
12101210
/// MemoryLocation during execution of the containing function.
12111211
bool isGuaranteedLoopInvariant(const Value *Ptr) {
1212-
auto IsGuaranteedLoopInvariantBase = [this](const Value *Ptr) {
1212+
auto IsGuaranteedLoopInvariantBase = [](const Value *Ptr) {
12131213
Ptr = Ptr->stripPointerCasts();
1214-
if (auto *I = dyn_cast<Instruction>(Ptr)) {
1215-
if (isa<AllocaInst>(Ptr))
1216-
return true;
1217-
1218-
if (isAllocLikeFn(I, &TLI))
1219-
return true;
1220-
1221-
return false;
1222-
}
1214+
if (auto *I = dyn_cast<Instruction>(Ptr))
1215+
return I->getParent()->isEntryBlock();
12231216
return true;
12241217
};
12251218

llvm/test/Transforms/DeadStoreElimination/store-after-loop.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S32"
77

88
; There is no dead store in this test. Make sure no store is deleted by DSE.
99
; Test case related to bug report PR52774.
10-
; NOTE: Showing actual (broken) DSE behavior.
1110

1211
define %struct.ilist* @test() {
1312
; CHECK-LABEL: @test(
@@ -19,6 +18,8 @@ define %struct.ilist* @test() {
1918
; CHECK-NEXT: [[LIST_NEW_ILIST_PTR]] = bitcast i8* [[LIST_NEW_I8_PTR]] to %struct.ilist*
2019
; CHECK-NEXT: [[GEP_NEW_VALUE:%.*]] = getelementptr inbounds [[STRUCT_ILIST:%.*]], %struct.ilist* [[LIST_NEW_ILIST_PTR]], i32 0, i32 0
2120
; CHECK-NEXT: store i32 42, i32* [[GEP_NEW_VALUE]], align 8
21+
; CHECK-NEXT: [[GEP_NEW_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_NEW_ILIST_PTR]], i32 0, i32 1
22+
; CHECK-NEXT: store %struct.ilist* [[LIST_NEXT]], %struct.ilist** [[GEP_NEW_NEXT]], align 4
2223
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
2324
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], 10
2425
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]

0 commit comments

Comments
 (0)