Skip to content

Commit ae57333

Browse files
committed
Revert "[DSE] Eliminate noop store even through has clobbering between LoadI and StoreI"
This reverts commit cd8f3e7. Causes miscompiles, see D132657
1 parent 5922b92 commit ae57333

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,23 +1874,8 @@ struct DSEState {
18741874
// We are searching for the definition of the store's destination.
18751875
// So, if that is the same definition as the load, then this is a
18761876
// noop. Otherwise, fail.
1877-
if (LoadAccess != Current) {
1878-
// This is a potentially clobbering store, but it writes the same
1879-
// value, so we can safely ignore it if alignment is as expected.
1880-
if (auto *CurrentDef = cast<MemoryDef>(Current))
1881-
if (auto *CurrentStoreI =
1882-
dyn_cast_or_null<StoreInst>(CurrentDef->getMemoryInst()))
1883-
// Check alignment to ensure load or store does not access at an
1884-
// offset.
1885-
if (CurrentStoreI->getValueOperand() == LoadI) {
1886-
TypeSize StoreSize = DL.getTypeStoreSize(LoadI->getType());
1887-
if (!StoreSize.isScalable() &&
1888-
std::min(CurrentStoreI->getAlign(), LoadI->getAlign()) >=
1889-
StoreSize)
1890-
continue;
1891-
}
1877+
if (LoadAccess != Current)
18921878
return false;
1893-
}
18941879
}
18951880
return true;
18961881
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ define void @store_same_i32_to_mayalias_loc(ptr %q, ptr %p) {
672672
; CHECK-LABEL: @store_same_i32_to_mayalias_loc(
673673
; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
674674
; CHECK-NEXT: store i32 [[V]], ptr [[Q:%.*]], align 4
675+
; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
675676
; CHECK-NEXT: ret void
676677
;
677678
%v = load i32, ptr %p, align 4
@@ -697,6 +698,7 @@ define void @store_same_i12_to_mayalias_loc(ptr %q, ptr %p) {
697698
; CHECK-LABEL: @store_same_i12_to_mayalias_loc(
698699
; CHECK-NEXT: [[V:%.*]] = load i12, ptr [[P:%.*]], align 2
699700
; CHECK-NEXT: store i12 [[V]], ptr [[Q:%.*]], align 2
701+
; CHECK-NEXT: store i12 [[V]], ptr [[P]], align 2
700702
; CHECK-NEXT: ret void
701703
;
702704
%v = load i12, ptr %p, align 2
@@ -722,6 +724,7 @@ define void @store_same_ptr_to_mayalias_loc(ptr %q, ptr %p) {
722724
; CHECK-LABEL: @store_same_ptr_to_mayalias_loc(
723725
; CHECK-NEXT: [[V:%.*]] = load ptr, ptr [[P:%.*]], align 8
724726
; CHECK-NEXT: store ptr [[V]], ptr [[Q:%.*]], align 8
727+
; CHECK-NEXT: store ptr [[V]], ptr [[P]], align 8
725728
; CHECK-NEXT: ret void
726729
;
727730
%v = load ptr, ptr %p, align 8

llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ define void @pr49927(ptr %q, ptr %p) {
594594
; CHECK-LABEL: @pr49927(
595595
; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
596596
; CHECK-NEXT: store i32 [[V]], ptr [[Q:%.*]], align 4
597+
; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
597598
; CHECK-NEXT: ret void
598599
;
599600
%v = load i32, ptr %p, align 4

0 commit comments

Comments
 (0)