[llvm] df4756e - [DSE,MemorySSA] Check for underlying objects first.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 10:52:42 PDT 2020


Author: Florian Hahn
Date: 2020-08-17T18:52:18+01:00
New Revision: df4756ec6cd6e501bba645245c168f606adb4e67

URL: https://github.com/llvm/llvm-project/commit/df4756ec6cd6e501bba645245c168f606adb4e67
DIFF: https://github.com/llvm/llvm-project/commit/df4756ec6cd6e501bba645245c168f606adb4e67.diff

LOG: [DSE,MemorySSA] Check for underlying objects first.

isWriteAtEndOfFunction needs to check all memory uses of Def, which is
much more expensive than getting the underlying objects in practice.
Switch the call order, as recommended by the TODO, which was added as
per an earlier review.

This shaves off a bit of compile-time.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index faa936e63c91..a757db100984 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -2045,29 +2045,28 @@ struct DSEState {
           !isRemovable(Def->getMemoryInst()))
         continue;
 
-      // TODO: Consider doing the underlying object check first, if it is
-      // beneficial compile-time wise.
-      if (isWriteAtEndOfFunction(Def)) {
-        Instruction *DefI = Def->getMemoryInst();
-        // See through pointer-to-pointer bitcasts
-        SmallVector<const Value *, 4> Pointers;
-        getUnderlyingObjects(getLocForWriteEx(DefI)->Ptr, Pointers);
+      Instruction *DefI = Def->getMemoryInst();
+      SmallVector<const Value *, 4> Pointers;
+      auto DefLoc = getLocForWriteEx(DefI);
+      if (!DefLoc)
+        continue;
+      getUnderlyingObjects(DefLoc->Ptr, Pointers);
 
-        LLVM_DEBUG(dbgs() << "   ... MemoryDef is not accessed until the end "
-                             "of the function\n");
-        bool CanKill = true;
-        for (const Value *Pointer : Pointers) {
-          if (!InvisibleToCallerAfterRet.count(Pointer)) {
-            CanKill = false;
-            break;
-          }
+      bool CanKill = true;
+      for (const Value *Pointer : Pointers) {
+        if (!InvisibleToCallerAfterRet.count(Pointer)) {
+          CanKill = false;
+          break;
         }
+      }
 
-        if (CanKill) {
-          deleteDeadInstruction(DefI);
-          ++NumFastStores;
-          MadeChange = true;
-        }
+      if (CanKill && isWriteAtEndOfFunction(Def)) {
+        // See through pointer-to-pointer bitcasts
+        LLVM_DEBUG(dbgs() << "   ... MemoryDef is not accessed until the end "
+                             "of the function\n");
+        deleteDeadInstruction(DefI);
+        ++NumFastStores;
+        MadeChange = true;
       }
     }
     return MadeChange;


        


More information about the llvm-commits mailing list