[llvm] 97484f4 - [NFCI][SCEV] `SCEVTraversal`: if search terminated, don't push further ops of nary

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 11 10:58:43 PST 2022


Author: Roman Lebedev
Date: 2022-02-11T21:58:19+03:00
New Revision: 97484f46eb7e8b90c42103925199caf93cc4aafd

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

LOG: [NFCI][SCEV] `SCEVTraversal`: if search terminated, don't push further ops of nary

Even if the search is marked as terminated after only looking at
the first operand, we'd still look at the remaining operands
before actually ending the search.

This seems pointless and wasteful, let's not do that.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
index ee305c895e439..4d15ac5735468 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
@@ -698,8 +698,11 @@ template <typename SV> class SCEVTraversal {
       case scUMinExpr:
       case scSequentialUMinExpr:
       case scAddRecExpr:
-        for (const auto *Op : cast<SCEVNAryExpr>(S)->operands())
+        for (const auto *Op : cast<SCEVNAryExpr>(S)->operands()) {
           push(Op);
+          if (Visitor.isDone())
+            break;
+        }
         continue;
       case scUDivExpr: {
         const SCEVUDivExpr *UDiv = cast<SCEVUDivExpr>(S);

diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index b50e6f5697aa7..e3a01440baade 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5909,9 +5909,6 @@ bool SCEVMinMaxExprContains(const SCEV *Root, const SCEV *OperandToFind,
                   RootKind)) {}
 
     bool follow(const SCEV *S) {
-      if (isDone())
-        return false;
-
       Found = S == OperandToFind;
 
       return !isDone() && canRecurseInto(S->getSCEVType());


        


More information about the llvm-commits mailing list