[llvm] [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (PR #94148)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 07:47:43 PDT 2024


================
@@ -2653,8 +2653,15 @@ static Instruction *foldFNegIntoConstant(Instruction &I, const DataLayout &DL) {
   // Fold negation into constant operand.
   // -(X * C) --> X * (-C)
   if (match(FNegOp, m_FMul(m_Value(X), m_Constant(C))))
-    if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL))
+    if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL)) {
+      if (match(C, m_AnyZeroFP()) && I.getFastMathFlags().noInfs()) {
+        return BinaryOperator::CreateFMulFMF(
+            X, NegC,
+            I.getFastMathFlags() &
+                cast<FPMathOperator>(I.getOperand(0))->getFastMathFlags());
----------------
SahilPatidar wrote:

Ok, we need to check all alive2 cases and then generate the flags.

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


More information about the llvm-commits mailing list