[llvm] [DA] Add tests for nsw doesn't hold on entier iteration (PR #162281)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 05:50:21 PST 2025


Meinersbur wrote:

Some background on how Polly handles this:
Each BasicBlock has a "domain" which is the set of possible values of i, j,n, ... . When there is a condition such as `i < 1000`, the domain includes the infomation $i < 1000$ which then can be used to rule out overflow, etc.

DA doesn't have an equivalent of execution domains, it has to assume Src/Dst may be executed for any `i`.  I don't think we need to bail out only because of the simple presence of conditionals/loop guards, it just means we cannot prove monotonicity in this case which may then cause to not be analyzable, but we would have no probles with loop guards such as `if (i >= 1)` or `if (debug)`.

When I said "has to assume Src/Dst may be executed for any `i`", this is not entirely true. `DependenceInfo::collectUpperBound` can infer an upper bound from the loop's BackedgeTakenCount. I think it could also collect the branch conditions in the acyclic control flow to reach Src/Dst instructions. This means that along a SCEV, one also needs to pass a context BB for such kind of analysis since the restricted upper bound only counds within the if-condition. This kind of context information is already used by `getSCEVAtScope`, but it passes only the loop and does not care for the paticular BB.

Although I wonder whether it is worth the effort. You get more complicated upper bound SCEVs such as `min(n, 10000)`.

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


More information about the llvm-commits mailing list