[llvm] [SCEVDivision] Prevent propagation of incorrect no-wrap flags (PR #154745)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 05:33:52 PDT 2025
================
@@ -479,14 +479,16 @@ for.cond.cleanup: ; preds = %for.cond.cleanup3,
;; for (int k = 1; k < o; k++)
;; = A[i*m*o + j*o + k]
;; A[i*m*o + j*o + k - 1] =
+;;
+;; FIXME: Currently fails to infer nsw for the SCEV `{0,+,1}<for.body8>`
define void @t8(i32 %n, i32 %m, i32 %o, ptr nocapture %A) {
; CHECK-LABEL: 't8'
; CHECK-NEXT: Src: %0 = load i32, ptr %arrayidx, align 4 --> Dst: %0 = load i32, ptr %arrayidx, align 4
; CHECK-NEXT: da analyze - none!
; CHECK-NEXT: Src: %0 = load i32, ptr %arrayidx, align 4 --> Dst: store i32 %add12, ptr %arrayidx2, align 4
-; CHECK-NEXT: da analyze - consistent anti [0 0 1]!
+; CHECK-NEXT: da analyze - anti [* * *|<]!
; CHECK-NEXT: Src: store i32 %add12, ptr %arrayidx2, align 4 --> Dst: store i32 %add12, ptr %arrayidx2, align 4
-; CHECK-NEXT: da analyze - none!
+; CHECK-NEXT: da analyze - output [* * *]!
----------------
kasuga-fj wrote:
The essential portion of the IR is as follows:
```llvm
preheader:
%guard = icmp sgt i32 %o, 0
br i1 %guard, label %loop, label %exit
loop:
%i = phi i32 [ 1, %preheader ], [ %inc, %loop ]
...
%inc = add nuw nsw i32 %i, 1
%exitcond = icmp eq i32 %inc, %o
br i1 %exitcond, label %exit, label %body
exit:
...
```
>From the loop-guard and the induction variable, we know the following:
- `0 <s %o`
- `{1,+,1}<%loop> <s %o`
- `{1,+,1}<%loop>` is nsw and nuw
IIUIC, in principle, we can deduce that `{0,+,1}<%loop>` is also nsw and nuw, but now the inference fails. Are there any good ways to address this case, or do we need to implement a separate inference specifically for it?
https://github.com/llvm/llvm-project/pull/154745
More information about the llvm-commits
mailing list