[flang-commits] [clang] [flang] [flang] add -floop-interchange and enable it with opt levels (PR #140182)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Thu Aug 21 10:50:28 PDT 2025


Meinersbur wrote:

> > There are fundamental flaws in DA's implementation, particularly in how it handles wrapping of SCEVs.
> 
> Tell me more about it in a separate bug, and let's see how we can work towards fixing it.

If you look over the code you can see that no attention was paid to integer wrapping behavior. For instance, `x < y` is implemented in multiple places (e.g. `DependenceInfo::isKnownLessThan`) as
```
SE->isKnownNegative(getMinusSCEV(x,y))
```

1. `isKnownNegative` always assumes an signed interpretation (otherwise it could never be negative), but the code may use unsigned loop variables/pointer indices
2. Even if it is signed, if eg `x = 1`, `y = INT_MIN` (so x is obviously larger) `x - y` would wrap back into the negative and return true. 


> Instead of spreading FUD around [...]

@kasuga-fj pointed out bugs in the current implementation. Whether those are sufficient to justify changing default behavior is subjective. Generally assume best intentions.

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


More information about the flang-commits mailing list