Issue 74297
Summary InstCombine: incorrect sink of FP math through select changes NaN value
Labels miscompilation, llvm:instcombine, floating-point
Assignees
Reporter nunoplopes
    This optimization changes the NaN payload. It requires the `nnan` flag.

```llvm
; test/Transforms/InstCombine/select-binop-foldable-floating-point.ll

define float @select_fadd(i1 %cond, float %A, float %B) {
  %C = fadd float %A, %B
  %D = select i1 %cond, float %C, float %A
  ret float %D
}
=>
define float @select_fadd(i1 %cond, float %A, float %B) {
  %C = select i1 %cond, float %B, float -0.000000
  %D = fadd float %C, %A
  ret float %D
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
i1 %cond = #x0 (0)
float %A = #x7f810000 (SNaN)
float %B = #x00000000 (+0.0)

Source:
float %C = #x7fc00000 (QNaN)
float %D = #x7f810000 (SNaN)

Target:
float %C = #x80000000 (-0.0)
float %D = #x7fc00000 (QNaN)
Source value: #x7f810000 (SNaN)
Target value: #x7fc00000 (QNaN)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to