Skip to content

Commit 33f7aa6

Browse files
mariannemststellar
authored andcommitted
[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 : #52774 Reviewed by: Florian Hahn Differential revision: https://reviews.llvm.org/D115965 (cherry picked from commit 90d1786)
1 parent 426297c commit 33f7aa6

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
@@ -1303,17 +1303,10 @@ struct DSEState {
13031303
/// loop. In particular, this guarantees that it only references a single
13041304
/// MemoryLocation during execution of the containing function.
13051305
bool isGuaranteedLoopInvariant(const Value *Ptr) {
1306-
auto IsGuaranteedLoopInvariantBase = [this](const Value *Ptr) {
1306+
auto IsGuaranteedLoopInvariantBase = [](const Value *Ptr) {
13071307
Ptr = Ptr->stripPointerCasts();
1308-
if (auto *I = dyn_cast<Instruction>(Ptr)) {
1309-
if (isa<AllocaInst>(Ptr))
1310-
return true;
1311-
1312-
if (isAllocLikeFn(I, &TLI))
1313-
return true;
1314-
1315-
return false;
1316-
}
1308+
if (auto *I = dyn_cast<Instruction>(Ptr))
1309+
return I->getParent()->isEntryBlock();
13171310
return true;
13181311
};
13191312

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)