[llvm] 2baabd2 - [LoopPredication][NFCI] Perform 'visited' check before pushing to worklist

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 04:04:31 PDT 2022


Author: Max Kazantsev
Date: 2022-11-02T18:04:23+07:00
New Revision: 2baabd2c19ee972926a96fa01838ccb7901cac32

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

LOG: [LoopPredication][NFCI] Perform 'visited' check before pushing to worklist

This prevents duplicates to be pushed into the stack and hypothetically
should reduce memory footprint on ugly cornercases with multiple repeating
duplicates in 'and' tree.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index fbd4a39c7949e..1e4060abeb885 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -763,17 +763,17 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks,
   // resulting list of subconditions in Checks vector.
   SmallVector<Value *, 4> Worklist(1, Condition);
   SmallPtrSet<Value *, 4> Visited;
+  Visited.insert(Condition);
   Value *WideableCond = nullptr;
   do {
     Value *Condition = Worklist.pop_back_val();
-    if (!Visited.insert(Condition).second)
-      continue;
-
     Value *LHS, *RHS;
     using namespace llvm::PatternMatch;
     if (match(Condition, m_And(m_Value(LHS), m_Value(RHS)))) {
-      Worklist.push_back(LHS);
-      Worklist.push_back(RHS);
+      if (Visited.insert(LHS).second)
+        Worklist.push_back(LHS);
+      if (Visited.insert(RHS).second)
+        Worklist.push_back(RHS);
       continue;
     }
 


        


More information about the llvm-commits mailing list