Add support for constant folding the pow intrinsic.
authorChad Rosier <mcrosier@apple.com>
Sat, 3 Dec 2011 00:00:03 +0000 (00:00 +0000)
committerChad Rosier <mcrosier@apple.com>
Sat, 3 Dec 2011 00:00:03 +0000 (00:00 +0000)
rdar://10514247

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145730 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
test/Transforms/ConstProp/calls.ll

index c4ff616575a191f0fe596e232cc29e11214b6a4b..d12476885e4036e159d164a33bc403f80b32f983 100644 (file)
@@ -1053,6 +1053,7 @@ bool
 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 @@ llvm::ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands,
                       (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 @@ llvm::ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands,
                       (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))
index b3ea122406c3ba0eac81f90a1571b70163f54425..7a405a539c51f945b3708015489f0a1597c88ed7 100644 (file)
@@ -61,6 +61,15 @@ declare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) nounwind readnone
 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_