From 85bd15a2b115caac021fd222ba2d3d910142289a Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Wed, 27 Dec 2017 01:30:12 +0000 Subject: [PATCH] [instcombine] add powi(x, 2) -> x * x llvm-svn: 321468 --- lib/Transforms/InstCombine/InstCombineCalls.cpp | 4 ++++ test/Transforms/InstCombine/intrinsics.ll | 5 +++++ 2 files changed, 9 insertions(+) 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) {