[llvm] [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (PR #94148)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 11:32:48 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());
----------------
arsenm wrote:
I think the correct logic is and flags, but can or-in NSZ or nnan from either op
https://github.com/llvm/llvm-project/pull/94148
More information about the llvm-commits
mailing list