# \[RFC\] Reducing Runtime Pointer Comparisons for Stencil Codes via Stencil Group Merging in LoopAccessAnalysis

**URL:** <https://discourse.llvm.org/t/rfc-reducing-runtime-pointer-comparisons-for-stencil-codes-via-stencil-group-merging-in-loopaccessanalysis/90239>\
**Category:** Loop Optimizations\
**Created:** [March 18, 2026, 12:33pm UTC](https://discourse.llvm.org/t/rfc-reducing-runtime-pointer-comparisons-for-stencil-codes-via-stencil-group-merging-in-loopaccessanalysis/90239 "2026-03-18T12:33:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![igogo-x86](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/igogo-x86/32/26968_2.png) [@igogo-x86](https://discourse.llvm.org/u/igogo-x86)\
**Post date:** [March 18, 2026, 5:25pm UTC](https://discourse.llvm.org/t/rfc-reducing-runtime-pointer-comparisons-for-stencil-codes-via-stencil-group-merging-in-loopaccessanalysis/90239/3 "2026-03-18T17:25:35Z")

</div>

Added a link to the patch.

> [@eas](#):
>
> nit/pedantic: That should have been “runtime offsets”, because the stride (in front of `i`) is still one. It caught my eyes because I’m trying to support actual runtime strides in LAA.

Aren’t they strides with respect to the mid and outer loops? I.e.:

- Inner loop (over i): stride = 1 element (consecutive)
- Mid loop (over j): stride = cdj (= grid width)
- Outer loop (over k): stride = cdk (= grid width × grid height)

That was my understanding of the term stride.

> [@eas](#):
>
> Why not `abs(stride) > 0` ?

This is somewhat a decision I had to make. We check for positive strides to get tighter ranges. If accesses are at `{-1cdj, +1cdj, +2cdj}`, the coefficient range is `[-1, 2]`, giving bounds `[base - cdj, base + 2cdj]`. For potentially negative strides the formula would be  
different, with wider ranges like `[base - 2abs(cdj), base + 2abs(cdj) + …]`. That’s actually worth discussing - which approach is better. I feel like negative strides in these expressions are something that won’t happen very often, if ever.

---

_[View the full topic](https://discourse.llvm.org/t/rfc-reducing-runtime-pointer-comparisons-for-stencil-codes-via-stencil-group-merging-in-loopaccessanalysis/90239)._
