diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-01-06 21:34:26 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-01-06 21:34:26 +0000 |
commit | d215fd3b74b90f5dc1964610926fcc2a20f959aa (patch) | |
tree | 0c9f21e40eae033d6760008729f37d2103e2c654 /lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 541dde6c47d2e..38604830b8852 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -728,6 +728,23 @@ 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); + } + } + // Handle symmetric situation in a 2-iteration loop Value *Opnd0 = Op0; Value *Opnd1 = Op1; |