[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 06:55:35 PDT 2024


================
@@ -814,8 +814,15 @@ 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/no-infs:
+  // X * 0.0 --> copysign(0.0, X)
+  // X * -0.0 --> copysign(0.0, -X)
+  if ((match(Op1, m_CombineOr(m_PosZeroFP(), m_NegZeroFP()))) &&
----------------
arsenm wrote:

instead of matching the zero twice, can you match m_APFloat, then take advantage of the isZero that ignores the sign? 

https://github.com/llvm/llvm-project/pull/85772


More information about the llvm-commits mailing list