diff --git a/include/llvm/Intrinsics.td b/include/llvm/Intrinsics.td index 4b1e419d651..ef4f0961ed5 100644 --- a/include/llvm/Intrinsics.td +++ b/include/llvm/Intrinsics.td @@ -178,18 +178,8 @@ let Properties = [IntrWriteArgMem] in { } let Properties = [IntrNoMem] in { - def int_sqrt_f32 : Intrinsic<[llvm_float_ty, llvm_float_ty]>; - def int_sqrt_f64 : Intrinsic<[llvm_double_ty, llvm_double_ty]>; - def int_sqrt_f80 : Intrinsic<[llvm_f80_ty, llvm_f80_ty]>; - def int_sqrt_f128 : Intrinsic<[llvm_f128_ty, llvm_f128_ty]>; - def int_sqrt_ppcf128 : Intrinsic<[llvm_ppcf128_ty, llvm_ppcf128_ty]>; - - def int_powi_f32 : Intrinsic<[llvm_float_ty, llvm_float_ty, llvm_i32_ty]>; - def int_powi_f64 : Intrinsic<[llvm_double_ty, llvm_double_ty, llvm_i32_ty]>; - def int_powi_f80 : Intrinsic<[llvm_f80_ty, llvm_f80_ty, llvm_i32_ty]>; - def int_powi_f128 : Intrinsic<[llvm_f128_ty, llvm_f128_ty, llvm_i32_ty]>; - def int_powi_ppcf128 : Intrinsic<[llvm_ppcf128_ty, llvm_ppcf128_ty, - llvm_i32_ty]>; + def int_sqrt : Intrinsic<[llvm_anyfloat_ty, LLVMMatchType<0>]>; + def int_powi : Intrinsic<[llvm_anyfloat_ty, LLVMMatchType<0>, llvm_i32_ty]>; } // NOTE: these are internal interfaces. diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index d68961580ec..599c7697a38 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -329,16 +329,8 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, bool llvm::canConstantFoldCallTo(Function *F) { switch (F->getIntrinsicID()) { - case Intrinsic::sqrt_f32: - case Intrinsic::sqrt_f64: - case Intrinsic::sqrt_f80: - case Intrinsic::sqrt_f128: - case Intrinsic::sqrt_ppcf128: - case Intrinsic::powi_f32: - case Intrinsic::powi_f64: - case Intrinsic::powi_f80: - case Intrinsic::powi_f128: - case Intrinsic::powi_ppcf128: + case Intrinsic::sqrt: + case Intrinsic::powi: case Intrinsic::bswap: case Intrinsic::ctpop: case Intrinsic::ctlz: @@ -539,12 +531,12 @@ llvm::ConstantFoldCall(Function *F, Constant** Operands, unsigned NumOperands) { } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast(Operands[0])) { + if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy) + return 0; double Op1V = Ty==Type::FloatTy ? (double)Op1->getValueAPF().convertToFloat(): Op1->getValueAPF().convertToDouble(); if (ConstantFP *Op2 = dyn_cast(Operands[1])) { - if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy) - return 0; double Op2V = Ty==Type::FloatTy ? (double)Op2->getValueAPF().convertToFloat(): Op2->getValueAPF().convertToDouble(); diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 0a2f0d6a517..cf47091a5c8 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -99,14 +99,20 @@ void IntrinsicLowering::AddPrototypes(Module &M) { PointerType::get(Type::Int8Ty), Type::Int32Ty, TD.getIntPtrType(), (Type *)0); break; - case Intrinsic::sqrt_f32: - case Intrinsic::sqrt_f64: - if(I->arg_begin()->getType() == Type::FloatTy) + case Intrinsic::sqrt: + switch((int)I->arg_begin()->getType()->getTypeID()) { + case Type::FloatTyID: EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(), Type::FloatTy); - else + case Type::DoubleTyID: EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(), Type::DoubleTy); + case Type::X86_FP80TyID: + case Type::FP128TyID: + case Type::PPC_FP128TyID: + EnsureFunctionExists(M, "sqrtl", I->arg_begin(), I->arg_end(), + I->arg_begin()->getType()); + } break; } } @@ -782,34 +788,27 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { MemsetFCache); break; } - case Intrinsic::sqrt_f32: { + case Intrinsic::sqrt: { static Constant *sqrtfFCache = 0; - ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(), - Type::FloatTy, sqrtfFCache); - break; - } - case Intrinsic::sqrt_f64: { static Constant *sqrtFCache = 0; - ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(), + static Constant *sqrtLDCache = 0; + switch (CI->getOperand(1)->getType()->getTypeID()) { + default: assert(0 && "Invalid type in sqrt"); abort(); + case Type::FloatTyID: + ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(), + Type::FloatTy, sqrtfFCache); + break; + case Type::DoubleTyID: + ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(), Type::DoubleTy, sqrtFCache); - break; - } - case Intrinsic::sqrt_f80: { - static Constant *sqrtF80Cache = 0; - ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(), - Type::X86_FP80Ty, sqrtF80Cache); - break; - } - case Intrinsic::sqrt_f128: { - static Constant *sqrtF128Cache = 0; - ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(), - Type::FP128Ty, sqrtF128Cache); - break; - } - case Intrinsic::sqrt_ppcf128: { - static Constant *sqrtppcF128Cache = 0; - ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(), - Type::PPC_FP128Ty, sqrtppcF128Cache); + break; + case Type::X86_FP80TyID: + case Type::FP128TyID: + case Type::PPC_FP128TyID: + ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(), + CI->getOperand(1)->getType(), sqrtLDCache); + break; + } break; } } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index b6bfd3cea33..ad4907dca01 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -2796,20 +2796,12 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { return 0; } - case Intrinsic::sqrt_f32: - case Intrinsic::sqrt_f64: - case Intrinsic::sqrt_f80: - case Intrinsic::sqrt_f128: - case Intrinsic::sqrt_ppcf128: + case Intrinsic::sqrt: setValue(&I, DAG.getNode(ISD::FSQRT, getValue(I.getOperand(1)).getValueType(), getValue(I.getOperand(1)))); return 0; - case Intrinsic::powi_f32: - case Intrinsic::powi_f64: - case Intrinsic::powi_f80: - case Intrinsic::powi_f128: - case Intrinsic::powi_ppcf128: + case Intrinsic::powi: setValue(&I, DAG.getNode(ISD::FPOWI, getValue(I.getOperand(1)).getValueType(), getValue(I.getOperand(1)), diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 6eef297dd66..343d6d7a5fa 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -2417,8 +2417,7 @@ void CWriter::lowerIntrinsics(Function &F) { case Intrinsic::longjmp: case Intrinsic::prefetch: case Intrinsic::dbg_stoppoint: - case Intrinsic::powi_f32: - case Intrinsic::powi_f64: + case Intrinsic::powi: // We directly implement these intrinsics break; default: @@ -2537,8 +2536,7 @@ void CWriter::visitCallInst(CallInst &I) { writeOperand(I.getOperand(1)); Out << ')'; return; - case Intrinsic::powi_f32: - case Intrinsic::powi_f64: + case Intrinsic::powi: Out << "__builtin_powi("; writeOperand(I.getOperand(1)); Out << ", ";