[llvm] r321468 - [instcombine] add powi(x, 2) -> x * x

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 26 17:30:13 PST 2017


Author: reames
Date: Tue Dec 26 17:30:12 2017
New Revision: 321468

URL: http://llvm.org/viewvc/llvm-project?rev=321468&view=rev
Log:
[instcombine] add powi(x, 2) -> x * x


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/intrinsics.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=321468&r1=321467&r2=321468&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Tue Dec 26 17:30:12 2017
@@ -1934,6 +1934,10 @@ Instruction *InstCombiner::visitCallInst
       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;
 

Modified: llvm/trunk/test/Transforms/InstCombine/intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/intrinsics.ll?rev=321468&r1=321467&r2=321468&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/intrinsics.ll Tue Dec 26 17:30:12 2017
@@ -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) {




More information about the llvm-commits mailing list