[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()) {
----------------
arsenm wrote:
Directionally this feels wrong. A constant, but not known literal 0/-0 may end up resolving to a 0 (e.g. degenerate constant expression casts or undef). I think this should first be written to handle the flags conservatively regardless of the value and we can try to refine for the known-non-0 cases if necessary
https://github.com/llvm/llvm-project/pull/94148
More information about the llvm-commits
mailing list