[flang-commits] [flang] [flang][FIRToSCF] Keep no-wrap flags when narrowing a typed induction variable (PR #219281)
via flang-commits
flang-commits at lists.llvm.org
Mon Aug 31 02:23:36 PDT 2026
https://github.com/jeanPerier commented:
> Fortran requires the trip count to be representable in the loop variable's type
The standard is not very specific (there is not written constraints that says this ASFAIK). In flang, we have so far decided that we would support loops where the trip count fits on 64 bit signed integer.
So something like `do i = -huge(i), huge(i)-1` should run correctly with `i` an integer(4), even though the trip count is `2*huge(i) = 2^32 -2` which does not fit on a signed i32.
Instead of truncating the trip count, could we do the calculations in index/64 bit arithmetic and then truncate the result to the loop variable type (which at that point should be guaranteed to not overflow)?
I know support for `do i = -huge(i), huge(i)-1` is not universal behavior among compilers, so if there are compelling reasons to not support `do i = -huge(i), huge(i)-1` with INTEGER(4), I am OK with it, but I would rather be able to support it.
Please wait for @vzakhari or @rscottmanley on this as they have more experience on loop representation than me.
https://github.com/llvm/llvm-project/pull/219281
More information about the flang-commits
mailing list