[llvm] [InstCombine] Fold more 'fcmp' 'select' instrs idioms into 'fabs' (PR #83381)
Yashwant Singh via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 01:52:26 PST 2024
================
@@ -2742,7 +2742,12 @@ static Instruction *foldSelectWithFCmpToFabs(SelectInst &SI,
// Note: We require "nnan" for this fold because fcmp ignores the signbit
// of NAN, but IEEE-754 specifies the signbit of NAN values with
// fneg/fabs operations.
- if (!SI.hasNoSignedZeros() || !SI.hasNoNaNs())
+ if (!SI.hasNoNaNs())
+ return nullptr;
+
+ bool FunctionHasNoSignedZeroes =
+ SI.getParent()->getParent()->hasFnAttribute("no-signed-zeros-fp-math");
----------------
yashssh wrote:
I'm unable to get it to work with floating point flags. `instcombine` requires `select` to have `nsz` flag to be able to fold a combination of `fcmp` `fneg` and `select` into a `fabs` intrinsic. But with current semantics, we can't safely propagate `nsz` to `select`. I might not be able to fully explain the problem in single comment but everything is well documented at #51601 particularly [this comment](https://github.com/llvm/llvm-project/issues/51601#issuecomment-981047527).
https://github.com/llvm/llvm-project/pull/83381
More information about the llvm-commits
mailing list