[llvm] [InstCombine] Don't convert a compare+select into a minnum/maxnum intrinsic that can't be lowered back to a compare+select (PR #177821)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 31 13:29:43 PST 2026
valadaptive wrote:
@SergeyShch01 Can you elaborate? I tried creating a repro on Compiler Explorer but [Clang 21 and trunk seem to compile it identically](https://llvm.godbolt.org/z/Tvfj5997j).
The code path I modified (converting a compare+select into a minnum/maxnum) shouldn't be taken unless the compiler can prove that the input is never zero or NaN, or it doesn't care because fast-math flags are enabled. I don't believe `-O3` enables any fast-math flags.
If I use `-Ofast`, [Clang trunk *does* optimize this to `fmaxnm`+`csel`](https://llvm.godbolt.org/z/5PvPfqMYe), because it enables fast-math flags. Those allow the compiler to assume that the sign of zero does not matter, and that no inputs are NaN so it can ignore the intricacies of NaN propagation. This code looks much more compact and contains significantly fewer branches, so I'd be surprised if it turns out to be slower.
Do you have any fast-math flags enabled that you did not list in the compiler flags you gave here?
https://github.com/llvm/llvm-project/pull/177821
More information about the llvm-commits
mailing list