[llvm] [InstCombine] Fold `fmul X, -0.0` into `copysign(0.0, -X)` (PR #85772)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 04:26:26 PDT 2024
================
@@ -814,8 +814,17 @@ Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) {
if (match(Op1, m_SpecificFP(-1.0)))
return UnaryOperator::CreateFNegFMF(Op0, &I);
- // With no-nans: X * 0.0 --> copysign(0.0, X)
- if (I.hasNoNaNs() && match(Op1, m_PosZeroFP())) {
+ // With no-nans:
+ // X * 0.0 --> copysign(0.0, X)
+ // X * -0.0 --> copysign(0.0, -X)
+ if (match(Op1, m_AnyZeroFP()) &&
+ isKnownNeverNaN(&I, /*Depth=*/0, SQ.getWithInstruction(&I))) {
+ if (match(Op1, m_NegZeroFP())) {
+ Op0 = Builder.CreateFNegFMF(Op0, &I);
+ // Canonicalize -0.0 to 0.0
+ Op1 = ConstantFoldUnaryOpOperand(Instruction::FNeg, cast<Constant>(Op1),
----------------
arsenm wrote:
I don't expect free constant fold calls to appear like this. Should visit copysign just simplify all constant signs it sees?
https://github.com/llvm/llvm-project/pull/85772
More information about the llvm-commits
mailing list