[PATCH] D132657: [DSE] Eliminate noop store even through has clobbering between LoadI and StoreI

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 19:22:59 PDT 2022


StephenFan updated this revision to Diff 456840.
StephenFan edited the summary of this revision.
StephenFan added a comment.

Reduce comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132657/new/

https://reviews.llvm.org/D132657

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


Index: llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
+++ llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
@@ -612,12 +612,10 @@
 ; CHECK-LABEL: @pr49927(
 ; CHECK-NEXT:    [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
 ; CHECK-NEXT:    store i32 [[V]], i32* [[Q:%.*]], align 4
-; CHECK-NEXT:    store i32 [[V]], i32* [[P]], align 4
 ; CHECK-NEXT:    ret void
 ;
   %v = load i32, i32* %p, align 4
   store i32 %v, i32* %q, align 4
-  ; FIXME: this store can be eliminated
   store i32 %v, i32* %p, align 4
   ret void
 }
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1861,8 +1861,16 @@
           // 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)
+          if (LoadAccess != Current) {
+            auto *CurrentStoreI =
+                dyn_cast<StoreInst>(cast<MemoryDef>(Current)->getMemoryInst());
+            if (CurrentStoreI && CurrentStoreI->getOperand(0) == LoadI) {
+              // This is a potentially clobbering here, but it writes the same value,
+              // so we can safely ignore it.
+              continue;
+            }
             return false;
+          }
         }
         return true;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132657.456840.patch
Type: text/x-patch
Size: 1689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220831/2da7dd37/attachment.bin>


More information about the llvm-commits mailing list