[DSE,MSSA] Check if Def is removable only wen we try to remove it.
authorFlorian Hahn <flo@fhahn.com>
Thu, 25 Jun 2020 12:31:11 +0000 (13:31 +0100)
committerFlorian Hahn <flo@fhahn.com>
Thu, 25 Jun 2020 13:01:10 +0000 (14:01 +0100)
Non-removable MemoryDefs can still eliminate other defs. Update the
isRemovable checks to only candidates for removal.

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/MSSA/simple.ll

index 336b966..f55278d 100644 (file)
@@ -1535,7 +1535,7 @@ struct DSEState {
 
         auto *MD = dyn_cast_or_null<MemoryDef>(MA);
         if (MD && State.MemDefs.size() < MemorySSADefsPerBlockLimit &&
-            State.getLocForWriteEx(&I) && isRemovable(&I))
+            State.getLocForWriteEx(&I))
           State.MemDefs.push_back(MD);
 
         // Track whether alloca and alloca-like objects are visible in the
@@ -1980,7 +1980,8 @@ struct DSEState {
         << "Trying to eliminate MemoryDefs at the end of the function\n");
     for (int I = MemDefs.size() - 1; I >= 0; I--) {
       MemoryDef *Def = MemDefs[I];
-      if (SkipStores.find(Def) != SkipStores.end())
+      if (SkipStores.find(Def) != SkipStores.end() ||
+          !isRemovable(Def->getMemoryInst()))
         continue;
 
       // TODO: Consider doing the underlying object check first, if it is
@@ -2069,7 +2070,7 @@ bool eliminateDeadStoresMemorySSA(Function &F, AliasAnalysis &AA,
     const Value *SILocUnd = GetUnderlyingObject(SILoc.Ptr, DL);
 
     // Check if the store is a no-op.
-    if (State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
+    if (isRemovable(SI) && State.storeIsNoop(KillingDef, SILoc, SILocUnd)) {
       LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n  DEAD: " << *SI << '\n');
       State.deleteDeadInstruction(SI);
       NumNoopStores++;
index 603b971..64b6611 100644 (file)
@@ -700,7 +700,6 @@ define void @test44_volatile(i32* %P) {
 
 define void @test45_volatile(i32* %P) {
 ; CHECK-LABEL: @test45_volatile(
-; CHECK-NEXT:    store i32 1, i32* [[P:%.*]], align 4
 ; CHECK-NEXT:    store volatile i32 2, i32* [[P]], align 4
 ; CHECK-NEXT:    store volatile i32 3, i32* [[P]], align 4
 ; CHECK-NEXT:    ret void
@@ -714,7 +713,6 @@ define void @test45_volatile(i32* %P) {
 define void @test46_volatile(i32* %P) {
 ; CHECK-LABEL: @test46_volatile(
 ; CHECK-NEXT:    store volatile i32 2, i32* [[P:%.*]], align 4
-; CHECK-NEXT:    store i32 1, i32* [[P]], align 4
 ; CHECK-NEXT:    store volatile i32 3, i32* [[P]], align 4
 ; CHECK-NEXT:    ret void
 ;