<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/139041>139041</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Wrong `select (fcmp ...) (fadd ...)` folding to llvm max intrinsic
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bongjunj
      </td>
    </tr>
</table>

<pre>
    ```llvm
define float @test_fcmp_ogt_fadd_select_rewrite_and_fastmath.2(float %in) {
  %cmp1 = fcmp nnan ogt float %in, 0.000000e+00
  %2 = fadd float %in, 1.000000e+00
 %sel = select fast i1 %cmp1, float %2, float 1.000000e+00
  ret float %sel
}
```

```
define float @test_fcmp_ogt_fadd_select_rewrite_and_fastmath(float %in) {
#0:
  %cmp1 = fcmp nnan ogt float %in, 0.000000
  %add = fadd float %in, 1.000000
  %sel = select fast i1 %cmp1, float %add, float 1.000000
  ret float %sel
}
=>
define float @test_fcmp_ogt_fadd_select_rewrite_and_fastmath(float %in) {
#0:
  %sel = fmax nnan ninf nsz float %in, 0.000000
  %add = fadd nnan ninf nsz float %sel, 1.000000
  ret float %add
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
float %in = #xff800000 (-oo)

Source:
i1 %cmp1 = #x0 (0)
float %add = #xff800000 (-oo)
float %sel = #x00000000 (+0.0)

Target:
float %sel = poison
float %add = poison
Source value: #x00000000 (+0.0)
Target value: poison

Summary:
 0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```

While the alive2 site (https://alive2.llvm.org/ce/z/50KuQH) complains that it used approximation so it could not conclude,
I think it may have nothing to do with approximation.

Targeted Commit of Test: https://github.com/llvm/llvm-project/commit/a0c4876eede8e68de22dc5296b037556c7cca981
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VU1v6zYQ_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