[llvm] [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (PR #94148)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 7 03:16:54 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:
Could we do it this way?
```cpp
FastMathFlags FMF = cast<FPMathOperator>(I.getOperand(0))->getFastMathFlags();
if (I.getFastMathFlags().noInfs() && !FMF.noInfs()) {
return BinaryOperator::CreateFMulFMF(X, NegC, FMF);
}
```
https://github.com/llvm/llvm-project/pull/94148
More information about the llvm-commits
mailing list