[flang-commits] [flang] [llvm] [mlir] [Flang][OpenMP] Add nsw flags to OMPIRBuilder loop IV arithmetic (PR #214165)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Wed Aug 5 06:24:08 PDT 2026
================
@@ -5808,7 +5808,8 @@ CanonicalLoopInfo *OpenMPIRBuilder::createLoopSkeleton(
Builder.SetInsertPoint(Latch);
Value *Next = Builder.CreateAdd(IndVarPHI, ConstantInt::get(IndVarTy, 1),
- "omp_" + Name + ".next", /*HasNUW=*/true);
+ "omp_" + Name + ".next", /*HasNUW=*/true,
+ /*HasNSW=*/Config.hasNoSignedWrap());
----------------
tblah wrote:
Strictly, this can't be signed no wrap because synthetic collapsed loops could have sizes not representable in a signed integer (even though the fortran type would be signed). For example
```
subroutine collapsed_tripcount_over_intmax()
integer :: i, j
!$omp simd collapse(2)
do i = 1, 46341
do j = 1, 46341
continue
end do
end do
end subroutine
```
(Found by codex)
That said, I would be hesitant to fix this theoretical example if that breaks your real performance case for real code. Maybe we could at least avoid adding the attribute in cases where we can determine statically that it is unsafe (such as in the example above).
https://github.com/llvm/llvm-project/pull/214165
More information about the flang-commits
mailing list