diff options
author | Philip Reames <listmail@philipreames.com> | 2017-12-27 01:30:12 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2017-12-27 01:30:12 +0000 |
commit | d43be2d8a96a9a756736f99f08fe3be1f85fdc7c (patch) | |
tree | b235bf9b89de0ba9fedac5752e36b407f366ce21 | |
parent | 89623b4cd2a123d66c08cb0a20e7d06d792ea373 (diff) |
[instcombine] add powi(x, 2) -> x * x
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321468 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 4 | ||||
-rw-r--r-- | test/Transforms/InstCombine/intrinsics.ll | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 4dfb22abb6e..5e0778d9ae2 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1934,6 +1934,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (Power->isMinusOne()) return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0), II->getArgOperand(0)); + // powi(x, 2) -> x*x + if (Power->equalsInt(2)) + return BinaryOperator::CreateFMul(II->getArgOperand(0), + II->getArgOperand(0)); } break; diff --git a/test/Transforms/InstCombine/intrinsics.ll b/test/Transforms/InstCombine/intrinsics.ll index c6f88fb9cf0..e0698f8b3b7 100644 --- a/test/Transforms/InstCombine/intrinsics.ll +++ b/test/Transforms/InstCombine/intrinsics.ll @@ -267,12 +267,17 @@ define void @powi(double %V, double *%P) { %C = tail call double @llvm.powi.f64(double %V, i32 1) nounwind store volatile double %C, double* %P + + %D = tail call double @llvm.powi.f64(double %V, i32 2) nounwind + store volatile double %D, double* %P ret void ; CHECK-LABEL: @powi( ; CHECK: %A = fdiv double 1.0{{.*}}, %V ; CHECK: store volatile double %A, ; CHECK: store volatile double 1.0 ; CHECK: store volatile double %V +; CHECK: %D = fmul double %V, %V +; CHECK: store volatile double %D } define i32 @cttz(i32 %a) { |