Skip to content

Commit be460d1

Browse files
fhahnmemfrob
authored andcommitted
[DSE] Remove noop stores after killing stores for a MemoryDef.
Currently we fail to eliminate some noop stores if there is a kill-able store between the starting def and the load. This is because we eliminate noop stores first. In practice it seems like eliminating noop stores after the main elimination for a def covers slightly more cases. This patch improves the number of stores slightly in 2 cases for X86 -O3 -flto Same hash: 235 (filtered out) Remaining: 2 Metric: dse.NumRedundantStores Program base patch diff test-suite...ce/Benchmarks/PAQ8p/paq8p.test 2.00 3.00 50.0% test-suite...006/453.povray/453.povray.test 18.00 21.00 16.7% There might be other phase ordering issues, but it appears that they do not show up in the test-suite/SPEC2000/SPEC2006. We can always tune the ordering later. Partly fixes PR47887. Reviewed By: asbirlea, zoecarver Differential Revision: https://reviews.llvm.org/D89650
1 parent e510533 commit be460d1

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,15 +2504,6 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
25042504
assert(SILoc.Ptr && "SILoc should not be null");
25052505
const Value *SILocUnd = getUnderlyingObject(SILoc.Ptr);
25062506

2507-
// Check if the store is a no-op.
2508-
if (isRemovable(SI) && State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
2509-
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *SI << '\n');
2510-
State.deleteDeadInstruction(SI);
2511-
NumRedundantStores++;
2512-
MadeChange = true;
2513-
continue;
2514-
}
2515-
25162507
MemoryAccess *Current = KillingDef;
25172508
LLVM_DEBUG(dbgs() << "Trying to eliminate MemoryDefs killed by "
25182509
<< *KillingDef << " (" << *SI << ")\n");
@@ -2522,10 +2513,11 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
25222513
unsigned PartialLimit = MemorySSAPartialStoreLimit;
25232514
// Worklist of MemoryAccesses that may be killed by KillingDef.
25242515
SetVector<MemoryAccess *> ToCheck;
2525-
ToCheck.insert(KillingDef->getDefiningAccess());
25262516

2527-
if (!SILocUnd)
2528-
continue;
2517+
if (SILocUnd)
2518+
ToCheck.insert(KillingDef->getDefiningAccess());
2519+
2520+
bool Shortend = false;
25292521
bool IsMemTerm = State.isMemTerminatorInst(SI);
25302522
DSEState::CheckCache Cache;
25312523
// Check if MemoryAccesses in the worklist are killed by KillingDef.
@@ -2612,6 +2604,7 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
26122604
++NumModifiedStores;
26132605
MadeChange = true;
26142606

2607+
Shortend = true;
26152608
// Remove later store and remove any outstanding overlap intervals
26162609
// for the updated store.
26172610
State.deleteDeadInstruction(Later);
@@ -2632,6 +2625,16 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
26322625
}
26332626
}
26342627
}
2628+
2629+
// Check if the store is a no-op.
2630+
if (!Shortend && isRemovable(SI) &&
2631+
State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
2632+
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *SI << '\n');
2633+
State.deleteDeadInstruction(SI);
2634+
NumRedundantStores++;
2635+
MadeChange = true;
2636+
continue;
2637+
}
26352638
}
26362639

26372640
if (EnablePartialOverwriteTracking)

llvm/test/Transforms/DeadStoreElimination/MSSA/calloc-store.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,9 @@ define i8* @test10() {
114114
ret i8* %p
115115
}
116116

117-
; TODO: we could also eliminate the last store i8 0, i8* %p.3.2, but currently
118-
; don't because those are eliminated before eliminating killed stores.
119117
define i8* @test11() {
120118
; CHECK-LABEL: @test11(
121119
; CHECK-NEXT: [[P:%.*]] = tail call noalias i8* @calloc(i64 1, i64 4)
122-
; CHECK-NEXT: [[P_3_2:%.*]] = getelementptr i8, i8* [[P]], i32 3
123-
; CHECK-NEXT: store i8 0, i8* [[P_3_2]], align 1
124120
; CHECK-NEXT: ret i8* [[P]]
125121
;
126122

llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ define void @test44(i32* %Q) {
208208

209209
define void @test45(i32* %Q) {
210210
; CHECK-LABEL: @test45(
211-
; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
212-
; CHECK-NEXT: store i32 [[A]], i32* [[Q]], align 4
213211
; CHECK-NEXT: ret void
214212
;
215213
%a = load i32, i32* %Q
@@ -252,16 +250,13 @@ bb2:
252250
ret i32 0
253251
}
254252

255-
; TODO: Remove both redundant stores if loaded value is in another block inside a loop.
256253
define i32 @test47(i1 %c, i32* %p, i32 %i) {
257254
; CHECK-LABEL: @test47(
258255
; CHECK-NEXT: entry:
259-
; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
260256
; CHECK-NEXT: br label [[BB1:%.*]]
261257
; CHECK: bb1:
262258
; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
263259
; CHECK: bb2:
264-
; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
265260
; CHECK-NEXT: br i1 [[C]], label [[BB3:%.*]], label [[BB1]]
266261
; CHECK: bb3:
267262
; CHECK-NEXT: ret i32 0
@@ -299,9 +294,7 @@ entry:
299294
define void @test_noalias_store_between_load_and_store_elimin_order(i32* noalias %x, i32* noalias %y) {
300295
; CHECK-LABEL: @test_noalias_store_between_load_and_store_elimin_order(
301296
; CHECK-NEXT: entry:
302-
; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[X:%.*]], align 4
303297
; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
304-
; CHECK-NEXT: store i32 [[LV]], i32* [[X]], align 4
305298
; CHECK-NEXT: ret void
306299
;
307300
entry:

0 commit comments

Comments
 (0)