LLVM API Documentation

LegalizeFloatTypes.cpp

Go to the documentation of this file.
00001 //===-------- LegalizeFloatTypes.cpp - Legalization of float types --------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements float type expansion and softening for LegalizeTypes.
00011 // Softening is the act of turning a computation in an illegal floating point
00012 // type into a computation in an integer type of the same size; also known as
00013 // "soft float".  For example, turning f32 arithmetic into operations using i32.
00014 // The resulting integer value is the same as what you would get by performing
00015 // the floating point operation and bitcasting the result to the integer type.
00016 // Expansion is the act of changing a computation in an illegal type to be a
00017 // computation in two identical registers of a smaller type.  For example,
00018 // implementing ppcf128 arithmetic in two f64 registers.
00019 //
00020 //===----------------------------------------------------------------------===//
00021 
00022 #include "LegalizeTypes.h"
00023 #include "llvm/Support/ErrorHandling.h"
00024 #include "llvm/Support/raw_ostream.h"
00025 using namespace llvm;
00026 
00027 /// GetFPLibCall - Return the right libcall for the given floating point type.
00028 static RTLIB::Libcall GetFPLibCall(EVT VT,
00029                                    RTLIB::Libcall Call_F32,
00030                                    RTLIB::Libcall Call_F64,
00031                                    RTLIB::Libcall Call_F80,
00032                                    RTLIB::Libcall Call_PPCF128) {
00033   return
00034     VT == MVT::f32 ? Call_F32 :
00035     VT == MVT::f64 ? Call_F64 :
00036     VT == MVT::f80 ? Call_F80 :
00037     VT == MVT::ppcf128 ? Call_PPCF128 :
00038     RTLIB::UNKNOWN_LIBCALL;
00039 }
00040 
00041 //===----------------------------------------------------------------------===//
00042 //  Result Float to Integer Conversion.
00043 //===----------------------------------------------------------------------===//
00044 
00045 void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
00046   DEBUG(errs() << "Soften float result " << ResNo << ": "; N->dump(&DAG);
00047         errs() << "\n");
00048   SDValue R = SDValue();
00049 
00050   switch (N->getOpcode()) {
00051   default:
00052 #ifndef NDEBUG
00053     errs() << "SoftenFloatResult #" << ResNo << ": ";
00054     N->dump(&DAG); errs() << "\n";
00055 #endif
00056     llvm_unreachable("Do not know how to soften the result of this operator!");
00057 
00058     case ISD::BIT_CONVERT: R = SoftenFloatRes_BIT_CONVERT(N); break;
00059     case ISD::BUILD_PAIR:  R = SoftenFloatRes_BUILD_PAIR(N); break;
00060     case ISD::ConstantFP:
00061       R = SoftenFloatRes_ConstantFP(cast<ConstantFPSDNode>(N));
00062       break;
00063     case ISD::EXTRACT_VECTOR_ELT:
00064       R = SoftenFloatRes_EXTRACT_VECTOR_ELT(N); break;
00065     case ISD::FABS:        R = SoftenFloatRes_FABS(N); break;
00066     case ISD::FADD:        R = SoftenFloatRes_FADD(N); break;
00067     case ISD::FCEIL:       R = SoftenFloatRes_FCEIL(N); break;
00068     case ISD::FCOPYSIGN:   R = SoftenFloatRes_FCOPYSIGN(N); break;
00069     case ISD::FCOS:        R = SoftenFloatRes_FCOS(N); break;
00070     case ISD::FDIV:        R = SoftenFloatRes_FDIV(N); break;
00071     case ISD::FEXP:        R = SoftenFloatRes_FEXP(N); break;
00072     case ISD::FEXP2:       R = SoftenFloatRes_FEXP2(N); break;
00073     case ISD::FFLOOR:      R = SoftenFloatRes_FFLOOR(N); break;
00074     case ISD::FLOG:        R = SoftenFloatRes_FLOG(N); break;
00075     case ISD::FLOG2:       R = SoftenFloatRes_FLOG2(N); break;
00076     case ISD::FLOG10:      R = SoftenFloatRes_FLOG10(N); break;
00077     case ISD::FMUL:        R = SoftenFloatRes_FMUL(N); break;
00078     case ISD::FNEARBYINT:  R = SoftenFloatRes_FNEARBYINT(N); break;
00079     case ISD::FNEG:        R = SoftenFloatRes_FNEG(N); break;
00080     case ISD::FP_EXTEND:   R = SoftenFloatRes_FP_EXTEND(N); break;
00081     case ISD::FP_ROUND:    R = SoftenFloatRes_FP_ROUND(N); break;
00082     case ISD::FPOW:        R = SoftenFloatRes_FPOW(N); break;
00083     case ISD::FPOWI:       R = SoftenFloatRes_FPOWI(N); break;
00084     case ISD::FREM:        R = SoftenFloatRes_FREM(N); break;
00085     case ISD::FRINT:       R = SoftenFloatRes_FRINT(N); break;
00086     case ISD::FSIN:        R = SoftenFloatRes_FSIN(N); break;
00087     case ISD::FSQRT:       R = SoftenFloatRes_FSQRT(N); break;
00088     case ISD::FSUB:        R = SoftenFloatRes_FSUB(N); break;
00089     case ISD::FTRUNC:      R = SoftenFloatRes_FTRUNC(N); break;
00090     case ISD::LOAD:        R = SoftenFloatRes_LOAD(N); break;
00091     case ISD::SELECT:      R = SoftenFloatRes_SELECT(N); break;
00092     case ISD::SELECT_CC:   R = SoftenFloatRes_SELECT_CC(N); break;
00093     case ISD::SINT_TO_FP:
00094     case ISD::UINT_TO_FP:  R = SoftenFloatRes_XINT_TO_FP(N); break;
00095     case ISD::UNDEF:       R = SoftenFloatRes_UNDEF(N); break;
00096     case ISD::VAARG:       R = SoftenFloatRes_VAARG(N); break;
00097   }
00098 
00099   // If R is null, the sub-method took care of registering the result.
00100   if (R.getNode())
00101     SetSoftenedFloat(SDValue(N, ResNo), R);
00102 }
00103 
00104 SDValue DAGTypeLegalizer::SoftenFloatRes_BIT_CONVERT(SDNode *N) {
00105   return BitConvertToInteger(N->getOperand(0));
00106 }
00107 
00108 SDValue DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode *N) {
00109   // Convert the inputs to integers, and build a new pair out of them.
00110   return DAG.getNode(ISD::BUILD_PAIR, N->getDebugLoc(),
00111                      TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)),
00112                      BitConvertToInteger(N->getOperand(0)),
00113                      BitConvertToInteger(N->getOperand(1)));
00114 }
00115 
00116 SDValue DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) {
00117   return DAG.getConstant(N->getValueAPF().bitcastToAPInt(),
00118                          TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)));
00119 }
00120 
00121 SDValue DAGTypeLegalizer::SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N) {
00122   SDValue NewOp = BitConvertVectorToIntegerVector(N->getOperand(0));
00123   return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, N->getDebugLoc(),
00124                      NewOp.getValueType().getVectorElementType(),
00125                      NewOp, N->getOperand(1));
00126 }
00127 
00128 SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
00129   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00130   unsigned Size = NVT.getSizeInBits();
00131 
00132   // Mask = ~(1 << (Size-1))
00133   SDValue Mask = DAG.getConstant(APInt::getAllOnesValue(Size).clear(Size-1),
00134                                  NVT);
00135   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00136   return DAG.getNode(ISD::AND, N->getDebugLoc(), NVT, Op, Mask);
00137 }
00138 
00139 SDValue DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode *N) {
00140   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00141   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00142                      GetSoftenedFloat(N->getOperand(1)) };
00143   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00144                                   RTLIB::ADD_F32,
00145                                   RTLIB::ADD_F64,
00146                                   RTLIB::ADD_F80,
00147                                   RTLIB::ADD_PPCF128),
00148                      NVT, Ops, 2, false, N->getDebugLoc());
00149 }
00150 
00151 SDValue DAGTypeLegalizer::SoftenFloatRes_FCEIL(SDNode *N) {
00152   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00153   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00154   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00155                                   RTLIB::CEIL_F32,
00156                                   RTLIB::CEIL_F64,
00157                                   RTLIB::CEIL_F80,
00158                                   RTLIB::CEIL_PPCF128),
00159                      NVT, &Op, 1, false, N->getDebugLoc());
00160 }
00161 
00162 SDValue DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode *N) {
00163   SDValue LHS = GetSoftenedFloat(N->getOperand(0));
00164   SDValue RHS = BitConvertToInteger(N->getOperand(1));
00165   DebugLoc dl = N->getDebugLoc();
00166 
00167   EVT LVT = LHS.getValueType();
00168   EVT RVT = RHS.getValueType();
00169 
00170   unsigned LSize = LVT.getSizeInBits();
00171   unsigned RSize = RVT.getSizeInBits();
00172 
00173   // First get the sign bit of second operand.
00174   SDValue SignBit = DAG.getNode(ISD::SHL, dl, RVT, DAG.getConstant(1, RVT),
00175                                   DAG.getConstant(RSize - 1,
00176                                                   TLI.getShiftAmountTy()));
00177   SignBit = DAG.getNode(ISD::AND, dl, RVT, RHS, SignBit);
00178 
00179   // Shift right or sign-extend it if the two operands have different types.
00180   int SizeDiff = RVT.getSizeInBits() - LVT.getSizeInBits();
00181   if (SizeDiff > 0) {
00182     SignBit = DAG.getNode(ISD::SRL, dl, RVT, SignBit,
00183                           DAG.getConstant(SizeDiff, TLI.getShiftAmountTy()));
00184     SignBit = DAG.getNode(ISD::TRUNCATE, dl, LVT, SignBit);
00185   } else if (SizeDiff < 0) {
00186     SignBit = DAG.getNode(ISD::ANY_EXTEND, dl, LVT, SignBit);
00187     SignBit = DAG.getNode(ISD::SHL, dl, LVT, SignBit,
00188                           DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy()));
00189   }
00190 
00191   // Clear the sign bit of the first operand.
00192   SDValue Mask = DAG.getNode(ISD::SHL, dl, LVT, DAG.getConstant(1, LVT),
00193                                DAG.getConstant(LSize - 1,
00194                                                TLI.getShiftAmountTy()));
00195   Mask = DAG.getNode(ISD::SUB, dl, LVT, Mask, DAG.getConstant(1, LVT));
00196   LHS = DAG.getNode(ISD::AND, dl, LVT, LHS, Mask);
00197 
00198   // Or the value with the sign bit.
00199   return DAG.getNode(ISD::OR, dl, LVT, LHS, SignBit);
00200 }
00201 
00202 SDValue DAGTypeLegalizer::SoftenFloatRes_FCOS(SDNode *N) {
00203   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00204   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00205   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00206                                   RTLIB::COS_F32,
00207                                   RTLIB::COS_F64,
00208                                   RTLIB::COS_F80,
00209                                   RTLIB::COS_PPCF128),
00210                      NVT, &Op, 1, false, N->getDebugLoc());
00211 }
00212 
00213 SDValue DAGTypeLegalizer::SoftenFloatRes_FDIV(SDNode *N) {
00214   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00215   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00216                      GetSoftenedFloat(N->getOperand(1)) };
00217   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00218                                   RTLIB::DIV_F32,
00219                                   RTLIB::DIV_F64,
00220                                   RTLIB::DIV_F80,
00221                                   RTLIB::DIV_PPCF128),
00222                      NVT, Ops, 2, false, N->getDebugLoc());
00223 }
00224 
00225 SDValue DAGTypeLegalizer::SoftenFloatRes_FEXP(SDNode *N) {
00226   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00227   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00228   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00229                                   RTLIB::EXP_F32,
00230                                   RTLIB::EXP_F64,
00231                                   RTLIB::EXP_F80,
00232                                   RTLIB::EXP_PPCF128),
00233                      NVT, &Op, 1, false, N->getDebugLoc());
00234 }
00235 
00236 SDValue DAGTypeLegalizer::SoftenFloatRes_FEXP2(SDNode *N) {
00237   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00238   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00239   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00240                                   RTLIB::EXP2_F32,
00241                                   RTLIB::EXP2_F64,
00242                                   RTLIB::EXP2_F80,
00243                                   RTLIB::EXP2_PPCF128),
00244                      NVT, &Op, 1, false, N->getDebugLoc());
00245 }
00246 
00247 SDValue DAGTypeLegalizer::SoftenFloatRes_FFLOOR(SDNode *N) {
00248   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00249   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00250   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00251                                   RTLIB::FLOOR_F32,
00252                                   RTLIB::FLOOR_F64,
00253                                   RTLIB::FLOOR_F80,
00254                                   RTLIB::FLOOR_PPCF128),
00255                      NVT, &Op, 1, false, N->getDebugLoc());
00256 }
00257 
00258 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG(SDNode *N) {
00259   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00260   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00261   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00262                                   RTLIB::LOG_F32,
00263                                   RTLIB::LOG_F64,
00264                                   RTLIB::LOG_F80,
00265                                   RTLIB::LOG_PPCF128),
00266                      NVT, &Op, 1, false, N->getDebugLoc());
00267 }
00268 
00269 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG2(SDNode *N) {
00270   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00271   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00272   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00273                                   RTLIB::LOG2_F32,
00274                                   RTLIB::LOG2_F64,
00275                                   RTLIB::LOG2_F80,
00276                                   RTLIB::LOG2_PPCF128),
00277                      NVT, &Op, 1, false, N->getDebugLoc());
00278 }
00279 
00280 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG10(SDNode *N) {
00281   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00282   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00283   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00284                                   RTLIB::LOG10_F32,
00285                                   RTLIB::LOG10_F64,
00286                                   RTLIB::LOG10_F80,
00287                                   RTLIB::LOG10_PPCF128),
00288                      NVT, &Op, 1, false, N->getDebugLoc());
00289 }
00290 
00291 SDValue DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode *N) {
00292   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00293   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00294                      GetSoftenedFloat(N->getOperand(1)) };
00295   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00296                                   RTLIB::MUL_F32,
00297                                   RTLIB::MUL_F64,
00298                                   RTLIB::MUL_F80,
00299                                   RTLIB::MUL_PPCF128),
00300                      NVT, Ops, 2, false, N->getDebugLoc());
00301 }
00302 
00303 SDValue DAGTypeLegalizer::SoftenFloatRes_FNEARBYINT(SDNode *N) {
00304   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00305   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00306   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00307                                   RTLIB::NEARBYINT_F32,
00308                                   RTLIB::NEARBYINT_F64,
00309                                   RTLIB::NEARBYINT_F80,
00310                                   RTLIB::NEARBYINT_PPCF128),
00311                      NVT, &Op, 1, false, N->getDebugLoc());
00312 }
00313 
00314 SDValue DAGTypeLegalizer::SoftenFloatRes_FNEG(SDNode *N) {
00315   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00316   // Expand Y = FNEG(X) -> Y = SUB -0.0, X
00317   SDValue Ops[2] = { DAG.getConstantFP(-0.0, N->getValueType(0)),
00318                      GetSoftenedFloat(N->getOperand(0)) };
00319   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00320                                   RTLIB::SUB_F32,
00321                                   RTLIB::SUB_F64,
00322                                   RTLIB::SUB_F80,
00323                                   RTLIB::SUB_PPCF128),
00324                      NVT, Ops, 2, false, N->getDebugLoc());
00325 }
00326 
00327 SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
00328   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00329   SDValue Op = N->getOperand(0);
00330   RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
00331   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
00332   return MakeLibCall(LC, NVT, &Op, 1, false, N->getDebugLoc());
00333 }
00334 
00335 SDValue DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) {
00336   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00337   SDValue Op = N->getOperand(0);
00338   RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), N->getValueType(0));
00339   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
00340   return MakeLibCall(LC, NVT, &Op, 1, false, N->getDebugLoc());
00341 }
00342 
00343 SDValue DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode *N) {
00344   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00345   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00346                      GetSoftenedFloat(N->getOperand(1)) };
00347   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00348                                   RTLIB::POW_F32,
00349                                   RTLIB::POW_F64,
00350                                   RTLIB::POW_F80,
00351                                   RTLIB::POW_PPCF128),
00352                      NVT, Ops, 2, false, N->getDebugLoc());
00353 }
00354 
00355 SDValue DAGTypeLegalizer::SoftenFloatRes_FPOWI(SDNode *N) {
00356   assert(N->getOperand(1).getValueType() == MVT::i32 &&
00357          "Unsupported power type!");
00358   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00359   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)), N->getOperand(1) };
00360   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00361                                   RTLIB::POWI_F32,
00362                                   RTLIB::POWI_F64,
00363                                   RTLIB::POWI_F80,
00364                                   RTLIB::POWI_PPCF128),
00365                      NVT, Ops, 2, false, N->getDebugLoc());
00366 }
00367 
00368 SDValue DAGTypeLegalizer::SoftenFloatRes_FREM(SDNode *N) {
00369   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00370   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00371                      GetSoftenedFloat(N->getOperand(1)) };
00372   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00373                                   RTLIB::REM_F32,
00374                                   RTLIB::REM_F64,
00375                                   RTLIB::REM_F80,
00376                                   RTLIB::REM_PPCF128),
00377                      NVT, Ops, 2, false, N->getDebugLoc());
00378 }
00379 
00380 SDValue DAGTypeLegalizer::SoftenFloatRes_FRINT(SDNode *N) {
00381   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00382   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00383   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00384                                   RTLIB::RINT_F32,
00385                                   RTLIB::RINT_F64,
00386                                   RTLIB::RINT_F80,
00387                                   RTLIB::RINT_PPCF128),
00388                      NVT, &Op, 1, false, N->getDebugLoc());
00389 }
00390 
00391 SDValue DAGTypeLegalizer::SoftenFloatRes_FSIN(SDNode *N) {
00392   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00393   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00394   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00395                                   RTLIB::SIN_F32,
00396                                   RTLIB::SIN_F64,
00397                                   RTLIB::SIN_F80,
00398                                   RTLIB::SIN_PPCF128),
00399                      NVT, &Op, 1, false, N->getDebugLoc());
00400 }
00401 
00402 SDValue DAGTypeLegalizer::SoftenFloatRes_FSQRT(SDNode *N) {
00403   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00404   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00405   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00406                                   RTLIB::SQRT_F32,
00407                                   RTLIB::SQRT_F64,
00408                                   RTLIB::SQRT_F80,
00409                                   RTLIB::SQRT_PPCF128),
00410                      NVT, &Op, 1, false, N->getDebugLoc());
00411 }
00412 
00413 SDValue DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode *N) {
00414   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00415   SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
00416                      GetSoftenedFloat(N->getOperand(1)) };
00417   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00418                                   RTLIB::SUB_F32,
00419                                   RTLIB::SUB_F64,
00420                                   RTLIB::SUB_F80,
00421                                   RTLIB::SUB_PPCF128),
00422                      NVT, Ops, 2, false, N->getDebugLoc());
00423 }
00424 
00425 SDValue DAGTypeLegalizer::SoftenFloatRes_FTRUNC(SDNode *N) {
00426   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00427   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00428   return MakeLibCall(GetFPLibCall(N->getValueType(0),
00429                                   RTLIB::TRUNC_F32,
00430                                   RTLIB::TRUNC_F64,
00431                                   RTLIB::TRUNC_F80,
00432                                   RTLIB::TRUNC_PPCF128),
00433                      NVT, &Op, 1, false, N->getDebugLoc());
00434 }
00435 
00436 SDValue DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode *N) {
00437   LoadSDNode *L = cast<LoadSDNode>(N);
00438   EVT VT = N->getValueType(0);
00439   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
00440   DebugLoc dl = N->getDebugLoc();
00441 
00442   SDValue NewL;
00443   if (L->getExtensionType() == ISD::NON_EXTLOAD) {
00444     NewL = DAG.getLoad(L->getAddressingMode(), dl, L->getExtensionType(),
00445                        NVT, L->getChain(), L->getBasePtr(), L->getOffset(),
00446                        L->getSrcValue(), L->getSrcValueOffset(), NVT,
00447                        L->isVolatile(), L->getAlignment());
00448     // Legalized the chain result - switch anything that used the old chain to
00449     // use the new one.
00450     ReplaceValueWith(SDValue(N, 1), NewL.getValue(1));
00451     return NewL;
00452   }
00453 
00454   // Do a non-extending load followed by FP_EXTEND.
00455   NewL = DAG.getLoad(L->getAddressingMode(), dl, ISD::NON_EXTLOAD,
00456                      L->getMemoryVT(), L->getChain(),
00457                      L->getBasePtr(), L->getOffset(),
00458                      L->getSrcValue(), L->getSrcValueOffset(),
00459                      L->getMemoryVT(),
00460                      L->isVolatile(), L->getAlignment());
00461   // Legalized the chain result - switch anything that used the old chain to
00462   // use the new one.
00463   ReplaceValueWith(SDValue(N, 1), NewL.getValue(1));
00464   return BitConvertToInteger(DAG.getNode(ISD::FP_EXTEND, dl, VT, NewL));
00465 }
00466 
00467 SDValue DAGTypeLegalizer::SoftenFloatRes_SELECT(SDNode *N) {
00468   SDValue LHS = GetSoftenedFloat(N->getOperand(1));
00469   SDValue RHS = GetSoftenedFloat(N->getOperand(2));
00470   return DAG.getNode(ISD::SELECT, N->getDebugLoc(),
00471                      LHS.getValueType(), N->getOperand(0),LHS,RHS);
00472 }
00473 
00474 SDValue DAGTypeLegalizer::SoftenFloatRes_SELECT_CC(SDNode *N) {
00475   SDValue LHS = GetSoftenedFloat(N->getOperand(2));
00476   SDValue RHS = GetSoftenedFloat(N->getOperand(3));
00477   return DAG.getNode(ISD::SELECT_CC, N->getDebugLoc(),
00478                      LHS.getValueType(), N->getOperand(0),
00479                      N->getOperand(1), LHS, RHS, N->getOperand(4));
00480 }
00481 
00482 SDValue DAGTypeLegalizer::SoftenFloatRes_UNDEF(SDNode *N) {
00483   return DAG.getUNDEF(TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0)));
00484 }
00485 
00486 SDValue DAGTypeLegalizer::SoftenFloatRes_VAARG(SDNode *N) {
00487   SDValue Chain = N->getOperand(0); // Get the chain.
00488   SDValue Ptr = N->getOperand(1); // Get the pointer.
00489   EVT VT = N->getValueType(0);
00490   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
00491   DebugLoc dl = N->getDebugLoc();
00492 
00493   SDValue NewVAARG;
00494   NewVAARG = DAG.getVAArg(NVT, dl, Chain, Ptr, N->getOperand(2));
00495 
00496   // Legalized the chain result - switch anything that used the old chain to
00497   // use the new one.
00498   ReplaceValueWith(SDValue(N, 1), NewVAARG.getValue(1));
00499   return NewVAARG;
00500 }
00501 
00502 SDValue DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode *N) {
00503   bool Signed = N->getOpcode() == ISD::SINT_TO_FP;
00504   EVT SVT = N->getOperand(0).getValueType();
00505   EVT RVT = N->getValueType(0);
00506   EVT NVT = EVT();
00507   DebugLoc dl = N->getDebugLoc();
00508 
00509   // If the input is not legal, eg: i1 -> fp, then it needs to be promoted to
00510   // a larger type, eg: i8 -> fp.  Even if it is legal, no libcall may exactly
00511   // match.  Look for an appropriate libcall.
00512   RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
00513   for (unsigned t = MVT::FIRST_INTEGER_VALUETYPE;
00514        t <= MVT::LAST_INTEGER_VALUETYPE && LC == RTLIB::UNKNOWN_LIBCALL; ++t) {
00515     NVT = (MVT::SimpleValueType)t;
00516     // The source needs to big enough to hold the operand.
00517     if (NVT.bitsGE(SVT))
00518       LC = Signed ? RTLIB::getSINTTOFP(NVT, RVT):RTLIB::getUINTTOFP (NVT, RVT);
00519   }
00520   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
00521 
00522   // Sign/zero extend the argument if the libcall takes a larger type.
00523   SDValue Op = DAG.getNode(Signed ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
00524                            NVT, N->getOperand(0));
00525   return MakeLibCall(LC, TLI.getTypeToTransformTo(*DAG.getContext(), RVT), &Op, 1, false, dl);
00526 }
00527 
00528 
00529 //===----------------------------------------------------------------------===//
00530 //  Operand Float to Integer Conversion..
00531 //===----------------------------------------------------------------------===//
00532 
00533 bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
00534   DEBUG(errs() << "Soften float operand " << OpNo << ": "; N->dump(&DAG);
00535         errs() << "\n");
00536   SDValue Res = SDValue();
00537 
00538   switch (N->getOpcode()) {
00539   default:
00540 #ifndef NDEBUG
00541     errs() << "SoftenFloatOperand Op #" << OpNo << ": ";
00542     N->dump(&DAG); errs() << "\n";
00543 #endif
00544     llvm_unreachable("Do not know how to soften this operator's operand!");
00545 
00546   case ISD::BIT_CONVERT: Res = SoftenFloatOp_BIT_CONVERT(N); break;
00547   case ISD::BR_CC:       Res = SoftenFloatOp_BR_CC(N); break;
00548   case ISD::FP_ROUND:    Res = SoftenFloatOp_FP_ROUND(N); break;
00549   case ISD::FP_TO_SINT:  Res = SoftenFloatOp_FP_TO_SINT(N); break;
00550   case ISD::FP_TO_UINT:  Res = SoftenFloatOp_FP_TO_UINT(N); break;
00551   case ISD::SELECT_CC:   Res = SoftenFloatOp_SELECT_CC(N); break;
00552   case ISD::SETCC:       Res = SoftenFloatOp_SETCC(N); break;
00553   case ISD::STORE:       Res = SoftenFloatOp_STORE(N, OpNo); break;
00554   }
00555 
00556   // If the result is null, the sub-method took care of registering results etc.
00557   if (!Res.getNode()) return false;
00558 
00559   // If the result is N, the sub-method updated N in place.  Tell the legalizer
00560   // core about this.
00561   if (Res.getNode() == N)
00562     return true;
00563 
00564   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
00565          "Invalid operand expansion");
00566 
00567   ReplaceValueWith(SDValue(N, 0), Res);
00568   return false;
00569 }
00570 
00571 /// SoftenSetCCOperands - Soften the operands of a comparison.  This code is
00572 /// shared among BR_CC, SELECT_CC, and SETCC handlers.
00573 void DAGTypeLegalizer::SoftenSetCCOperands(SDValue &NewLHS, SDValue &NewRHS,
00574                                            ISD::CondCode &CCCode, DebugLoc dl) {
00575   SDValue LHSInt = GetSoftenedFloat(NewLHS);
00576   SDValue RHSInt = GetSoftenedFloat(NewRHS);
00577   EVT VT = NewLHS.getValueType();
00578 
00579   assert((VT == MVT::f32 || VT == MVT::f64) && "Unsupported setcc type!");
00580 
00581   // Expand into one or more soft-fp libcall(s).
00582   RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL;
00583   switch (CCCode) {
00584   case ISD::SETEQ:
00585   case ISD::SETOEQ:
00586     LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
00587     break;
00588   case ISD::SETNE:
00589   case ISD::SETUNE:
00590     LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64;
00591     break;
00592   case ISD::SETGE:
00593   case ISD::SETOGE:
00594     LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
00595     break;
00596   case ISD::SETLT:
00597   case ISD::SETOLT:
00598     LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
00599     break;
00600   case ISD::SETLE:
00601   case ISD::SETOLE:
00602     LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
00603     break;
00604   case ISD::SETGT:
00605   case ISD::SETOGT:
00606     LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
00607     break;
00608   case ISD::SETUO:
00609     LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
00610     break;
00611   case ISD::SETO:
00612     LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64;
00613     break;
00614   default:
00615     LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
00616     switch (CCCode) {
00617     case ISD::SETONE:
00618       // SETONE = SETOLT | SETOGT
00619       LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
00620       // Fallthrough
00621     case ISD::SETUGT:
00622       LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
00623       break;
00624     case ISD::SETUGE:
00625       LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
00626       break;
00627     case ISD::SETULT:
00628       LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
00629       break;
00630     case ISD::SETULE:
00631       LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
00632       break;
00633     case ISD::SETUEQ:
00634       LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
00635       break;
00636     default: assert(false && "Do not know how to soften this setcc!");
00637     }
00638   }
00639 
00640   EVT RetVT = MVT::i32; // FIXME: is this the correct return type?
00641   SDValue Ops[2] = { LHSInt, RHSInt };
00642   NewLHS = MakeLibCall(LC1, RetVT, Ops, 2, false/*sign irrelevant*/, dl);
00643   NewRHS = DAG.getConstant(0, RetVT);
00644   CCCode = TLI.getCmpLibcallCC(LC1);
00645   if (LC2 != RTLIB::UNKNOWN_LIBCALL) {
00646     SDValue Tmp = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(RetVT),
00647                                 NewLHS, NewRHS, DAG.getCondCode(CCCode));
00648     NewLHS = MakeLibCall(LC2, RetVT, Ops, 2, false/*sign irrelevant*/, dl);
00649     NewLHS = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(RetVT), NewLHS,
00650                          NewRHS, DAG.getCondCode(TLI.getCmpLibcallCC(LC2)));
00651     NewLHS = DAG.getNode(ISD::OR, dl, Tmp.getValueType(), Tmp, NewLHS);
00652     NewRHS = SDValue();
00653   }
00654 }
00655 
00656 SDValue DAGTypeLegalizer::SoftenFloatOp_BIT_CONVERT(SDNode *N) {
00657   return DAG.getNode(ISD::BIT_CONVERT, N->getDebugLoc(), N->getValueType(0),
00658                      GetSoftenedFloat(N->getOperand(0)));
00659 }
00660 
00661 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode *N) {
00662   EVT SVT = N->getOperand(0).getValueType();
00663   EVT RVT = N->getValueType(0);
00664 
00665   RTLIB::Libcall LC = RTLIB::getFPROUND(SVT, RVT);
00666   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND libcall");
00667 
00668   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00669   return MakeLibCall(LC, RVT, &Op, 1, false, N->getDebugLoc());
00670 }
00671 
00672 SDValue DAGTypeLegalizer::SoftenFloatOp_BR_CC(SDNode *N) {
00673   SDValue NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
00674   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
00675   SoftenSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
00676 
00677   // If SoftenSetCCOperands returned a scalar, we need to compare the result
00678   // against zero to select between true and false values.
00679   if (NewRHS.getNode() == 0) {
00680     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
00681     CCCode = ISD::SETNE;
00682   }
00683 
00684   // Update N to have the operands specified.
00685   return DAG.UpdateNodeOperands(SDValue(N, 0), N->getOperand(0),
00686                                 DAG.getCondCode(CCCode), NewLHS, NewRHS,
00687                                 N->getOperand(4));
00688 }
00689 
00690 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_TO_SINT(SDNode *N) {
00691   EVT RVT = N->getValueType(0);
00692   RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
00693   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
00694   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00695   return MakeLibCall(LC, RVT, &Op, 1, false, N->getDebugLoc());
00696 }
00697 
00698 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_TO_UINT(SDNode *N) {
00699   EVT RVT = N->getValueType(0);
00700   RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
00701   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
00702   SDValue Op = GetSoftenedFloat(N->getOperand(0));
00703   return MakeLibCall(LC, RVT, &Op, 1, false, N->getDebugLoc());
00704 }
00705 
00706 SDValue DAGTypeLegalizer::SoftenFloatOp_SELECT_CC(SDNode *N) {
00707   SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
00708   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
00709   SoftenSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
00710 
00711   // If SoftenSetCCOperands returned a scalar, we need to compare the result
00712   // against zero to select between true and false values.
00713   if (NewRHS.getNode() == 0) {
00714     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
00715     CCCode = ISD::SETNE;
00716   }
00717 
00718   // Update N to have the operands specified.
00719   return DAG.UpdateNodeOperands(SDValue(N, 0), NewLHS, NewRHS,
00720                                 N->getOperand(2), N->getOperand(3),
00721                                 DAG.getCondCode(CCCode));
00722 }
00723 
00724 SDValue DAGTypeLegalizer::SoftenFloatOp_SETCC(SDNode *N) {
00725   SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
00726   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
00727   SoftenSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
00728 
00729   // If SoftenSetCCOperands returned a scalar, use it.
00730   if (NewRHS.getNode() == 0) {
00731     assert(NewLHS.getValueType() == N->getValueType(0) &&
00732            "Unexpected setcc expansion!");
00733     return NewLHS;
00734   }
00735 
00736   // Otherwise, update N to have the operands specified.
00737   return DAG.UpdateNodeOperands(SDValue(N, 0), NewLHS, NewRHS,
00738                                 DAG.getCondCode(CCCode));
00739 }
00740 
00741 SDValue DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode *N, unsigned OpNo) {
00742   assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
00743   assert(OpNo == 1 && "Can only soften the stored value!");
00744   StoreSDNode *ST = cast<StoreSDNode>(N);
00745   SDValue Val = ST->getValue();
00746   DebugLoc dl = N->getDebugLoc();
00747 
00748   if (ST->isTruncatingStore())
00749     // Do an FP_ROUND followed by a non-truncating store.
00750     Val = BitConvertToInteger(DAG.getNode(ISD::FP_ROUND, dl, ST->getMemoryVT(),
00751                                           Val, DAG.getIntPtrConstant(0)));
00752   else
00753     Val = GetSoftenedFloat(Val);
00754 
00755   return DAG.getStore(ST->getChain(), dl, Val, ST->getBasePtr(),
00756                       ST->getSrcValue(), ST->getSrcValueOffset(),
00757                       ST->isVolatile(), ST->getAlignment());
00758 }
00759 
00760 
00761 //===----------------------------------------------------------------------===//
00762 //  Float Result Expansion
00763 //===----------------------------------------------------------------------===//
00764 
00765 /// ExpandFloatResult - This method is called when the specified result of the
00766 /// specified node is found to need expansion.  At this point, the node may also
00767 /// have invalid operands or may have other results that need promotion, we just
00768 /// know that (at least) one result needs expansion.
00769 void DAGTypeLegalizer::ExpandFloatResult(SDNode *N, unsigned ResNo) {
00770   DEBUG(errs() << "Expand float result: "; N->dump(&DAG); errs() << "\n");
00771   SDValue Lo, Hi;
00772   Lo = Hi = SDValue();
00773 
00774   // See if the target wants to custom expand this node.
00775   if (CustomLowerNode(N, N->getValueType(ResNo), true))
00776     return;
00777 
00778   switch (N->getOpcode()) {
00779   default:
00780 #ifndef NDEBUG
00781     errs() << "ExpandFloatResult #" << ResNo << ": ";
00782     N->dump(&DAG); errs() << "\n";
00783 #endif
00784     llvm_unreachable("Do not know how to expand the result of this operator!");
00785 
00786   case ISD::MERGE_VALUES: SplitRes_MERGE_VALUES(N, Lo, Hi); break;
00787   case ISD::UNDEF:        SplitRes_UNDEF(N, Lo, Hi); break;
00788   case ISD::SELECT:       SplitRes_SELECT(N, Lo, Hi); break;
00789   case ISD::SELECT_CC:    SplitRes_SELECT_CC(N, Lo, Hi); break;
00790 
00791   case ISD::BIT_CONVERT:        ExpandRes_BIT_CONVERT(N, Lo, Hi); break;
00792   case ISD::BUILD_PAIR:         ExpandRes_BUILD_PAIR(N, Lo, Hi); break;
00793   case ISD::EXTRACT_ELEMENT:    ExpandRes_EXTRACT_ELEMENT(N, Lo, Hi); break;
00794   case ISD::EXTRACT_VECTOR_ELT: ExpandRes_EXTRACT_VECTOR_ELT(N, Lo, Hi); break;
00795   case ISD::VAARG:              ExpandRes_VAARG(N, Lo, Hi); break;
00796 
00797   case ISD::ConstantFP: ExpandFloatRes_ConstantFP(N, Lo, Hi); break;
00798   case ISD::FABS:       ExpandFloatRes_FABS(N, Lo, Hi); break;
00799   case ISD::FADD:       ExpandFloatRes_FADD(N, Lo, Hi); break;
00800   case ISD::FCEIL:      ExpandFloatRes_FCEIL(N, Lo, Hi); break;
00801   case ISD::FCOS:       ExpandFloatRes_FCOS(N, Lo, Hi); break;
00802   case ISD::FDIV:       ExpandFloatRes_FDIV(N, Lo, Hi); break;
00803   case ISD::FEXP:       ExpandFloatRes_FEXP(N, Lo, Hi); break;
00804   case ISD::FEXP2:      ExpandFloatRes_FEXP2(N, Lo, Hi); break;
00805   case ISD::FFLOOR:     ExpandFloatRes_FFLOOR(N, Lo, Hi); break;
00806   case ISD::FLOG:       ExpandFloatRes_FLOG(N, Lo, Hi); break;
00807   case ISD::FLOG2:      ExpandFloatRes_FLOG2(N, Lo, Hi); break;
00808   case ISD::FLOG10:     ExpandFloatRes_FLOG10(N, Lo, Hi); break;
00809   case ISD::FMUL:       ExpandFloatRes_FMUL(N, Lo, Hi); break;
00810   case ISD::FNEARBYINT: ExpandFloatRes_FNEARBYINT(N, Lo, Hi); break;
00811   case ISD::FNEG:       ExpandFloatRes_FNEG(N, Lo, Hi); break;
00812   case ISD::FP_EXTEND:  ExpandFloatRes_FP_EXTEND(N, Lo, Hi); break;
00813   case ISD::FPOW:       ExpandFloatRes_FPOW(N, Lo, Hi); break;
00814   case ISD::FPOWI:      ExpandFloatRes_FPOWI(N, Lo, Hi); break;
00815   case ISD::FRINT:      ExpandFloatRes_FRINT(N, Lo, Hi); break;
00816   case ISD::FSIN:       ExpandFloatRes_FSIN(N, Lo, Hi); break;
00817   case ISD::FSQRT:      ExpandFloatRes_FSQRT(N, Lo, Hi); break;
00818   case ISD::FSUB:       ExpandFloatRes_FSUB(N, Lo, Hi); break;
00819   case ISD::FTRUNC:     ExpandFloatRes_FTRUNC(N, Lo, Hi); break;
00820   case ISD::LOAD:       ExpandFloatRes_LOAD(N, Lo, Hi); break;
00821   case ISD::SINT_TO_FP:
00822   case ISD::UINT_TO_FP: ExpandFloatRes_XINT_TO_FP(N, Lo, Hi); break;
00823   }
00824 
00825   // If Lo/Hi is null, the sub-method took care of registering results etc.
00826   if (Lo.getNode())
00827     SetExpandedFloat(SDValue(N, ResNo), Lo, Hi);
00828 }
00829 
00830 void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo,
00831                                                  SDValue &Hi) {
00832   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00833   assert(NVT.getSizeInBits() == integerPartWidth &&
00834          "Do not know how to expand this float constant!");
00835   APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().bitcastToAPInt();
00836   Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
00837                                        &C.getRawData()[1])), NVT);
00838   Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
00839                                        &C.getRawData()[0])), NVT);
00840 }
00841 
00842 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDValue &Lo,
00843                                            SDValue &Hi) {
00844   assert(N->getValueType(0) == MVT::ppcf128 &&
00845          "Logic only correct for ppcf128!");
00846   DebugLoc dl = N->getDebugLoc();
00847   SDValue Tmp;
00848   GetExpandedFloat(N->getOperand(0), Lo, Tmp);
00849   Hi = DAG.getNode(ISD::FABS, dl, Tmp.getValueType(), Tmp);
00850   // Lo = Hi==fabs(Hi) ? Lo : -Lo;
00851   Lo = DAG.getNode(ISD::SELECT_CC, dl, Lo.getValueType(), Tmp, Hi, Lo,
00852                    DAG.getNode(ISD::FNEG, dl, Lo.getValueType(), Lo),
00853                    DAG.getCondCode(ISD::SETEQ));
00854 }
00855 
00856 void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode *N, SDValue &Lo,
00857                                            SDValue &Hi) {
00858   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00859                                          RTLIB::ADD_F32, RTLIB::ADD_F64,
00860                                          RTLIB::ADD_F80, RTLIB::ADD_PPCF128),
00861                             N, false);
00862   GetPairElements(Call, Lo, Hi);
00863 }
00864 
00865 void DAGTypeLegalizer::ExpandFloatRes_FCEIL(SDNode *N,
00866                                             SDValue &Lo, SDValue &Hi) {
00867   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00868                                          RTLIB::CEIL_F32, RTLIB::CEIL_F64,
00869                                          RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128),
00870                             N, false);
00871   GetPairElements(Call, Lo, Hi);
00872 }
00873 
00874 void DAGTypeLegalizer::ExpandFloatRes_FCOS(SDNode *N,
00875                                            SDValue &Lo, SDValue &Hi) {
00876   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00877                                          RTLIB::COS_F32, RTLIB::COS_F64,
00878                                          RTLIB::COS_F80, RTLIB::COS_PPCF128),
00879                             N, false);
00880   GetPairElements(Call, Lo, Hi);
00881 }
00882 
00883 void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode *N, SDValue &Lo,
00884                                            SDValue &Hi) {
00885   SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
00886   SDValue Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
00887                                           RTLIB::DIV_F32,
00888                                           RTLIB::DIV_F64,
00889                                           RTLIB::DIV_F80,
00890                                           RTLIB::DIV_PPCF128),
00891                              N->getValueType(0), Ops, 2, false,
00892                              N->getDebugLoc());
00893   GetPairElements(Call, Lo, Hi);
00894 }
00895 
00896 void DAGTypeLegalizer::ExpandFloatRes_FEXP(SDNode *N,
00897                                            SDValue &Lo, SDValue &Hi) {
00898   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00899                                          RTLIB::EXP_F32, RTLIB::EXP_F64,
00900                                          RTLIB::EXP_F80, RTLIB::EXP_PPCF128),
00901                             N, false);
00902   GetPairElements(Call, Lo, Hi);
00903 }
00904 
00905 void DAGTypeLegalizer::ExpandFloatRes_FEXP2(SDNode *N,
00906                                             SDValue &Lo, SDValue &Hi) {
00907   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00908                                          RTLIB::EXP2_F32, RTLIB::EXP2_F64,
00909                                          RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128),
00910                             N, false);
00911   GetPairElements(Call, Lo, Hi);
00912 }
00913 
00914 void DAGTypeLegalizer::ExpandFloatRes_FFLOOR(SDNode *N,
00915                                              SDValue &Lo, SDValue &Hi) {
00916   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00917                                          RTLIB::FLOOR_F32,RTLIB::FLOOR_F64,
00918                                          RTLIB::FLOOR_F80,RTLIB::FLOOR_PPCF128),
00919                             N, false);
00920   GetPairElements(Call, Lo, Hi);
00921 }
00922 
00923 void DAGTypeLegalizer::ExpandFloatRes_FLOG(SDNode *N,
00924                                            SDValue &Lo, SDValue &Hi) {
00925   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00926                                          RTLIB::LOG_F32, RTLIB::LOG_F64,
00927                                          RTLIB::LOG_F80, RTLIB::LOG_PPCF128),
00928                             N, false);
00929   GetPairElements(Call, Lo, Hi);
00930 }
00931 
00932 void DAGTypeLegalizer::ExpandFloatRes_FLOG2(SDNode *N,
00933                                             SDValue &Lo, SDValue &Hi) {
00934   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00935                                          RTLIB::LOG2_F32, RTLIB::LOG2_F64,
00936                                          RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128),
00937                             N, false);
00938   GetPairElements(Call, Lo, Hi);
00939 }
00940 
00941 void DAGTypeLegalizer::ExpandFloatRes_FLOG10(SDNode *N,
00942                                              SDValue &Lo, SDValue &Hi) {
00943   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00944                                          RTLIB::LOG10_F32,RTLIB::LOG10_F64,
00945                                          RTLIB::LOG10_F80,RTLIB::LOG10_PPCF128),
00946                             N, false);
00947   GetPairElements(Call, Lo, Hi);
00948 }
00949 
00950 void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode *N, SDValue &Lo,
00951                                            SDValue &Hi) {
00952   SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
00953   SDValue Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
00954                                           RTLIB::MUL_F32,
00955                                           RTLIB::MUL_F64,
00956                                           RTLIB::MUL_F80,
00957                                           RTLIB::MUL_PPCF128),
00958                              N->getValueType(0), Ops, 2, false,
00959                              N->getDebugLoc());
00960   GetPairElements(Call, Lo, Hi);
00961 }
00962 
00963 void DAGTypeLegalizer::ExpandFloatRes_FNEARBYINT(SDNode *N,
00964                                                  SDValue &Lo, SDValue &Hi) {
00965   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00966                                          RTLIB::NEARBYINT_F32,
00967                                          RTLIB::NEARBYINT_F64,
00968                                          RTLIB::NEARBYINT_F80,
00969                                          RTLIB::NEARBYINT_PPCF128),
00970                             N, false);
00971   GetPairElements(Call, Lo, Hi);
00972 }
00973 
00974 void DAGTypeLegalizer::ExpandFloatRes_FNEG(SDNode *N, SDValue &Lo,
00975                                            SDValue &Hi) {
00976   DebugLoc dl = N->getDebugLoc();
00977   GetExpandedFloat(N->getOperand(0), Lo, Hi);
00978   Lo = DAG.getNode(ISD::FNEG, dl, Lo.getValueType(), Lo);
00979   Hi = DAG.getNode(ISD::FNEG, dl, Hi.getValueType(), Hi);
00980 }
00981 
00982 void DAGTypeLegalizer::ExpandFloatRes_FP_EXTEND(SDNode *N, SDValue &Lo,
00983                                                 SDValue &Hi) {
00984   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
00985   Hi = DAG.getNode(ISD::FP_EXTEND, N->getDebugLoc(), NVT, N->getOperand(0));
00986   Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
00987 }
00988 
00989 void DAGTypeLegalizer::ExpandFloatRes_FPOW(SDNode *N,
00990                                            SDValue &Lo, SDValue &Hi) {
00991   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
00992                                          RTLIB::POW_F32, RTLIB::POW_F64,
00993                                          RTLIB::POW_F80, RTLIB::POW_PPCF128),
00994                             N, false);
00995   GetPairElements(Call, Lo, Hi);
00996 }
00997 
00998 void DAGTypeLegalizer::ExpandFloatRes_FPOWI(SDNode *N,
00999                                             SDValue &Lo, SDValue &Hi) {
01000   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
01001                                          RTLIB::POWI_F32, RTLIB::POWI_F64,
01002                                          RTLIB::POWI_F80, RTLIB::POWI_PPCF128),
01003                             N, false);
01004   GetPairElements(Call, Lo, Hi);
01005 }
01006 
01007 void DAGTypeLegalizer::ExpandFloatRes_FRINT(SDNode *N,
01008                                             SDValue &Lo, SDValue &Hi) {
01009   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
01010                                          RTLIB::RINT_F32, RTLIB::RINT_F64,
01011                                          RTLIB::RINT_F80, RTLIB::RINT_PPCF128),
01012                             N, false);
01013   GetPairElements(Call, Lo, Hi);
01014 }
01015 
01016 void DAGTypeLegalizer::ExpandFloatRes_FSIN(SDNode *N,
01017                                            SDValue &Lo, SDValue &Hi) {
01018   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
01019                                          RTLIB::SIN_F32, RTLIB::SIN_F64,
01020                                          RTLIB::SIN_F80, RTLIB::SIN_PPCF128),
01021                             N, false);
01022   GetPairElements(Call, Lo, Hi);
01023 }
01024 
01025 void DAGTypeLegalizer::ExpandFloatRes_FSQRT(SDNode *N,
01026                                             SDValue &Lo, SDValue &Hi) {
01027   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
01028                                          RTLIB::SQRT_F32, RTLIB::SQRT_F64,
01029                                          RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128),
01030                             N, false);
01031   GetPairElements(Call, Lo, Hi);
01032 }
01033 
01034 void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode *N, SDValue &Lo,
01035                                            SDValue &Hi) {
01036   SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
01037   SDValue Call = MakeLibCall(GetFPLibCall(N->getValueType(0),
01038                                           RTLIB::SUB_F32,
01039                                           RTLIB::SUB_F64,
01040                                           RTLIB::SUB_F80,
01041                                           RTLIB::SUB_PPCF128),
01042                              N->getValueType(0), Ops, 2, false,
01043                              N->getDebugLoc());
01044   GetPairElements(Call, Lo, Hi);
01045 }
01046 
01047 void DAGTypeLegalizer::ExpandFloatRes_FTRUNC(SDNode *N,
01048                                              SDValue &Lo, SDValue &Hi) {
01049   SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
01050                                          RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
01051                                          RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128),
01052                             N, false);
01053   GetPairElements(Call, Lo, Hi);
01054 }
01055 
01056 void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode *N, SDValue &Lo,
01057                                            SDValue &Hi) {
01058   if (ISD::isNormalLoad(N)) {
01059     ExpandRes_NormalLoad(N, Lo, Hi);
01060     return;
01061   }
01062 
01063   assert(ISD::isUNINDEXEDLoad(N) && "Indexed load during type legalization!");
01064   LoadSDNode *LD = cast<LoadSDNode>(N);
01065   SDValue Chain = LD->getChain();
01066   SDValue Ptr = LD->getBasePtr();
01067   DebugLoc dl = N->getDebugLoc();
01068 
01069   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), LD->getValueType(0));
01070   assert(NVT.isByteSized() && "Expanded type not byte sized!");
01071   assert(LD->getMemoryVT().bitsLE(NVT) && "Float type not round?");
01072 
01073   Hi = DAG.getExtLoad(LD->getExtensionType(), dl, NVT, Chain, Ptr,
01074                       LD->getSrcValue(), LD->getSrcValueOffset(),
01075                       LD->getMemoryVT(),
01076                       LD->isVolatile(), LD->getAlignment());
01077 
01078   // Remember the chain.
01079   Chain = Hi.getValue(1);
01080 
01081   // The low part is zero.
01082   Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
01083 
01084   // Modified the chain - switch anything that used the old chain to use the
01085   // new one.
01086   ReplaceValueWith(SDValue(LD, 1), Chain);
01087 }
01088 
01089 void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo,
01090                                                  SDValue &Hi) {
01091   assert(N->getValueType(0) == MVT::ppcf128 && "Unsupported XINT_TO_FP!");
01092   EVT VT = N->getValueType(0);
01093   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
01094   SDValue Src = N->getOperand(0);
01095   EVT SrcVT = Src.getValueType();
01096   bool isSigned = N->getOpcode() == ISD::SINT_TO_FP;
01097   DebugLoc dl = N->getDebugLoc();
01098 
01099   // First do an SINT_TO_FP, whether the original was signed or unsigned.
01100   // When promoting partial word types to i32 we must honor the signedness,
01101   // though.
01102   if (SrcVT.bitsLE(MVT::i32)) {
01103     // The integer can be represented exactly in an f64.
01104     Src = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
01105                       MVT::i32, Src);
01106     Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT);
01107     Hi = DAG.getNode(ISD::SINT_TO_FP, dl, NVT, Src);
01108   } else {
01109     RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
01110     if (SrcVT.bitsLE(MVT::i64)) {
01111       Src = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
01112                         MVT::i64, Src);
01113       LC = RTLIB::SINTTOFP_I64_PPCF128;
01114     } else if (SrcVT.bitsLE(MVT::i128)) {
01115       Src = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i128, Src);
01116       LC = RTLIB::SINTTOFP_I128_PPCF128;
01117     }
01118     assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
01119 
01120     Hi = MakeLibCall(LC, VT, &Src, 1, true, dl);
01121     GetPairElements(Hi, Lo, Hi);
01122   }
01123 
01124   if (isSigned)
01125     return;
01126 
01127   // Unsigned - fix up the SINT_TO_FP value just calculated.
01128   Hi = DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi);
01129   SrcVT = Src.getValueType();
01130 
01131   // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128.
01132   static const uint64_t TwoE32[]  = { 0x41f0000000000000LL, 0 };
01133   static const uint64_t TwoE64[]  = { 0x43f0000000000000LL, 0 };
01134   static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
01135   const uint64_t *Parts = 0;
01136 
01137   switch (SrcVT.getSimpleVT().SimpleTy) {
01138   default:
01139     assert(false && "Unsupported UINT_TO_FP!");
01140   case MVT::i32:
01141     Parts = TwoE32;
01142     break;
01143   case MVT::i64:
01144     Parts = TwoE64;
01145     break;
01146   case MVT::i128:
01147     Parts = TwoE128;
01148     break;
01149   }
01150 
01151   Lo = DAG.getNode(ISD::FADD, dl, VT, Hi,
01152                    DAG.getConstantFP(APFloat(APInt(128, 2, Parts)),
01153                                      MVT::ppcf128));
01154   Lo = DAG.getNode(ISD::SELECT_CC, dl, VT, Src, DAG.getConstant(0, SrcVT),
01155                    Lo, Hi, DAG.getCondCode(ISD::SETLT));
01156   GetPairElements(Lo, Lo, Hi);
01157 }
01158 
01159 
01160 //===----------------------------------------------------------------------===//
01161 //  Float Operand Expansion
01162 //===----------------------------------------------------------------------===//
01163 
01164 /// ExpandFloatOperand - This method is called when the specified operand of the
01165 /// specified node is found to need expansion.  At this point, all of the result
01166 /// types of the node are known to be legal, but other operands of the node may
01167 /// need promotion or expansion as well as the specified one.
01168 bool DAGTypeLegalizer::ExpandFloatOperand(SDNode *N, unsigned OpNo) {
01169   DEBUG(errs() << "Expand float operand: "; N->dump(&DAG); errs() << "\n");
01170   SDValue Res = SDValue();
01171 
01172   if (TLI.getOperationAction(N->getOpcode(), N->getOperand(OpNo).getValueType())
01173       == TargetLowering::Custom)
01174     Res = TLI.LowerOperation(SDValue(N, 0), DAG);
01175 
01176   if (Res.getNode() == 0) {
01177     switch (N->getOpcode()) {
01178     default:
01179   #ifndef NDEBUG
01180       errs() << "ExpandFloatOperand Op #" << OpNo << ": ";
01181       N->dump(&DAG); errs() << "\n";
01182   #endif
01183       llvm_unreachable("Do not know how to expand this operator's operand!");
01184 
01185     case ISD::BIT_CONVERT:     Res = ExpandOp_BIT_CONVERT(N); break;
01186     case ISD::BUILD_VECTOR:    Res = ExpandOp_BUILD_VECTOR(N); break;
01187     case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break;
01188 
01189     case ISD::BR_CC:      Res = ExpandFloatOp_BR_CC(N); break;
01190     case ISD::FP_ROUND:   Res = ExpandFloatOp_FP_ROUND(N); break;
01191     case ISD::FP_TO_SINT: Res = ExpandFloatOp_FP_TO_SINT(N); break;
01192     case ISD::FP_TO_UINT: Res = ExpandFloatOp_FP_TO_UINT(N); break;
01193     case ISD::SELECT_CC:  Res = ExpandFloatOp_SELECT_CC(N); break;
01194     case ISD::SETCC:      Res = ExpandFloatOp_SETCC(N); break;
01195     case ISD::STORE:      Res = ExpandFloatOp_STORE(cast<StoreSDNode>(N),
01196                                                     OpNo); break;
01197     }
01198   }
01199 
01200   // If the result is null, the sub-method took care of registering results etc.
01201   if (!Res.getNode()) return false;
01202 
01203   // If the result is N, the sub-method updated N in place.  Tell the legalizer
01204   // core about this.
01205   if (Res.getNode() == N)
01206     return true;
01207 
01208   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
01209          "Invalid operand expansion");
01210 
01211   ReplaceValueWith(SDValue(N, 0), Res);
01212   return false;
01213 }
01214 
01215 /// FloatExpandSetCCOperands - Expand the operands of a comparison.  This code
01216 /// is shared among BR_CC, SELECT_CC, and SETCC handlers.
01217 void DAGTypeLegalizer::FloatExpandSetCCOperands(SDValue &NewLHS,
01218                                                 SDValue &NewRHS,
01219                                                 ISD::CondCode &CCCode,
01220                                                 DebugLoc dl) {
01221   SDValue LHSLo, LHSHi, RHSLo, RHSHi;
01222   GetExpandedFloat(NewLHS, LHSLo, LHSHi);
01223   GetExpandedFloat(NewRHS, RHSLo, RHSHi);
01224 
01225   EVT VT = NewLHS.getValueType();
01226   assert(VT == MVT::ppcf128 && "Unsupported setcc type!");
01227 
01228   // FIXME:  This generated code sucks.  We want to generate
01229   //         FCMPU crN, hi1, hi2
01230   //         BNE crN, L:
01231   //         FCMPU crN, lo1, lo2
01232   // The following can be improved, but not that much.
01233   SDValue Tmp1, Tmp2, Tmp3;
01234   Tmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
01235                       LHSHi, RHSHi, ISD::SETOEQ);
01236   Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSLo.getValueType()),
01237                       LHSLo, RHSLo, CCCode);
01238   Tmp3 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
01239   Tmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
01240                       LHSHi, RHSHi, ISD::SETUNE);
01241   Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
01242                       LHSHi, RHSHi, CCCode);
01243   Tmp1 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
01244   NewLHS = DAG.getNode(ISD::OR, dl, Tmp1.getValueType(), Tmp1, Tmp3);
01245   NewRHS = SDValue();   // LHS is the result, not a compare.
01246 }
01247 
01248 SDValue DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode *N) {
01249   SDValue NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
01250   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
01251   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
01252 
01253   // If ExpandSetCCOperands returned a scalar, we need to compare the result
01254   // against zero to select between true and false values.
01255   if (NewRHS.getNode() == 0) {
01256     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
01257     CCCode = ISD::SETNE;
01258   }
01259 
01260   // Update N to have the operands specified.
01261   return DAG.UpdateNodeOperands(SDValue(N, 0), N->getOperand(0),
01262                                 DAG.getCondCode(CCCode), NewLHS, NewRHS,
01263                                 N->getOperand(4));
01264 }
01265 
01266 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode *N) {
01267   assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
01268          "Logic only correct for ppcf128!");
01269   SDValue Lo, Hi;
01270   GetExpandedFloat(N->getOperand(0), Lo, Hi);
01271   // Round it the rest of the way (e.g. to f32) if needed.
01272   return DAG.getNode(ISD::FP_ROUND, N->getDebugLoc(),
01273                      N->getValueType(0), Hi, N->getOperand(1));
01274 }
01275 
01276 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) {
01277   EVT RVT = N->getValueType(0);
01278   DebugLoc dl = N->getDebugLoc();
01279 
01280   // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on
01281   // PPC (the libcall is not available).  FIXME: Do this in a less hacky way.
01282   if (RVT == MVT::i32) {
01283     assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
01284            "Logic only correct for ppcf128!");
01285     SDValue Res = DAG.getNode(ISD::FP_ROUND_INREG, dl, MVT::ppcf128,
01286                               N->getOperand(0), DAG.getValueType(MVT::f64));
01287     Res = DAG.getNode(ISD::FP_ROUND, dl, MVT::f64, Res,
01288                       DAG.getIntPtrConstant(1));
01289     return DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32, Res);
01290   }
01291 
01292   RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
01293   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
01294   return MakeLibCall(LC, RVT, &N->getOperand(0), 1, false, dl);
01295 }
01296 
01297 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
01298   EVT RVT = N->getValueType(0);
01299   DebugLoc dl = N->getDebugLoc();
01300 
01301   // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on
01302   // PPC (the libcall is not available).  FIXME: Do this in a less hacky way.
01303   if (RVT == MVT::i32) {
01304     assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
01305            "Logic only correct for ppcf128!");
01306     const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
01307     APFloat APF = APFloat(APInt(128, 2, TwoE31));
01308     SDValue Tmp = DAG.getConstantFP(APF, MVT::ppcf128);
01309     //  X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
01310     // FIXME: generated code sucks.
01311     return DAG.getNode(ISD::SELECT_CC, dl, MVT::i32, N->getOperand(0), Tmp,
01312                        DAG.getNode(ISD::ADD, dl, MVT::i32,
01313                                    DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32,
01314                                                DAG.getNode(ISD::FSUB, dl,
01315                                                            MVT::ppcf128,
01316                                                            N->getOperand(0),
01317                                                            Tmp)),
01318                                    DAG.getConstant(0x80000000, MVT::i32)),
01319                        DAG.getNode(ISD::FP_TO_SINT, dl,
01320                                    MVT::i32, N->getOperand(0)),
01321                        DAG.getCondCode(ISD::SETGE));
01322   }
01323 
01324   RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
01325   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
01326   return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false, dl);
01327 }
01328 
01329 SDValue DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode *N) {
01330   SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
01331   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
01332   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
01333 
01334   // If ExpandSetCCOperands returned a scalar, we need to compare the result
01335   // against zero to select between true and false values.
01336   if (NewRHS.getNode() == 0) {
01337     NewRHS = DAG.getConstant(0, NewLHS.getValueType());
01338     CCCode = ISD::SETNE;
01339   }
01340 
01341   // Update N to have the operands specified.
01342   return DAG.UpdateNodeOperands(SDValue(N, 0), NewLHS, NewRHS,
01343                                 N->getOperand(2), N->getOperand(3),
01344                                 DAG.getCondCode(CCCode));
01345 }
01346 
01347 SDValue DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode *N) {
01348   SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
01349   ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
01350   FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, N->getDebugLoc());
01351 
01352   // If ExpandSetCCOperands returned a scalar, use it.
01353   if (NewRHS.getNode() == 0) {
01354     assert(NewLHS.getValueType() == N->getValueType(0) &&
01355            "Unexpected setcc expansion!");
01356     return NewLHS;
01357   }
01358 
01359   // Otherwise, update N to have the operands specified.
01360   return DAG.UpdateNodeOperands(SDValue(N, 0), NewLHS, NewRHS,
01361                                 DAG.getCondCode(CCCode));
01362 }
01363 
01364 SDValue DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode *N, unsigned OpNo) {
01365   if (ISD::isNormalStore(N))
01366     return ExpandOp_NormalStore(N, OpNo);
01367 
01368   assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
01369   assert(OpNo == 1 && "Can only expand the stored value so far");
01370   StoreSDNode *ST = cast<StoreSDNode>(N);
01371 
01372   SDValue Chain = ST->getChain();
01373   SDValue Ptr = ST->getBasePtr();
01374 
01375   EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), ST->getValue().getValueType());
01376   assert(NVT.isByteSized() && "Expanded type not byte sized!");
01377   assert(ST->getMemoryVT().bitsLE(NVT) && "Float type not round?");
01378 
01379   SDValue Lo, Hi;
01380   GetExpandedOp(ST->getValue(), Lo, Hi);
01381 
01382   return DAG.getTruncStore(Chain, N->getDebugLoc(), Hi, Ptr,
01383                            ST->getSrcValue(), ST->getSrcValueOffset(),
01384                            ST->getMemoryVT(),
01385                            ST->isVolatile(), ST->getAlignment());
01386 }