[llvm] ba2b34b - [DSE] Simplify isGuaranteedLoopInvariant() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 24 00:41:15 PST 2021


Author: Nikita Popov
Date: 2021-12-24T09:39:44+01:00
New Revision: ba2b34b1c7d47a5cb1f5c73400356b975cc16298

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

LOG: [DSE] Simplify isGuaranteedLoopInvariant() (NFC)

We have Value->stripInBoundsConstantOffsets() which does what we
want here, but the inbounds requirement isn't actually necessary.
We should probably add Value->stripConstantOffsets() as well.

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 683ac537bbe42..883d3a57117bd 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1195,23 +1195,14 @@ struct DSEState {
   /// loop. In particular, this guarantees that it only references a single
   /// MemoryLocation during execution of the containing function.
   bool isGuaranteedLoopInvariant(const Value *Ptr) {
-    auto IsGuaranteedLoopInvariantBase = [](const Value *Ptr) {
-      Ptr = Ptr->stripPointerCasts();
-      if (auto *I = dyn_cast<Instruction>(Ptr))
-        return I->getParent()->isEntryBlock();
-      return true;
-    };
-
     Ptr = Ptr->stripPointerCasts();
-    if (auto *I = dyn_cast<Instruction>(Ptr)) {
-      if (I->getParent()->isEntryBlock())
-        return true;
-    }
-    if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
-      return IsGuaranteedLoopInvariantBase(GEP->getPointerOperand()) &&
-             GEP->hasAllConstantIndices();
-    }
-    return IsGuaranteedLoopInvariantBase(Ptr);
+    if (auto *GEP = dyn_cast<GEPOperator>(Ptr))
+      if (GEP->hasAllConstantIndices())
+        Ptr = GEP->getPointerOperand()->stripPointerCasts();
+
+    if (auto *I = dyn_cast<Instruction>(Ptr))
+      return I->getParent()->isEntryBlock();
+    return true;
   }
 
   // Find a MemoryDef writing to \p KillingLoc and dominating \p StartAccess,


        


More information about the llvm-commits mailing list