[llvm] 6dc301f - [Delinearization] Limit the scope of collecting strides (#206688)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 04:05:38 PDT 2026


Author: Ryotaro Kasuga
Date: 2026-06-30T11:05:33Z
New Revision: 6dc301f1112dc63033c5e40d1eb6fa91f5409ba4

URL: https://github.com/llvm/llvm-project/commit/6dc301f1112dc63033c5e40d1eb6fa91f5409ba4
DIFF: https://github.com/llvm/llvm-project/commit/6dc301f1112dc63033c5e40d1eb6fa91f5409ba4.diff

LOG: [Delinearization] Limit the scope of collecting strides (#206688)

Similar to #204145, this patch limits the scope of stride collection
performed by `SCEVCollectStrides`. Before this change, it traversed all
kinds of SCEV expressions. For example, given the expression `{(sext
{0,+,%x}),+,%y}`, it would collect `%x` and `%y` as strides, even though
their integer types (bit widths) differ.

Collecting strides whose types differ from that of the original
expression is not particularly meaningful, because such strides probably
cannot contribute to a successful delinearization of the entire
expression. Furthermore, #204146 revealed that they can trigger
undesirable calls to `SCEVDivision::divide`. Currently, when such
strides are collected, `SCEVDivision::divide` may be invoked on
expressions with different integer types, resulting in division attempts
between incompatible types.

This patch does not add any tests because I could not find a case where
it changes the result. I also did not mark it as NFCI, since it changes
some debug output. However, I believe it does not affect the outcome of
the delinearization itself.

Added: 
    

Modified: 
    llvm/lib/Analysis/Delinearization.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Delinearization.cpp b/llvm/lib/Analysis/Delinearization.cpp
index 5b525b43e4931..cbde9f473e07b 100644
--- a/llvm/lib/Analysis/Delinearization.cpp
+++ b/llvm/lib/Analysis/Delinearization.cpp
@@ -56,8 +56,11 @@ struct SCEVCollectStrides {
       : SE(SE), Strides(S) {}
 
   bool follow(const SCEV *S) {
-    if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S))
-      Strides.push_back(AR->getStepRecurrence(SE));
+    const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S);
+    if (!AR || !AR->isAffine())
+      return false;
+
+    Strides.push_back(AR->getStepRecurrence(SE));
     return true;
   }
 


        


More information about the llvm-commits mailing list