[Mlir-commits] [mlir] [mlir][affine] Use value bound inference to determine minimum/maximum trip counts in loop analysis (PR #128113)

lonely eagle llvmlistbot at llvm.org
Tue Jun 24 08:57:53 PDT 2025


linuxlonelyeagle wrote:

> Suppose we have a loop where the lower bounds are L = {l1, l2, ... lM}, and the upper bounds are U = {u1, u2, ..., uN} and step S . This means that the trip count T is bounded by `min(U) - max(L)) ceildiv S <= T <= (max(U) - min(L)) ceildiv S`.
> 

I'm a little confused about that.You can read what I was talking about earlier with @ftynse.https://github.com/llvm/llvm-project/pull/128113#issuecomment-2803606526 and https://github.com/llvm/llvm-project/pull/128113#issuecomment-2801043226

> I think where unrolling comes in is that if T >= n * F for some unrolling factor F, you can unroll n iterations of the loop, and then your lower bound becomes {l1, 2, ..., ln} - n * F * S and your upper bound becomes {u1, u2, ..., uN} - n * F * S.

I totally understand what's going on here.But the current practice is similar to this one, but with some differences.Two parts are included.
```
// unroll out of affine.for
affine.for xxx {

}

// Remaining affine.for, equivalent to affine.if, 
// lower bound becomes {l1, 2, ..., ln} +  n * F * S, upper bound becomes {u1, u2, ..., uN} .
affine.for xxx {
}

```

@krzysz00 @ftynse I'm sorry to have kept you waiting so long.Please let me know further improvement suggestions for this PR. Thank you all.


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


More information about the Mlir-commits mailing list