LegalizeFloatTypes.cpp revision 75ee49e55747b7027802d40d14c5cac923544457
1//===-------- LegalizeFloatTypes.cpp - Legalization of float types --------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file implements float type expansion and softening for LegalizeTypes. 11// Softening is the act of turning a computation in an illegal floating point 12// type into a computation in an integer type of the same size; also known as 13// "soft float". For example, turning f32 arithmetic into operations using i32. 14// The resulting integer value is the same as what you would get by performing 15// the floating point operation and bitcasting the result to the integer type. 16// Expansion is the act of changing a computation in an illegal type to be a 17// computation in two identical registers of a smaller type. For example, 18// implementing ppcf128 arithmetic in two f64 registers. 19// 20//===----------------------------------------------------------------------===// 21 22#include "LegalizeTypes.h" 23#include "llvm/CodeGen/PseudoSourceValue.h" 24#include "llvm/Constants.h" 25#include "llvm/DerivedTypes.h" 26using namespace llvm; 27 28/// GetFPLibCall - Return the right libcall for the given floating point type. 29static RTLIB::Libcall GetFPLibCall(MVT VT, 30 RTLIB::Libcall Call_F32, 31 RTLIB::Libcall Call_F64, 32 RTLIB::Libcall Call_F80, 33 RTLIB::Libcall Call_PPCF128) { 34 return 35 VT == MVT::f32 ? Call_F32 : 36 VT == MVT::f64 ? Call_F64 : 37 VT == MVT::f80 ? Call_F80 : 38 VT == MVT::ppcf128 ? Call_PPCF128 : 39 RTLIB::UNKNOWN_LIBCALL; 40} 41 42//===----------------------------------------------------------------------===// 43// Result Float to Integer Conversion. 44//===----------------------------------------------------------------------===// 45 46void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) { 47 DEBUG(cerr << "Soften float result " << ResNo << ": "; N->dump(&DAG); 48 cerr << "\n"); 49 SDOperand R = SDOperand(); 50 51 // See if the target wants to custom expand this node. 52 if (TLI.getOperationAction(N->getOpcode(), N->getValueType(ResNo)) == 53 TargetLowering::Custom) { 54 // If the target wants to, allow it to lower this itself. 55 if (SDNode *P = TLI.ReplaceNodeResults(N, DAG)) { 56 // Everything that once used N now uses P. We are guaranteed that the 57 // result value types of N and the result value types of P match. 58 ReplaceNodeWith(N, P); 59 return; 60 } 61 } 62 63 switch (N->getOpcode()) { 64 default: 65#ifndef NDEBUG 66 cerr << "SoftenFloatResult #" << ResNo << ": "; 67 N->dump(&DAG); cerr << "\n"; 68#endif 69 assert(0 && "Do not know how to soften the result of this operator!"); 70 abort(); 71 72 case ISD::BIT_CONVERT: R = SoftenFloatRes_BIT_CONVERT(N); break; 73 case ISD::BUILD_PAIR: R = SoftenFloatRes_BUILD_PAIR(N); break; 74 case ISD::ConstantFP: 75 R = SoftenFloatRes_ConstantFP(cast<ConstantFPSDNode>(N)); 76 break; 77 case ISD::FCOPYSIGN: R = SoftenFloatRes_FCOPYSIGN(N); break; 78 case ISD::FP_EXTEND: R = SoftenFloatRes_FP_EXTEND(N); break; 79 case ISD::FP_ROUND: R = SoftenFloatRes_FP_ROUND(N); break; 80 case ISD::LOAD: R = SoftenFloatRes_LOAD(N); break; 81 case ISD::SINT_TO_FP: 82 case ISD::UINT_TO_FP: R = SoftenFloatRes_XINT_TO_FP(N); break; 83 84 case ISD::FADD: R = SoftenFloatRes_FADD(N); break; 85 case ISD::FMUL: R = SoftenFloatRes_FMUL(N); break; 86 case ISD::FSUB: R = SoftenFloatRes_FSUB(N); break; 87 } 88 89 // If R is null, the sub-method took care of registering the result. 90 if (R.Val) 91 SetSoftenedFloat(SDOperand(N, ResNo), R); 92} 93 94SDOperand DAGTypeLegalizer::SoftenFloatRes_BIT_CONVERT(SDNode *N) { 95 return BitConvertToInteger(N->getOperand(0)); 96} 97 98SDOperand DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode *N) { 99 // Convert the inputs to integers, and build a new pair out of them. 100 return DAG.getNode(ISD::BUILD_PAIR, 101 TLI.getTypeToTransformTo(N->getValueType(0)), 102 BitConvertToInteger(N->getOperand(0)), 103 BitConvertToInteger(N->getOperand(1))); 104} 105 106SDOperand DAGTypeLegalizer::SoftenFloatRes_ConstantFP(ConstantFPSDNode *N) { 107 return DAG.getConstant(N->getValueAPF().convertToAPInt(), 108 TLI.getTypeToTransformTo(N->getValueType(0))); 109} 110 111SDOperand DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode *N) { 112 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 113 SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)), 114 GetSoftenedFloat(N->getOperand(1)) }; 115 return MakeLibCall(GetFPLibCall(N->getValueType(0), 116 RTLIB::ADD_F32, 117 RTLIB::ADD_F64, 118 RTLIB::ADD_F80, 119 RTLIB::ADD_PPCF128), 120 NVT, Ops, 2, false); 121} 122 123SDOperand DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode *N) { 124 SDOperand LHS = GetSoftenedFloat(N->getOperand(0)); 125 SDOperand RHS = BitConvertToInteger(N->getOperand(1)); 126 127 MVT LVT = LHS.getValueType(); 128 MVT RVT = RHS.getValueType(); 129 130 unsigned LSize = LVT.getSizeInBits(); 131 unsigned RSize = RVT.getSizeInBits(); 132 133 // First get the sign bit of second operand. 134 SDOperand SignBit = DAG.getNode(ISD::SHL, RVT, DAG.getConstant(1, RVT), 135 DAG.getConstant(RSize - 1, 136 TLI.getShiftAmountTy())); 137 SignBit = DAG.getNode(ISD::AND, RVT, RHS, SignBit); 138 139 // Shift right or sign-extend it if the two operands have different types. 140 int SizeDiff = RVT.getSizeInBits() - LVT.getSizeInBits(); 141 if (SizeDiff > 0) { 142 SignBit = DAG.getNode(ISD::SRL, RVT, SignBit, 143 DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); 144 SignBit = DAG.getNode(ISD::TRUNCATE, LVT, SignBit); 145 } else if (SizeDiff < 0) { 146 SignBit = DAG.getNode(ISD::ANY_EXTEND, LVT, SignBit); 147 SignBit = DAG.getNode(ISD::SHL, LVT, SignBit, 148 DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy())); 149 } 150 151 // Clear the sign bit of the first operand. 152 SDOperand Mask = DAG.getNode(ISD::SHL, LVT, DAG.getConstant(1, LVT), 153 DAG.getConstant(LSize - 1, 154 TLI.getShiftAmountTy())); 155 Mask = DAG.getNode(ISD::SUB, LVT, Mask, DAG.getConstant(1, LVT)); 156 LHS = DAG.getNode(ISD::AND, LVT, LHS, Mask); 157 158 // Or the value with the sign bit. 159 return DAG.getNode(ISD::OR, LVT, LHS, SignBit); 160} 161 162SDOperand DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode *N) { 163 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 164 SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)), 165 GetSoftenedFloat(N->getOperand(1)) }; 166 return MakeLibCall(GetFPLibCall(N->getValueType(0), 167 RTLIB::MUL_F32, 168 RTLIB::MUL_F64, 169 RTLIB::MUL_F80, 170 RTLIB::MUL_PPCF128), 171 NVT, Ops, 2, false); 172} 173 174SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) { 175 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 176 SDOperand Op = N->getOperand(0); 177 178 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 179 switch (Op.getValueType().getSimpleVT()) { 180 default: 181 assert(false && "Unsupported FP_EXTEND!"); 182 case MVT::f32: 183 switch (N->getValueType(0).getSimpleVT()) { 184 default: 185 assert(false && "Unsupported FP_EXTEND!"); 186 case MVT::f64: 187 LC = RTLIB::FPEXT_F32_F64; 188 } 189 } 190 191 return MakeLibCall(LC, NVT, &Op, 1, false); 192} 193 194SDOperand DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) { 195 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 196 SDOperand Op = N->getOperand(0); 197 198 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 199 switch (Op.getValueType().getSimpleVT()) { 200 default: 201 assert(false && "Unsupported FP_ROUND!"); 202 case MVT::f64: 203 switch (N->getValueType(0).getSimpleVT()) { 204 default: 205 assert(false && "Unsupported FP_ROUND!"); 206 case MVT::f32: 207 LC = RTLIB::FPROUND_F64_F32; 208 } 209 } 210 211 return MakeLibCall(LC, NVT, &Op, 1, false); 212} 213 214SDOperand DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode *N) { 215 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 216 SDOperand Ops[2] = { GetSoftenedFloat(N->getOperand(0)), 217 GetSoftenedFloat(N->getOperand(1)) }; 218 return MakeLibCall(GetFPLibCall(N->getValueType(0), 219 RTLIB::SUB_F32, 220 RTLIB::SUB_F64, 221 RTLIB::SUB_F80, 222 RTLIB::SUB_PPCF128), 223 NVT, Ops, 2, false); 224} 225 226SDOperand DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode *N) { 227 LoadSDNode *L = cast<LoadSDNode>(N); 228 MVT VT = N->getValueType(0); 229 MVT NVT = TLI.getTypeToTransformTo(VT); 230 231 if (L->getExtensionType() == ISD::NON_EXTLOAD) 232 return DAG.getLoad(L->getAddressingMode(), L->getExtensionType(), 233 NVT, L->getChain(), L->getBasePtr(), L->getOffset(), 234 L->getSrcValue(), L->getSrcValueOffset(), NVT, 235 L->isVolatile(), L->getAlignment()); 236 237 // Do a non-extending load followed by FP_EXTEND. 238 SDOperand NL = DAG.getLoad(L->getAddressingMode(), ISD::NON_EXTLOAD, 239 L->getMemoryVT(), L->getChain(), 240 L->getBasePtr(), L->getOffset(), 241 L->getSrcValue(), L->getSrcValueOffset(), 242 L->getMemoryVT(), 243 L->isVolatile(), L->getAlignment()); 244 return BitConvertToInteger(DAG.getNode(ISD::FP_EXTEND, VT, NL)); 245} 246 247SDOperand DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode *N) { 248 bool isSigned = N->getOpcode() == ISD::SINT_TO_FP; 249 MVT DestVT = N->getValueType(0); 250 SDOperand Op = N->getOperand(0); 251 252 if (Op.getValueType() == MVT::i32) { 253 // simple 32-bit [signed|unsigned] integer to float/double expansion 254 255 // Get the stack frame index of a 8 byte buffer. 256 SDOperand StackSlot = DAG.CreateStackTemporary(MVT::f64); 257 258 // word offset constant for Hi/Lo address computation 259 SDOperand Offset = 260 DAG.getConstant(MVT(MVT::i32).getSizeInBits() / 8, 261 TLI.getPointerTy()); 262 // set up Hi and Lo (into buffer) address based on endian 263 SDOperand Hi = StackSlot; 264 SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot, Offset); 265 if (TLI.isLittleEndian()) 266 std::swap(Hi, Lo); 267 268 // if signed map to unsigned space 269 SDOperand OpMapped; 270 if (isSigned) { 271 // constant used to invert sign bit (signed to unsigned mapping) 272 SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); 273 OpMapped = DAG.getNode(ISD::XOR, MVT::i32, Op, SignBit); 274 } else { 275 OpMapped = Op; 276 } 277 // store the lo of the constructed double - based on integer input 278 SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), 279 OpMapped, Lo, NULL, 0); 280 // initial hi portion of constructed double 281 SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); 282 // store the hi of the constructed double - biased exponent 283 SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); 284 // load the constructed double 285 SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); 286 // FP constant to bias correct the final result 287 SDOperand Bias = DAG.getConstantFP(isSigned ? 288 BitsToDouble(0x4330000080000000ULL) 289 : BitsToDouble(0x4330000000000000ULL), 290 MVT::f64); 291 // subtract the bias 292 SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); 293 // final result 294 SDOperand Result; 295 // handle final rounding 296 if (DestVT == MVT::f64) { 297 // do nothing 298 Result = Sub; 299 } else if (DestVT.bitsLT(MVT::f64)) { 300 Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub, 301 DAG.getIntPtrConstant(0)); 302 } else if (DestVT.bitsGT(MVT::f64)) { 303 Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub); 304 } 305 return BitConvertToInteger(Result); 306 } 307 assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); 308 SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op); 309 310 SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op), Op, 311 DAG.getConstant(0, Op.getValueType()), 312 ISD::SETLT); 313 SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4); 314 SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), 315 SignSet, Four, Zero); 316 317 // If the sign bit of the integer is set, the large number will be treated 318 // as a negative number. To counteract this, the dynamic code adds an 319 // offset depending on the data type. 320 uint64_t FF; 321 switch (Op.getValueType().getSimpleVT()) { 322 default: assert(0 && "Unsupported integer type!"); 323 case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) 324 case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) 325 case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) 326 case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) 327 } 328 if (TLI.isLittleEndian()) FF <<= 32; 329 static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); 330 331 SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); 332 CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); 333 SDOperand FudgeInReg; 334 if (DestVT == MVT::f32) 335 FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, 336 PseudoSourceValue::getConstantPool(), 0); 337 else { 338 FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestVT, 339 DAG.getEntryNode(), CPIdx, 340 PseudoSourceValue::getConstantPool(), 0, 341 MVT::f32); 342 } 343 344 return BitConvertToInteger(DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg)); 345} 346 347 348//===----------------------------------------------------------------------===// 349// Operand Float to Integer Conversion.. 350//===----------------------------------------------------------------------===// 351 352bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) { 353 DEBUG(cerr << "Soften float operand " << OpNo << ": "; N->dump(&DAG); 354 cerr << "\n"); 355 SDOperand Res(0, 0); 356 357 if (TLI.getOperationAction(N->getOpcode(), N->getOperand(OpNo).getValueType()) 358 == TargetLowering::Custom) 359 Res = TLI.LowerOperation(SDOperand(N, OpNo), DAG); 360 361 if (Res.Val == 0) { 362 switch (N->getOpcode()) { 363 default: 364#ifndef NDEBUG 365 cerr << "SoftenFloatOperand Op #" << OpNo << ": "; 366 N->dump(&DAG); cerr << "\n"; 367#endif 368 assert(0 && "Do not know how to soften this operator's operand!"); 369 abort(); 370 371 case ISD::BIT_CONVERT: Res = SoftenFloatOp_BIT_CONVERT(N); break; 372 373 case ISD::BR_CC: Res = SoftenFloatOp_BR_CC(N); break; 374 case ISD::SELECT_CC: Res = SoftenFloatOp_SELECT_CC(N); break; 375 case ISD::SETCC: Res = SoftenFloatOp_SETCC(N); break; 376 case ISD::STORE: Res = SoftenFloatOp_STORE(N, OpNo); break; 377 } 378 } 379 380 // If the result is null, the sub-method took care of registering results etc. 381 if (!Res.Val) return false; 382 383 // If the result is N, the sub-method updated N in place. Check to see if any 384 // operands are new, and if so, mark them. 385 if (Res.Val == N) { 386 // Mark N as new and remark N and its operands. This allows us to correctly 387 // revisit N if it needs another step of promotion and allows us to visit 388 // any new operands to N. 389 ReanalyzeNode(N); 390 return true; 391 } 392 393 assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 && 394 "Invalid operand expansion"); 395 396 ReplaceValueWith(SDOperand(N, 0), Res); 397 return false; 398} 399 400/// SoftenSetCCOperands - Soften the operands of a comparison. This code is 401/// shared among BR_CC, SELECT_CC, and SETCC handlers. 402void DAGTypeLegalizer::SoftenSetCCOperands(SDOperand &NewLHS, SDOperand &NewRHS, 403 ISD::CondCode &CCCode) { 404 SDOperand LHSInt = GetSoftenedFloat(NewLHS); 405 SDOperand RHSInt = GetSoftenedFloat(NewRHS); 406 MVT VT = NewLHS.getValueType(); 407 MVT NVT = LHSInt.getValueType(); 408 409 assert((VT == MVT::f32 || VT == MVT::f64) && "Unsupported setcc type!"); 410 411 // Expand into one or more soft-fp libcall(s). 412 RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL; 413 switch (CCCode) { 414 case ISD::SETEQ: 415 case ISD::SETOEQ: 416 LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; 417 break; 418 case ISD::SETNE: 419 case ISD::SETUNE: 420 LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; 421 break; 422 case ISD::SETGE: 423 case ISD::SETOGE: 424 LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; 425 break; 426 case ISD::SETLT: 427 case ISD::SETOLT: 428 LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 429 break; 430 case ISD::SETLE: 431 case ISD::SETOLE: 432 LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; 433 break; 434 case ISD::SETGT: 435 case ISD::SETOGT: 436 LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; 437 break; 438 case ISD::SETUO: 439 LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; 440 break; 441 case ISD::SETO: 442 break; 443 default: 444 LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; 445 switch (CCCode) { 446 case ISD::SETONE: 447 // SETONE = SETOLT | SETOGT 448 LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 449 // Fallthrough 450 case ISD::SETUGT: 451 LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; 452 break; 453 case ISD::SETUGE: 454 LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; 455 break; 456 case ISD::SETULT: 457 LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 458 break; 459 case ISD::SETULE: 460 LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; 461 break; 462 case ISD::SETUEQ: 463 LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; 464 break; 465 default: assert(false && "Do not know how to soften this setcc!"); 466 } 467 } 468 469 SDOperand Ops[2] = { LHSInt, RHSInt }; 470 NewLHS = MakeLibCall(LC1, NVT, Ops, 2, false/*sign irrelevant*/); 471 NewRHS = DAG.getConstant(0, NVT); 472 if (LC2 != RTLIB::UNKNOWN_LIBCALL) { 473 SDOperand Tmp = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(NewLHS), 474 NewLHS, NewRHS, 475 DAG.getCondCode(TLI.getCmpLibcallCC(LC1))); 476 NewLHS = MakeLibCall(LC2, NVT, Ops, 2, false/*sign irrelevant*/); 477 NewLHS = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(NewLHS), NewLHS, 478 NewRHS, DAG.getCondCode(TLI.getCmpLibcallCC(LC2))); 479 NewLHS = DAG.getNode(ISD::OR, Tmp.getValueType(), Tmp, NewLHS); 480 NewRHS = SDOperand(); 481 } 482} 483 484SDOperand DAGTypeLegalizer::SoftenFloatOp_BIT_CONVERT(SDNode *N) { 485 return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0), 486 GetSoftenedFloat(N->getOperand(0))); 487} 488 489SDOperand DAGTypeLegalizer::SoftenFloatOp_BR_CC(SDNode *N) { 490 SDOperand NewLHS = N->getOperand(2), NewRHS = N->getOperand(3); 491 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get(); 492 SoftenSetCCOperands(NewLHS, NewRHS, CCCode); 493 494 // If SoftenSetCCOperands returned a scalar, we need to compare the result 495 // against zero to select between true and false values. 496 if (NewRHS.Val == 0) { 497 NewRHS = DAG.getConstant(0, NewLHS.getValueType()); 498 CCCode = ISD::SETNE; 499 } 500 501 // Update N to have the operands specified. 502 return DAG.UpdateNodeOperands(SDOperand(N, 0), N->getOperand(0), 503 DAG.getCondCode(CCCode), NewLHS, NewRHS, 504 N->getOperand(4)); 505} 506 507SDOperand DAGTypeLegalizer::SoftenFloatOp_SELECT_CC(SDNode *N) { 508 SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1); 509 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get(); 510 SoftenSetCCOperands(NewLHS, NewRHS, CCCode); 511 512 // If SoftenSetCCOperands returned a scalar, we need to compare the result 513 // against zero to select between true and false values. 514 if (NewRHS.Val == 0) { 515 NewRHS = DAG.getConstant(0, NewLHS.getValueType()); 516 CCCode = ISD::SETNE; 517 } 518 519 // Update N to have the operands specified. 520 return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS, 521 N->getOperand(2), N->getOperand(3), 522 DAG.getCondCode(CCCode)); 523} 524 525SDOperand DAGTypeLegalizer::SoftenFloatOp_SETCC(SDNode *N) { 526 SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1); 527 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get(); 528 SoftenSetCCOperands(NewLHS, NewRHS, CCCode); 529 530 // If SoftenSetCCOperands returned a scalar, use it. 531 if (NewRHS.Val == 0) { 532 assert(NewLHS.getValueType() == N->getValueType(0) && 533 "Unexpected setcc expansion!"); 534 return NewLHS; 535 } 536 537 // Otherwise, update N to have the operands specified. 538 return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS, 539 DAG.getCondCode(CCCode)); 540} 541 542SDOperand DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode *N, unsigned OpNo) { 543 assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!"); 544 assert(OpNo == 1 && "Can only soften the stored value!"); 545 StoreSDNode *ST = cast<StoreSDNode>(N); 546 SDOperand Val = ST->getValue(); 547 548 if (ST->isTruncatingStore()) 549 // Do an FP_ROUND followed by a non-truncating store. 550 Val = BitConvertToInteger(DAG.getNode(ISD::FP_ROUND, ST->getMemoryVT(), 551 Val, DAG.getIntPtrConstant(0))); 552 else 553 Val = GetSoftenedFloat(Val); 554 555 return DAG.getStore(ST->getChain(), Val, ST->getBasePtr(), 556 ST->getSrcValue(), ST->getSrcValueOffset(), 557 ST->isVolatile(), ST->getAlignment()); 558} 559 560 561//===----------------------------------------------------------------------===// 562// Float Result Expansion 563//===----------------------------------------------------------------------===// 564 565/// ExpandFloatResult - This method is called when the specified result of the 566/// specified node is found to need expansion. At this point, the node may also 567/// have invalid operands or may have other results that need promotion, we just 568/// know that (at least) one result needs expansion. 569void DAGTypeLegalizer::ExpandFloatResult(SDNode *N, unsigned ResNo) { 570 DEBUG(cerr << "Expand float result: "; N->dump(&DAG); cerr << "\n"); 571 SDOperand Lo, Hi; 572 Lo = Hi = SDOperand(); 573 574 // See if the target wants to custom expand this node. 575 if (TLI.getOperationAction(N->getOpcode(), N->getValueType(ResNo)) == 576 TargetLowering::Custom) { 577 // If the target wants to, allow it to lower this itself. 578 if (SDNode *P = TLI.ReplaceNodeResults(N, DAG)) { 579 // Everything that once used N now uses P. We are guaranteed that the 580 // result value types of N and the result value types of P match. 581 ReplaceNodeWith(N, P); 582 return; 583 } 584 } 585 586 switch (N->getOpcode()) { 587 default: 588#ifndef NDEBUG 589 cerr << "ExpandFloatResult #" << ResNo << ": "; 590 N->dump(&DAG); cerr << "\n"; 591#endif 592 assert(0 && "Do not know how to expand the result of this operator!"); 593 abort(); 594 595 case ISD::MERGE_VALUES: SplitRes_MERGE_VALUES(N, Lo, Hi); break; 596 case ISD::UNDEF: SplitRes_UNDEF(N, Lo, Hi); break; 597 case ISD::SELECT: SplitRes_SELECT(N, Lo, Hi); break; 598 case ISD::SELECT_CC: SplitRes_SELECT_CC(N, Lo, Hi); break; 599 600 case ISD::BIT_CONVERT: ExpandRes_BIT_CONVERT(N, Lo, Hi); break; 601 case ISD::BUILD_PAIR: ExpandRes_BUILD_PAIR(N, Lo, Hi); break; 602 case ISD::EXTRACT_ELEMENT: ExpandRes_EXTRACT_ELEMENT(N, Lo, Hi); break; 603 case ISD::EXTRACT_VECTOR_ELT: ExpandRes_EXTRACT_VECTOR_ELT(N, Lo, Hi); break; 604 605 case ISD::ConstantFP: ExpandFloatRes_ConstantFP(N, Lo, Hi); break; 606 case ISD::FADD: ExpandFloatRes_FADD(N, Lo, Hi); break; 607 case ISD::FDIV: ExpandFloatRes_FDIV(N, Lo, Hi); break; 608 case ISD::FMUL: ExpandFloatRes_FMUL(N, Lo, Hi); break; 609 case ISD::FSUB: ExpandFloatRes_FSUB(N, Lo, Hi); break; 610 case ISD::LOAD: ExpandFloatRes_LOAD(N, Lo, Hi); break; 611 case ISD::SINT_TO_FP: 612 case ISD::UINT_TO_FP: ExpandFloatRes_XINT_TO_FP(N, Lo, Hi); break; 613 } 614 615 // If Lo/Hi is null, the sub-method took care of registering results etc. 616 if (Lo.Val) 617 SetExpandedFloat(SDOperand(N, ResNo), Lo, Hi); 618} 619 620void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDOperand &Lo, 621 SDOperand &Hi) { 622 MVT NVT = TLI.getTypeToTransformTo(N->getValueType(0)); 623 assert(NVT.getSizeInBits() == integerPartWidth && 624 "Do not know how to expand this float constant!"); 625 APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().convertToAPInt(); 626 Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1, 627 &C.getRawData()[1])), NVT); 628 Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1, 629 &C.getRawData()[0])), NVT); 630} 631 632void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode *N, SDOperand &Lo, 633 SDOperand &Hi) { 634 SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) }; 635 SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0), 636 RTLIB::ADD_F32, 637 RTLIB::ADD_F64, 638 RTLIB::ADD_F80, 639 RTLIB::ADD_PPCF128), 640 N->getValueType(0), Ops, 2, 641 false); 642 assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!"); 643 Lo = Call.getOperand(0); Hi = Call.getOperand(1); 644} 645 646void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode *N, SDOperand &Lo, 647 SDOperand &Hi) { 648 SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) }; 649 SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0), 650 RTLIB::DIV_F32, 651 RTLIB::DIV_F64, 652 RTLIB::DIV_F80, 653 RTLIB::DIV_PPCF128), 654 N->getValueType(0), Ops, 2, 655 false); 656 assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!"); 657 Lo = Call.getOperand(0); Hi = Call.getOperand(1); 658} 659 660void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode *N, SDOperand &Lo, 661 SDOperand &Hi) { 662 SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) }; 663 SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0), 664 RTLIB::MUL_F32, 665 RTLIB::MUL_F64, 666 RTLIB::MUL_F80, 667 RTLIB::MUL_PPCF128), 668 N->getValueType(0), Ops, 2, 669 false); 670 assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!"); 671 Lo = Call.getOperand(0); Hi = Call.getOperand(1); 672} 673 674void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode *N, SDOperand &Lo, 675 SDOperand &Hi) { 676 SDOperand Ops[2] = { N->getOperand(0), N->getOperand(1) }; 677 SDOperand Call = MakeLibCall(GetFPLibCall(N->getValueType(0), 678 RTLIB::SUB_F32, 679 RTLIB::SUB_F64, 680 RTLIB::SUB_F80, 681 RTLIB::SUB_PPCF128), 682 N->getValueType(0), Ops, 2, 683 false); 684 assert(Call.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!"); 685 Lo = Call.getOperand(0); Hi = Call.getOperand(1); 686} 687 688void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode *N, SDOperand &Lo, 689 SDOperand &Hi) { 690 if (ISD::isNormalLoad(N)) { 691 ExpandRes_NormalLoad(N, Lo, Hi); 692 return; 693 } 694 695 assert(ISD::isUNINDEXEDLoad(N) && "Indexed load during type legalization!"); 696 LoadSDNode *LD = cast<LoadSDNode>(N); 697 SDOperand Chain = LD->getChain(); 698 SDOperand Ptr = LD->getBasePtr(); 699 700 MVT NVT = TLI.getTypeToTransformTo(LD->getValueType(0)); 701 assert(NVT.isByteSized() && "Expanded type not byte sized!"); 702 assert(LD->getMemoryVT().bitsLE(NVT) && "Float type not round?"); 703 704 Lo = DAG.getExtLoad(LD->getExtensionType(), NVT, Chain, Ptr, 705 LD->getSrcValue(), LD->getSrcValueOffset(), 706 LD->getMemoryVT(), 707 LD->isVolatile(), LD->getAlignment()); 708 709 // Remember the chain. 710 Chain = Lo.getValue(1); 711 712 // The high part is undefined. 713 Hi = DAG.getNode(ISD::UNDEF, NVT); 714 715 // Modified the chain - switch anything that used the old chain to use the 716 // new one. 717 ReplaceValueWith(SDOperand(LD, 1), Chain); 718} 719 720void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDOperand &Lo, 721 SDOperand &Hi) { 722 assert(N->getValueType(0) == MVT::ppcf128 && "Unsupported XINT_TO_FP!"); 723 MVT VT = N->getValueType(0); 724 MVT NVT = TLI.getTypeToTransformTo(VT); 725 SDOperand Src = N->getOperand(0); 726 MVT SrcVT = Src.getValueType(); 727 728 // First do an SINT_TO_FP, whether the original was signed or unsigned. 729 if (SrcVT.bitsLE(MVT::i32)) { 730 // The integer can be represented exactly in an f64. 731 Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Src); 732 Lo = DAG.getConstantFP(APFloat(APInt(NVT.getSizeInBits(), 0)), NVT); 733 Hi = DAG.getNode(ISD::SINT_TO_FP, NVT, Src); 734 } else { 735 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 736 if (SrcVT.bitsLE(MVT::i64)) { 737 Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Src); 738 LC = RTLIB::SINTTOFP_I64_PPCF128; 739 } else if (SrcVT.bitsLE(MVT::i128)) { 740 Src = DAG.getNode(ISD::SIGN_EXTEND, MVT::i128, Src); 741 LC = RTLIB::SINTTOFP_I128_PPCF128; 742 } 743 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!"); 744 745 Hi = MakeLibCall(LC, VT, &Src, 1, true); 746 assert(Hi.Val->getOpcode() == ISD::BUILD_PAIR && "Call lowered wrongly!"); 747 Lo = Hi.getOperand(0); Hi = Hi.getOperand(1); 748 } 749 750 if (N->getOpcode() == ISD::SINT_TO_FP) 751 return; 752 753 // Unsigned - fix up the SINT_TO_FP value just calculated. 754 Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi); 755 SrcVT = Src.getValueType(); 756 757 // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128. 758 static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 }; 759 static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 }; 760 static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 }; 761 const uint64_t *Parts = 0; 762 763 switch (SrcVT.getSimpleVT()) { 764 default: 765 assert(false && "Unsupported UINT_TO_FP!"); 766 case MVT::i32: 767 Parts = TwoE32; 768 case MVT::i64: 769 Parts = TwoE64; 770 case MVT::i128: 771 Parts = TwoE128; 772 } 773 774 Lo = DAG.getNode(ISD::FADD, VT, Hi, 775 DAG.getConstantFP(APFloat(APInt(128, 2, Parts)), 776 MVT::ppcf128)); 777 Lo = DAG.getNode(ISD::SELECT_CC, VT, Src, DAG.getConstant(0, SrcVT), Lo, Hi, 778 DAG.getCondCode(ISD::SETLT)); 779 Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo, 780 DAG.getConstant(1, TLI.getPointerTy())); 781 Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, NVT, Lo, 782 DAG.getConstant(0, TLI.getPointerTy())); 783} 784 785 786//===----------------------------------------------------------------------===// 787// Float Operand Expansion 788//===----------------------------------------------------------------------===// 789 790/// ExpandFloatOperand - This method is called when the specified operand of the 791/// specified node is found to need expansion. At this point, all of the result 792/// types of the node are known to be legal, but other operands of the node may 793/// need promotion or expansion as well as the specified one. 794bool DAGTypeLegalizer::ExpandFloatOperand(SDNode *N, unsigned OpNo) { 795 DEBUG(cerr << "Expand float operand: "; N->dump(&DAG); cerr << "\n"); 796 SDOperand Res(0, 0); 797 798 if (TLI.getOperationAction(N->getOpcode(), N->getOperand(OpNo).getValueType()) 799 == TargetLowering::Custom) 800 Res = TLI.LowerOperation(SDOperand(N, OpNo), DAG); 801 802 if (Res.Val == 0) { 803 switch (N->getOpcode()) { 804 default: 805 #ifndef NDEBUG 806 cerr << "ExpandFloatOperand Op #" << OpNo << ": "; 807 N->dump(&DAG); cerr << "\n"; 808 #endif 809 assert(0 && "Do not know how to expand this operator's operand!"); 810 abort(); 811 812 case ISD::BIT_CONVERT: Res = ExpandOp_BIT_CONVERT(N); break; 813 case ISD::BUILD_VECTOR: Res = ExpandOp_BUILD_VECTOR(N); break; 814 case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break; 815 816 case ISD::BR_CC: Res = ExpandFloatOp_BR_CC(N); break; 817 case ISD::SELECT_CC: Res = ExpandFloatOp_SELECT_CC(N); break; 818 case ISD::SETCC: Res = ExpandFloatOp_SETCC(N); break; 819 820 case ISD::FP_ROUND: Res = ExpandFloatOp_FP_ROUND(N); break; 821 case ISD::FP_TO_SINT: Res = ExpandFloatOp_FP_TO_SINT(N); break; 822 case ISD::FP_TO_UINT: Res = ExpandFloatOp_FP_TO_UINT(N); break; 823 824 case ISD::STORE: 825 Res = ExpandFloatOp_STORE(cast<StoreSDNode>(N), OpNo); 826 break; 827 } 828 } 829 830 // If the result is null, the sub-method took care of registering results etc. 831 if (!Res.Val) return false; 832 // If the result is N, the sub-method updated N in place. Check to see if any 833 // operands are new, and if so, mark them. 834 if (Res.Val == N) { 835 // Mark N as new and remark N and its operands. This allows us to correctly 836 // revisit N if it needs another step of expansion and allows us to visit 837 // any new operands to N. 838 ReanalyzeNode(N); 839 return true; 840 } 841 842 assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 && 843 "Invalid operand expansion"); 844 845 ReplaceValueWith(SDOperand(N, 0), Res); 846 return false; 847} 848 849/// FloatExpandSetCCOperands - Expand the operands of a comparison. This code 850/// is shared among BR_CC, SELECT_CC, and SETCC handlers. 851void DAGTypeLegalizer::FloatExpandSetCCOperands(SDOperand &NewLHS, 852 SDOperand &NewRHS, 853 ISD::CondCode &CCCode) { 854 SDOperand LHSLo, LHSHi, RHSLo, RHSHi; 855 GetExpandedFloat(NewLHS, LHSLo, LHSHi); 856 GetExpandedFloat(NewRHS, RHSLo, RHSHi); 857 858 MVT VT = NewLHS.getValueType(); 859 assert(VT == MVT::ppcf128 && "Unsupported setcc type!"); 860 861 // FIXME: This generated code sucks. We want to generate 862 // FCMP crN, hi1, hi2 863 // BNE crN, L: 864 // FCMP crN, lo1, lo2 865 // The following can be improved, but not that much. 866 SDOperand Tmp1, Tmp2, Tmp3; 867 Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETEQ); 868 Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode); 869 Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); 870 Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETNE); 871 Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode); 872 Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2); 873 NewLHS = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3); 874 NewRHS = SDOperand(); // LHS is the result, not a compare. 875} 876 877SDOperand DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode *N) { 878 SDOperand NewLHS = N->getOperand(2), NewRHS = N->getOperand(3); 879 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get(); 880 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode); 881 882 // If ExpandSetCCOperands returned a scalar, we need to compare the result 883 // against zero to select between true and false values. 884 if (NewRHS.Val == 0) { 885 NewRHS = DAG.getConstant(0, NewLHS.getValueType()); 886 CCCode = ISD::SETNE; 887 } 888 889 // Update N to have the operands specified. 890 return DAG.UpdateNodeOperands(SDOperand(N, 0), N->getOperand(0), 891 DAG.getCondCode(CCCode), NewLHS, NewRHS, 892 N->getOperand(4)); 893} 894 895SDOperand DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode *N) { 896 SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1); 897 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get(); 898 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode); 899 900 // If ExpandSetCCOperands returned a scalar, we need to compare the result 901 // against zero to select between true and false values. 902 if (NewRHS.Val == 0) { 903 NewRHS = DAG.getConstant(0, NewLHS.getValueType()); 904 CCCode = ISD::SETNE; 905 } 906 907 // Update N to have the operands specified. 908 return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS, 909 N->getOperand(2), N->getOperand(3), 910 DAG.getCondCode(CCCode)); 911} 912 913SDOperand DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode *N) { 914 SDOperand NewLHS = N->getOperand(0), NewRHS = N->getOperand(1); 915 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get(); 916 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode); 917 918 // If ExpandSetCCOperands returned a scalar, use it. 919 if (NewRHS.Val == 0) { 920 assert(NewLHS.getValueType() == N->getValueType(0) && 921 "Unexpected setcc expansion!"); 922 return NewLHS; 923 } 924 925 // Otherwise, update N to have the operands specified. 926 return DAG.UpdateNodeOperands(SDOperand(N, 0), NewLHS, NewRHS, 927 DAG.getCondCode(CCCode)); 928} 929 930SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) { 931 assert(N->getOperand(0).getValueType() == MVT::ppcf128 && 932 "Unsupported FP_TO_UINT!"); 933 934 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 935 switch (N->getValueType(0).getSimpleVT()) { 936 default: 937 assert(false && "Unsupported FP_TO_UINT!"); 938 case MVT::i32: 939 LC = RTLIB::FPTOUINT_PPCF128_I32; 940 break; 941 case MVT::i64: 942 LC = RTLIB::FPTOUINT_PPCF128_I64; 943 break; 944 case MVT::i128: 945 LC = RTLIB::FPTOUINT_PPCF128_I128; 946 break; 947 } 948 949 return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false); 950} 951 952SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) { 953 assert(N->getOperand(0).getValueType() == MVT::ppcf128 && 954 "Unsupported FP_TO_SINT!"); 955 956 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 957 switch (N->getValueType(0).getSimpleVT()) { 958 default: 959 assert(false && "Unsupported FP_TO_SINT!"); 960 case MVT::i32: 961 LC = RTLIB::FPTOSINT_PPCF128_I32; 962 case MVT::i64: 963 LC = RTLIB::FPTOSINT_PPCF128_I64; 964 break; 965 case MVT::i128: 966 LC = RTLIB::FPTOSINT_PPCF128_I64; 967 break; 968 } 969 970 return MakeLibCall(LC, N->getValueType(0), &N->getOperand(0), 1, false); 971} 972 973SDOperand DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode *N) { 974 assert(N->getOperand(0).getValueType() == MVT::ppcf128 && 975 "Logic only correct for ppcf128!"); 976 SDOperand Lo, Hi; 977 GetExpandedFloat(N->getOperand(0), Lo, Hi); 978 // Round it the rest of the way (e.g. to f32) if needed. 979 return DAG.getNode(ISD::FP_ROUND, N->getValueType(0), Hi, N->getOperand(1)); 980} 981 982SDOperand DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode *N, unsigned OpNo) { 983 if (ISD::isNormalStore(N)) 984 return ExpandOp_NormalStore(N, OpNo); 985 986 assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!"); 987 assert(OpNo == 1 && "Can only expand the stored value so far"); 988 StoreSDNode *ST = cast<StoreSDNode>(N); 989 990 SDOperand Chain = ST->getChain(); 991 SDOperand Ptr = ST->getBasePtr(); 992 993 MVT NVT = TLI.getTypeToTransformTo(ST->getValue().getValueType()); 994 assert(NVT.isByteSized() && "Expanded type not byte sized!"); 995 assert(ST->getMemoryVT().bitsLE(NVT) && "Float type not round?"); 996 997 SDOperand Lo, Hi; 998 GetExpandedOp(ST->getValue(), Lo, Hi); 999 1000 return DAG.getTruncStore(Chain, Lo, Ptr, 1001 ST->getSrcValue(), ST->getSrcValueOffset(), 1002 ST->getMemoryVT(), 1003 ST->isVolatile(), ST->getAlignment()); 1004} 1005