mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
Rewrite sqrt and powi to use anyfloat. By popular demand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42537 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -178,18 +178,8 @@ let Properties = [IntrWriteArgMem] in {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Properties = [IntrNoMem] in {
|
let Properties = [IntrNoMem] in {
|
||||||
def int_sqrt_f32 : Intrinsic<[llvm_float_ty, llvm_float_ty]>;
|
def int_sqrt : Intrinsic<[llvm_anyfloat_ty, LLVMMatchType<0>]>;
|
||||||
def int_sqrt_f64 : Intrinsic<[llvm_double_ty, llvm_double_ty]>;
|
def int_powi : Intrinsic<[llvm_anyfloat_ty, LLVMMatchType<0>, llvm_i32_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]>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: these are internal interfaces.
|
// NOTE: these are internal interfaces.
|
||||||
|
@@ -329,16 +329,8 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
|
|||||||
bool
|
bool
|
||||||
llvm::canConstantFoldCallTo(Function *F) {
|
llvm::canConstantFoldCallTo(Function *F) {
|
||||||
switch (F->getIntrinsicID()) {
|
switch (F->getIntrinsicID()) {
|
||||||
case Intrinsic::sqrt_f32:
|
case Intrinsic::sqrt:
|
||||||
case Intrinsic::sqrt_f64:
|
case Intrinsic::powi:
|
||||||
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::bswap:
|
case Intrinsic::bswap:
|
||||||
case Intrinsic::ctpop:
|
case Intrinsic::ctpop:
|
||||||
case Intrinsic::ctlz:
|
case Intrinsic::ctlz:
|
||||||
@@ -539,12 +531,12 @@ llvm::ConstantFoldCall(Function *F, Constant** Operands, unsigned NumOperands) {
|
|||||||
}
|
}
|
||||||
} else if (NumOperands == 2) {
|
} else if (NumOperands == 2) {
|
||||||
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
|
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
|
||||||
|
if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
|
||||||
|
return 0;
|
||||||
double Op1V = Ty==Type::FloatTy ?
|
double Op1V = Ty==Type::FloatTy ?
|
||||||
(double)Op1->getValueAPF().convertToFloat():
|
(double)Op1->getValueAPF().convertToFloat():
|
||||||
Op1->getValueAPF().convertToDouble();
|
Op1->getValueAPF().convertToDouble();
|
||||||
if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
|
if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
|
||||||
if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
|
|
||||||
return 0;
|
|
||||||
double Op2V = Ty==Type::FloatTy ?
|
double Op2V = Ty==Type::FloatTy ?
|
||||||
(double)Op2->getValueAPF().convertToFloat():
|
(double)Op2->getValueAPF().convertToFloat():
|
||||||
Op2->getValueAPF().convertToDouble();
|
Op2->getValueAPF().convertToDouble();
|
||||||
|
@@ -99,14 +99,20 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
|
|||||||
PointerType::get(Type::Int8Ty), Type::Int32Ty,
|
PointerType::get(Type::Int8Ty), Type::Int32Ty,
|
||||||
TD.getIntPtrType(), (Type *)0);
|
TD.getIntPtrType(), (Type *)0);
|
||||||
break;
|
break;
|
||||||
case Intrinsic::sqrt_f32:
|
case Intrinsic::sqrt:
|
||||||
case Intrinsic::sqrt_f64:
|
switch((int)I->arg_begin()->getType()->getTypeID()) {
|
||||||
if(I->arg_begin()->getType() == Type::FloatTy)
|
case Type::FloatTyID:
|
||||||
EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(),
|
EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(),
|
||||||
Type::FloatTy);
|
Type::FloatTy);
|
||||||
else
|
case Type::DoubleTyID:
|
||||||
EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(),
|
EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(),
|
||||||
Type::DoubleTy);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -782,34 +788,27 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
|||||||
MemsetFCache);
|
MemsetFCache);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Intrinsic::sqrt_f32: {
|
case Intrinsic::sqrt: {
|
||||||
static Constant *sqrtfFCache = 0;
|
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;
|
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);
|
Type::DoubleTy, sqrtFCache);
|
||||||
break;
|
break;
|
||||||
}
|
case Type::X86_FP80TyID:
|
||||||
case Intrinsic::sqrt_f80: {
|
case Type::FP128TyID:
|
||||||
static Constant *sqrtF80Cache = 0;
|
case Type::PPC_FP128TyID:
|
||||||
ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
|
ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
|
||||||
Type::X86_FP80Ty, sqrtF80Cache);
|
CI->getOperand(1)->getType(), sqrtLDCache);
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2796,20 +2796,12 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Intrinsic::sqrt_f32:
|
case Intrinsic::sqrt:
|
||||||
case Intrinsic::sqrt_f64:
|
|
||||||
case Intrinsic::sqrt_f80:
|
|
||||||
case Intrinsic::sqrt_f128:
|
|
||||||
case Intrinsic::sqrt_ppcf128:
|
|
||||||
setValue(&I, DAG.getNode(ISD::FSQRT,
|
setValue(&I, DAG.getNode(ISD::FSQRT,
|
||||||
getValue(I.getOperand(1)).getValueType(),
|
getValue(I.getOperand(1)).getValueType(),
|
||||||
getValue(I.getOperand(1))));
|
getValue(I.getOperand(1))));
|
||||||
return 0;
|
return 0;
|
||||||
case Intrinsic::powi_f32:
|
case Intrinsic::powi:
|
||||||
case Intrinsic::powi_f64:
|
|
||||||
case Intrinsic::powi_f80:
|
|
||||||
case Intrinsic::powi_f128:
|
|
||||||
case Intrinsic::powi_ppcf128:
|
|
||||||
setValue(&I, DAG.getNode(ISD::FPOWI,
|
setValue(&I, DAG.getNode(ISD::FPOWI,
|
||||||
getValue(I.getOperand(1)).getValueType(),
|
getValue(I.getOperand(1)).getValueType(),
|
||||||
getValue(I.getOperand(1)),
|
getValue(I.getOperand(1)),
|
||||||
|
@@ -2417,8 +2417,7 @@ void CWriter::lowerIntrinsics(Function &F) {
|
|||||||
case Intrinsic::longjmp:
|
case Intrinsic::longjmp:
|
||||||
case Intrinsic::prefetch:
|
case Intrinsic::prefetch:
|
||||||
case Intrinsic::dbg_stoppoint:
|
case Intrinsic::dbg_stoppoint:
|
||||||
case Intrinsic::powi_f32:
|
case Intrinsic::powi:
|
||||||
case Intrinsic::powi_f64:
|
|
||||||
// We directly implement these intrinsics
|
// We directly implement these intrinsics
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -2537,8 +2536,7 @@ void CWriter::visitCallInst(CallInst &I) {
|
|||||||
writeOperand(I.getOperand(1));
|
writeOperand(I.getOperand(1));
|
||||||
Out << ')';
|
Out << ')';
|
||||||
return;
|
return;
|
||||||
case Intrinsic::powi_f32:
|
case Intrinsic::powi:
|
||||||
case Intrinsic::powi_f64:
|
|
||||||
Out << "__builtin_powi(";
|
Out << "__builtin_powi(";
|
||||||
writeOperand(I.getOperand(1));
|
writeOperand(I.getOperand(1));
|
||||||
Out << ", ";
|
Out << ", ";
|
||||||
|
Reference in New Issue
Block a user