[llvm] [LAA] Add stencil group merging to reduce runtime pointer checks (PR #187252)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed May 13 05:39:56 PDT 2026
================
@@ -737,6 +752,367 @@ void RuntimePointerChecking::groupChecks(
}
}
+/// Result of decomposing a SCEV expression into stencil offset form:
+/// Offset = Constant + sum(Coefficients[stride] * stride)
+/// where each stride is a loop-invariant SCEV expression.
+struct StencilDecomposition {
+ int64_t Constant = 0;
+ /// Map from loop-invariant stride SCEV to its integer coefficient.
+ SmallMapVector<const SCEV *, int64_t, 4> Coefficients;
+};
+
+/// Try to decompose \p Expr into a stencil offset function of loop-invariant
+/// strides: C + a1*s1 + a2*s2 + ...
+/// Relies on SCEV's canonical form: AddExpr operands are flattened (N-ary),
+/// MulExpr has the constant operand first when present.
+/// Returns std::nullopt if the expression contains non-stencil terms or any
+/// SCEV constant doesn't fit in int64_t (we commit to the signed
+/// interpretation; values that need more than 64 significant bits are
+/// out of scope).
+static std::optional<StencilDecomposition>
+decomposeStencilOffset(const SCEV *Expr, ScalarEvolution &SE, const Loop &L) {
+ StencilDecomposition D;
+
+ auto ToInt64 = [](const APInt &V) -> std::optional<int64_t> {
+ if (V.getSignificantBits() > 64)
+ return std::nullopt;
----------------
fhahn wrote:
could you add a test that hits this codepath? Something like an address space with i128 index width
https://github.com/llvm/llvm-project/pull/187252
More information about the llvm-commits
mailing list