[llvm-commits] [llvm] r145730 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/ConstProp/calls.ll

Chad Rosier mcrosier at apple.com
Fri Dec 2 16:00:03 PST 2011


Author: mcrosier
Date: Fri Dec  2 18:00:03 2011
New Revision: 145730

URL: http://llvm.org/viewvc/llvm-project?rev=145730&view=rev
Log:
Add support for constant folding the pow intrinsic.
rdar://10514247

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/ConstProp/calls.ll

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=145730&r1=145729&r2=145730&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Fri Dec  2 18:00:03 2011
@@ -1053,6 +1053,7 @@
 llvm::canConstantFoldCallTo(const Function *F) {
   switch (F->getIntrinsicID()) {
   case Intrinsic::sqrt:
+  case Intrinsic::pow:
   case Intrinsic::powi:
   case Intrinsic::bswap:
   case Intrinsic::ctpop:
@@ -1346,9 +1347,6 @@
                       (double)Op1->getValueAPF().convertToFloat() :
                       Op1->getValueAPF().convertToDouble();
       if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
-        if (!TLI)
-          return 0;
-
         if (Op2->getType() != Op1->getType())
           return 0;
 
@@ -1356,6 +1354,11 @@
                       (double)Op2->getValueAPF().convertToFloat():
                       Op2->getValueAPF().convertToDouble();
 
+        if (F->getIntrinsicID() == Intrinsic::pow) {
+          return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
+        }
+        if (!TLI)
+          return 0;
         if (Name == "pow" && TLI->has(LibFunc::pow))
           return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
         if (Name == "fmod" && TLI->has(LibFunc::fmod))

Modified: llvm/trunk/test/Transforms/ConstProp/calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/calls.ll?rev=145730&r1=145729&r2=145730&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/calls.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/calls.ll Fri Dec  2 18:00:03 2011
@@ -61,6 +61,15 @@
 declare i64 @llvm.x86.sse2.cvtsd2si64(<2 x double>) nounwind readnone
 declare i64 @llvm.x86.sse2.cvttsd2si64(<2 x double>) nounwind readnone
 
+define double @test_intrinsic_pow() nounwind uwtable ssp {
+entry:
+; CHECK: @test_intrinsic_pow
+; CHECK-NOT: call
+  %0 = call double @llvm.pow.f64(double 1.500000e+00, double 3.000000e+00)
+  ret double %0
+}
+declare double @llvm.pow.f64(double, double) nounwind readonly
+
 ; Shouldn't fold because of -fno-builtin
 define double @sin_() nounwind uwtable ssp {
 ; FNOBUILTIN: @sin_





More information about the llvm-commits mailing list