[llvm] 477551f - [SCEVExpander] Minor cleanup in value reuse (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 01:32:24 PDT 2021


Author: Nikita Popov
Date: 2021-10-25T10:32:17+02:00
New Revision: 477551fd0957326d1988dd1a74b39642241bd86c

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

LOG: [SCEVExpander] Minor cleanup in value reuse (NFC)

Use dyn_cast_or_null and convert one of the checks into an
assertion. SCEV is a per-function analysis.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index a25f9d6ae923f..9b8dbe35a02c1 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1844,16 +1844,18 @@ SCEVExpander::FindValueInExprValueMap(const SCEV *S,
   if (CanonicalMode || !SE.containsAddRecurrence(S)) {
     // If S is scConstant, it may be worse to reuse an existing Value.
     if (S->getSCEVType() != scConstant && Set) {
-      // Choose a Value from the set which dominates the insertPt.
-      // insertPt should be inside the Value's parent loop so as not to break
+      // Choose a Value from the set which dominates the InsertPt.
+      // InsertPt should be inside the Value's parent loop so as not to break
       // the LCSSA form.
       for (auto const &VOPair : *Set) {
         Value *V = VOPair.first;
         ConstantInt *Offset = VOPair.second;
-        Instruction *EntInst = nullptr;
-        if (V && isa<Instruction>(V) && (EntInst = cast<Instruction>(V)) &&
-            S->getType() == V->getType() &&
-            EntInst->getFunction() == InsertPt->getFunction() &&
+        Instruction *EntInst = dyn_cast_or_null<Instruction>(V);
+        if (!EntInst)
+          continue;
+
+        assert(EntInst->getFunction() == InsertPt->getFunction());
+        if (S->getType() == V->getType() &&
             SE.DT.dominates(EntInst, InsertPt) &&
             (SE.LI.getLoopFor(EntInst->getParent()) == nullptr ||
              SE.LI.getLoopFor(EntInst->getParent())->contains(InsertPt)))


        


More information about the llvm-commits mailing list