[InstSimplify] reduce code duplication for fmul folds; NFC
The constant is already commuted for an fmul opcode, but this code can be called more directly for fma, so we have to swap for that caller. There are tests in InstSimplify and InstCombine to verify that this works as expected.
This commit is contained in:
parent
4987ae8462
commit
7b7940f9da
|
@ -5325,22 +5325,18 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
|
|||
if (!isDefaultFPEnvironment(ExBehavior, Rounding))
|
||||
return nullptr;
|
||||
|
||||
// fmul X, 1.0 ==> X
|
||||
// Canonicalize constant as operand 1.
|
||||
if (match(Op0, m_ImmConstant()))
|
||||
std::swap(Op0, Op1);
|
||||
|
||||
// X * 1.0 --> X
|
||||
if (match(Op1, m_FPOne()))
|
||||
return Op0;
|
||||
|
||||
// fmul 1.0, X ==> X
|
||||
if (match(Op0, m_FPOne()))
|
||||
return Op1;
|
||||
|
||||
// fmul nnan nsz X, 0 ==> 0
|
||||
// X * 0.0 --> 0.0 (with nnan and nsz)
|
||||
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op1, m_AnyZeroFP()))
|
||||
return ConstantFP::getNullValue(Op0->getType());
|
||||
|
||||
// fmul nnan nsz 0, X ==> 0
|
||||
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
|
||||
return ConstantFP::getNullValue(Op1->getType());
|
||||
|
||||
// sqrt(X) * sqrt(X) --> X, if we can:
|
||||
// 1. Remove the intermediate rounding (reassociate).
|
||||
// 2. Ignore non-zero negative numbers because sqrt would produce NAN.
|
||||
|
|
|
@ -161,9 +161,9 @@ define <2 x float> @fadd_x_n0_vec_undef_elt(<2 x float> %a) {
|
|||
ret <2 x float> %ret
|
||||
}
|
||||
|
||||
; fmul X, 1.0 ==> X
|
||||
define double @fmul_X_1(double %a) {
|
||||
; CHECK-LABEL: @fmul_X_1(
|
||||
; fmul 1.0, X ==> X
|
||||
define double @fmul_1_X(double %a) {
|
||||
; CHECK-LABEL: @fmul_1_X(
|
||||
; CHECK-NEXT: ret double [[A:%.*]]
|
||||
;
|
||||
%b = fmul double 1.0, %a
|
||||
|
|
Loading…
Reference in New Issue