summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2017-12-27 01:30:12 +0000
committerPhilip Reames <listmail@philipreames.com>2017-12-27 01:30:12 +0000
commitd43be2d8a96a9a756736f99f08fe3be1f85fdc7c (patch)
treeb235bf9b89de0ba9fedac5752e36b407f366ce21
parent89623b4cd2a123d66c08cb0a20e7d06d792ea373 (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.cpp4
-rw-r--r--test/Transforms/InstCombine/intrinsics.ll5
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) {