Add support for FP->INT conversions and back.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19369 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-01-08 08:08:56 +00:00
parent 1645ed0b93
commit ae0aacb833
3 changed files with 42 additions and 17 deletions

View File

@ -575,6 +575,11 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
case ISD::TRUNCATE: case ISD::TRUNCATE:
case ISD::FP_EXTEND: case ISD::FP_EXTEND:
case ISD::FP_ROUND: case ISD::FP_ROUND:
case ISD::FP_TO_SINT:
case ISD::FP_TO_UINT:
case ISD::SINT_TO_FP:
case ISD::UINT_TO_FP:
switch (getTypeAction(Node->getOperand(0).getValueType())) { switch (getTypeAction(Node->getOperand(0).getValueType())) {
case Legal: case Legal:
Tmp1 = LegalizeOp(Node->getOperand(0)); Tmp1 = LegalizeOp(Node->getOperand(0));

View File

@ -396,6 +396,8 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
case ISD::SIGN_EXTEND: return getConstant(C->getSignExtended(), VT); case ISD::SIGN_EXTEND: return getConstant(C->getSignExtended(), VT);
case ISD::ZERO_EXTEND: return getConstant(Val, VT); case ISD::ZERO_EXTEND: return getConstant(Val, VT);
case ISD::TRUNCATE: return getConstant(Val, VT); case ISD::TRUNCATE: return getConstant(Val, VT);
case ISD::SINT_TO_FP: return getConstantFP(C->getSignExtended(), VT);
case ISD::UINT_TO_FP: return getConstantFP(C->getValue(), VT);
} }
} }
@ -404,6 +406,10 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
case ISD::FP_ROUND: case ISD::FP_ROUND:
case ISD::FP_EXTEND: case ISD::FP_EXTEND:
return getConstantFP(C->getValue(), VT); return getConstantFP(C->getValue(), VT);
case ISD::FP_TO_SINT:
return getConstant((int64_t)C->getValue(), VT);
case ISD::FP_TO_UINT:
return getConstant((uint64_t)C->getValue(), VT);
} }
unsigned OpOpcode = Operand.Val->getOpcode(); unsigned OpOpcode = Operand.Val->getOpcode();
@ -821,6 +827,11 @@ void SDNode::dump() const {
case ISD::FP_ROUND: std::cerr << "fp_round"; break; case ISD::FP_ROUND: std::cerr << "fp_round"; break;
case ISD::FP_EXTEND: std::cerr << "fp_extend"; break; case ISD::FP_EXTEND: std::cerr << "fp_extend"; break;
case ISD::SINT_TO_FP: std::cerr << "sint_to_fp"; break;
case ISD::UINT_TO_FP: std::cerr << "uint_to_fp"; break;
case ISD::FP_TO_SINT: std::cerr << "fp_to_sint"; break;
case ISD::FP_TO_UINT: std::cerr << "fp_to_uint"; break;
// Control flow instructions // Control flow instructions
case ISD::BR: std::cerr << "br"; break; case ISD::BR: std::cerr << "br"; break;
case ISD::BRCOND: std::cerr << "brcond"; break; case ISD::BRCOND: std::cerr << "brcond"; break;

View File

@ -434,24 +434,33 @@ void SelectionDAGLowering::visitCast(User &I) {
if (N.getValueType() == DestTy) { if (N.getValueType() == DestTy) {
setValue(&I, N); // noop cast. setValue(&I, N); // noop cast.
return; } else if (isInteger(SrcTy)) {
} else if (isInteger(SrcTy) && isInteger(DestTy)) { if (isInteger(DestTy)) { // Int -> Int cast
if (DestTy < SrcTy) // Truncating cast? if (DestTy < SrcTy) // Truncating cast?
setValue(&I, DAG.getNode(ISD::TRUNCATE, DestTy, N)); setValue(&I, DAG.getNode(ISD::TRUNCATE, DestTy, N));
else if (I.getOperand(0)->getType()->isSigned()) else if (I.getOperand(0)->getType()->isSigned())
setValue(&I, DAG.getNode(ISD::SIGN_EXTEND, DestTy, N)); setValue(&I, DAG.getNode(ISD::SIGN_EXTEND, DestTy, N));
else else
setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, DestTy, N)); setValue(&I, DAG.getNode(ISD::ZERO_EXTEND, DestTy, N));
return; } else { // Int -> FP cast
} else if (isFloatingPoint(SrcTy) && isFloatingPoint(DestTy)) { if (I.getOperand(0)->getType()->isSigned())
setValue(&I, DAG.getNode(ISD::SINT_TO_FP, DestTy, N));
else
setValue(&I, DAG.getNode(ISD::UINT_TO_FP, DestTy, N));
}
} else {
assert(isFloatingPoint(SrcTy) && "Unknown value type!");
if (isFloatingPoint(DestTy)) { // FP -> FP cast
if (DestTy < SrcTy) // Rounding cast? if (DestTy < SrcTy) // Rounding cast?
setValue(&I, DAG.getNode(ISD::FP_ROUND, DestTy, N)); setValue(&I, DAG.getNode(ISD::FP_ROUND, DestTy, N));
else else
setValue(&I, DAG.getNode(ISD::FP_EXTEND, DestTy, N)); setValue(&I, DAG.getNode(ISD::FP_EXTEND, DestTy, N));
} else { } else { // FP -> Int cast.
// F->I or I->F if (I.getType()->isSigned())
// FIXME: implement integer/fp conversions! setValue(&I, DAG.getNode(ISD::FP_TO_SINT, DestTy, N));
assert(0 && "This CAST is not yet implemented!\n"); else
setValue(&I, DAG.getNode(ISD::FP_TO_UINT, DestTy, N));
}
} }
} }