[llvm] [InstCombine] Fold (X * 0.0) * constant => X * 0.0 #85241 (PR #92512)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 03:04:07 PDT 2024


================
@@ -905,6 +905,16 @@ Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) {
     }
   }
 
+  // (X * 0.0) * constant => X * 0.0
+  if (match(Op0, m_FMul(m_Value(X), m_AnyZeroFP())) &&
+      match(Op1, m_Constant(C))) {
+    Constant *C1 = cast<Constant>(cast<Instruction>(Op0)->getOperand(1));
+    if (Constant *CC1 =
+            ConstantFoldBinaryOpOperands(Instruction::FMul, C, C1, DL)) {
+      return BinaryOperator::CreateFMulFMF(X, CC1, I.getFastMathFlags());
----------------
arsenm wrote:

Flags shouldn't just appear out of nowhere from CreateFMul. 

Most straightforward should be `I.getFastMathFlags() & cast<FPMathOperator>(Op0)->getFastMathFlags()`.

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


More information about the llvm-commits mailing list