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

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 27 07:17:01 PDT 2024


================
@@ -2682,8 +2682,12 @@ 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))
-      return BinaryOperator::CreateFMulFMF(X, NegC, &I);
+    if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL)) {
+      FastMathFlags Flag = I.getFastMathFlags() | FNegOp->getFastMathFlags();
+      Flag.setNoInfs(I.getFastMathFlags().noInfs() &&
+                     FNegOp->getFastMathFlags().noInfs());
----------------
SahilPatidar wrote:

done

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


More information about the llvm-commits mailing list