[InstCombine] Fix FMF propagation in `foldSelectWithFCmpToFabs` (#121580)
commit3ec6a6b85aed838b7d56bd6843cad52e822b9111
authorYingwei Zheng <dtcxzyw2333@gmail.com>
Sat, 1 Feb 2025 07:14:17 +0000 (1 15:14 +0800)
committerGitHub <noreply@github.com>
Sat, 1 Feb 2025 07:14:17 +0000 (1 15:14 +0800)
tree1839bf8f14c9f1b133a945407c12f6c50f44b7a1
parent626c23112fe25c1e327f5b17ad94f805588cec1c
[InstCombine] Fix FMF propagation in `foldSelectWithFCmpToFabs` (#121580)

Consider the following pattern:
```
%cmp = fcmp <pred> double %x, 0.000000e+00
%negX = fneg <fmf> double %x
%sel = select i1 %cmp, double %x, double %negX
```
We cannot propagate ninf from fneg to select since `%negX` may not be
chosen. Similarly, we cannot propagate nnan unless `%negX` is guaranteed
to be selected when `%x` is NaN.
This patch also propagates nnan/ninf from fcmp to avoid regression in
`PhaseOrdering/generate-fabs.ll`.

Alive2: https://alive2.llvm.org/ce/z/t6U-tA
Closes https://github.com/llvm/llvm-project/issues/121430 and
https://github.com/llvm/llvm-project/issues/113989.
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/fabs.ll
llvm/test/Transforms/InstCombine/fneg-fabs.ll