[llvm] 00ff746 - [LoopSimplify] Reduce amount of redundant SCEV invalidation (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 01:03:50 PDT 2023


Author: Nikita Popov
Date: 2023-05-05T10:03:42+02:00
New Revision: 00ff746f6e81b6be5886160327805020c39e4ce3

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

LOG: [LoopSimplify] Reduce amount of redundant SCEV invalidation (NFCI)

We are simplifying the loop and all its children. Each time, we
invalidate the top-most loop. The top-most loop is going to be
the same every time. The cost of SCEV invalidation is largely
independent from how data about the loop is actually cached, so
we should avoid redundant invalidations.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index 692a8729ffc31..1b36a29bdf772 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -693,12 +693,6 @@ static bool simplifyOneLoop(Loop *L, SmallVectorImpl<Loop *> &Worklist,
     }
   }
 
-  // Changing exit conditions for blocks may affect exit counts of this loop and
-  // any of its paretns, so we must invalidate the entire subtree if we've made
-  // any changes.
-  if (Changed && SE)
-    SE->forgetTopmostLoop(L);
-
   if (MSSAU && VerifyMemorySSA)
     MSSAU->getMemorySSA()->verifyMemorySSA();
 
@@ -737,6 +731,13 @@ bool llvm::simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI,
     Changed |= simplifyOneLoop(Worklist.pop_back_val(), Worklist, DT, LI, SE,
                                AC, MSSAU, PreserveLCSSA);
 
+  // Changing exit conditions for blocks may affect exit counts of this loop and
+  // any of its parents, so we must invalidate the entire subtree if we've made
+  // any changes. Do this here rather than in simplifyOneLoop() as the top-most
+  // loop is going to be the same for all child loops.
+  if (Changed && SE)
+    SE->forgetTopmostLoop(L);
+
   return Changed;
 }
 


        


More information about the llvm-commits mailing list