[llvm] [SCEV] Try to re-use pointer LCSSA phis when expanding SCEVs. (PR #147824)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 02:44:18 PDT 2025


================
@@ -1224,18 +1226,37 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
 }
 
 Value *SCEVExpander::tryToReuseLCSSAPhi(const SCEVAddRecExpr *S) {
+  Type *STy = S->getType();
   const Loop *L = S->getLoop();
   BasicBlock *EB = L->getExitBlock();
   if (!EB || !EB->getSinglePredecessor() ||
       !SE.DT.dominates(EB, Builder.GetInsertBlock()))
     return nullptr;
 
   for (auto &PN : EB->phis()) {
-    if (!SE.isSCEVable(PN.getType()) || PN.getType() != S->getType())
+    if (!SE.isSCEVable(PN.getType()))
       continue;
-    auto *ExitV = SE.getSCEV(&PN);
-    if (S == ExitV)
-      return &PN;
+    auto *ExitSCEV = SE.getSCEV(&PN);
----------------
nikic wrote:

Can we early exit if `ExitSCEV` is not an addrec?

https://github.com/llvm/llvm-project/pull/147824


More information about the llvm-commits mailing list