[llvm] [SCEV] Try to prove no-wrap for AddRecs via BTC. (PR #131538)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 21 00:47:22 PDT 2025


https://github.com/fhahn commented:

> You need to update the polly test failure.
> 
> There's a roughly analogous piece of code already in computeExitLimitFromICmp which is guarded by ControllingFiniteLoop. Unfortunately, I think that's needed. Imagine an induction variable which _isn't_ used to control a loop exit. Take something simple like an i8 which wraps around repeatedly in a loop controlled by an separate i32 induction. I believe we can sometimes prove the BTC of the small induction variable (from the larger one), but that doesn't prevent the inner one from wrapping repeatedly. I think this case might be guarded by your widen type check, but if so, that needs to be pretty explicitly spelled out.

Thanks, there should be no polly test failures in the latest version.

In the latest version, I added checks that `Start + BTC` won't overflow (via `willNotOverflow`) to correctly handle the case you mentioned, while also allowing to apply the logic to cases where the AddRec isn't controlling the loop exit.

`llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll` in the original cases contained a a number of cases where the patch originally incorrectly inferred NUW, while Start+BTC could wrap.

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


More information about the llvm-commits mailing list