Author: johannes Date: Tue Oct 2 12:43:59 2007 New Revision: 42537 URL: http://llvm.org/viewvc/llvm-project?rev=42537&view=rev Log: Rewrite sqrt and powi to use anyfloat. By popular demand.
Modified: llvm/trunk/include/llvm/Intrinsics.td llvm/trunk/lib/Analysis/ConstantFolding.cpp llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp llvm/trunk/lib/Target/CBackend/CBackend.cpp Modified: llvm/trunk/include/llvm/Intrinsics.td URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Intrinsics.td?rev=42537&r1=42536&r2=42537&view=diff ============================================================================== --- llvm/trunk/include/llvm/Intrinsics.td (original) +++ llvm/trunk/include/llvm/Intrinsics.td Tue Oct 2 12:43:59 2007 @@ -178,18 +178,8 @@ } 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. Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=42537&r1=42536&r2=42537&view=diff ============================================================================== --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original) +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Tue Oct 2 12:43:59 2007 @@ -329,16 +329,8 @@ 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 @@ } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast<ConstantFP>(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<ConstantFP>(Operands[1])) { - if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy) - return 0; double Op2V = Ty==Type::FloatTy ? (double)Op2->getValueAPF().convertToFloat(): Op2->getValueAPF().convertToDouble(); Modified: llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp?rev=42537&r1=42536&r2=42537&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp (original) +++ llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp Tue Oct 2 12:43:59 2007 @@ -99,14 +99,20 @@ 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 @@ 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; } } Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=42537&r1=42536&r2=42537&view=diff ============================================================================== --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original) +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Tue Oct 2 12:43:59 2007 @@ -2796,20 +2796,12 @@ 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)), Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=42537&r1=42536&r2=42537&view=diff ============================================================================== --- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original) +++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Tue Oct 2 12:43:59 2007 @@ -2417,8 +2417,7 @@ 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 @@ 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 << ", "; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits