Revert "[DSE] Eliminate noop store even through has clobbering between LoadI and...
authorArthur Eubanks <aeubanks@google.com>
Thu, 6 Oct 2022 17:29:46 +0000 (10:29 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 6 Oct 2022 17:36:02 +0000 (10:36 -0700)
This reverts commit cd8f3e75813995c1d2da35370ffcf5af3aff9c2f.

Causes miscompiles, see D132657

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/noop-stores.ll
llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll

index 0036020..93abda0 100644 (file)
@@ -1874,23 +1874,8 @@ struct DSEState {
           // We are searching for the definition of the store's destination.
           // So, if that is the same definition as the load, then this is a
           // noop. Otherwise, fail.
-          if (LoadAccess != Current) {
-            // This is a potentially clobbering store, but it writes the same
-            // value, so we can safely ignore it if alignment is as expected.
-            if (auto *CurrentDef = cast<MemoryDef>(Current))
-              if (auto *CurrentStoreI =
-                      dyn_cast_or_null<StoreInst>(CurrentDef->getMemoryInst()))
-                // Check alignment to ensure load or store does not access at an
-                // offset.
-                if (CurrentStoreI->getValueOperand() == LoadI) {
-                  TypeSize StoreSize = DL.getTypeStoreSize(LoadI->getType());
-                  if (!StoreSize.isScalable() &&
-                      std::min(CurrentStoreI->getAlign(), LoadI->getAlign()) >=
-                          StoreSize)
-                    continue;
-                }
+          if (LoadAccess != Current)
             return false;
-          }
         }
         return true;
       }
index 030815a..2ee8df3 100644 (file)
@@ -672,6 +672,7 @@ define void @store_same_i32_to_mayalias_loc(ptr %q, ptr %p) {
 ; CHECK-LABEL: @store_same_i32_to_mayalias_loc(
 ; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
 ; CHECK-NEXT:    store i32 [[V]], ptr [[Q:%.*]], align 4
+; CHECK-NEXT:    store i32 [[V]], ptr [[P]], align 4
 ; CHECK-NEXT:    ret void
 ;
   %v = load i32, ptr %p, align 4
@@ -697,6 +698,7 @@ define void @store_same_i12_to_mayalias_loc(ptr %q, ptr %p) {
 ; CHECK-LABEL: @store_same_i12_to_mayalias_loc(
 ; CHECK-NEXT:    [[V:%.*]] = load i12, ptr [[P:%.*]], align 2
 ; CHECK-NEXT:    store i12 [[V]], ptr [[Q:%.*]], align 2
+; CHECK-NEXT:    store i12 [[V]], ptr [[P]], align 2
 ; CHECK-NEXT:    ret void
 ;
   %v = load i12, ptr %p, align 2
@@ -722,6 +724,7 @@ define void @store_same_ptr_to_mayalias_loc(ptr %q, ptr %p) {
 ; CHECK-LABEL: @store_same_ptr_to_mayalias_loc(
 ; CHECK-NEXT:    [[V:%.*]] = load ptr, ptr [[P:%.*]], align 8
 ; CHECK-NEXT:    store ptr [[V]], ptr [[Q:%.*]], align 8
+; CHECK-NEXT:    store ptr [[V]], ptr [[P]], align 8
 ; CHECK-NEXT:    ret void
 ;
   %v = load ptr, ptr %p, align 8
index be750d9..f5e1af9 100644 (file)
@@ -594,6 +594,7 @@ define void @pr49927(ptr %q, ptr %p) {
 ; CHECK-LABEL: @pr49927(
 ; CHECK-NEXT:    [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
 ; CHECK-NEXT:    store i32 [[V]], ptr [[Q:%.*]], align 4
+; CHECK-NEXT:    store i32 [[V]], ptr [[P]], align 4
 ; CHECK-NEXT:    ret void
 ;
   %v = load i32, ptr %p, align 4