Skip to content

Commit 7f7a0f2

Browse files
committed
[InstSimplify] reduce code duplication for fmul folds; NFC
This is a modification of the earlier attempt from: 7b7940f For fma callers, we only want to swap a 0.0 or 1.0 constant.
1 parent c931040 commit 7f7a0f2

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5325,22 +5325,18 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
53255325
if (!isDefaultFPEnvironment(ExBehavior, Rounding))
53265326
return nullptr;
53275327

5328-
// fmul X, 1.0 ==> X
5328+
// Canonicalize special constants as operand 1.
5329+
if (match(Op0, m_FPOne()) || match(Op0, m_AnyZeroFP()))
5330+
std::swap(Op0, Op1);
5331+
5332+
// X * 1.0 --> X
53295333
if (match(Op1, m_FPOne()))
53305334
return Op0;
53315335

5332-
// fmul 1.0, X ==> X
5333-
if (match(Op0, m_FPOne()))
5334-
return Op1;
5335-
5336-
// fmul nnan nsz X, 0 ==> 0
5336+
// X * 0.0 --> 0.0 (with nnan and nsz)
53375337
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op1, m_AnyZeroFP()))
53385338
return ConstantFP::getNullValue(Op0->getType());
53395339

5340-
// fmul nnan nsz 0, X ==> 0
5341-
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
5342-
return ConstantFP::getNullValue(Op1->getType());
5343-
53445340
// sqrt(X) * sqrt(X) --> X, if we can:
53455341
// 1. Remove the intermediate rounding (reassociate).
53465342
// 2. Ignore non-zero negative numbers because sqrt would produce NAN.

0 commit comments

Comments
 (0)