[llvm] [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (PR #94148)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 08:05:50 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 ninf is the only problematic flag, since ninf on the fneg does not imply fneg on fmul, and fmul inf * 0 = nan.
So you need something like
Flags = FnegFlags | FMulFlags
Flags.ninf &= FmulFlags.ninf
https://github.com/llvm/llvm-project/pull/94148
More information about the llvm-commits
mailing list