summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-02-23 21:16:12 +0000
committerSanjay Patel <spatel@rotateright.com>2018-02-23 21:16:12 +0000
commitd32104e1b2867a41ba98a57881486fbb6b472e76 (patch)
tree64fdc548894bfe73ba692c77a6e6fbbb438af2b7 /llvm/lib/Transforms/InstCombine
parent545932bec992f5845fa780c26610d08cbb764bc0 (diff)
downloadbcm5719-llvm-d32104e1b2867a41ba98a57881486fbb6b472e76.tar.gz
bcm5719-llvm-d32104e1b2867a41ba98a57881486fbb6b472e76.zip
[InstCombine] allow fmul-sqrt folds with less than full -ffast-math
Also, add a Builder method for intrinsics to reduce code duplication for clients. llvm-svn: 325960
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index cb48b93473e..d5456cc532f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -662,24 +662,17 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
}
}
- // sqrt(a) * sqrt(b) -> sqrt(a * b)
- if (AllowReassociate && Op0->hasOneUse() && Op1->hasOneUse()) {
- Value *Opnd0 = nullptr;
- Value *Opnd1 = nullptr;
- if (match(Op0, m_Intrinsic<Intrinsic::sqrt>(m_Value(Opnd0))) &&
- match(Op1, m_Intrinsic<Intrinsic::sqrt>(m_Value(Opnd1)))) {
- BuilderTy::FastMathFlagGuard Guard(Builder);
- Builder.setFastMathFlags(I.getFastMathFlags());
- Value *FMulVal = Builder.CreateFMul(Opnd0, Opnd1);
- Value *Sqrt = Intrinsic::getDeclaration(I.getModule(),
- Intrinsic::sqrt, I.getType());
- Value *SqrtCall = Builder.CreateCall(Sqrt, FMulVal);
- return replaceInstUsesWith(I, SqrtCall);
- }
+ // sqrt(X) * sqrt(Y) -> sqrt(X * Y)
+ Value *X, *Y;
+ if (I.hasAllowReassoc() &&
+ match(Op0, m_OneUse(m_Intrinsic<Intrinsic::sqrt>(m_Value(X)))) &&
+ match(Op1, m_OneUse(m_Intrinsic<Intrinsic::sqrt>(m_Value(Y))))) {
+ Value *XY = Builder.CreateFMulFMF(X, Y, &I);
+ Value *Sqrt = Builder.CreateIntrinsic(Intrinsic::sqrt, { XY }, &I);
+ return replaceInstUsesWith(I, Sqrt);
}
// -X * -Y --> X * Y
- Value *X, *Y;
if (match(Op0, m_FNeg(m_Value(X))) && match(Op1, m_FNeg(m_Value(Y))))
return BinaryOperator::CreateFMulFMF(X, Y, &I);
OpenPOWER on IntegriCloud