| Issue |
233452
|
| Summary |
[InstCombine] Folding dependent IVs copies `nnan` onto the new first-iteration value
|
| Labels |
miscompilation,
llvm:instcombine,
generated by fuzzer
|
| Assignees |
|
| Reporter |
ChoKyuWon
|
### reproducer
godbolt: https://godbolt.org/z/vbdTr37x9
alive: https://alive2.llvm.org/ce/z/A6ycs6
```llvm
define float @f(float %start, i1 %c) {
entry:
br label %loop
loop:
%iv = phi float [ %start, %entry ], [ %iv.next, %loop ]
%iv2 = phi float [ -0.0, %entry ], [ %iv2.next, %loop ]
%iv2.next = fadd float %iv2, 1.0
%iv.next = fadd nnan float %start, %iv2.next
br i1 %c, label %exit, label %loop
exit:
ret float %iv
}
```
```console
$ opt -S -passes=instcombine repro.ll
define float @f(float %start, i1 %c) {
entry:
br label %loop
loop:
%iv2 = phi float [ -0.000000e+00, %entry ], [ %iv2.next, %loop ]
%iv2.next = fadd float %iv2, 1.000000e+00
br i1 %c, label %exit, label %loop
exit:
%iv = fadd nnan float %iv2, %start
ret float %iv
}
$ alive-tv --disable-undef-input --disable-poison-input --passes=instcombine --src-unroll=2 --tgt-unroll=2 repro.ll
ERROR: Target is more poisonous than source
Example:
float %start = #x7f880000 (SNaN)
i1 %c = #x1 (1)
Source value: #x7f880000 (SNaN)
Target value: poison
```
### suggested fix
`foldDependentIVs` (InstCombinePHI.cpp) builds `%iv = %iv2 op %start` and calls `copyIRFlags(BO)` from `%iv.next`. On the first iteration that instruction computes `identity op %start`, which the source never evaluates (it yields `%start` itself), so `nnan`/`ninf` make it poison for a NaN/Inf `%start`.
Do not copy fast-math flags onto the new instruction (the integer wrap flags and the GEP path are fine: `0 + x` and `1 * x` never wrap, and a GEP with a zero index is always `inbounds`/`nusw`/`nuw`).
> Disclaimer: This test case was generated by a fuzzer, and the report was written with LLM assistance.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs