aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-08-16 16:47:13 +0200
committerNikita Popov <npopov@redhat.com>2024-08-16 16:47:13 +0200
commit60bffe221a1d615ffc7c6b632287d0fbd27ef863 (patch)
treea551470e95585bf34f986792ff69cfbdb2afbbca /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parent83bf1d661213cb8ec8e79ac085f793009721aaf5 (diff)
downloadllvm-60bffe221a1d615ffc7c6b632287d0fbd27ef863.zip
llvm-60bffe221a1d615ffc7c6b632287d0fbd27ef863.tar.gz
llvm-60bffe221a1d615ffc7c6b632287d0fbd27ef863.tar.bz2
[InstCombine] Handle commuted variant of sqrt transform
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index be4d459..fb2efe5 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2758,14 +2758,17 @@ Value *LibCallSimplifier::optimizeSqrt(CallInst *CI, IRBuilderBase &B) {
// Note: We don't bother looking any deeper than this first level or for
// variations of this pattern because instcombine's visitFMUL and/or the
// reassociation pass should give us this form.
- Value *OtherMul0, *OtherMul1;
- if (match(Op0, m_FMul(m_Value(OtherMul0), m_Value(OtherMul1)))) {
- // Pattern: sqrt((x * y) * z)
- if (OtherMul0 == OtherMul1 && cast<Instruction>(Op0)->isFast()) {
- // Matched: sqrt((x * x) * z)
- RepeatOp = OtherMul0;
- OtherOp = Op1;
- }
+ Value *MulOp;
+ if (match(Op0, m_FMul(m_Value(MulOp), m_Deferred(MulOp))) &&
+ cast<Instruction>(Op0)->isFast()) {
+ // Pattern: sqrt((x * x) * z)
+ RepeatOp = MulOp;
+ OtherOp = Op1;
+ } else if (match(Op1, m_FMul(m_Value(MulOp), m_Deferred(MulOp))) &&
+ cast<Instruction>(Op1)->isFast()) {
+ // Pattern: sqrt(z * (x * x))
+ RepeatOp = MulOp;
+ OtherOp = Op0;
}
}
if (!RepeatOp)