[llvm] [InstCombine] Fold (X * 0.0) * constant => X * 0.0 #85241 (PR #92512)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 21:14:15 PDT 2024
================
@@ -905,6 +905,16 @@ Instruction *InstCombinerImpl::visitFMul(BinaryOperator &I) {
}
}
+ // (X * 0.0) * constant => X * 0.0
+ if (match(Op0, m_FMul(m_Value(X), m_AnyZeroFP())) &&
+ match(Op1, m_Constant(C))) {
+ Constant *C1 = cast<Constant>(cast<Instruction>(Op0)->getOperand(1));
+ if (Constant *CC1 =
+ ConstantFoldBinaryOpOperands(Instruction::FMul, C, C1, DL)) {
+ return BinaryOperator::CreateFMulFMF(X, CC1, I.getFastMathFlags());
----------------
SahilPatidar wrote:
Am I doing something wrong?
```cpp
FastMathFlags FMF = I.getFastMathFlags() &
cast<FPMathOperator>(Op0)->getFastMathFlags();
return BinaryOperator::CreateFMulFMF(X, CC1, FMF);
```
still propagating `ninf` flag.
```LLVM
define float @mul_pos_zero_neg_const_ninf_res(float %a) {
; CHECK-LABEL: @mul_pos_zero_neg_const_ninf_res(
; CHECK-NEXT: [[F2:%.*]] = fmul ninf float [[A:%.*]], -0.000000e+00
; CHECK-NEXT: ret float [[F2]]
;
%f1 = fmul float %a, 0.000000
%f2 = fmul ninf float %f1, -1.000000
ret float %f2
}
```
https://github.com/llvm/llvm-project/pull/92512
More information about the llvm-commits
mailing list