mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Rewrite sqrt and powi to use anyfloat. By popular demand.
llvm-svn: 42537
This commit is contained in:
parent
24d20858a3
commit
a4e3643cb3
@ -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.
|
||||
|
@ -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<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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -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 << ", ";
|
||||
|
Loading…
Reference in New Issue
Block a user