[llvm] [Delinearization] Limit the scope of collecting strides (PR #206688)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 02:54:46 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Ryotaro Kasuga (kasuga-fj)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/206688.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/Delinearization.cpp (+5-2) 


``````````diff
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;
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list