Lower llvm.sqrt -> fsqrt/sqrt
authorChris Lattner <sabre@nondot.org>
Sat, 30 Apr 2005 04:07:50 +0000 (04:07 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 30 Apr 2005 04:07:50 +0000 (04:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21629 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/IntrinsicLowering.cpp

index db3c10e7eadfdf50aaaa68a2daba9e0e6b152692..712ec0482c477d8548de178e8c34b23e032db65c 100644 (file)
@@ -110,8 +110,13 @@ void DefaultIntrinsicLowering::AddPrototypes(Module &M) {
       case Intrinsic::isunordered:
         EnsureFunctionExists(M, "isunordered", I->arg_begin(), I->arg_end(), Type::BoolTy);
         break;
+      case Intrinsic::sqrt:
+        if(I->abegin()->getType() == Type::FloatTy)
+          EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(), Type::FloatTy);
+        else
+          EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(), Type::DoubleTy);
+        break;
       }
-
 }
 
 void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
@@ -219,6 +224,17 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                              "isunordered", CI));
     break;
   }
+  case Intrinsic::sqrt: {
+    static Function *sqrtFCache = 0;
+    static Function *sqrtfFCache = 0;
+    if(CI->getType() == Type::FloatTy)
+      ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
+                      Type::FloatTy, sqrtfFCache);
+    else
+      ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
+                      Type::DoubleTy, sqrtFCache);
+    break;
+  }
   }
 
   assert(CI->use_empty() &&