Add the next limited-precision expansion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55856 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen 2008-09-05 21:27:19 +00:00
parent 31d26912cc
commit 852680a8fa

View File

@ -2798,10 +2798,49 @@ SelectionDAGLowering::visitLog2(CallInst &I) {
void
SelectionDAGLowering::visitLog10(CallInst &I) {
SDValue result;
if (getValue(I.getOperand(1)).getValueType() == MVT::f32 &&
LimitFloatPrecision>0 && LimitFloatPrecision<=12) {
SDValue operand = getValue(I.getOperand(1));
SDValue operand1 = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, operand);
SDValue t0 = DAG.getNode(ISD::SRL, MVT::i32, operand1,
DAG.getConstant(23, MVT::i32));
SDValue t1 = DAG.getNode(ISD::AND, MVT::i32, t0,
DAG.getConstant(255, MVT::i32));
SDValue t2 = DAG.getNode(ISD::SUB, MVT::i32, t1,
DAG.getConstant(127, MVT::i32));
SDValue t3 = DAG.getNode(ISD::UINT_TO_FP, MVT::f32, t2);
SDValue t4 = DAG.getNode(ISD::FMUL, MVT::f32, t3,
DAG.getConstantFP(APFloat(
APInt(32, 0x3e9a209a)), MVT::f32));
SDValue t5 = DAG.getNode(ISD::OR, MVT::i32, operand1,
DAG.getConstant(1065353216, MVT::i32));
SDValue t6 = DAG.getNode(ISD::AND, MVT::i32, t5,
DAG.getConstant(1073741823, MVT::i32));
SDValue t7 = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, t6);
SDValue t8 = DAG.getNode(ISD::FP_EXTEND, MVT::f64, t7);
SDValue t9 = DAG.getNode(ISD::FMUL, MVT::f64, t8,
DAG.getConstantFP(APFloat(
APInt(64, 0x3fa863e61d44a337ULL)), MVT::f64));
SDValue t10 = DAG.getNode(ISD::FSUB, MVT::f64, t9,
DAG.getConstantFP(APFloat(
APInt(64, 0x3fd443f63982ad9aULL)), MVT::f64));
SDValue t11 = DAG.getNode(ISD::FMUL, MVT::f64, t10, t8);
SDValue t12 = DAG.getNode(ISD::FADD, MVT::f64, t11,
DAG.getConstantFP(APFloat(
APInt(64, 0x3fed5c4641d8bd71ULL)), MVT::f64));
SDValue t13 = DAG.getNode(ISD::FMUL, MVT::f64, t12, t8);
SDValue t14 = DAG.getNode(ISD::FSUB, MVT::f64, t13,
DAG.getConstantFP(APFloat(
APInt(64, 0x3fe4bef863538c6fULL)), MVT::f64));
SDValue t15 = DAG.getNode(ISD::FP_ROUND, MVT::f32, t14,
DAG.getConstant(0, MVT::i32));
result = DAG.getNode(ISD::FADD, MVT::f32, t4, t15);
} else {
// No special expansion.
result = DAG.getNode(ISD::FLOG10,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
result = DAG.getNode(ISD::FLOG10,
getValue(I.getOperand(1)).getValueType(),
getValue(I.getOperand(1)));
}
setValue(&I, result);
}