1 //===-------- LegalizeFloatTypes.cpp - Legalization of float types --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
20 //===----------------------------------------------------------------------===//
22 #include "LegalizeTypes.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/raw_ostream.h"
27 #define DEBUG_TYPE "legalize-types"
29 /// GetFPLibCall - Return the right libcall for the given floating point type.
30 static RTLIB::Libcall GetFPLibCall(EVT VT,
31 RTLIB::Libcall Call_F32,
32 RTLIB::Libcall Call_F64,
33 RTLIB::Libcall Call_F80,
34 RTLIB::Libcall Call_F128,
35 RTLIB::Libcall Call_PPCF128) {
37 VT == MVT::f32 ? Call_F32 :
38 VT == MVT::f64 ? Call_F64 :
39 VT == MVT::f80 ? Call_F80 :
40 VT == MVT::f128 ? Call_F128 :
41 VT == MVT::ppcf128 ? Call_PPCF128 :
42 RTLIB::UNKNOWN_LIBCALL;
45 //===----------------------------------------------------------------------===//
46 // Convert Float Results to Integer for Non-HW-supported Operations.
47 //===----------------------------------------------------------------------===//
49 bool DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
50 DEBUG(dbgs() << "Soften float result " << ResNo << ": "; N->dump(&DAG);
52 SDValue R = SDValue();
54 switch (N->getOpcode()) {
57 dbgs() << "SoftenFloatResult #" << ResNo << ": ";
58 N->dump(&DAG); dbgs() << "\n";
60 llvm_unreachable("Do not know how to soften the result of this operator!");
63 case ISD::CopyFromReg:
65 assert(isLegalInHWReg(N->getValueType(ResNo)) &&
66 "Unsupported SoftenFloatRes opcode!");
67 // Only when isLegalInHWReg, we can skip check of the operands.
68 R = SDValue(N, ResNo);
70 case ISD::MERGE_VALUES:R = SoftenFloatRes_MERGE_VALUES(N, ResNo); break;
71 case ISD::BITCAST: R = SoftenFloatRes_BITCAST(N, ResNo); break;
72 case ISD::BUILD_PAIR: R = SoftenFloatRes_BUILD_PAIR(N); break;
73 case ISD::ConstantFP: R = SoftenFloatRes_ConstantFP(N, ResNo); break;
74 case ISD::EXTRACT_VECTOR_ELT:
75 R = SoftenFloatRes_EXTRACT_VECTOR_ELT(N); break;
76 case ISD::FABS: R = SoftenFloatRes_FABS(N, ResNo); break;
77 case ISD::FMINNUM: R = SoftenFloatRes_FMINNUM(N); break;
78 case ISD::FMAXNUM: R = SoftenFloatRes_FMAXNUM(N); break;
79 case ISD::FADD: R = SoftenFloatRes_FADD(N); break;
80 case ISD::FCEIL: R = SoftenFloatRes_FCEIL(N); break;
81 case ISD::FCOPYSIGN: R = SoftenFloatRes_FCOPYSIGN(N, ResNo); break;
82 case ISD::FCOS: R = SoftenFloatRes_FCOS(N); break;
83 case ISD::FDIV: R = SoftenFloatRes_FDIV(N); break;
84 case ISD::FEXP: R = SoftenFloatRes_FEXP(N); break;
85 case ISD::FEXP2: R = SoftenFloatRes_FEXP2(N); break;
86 case ISD::FFLOOR: R = SoftenFloatRes_FFLOOR(N); break;
87 case ISD::FLOG: R = SoftenFloatRes_FLOG(N); break;
88 case ISD::FLOG2: R = SoftenFloatRes_FLOG2(N); break;
89 case ISD::FLOG10: R = SoftenFloatRes_FLOG10(N); break;
90 case ISD::FMA: R = SoftenFloatRes_FMA(N); break;
91 case ISD::FMUL: R = SoftenFloatRes_FMUL(N); break;
92 case ISD::FNEARBYINT: R = SoftenFloatRes_FNEARBYINT(N); break;
93 case ISD::FNEG: R = SoftenFloatRes_FNEG(N, ResNo); break;
94 case ISD::FP_EXTEND: R = SoftenFloatRes_FP_EXTEND(N); break;
95 case ISD::FP_ROUND: R = SoftenFloatRes_FP_ROUND(N); break;
96 case ISD::FP16_TO_FP: R = SoftenFloatRes_FP16_TO_FP(N); break;
97 case ISD::FPOW: R = SoftenFloatRes_FPOW(N); break;
98 case ISD::FPOWI: R = SoftenFloatRes_FPOWI(N); break;
99 case ISD::FREM: R = SoftenFloatRes_FREM(N); break;
100 case ISD::FRINT: R = SoftenFloatRes_FRINT(N); break;
101 case ISD::FROUND: R = SoftenFloatRes_FROUND(N); break;
102 case ISD::FSIN: R = SoftenFloatRes_FSIN(N); break;
103 case ISD::FSQRT: R = SoftenFloatRes_FSQRT(N); break;
104 case ISD::FSUB: R = SoftenFloatRes_FSUB(N); break;
105 case ISD::FTRUNC: R = SoftenFloatRes_FTRUNC(N); break;
106 case ISD::LOAD: R = SoftenFloatRes_LOAD(N, ResNo); break;
107 case ISD::SELECT: R = SoftenFloatRes_SELECT(N, ResNo); break;
108 case ISD::SELECT_CC: R = SoftenFloatRes_SELECT_CC(N, ResNo); break;
109 case ISD::SINT_TO_FP:
110 case ISD::UINT_TO_FP: R = SoftenFloatRes_XINT_TO_FP(N); break;
111 case ISD::UNDEF: R = SoftenFloatRes_UNDEF(N); break;
112 case ISD::VAARG: R = SoftenFloatRes_VAARG(N); break;
115 // If R is null, the sub-method took care of registering the result.
117 SetSoftenedFloat(SDValue(N, ResNo), R);
118 ReplaceSoftenFloatResult(N, ResNo, R);
120 // Return true only if the node is changed,
121 // assuming that the operands are also converted when necessary.
122 // Otherwise, return false to tell caller to scan operands.
123 return R.getNode() && R.getNode() != N;
126 SDValue DAGTypeLegalizer::SoftenFloatRes_BITCAST(SDNode *N, unsigned ResNo) {
127 if (isLegalInHWReg(N->getValueType(ResNo)))
128 return SDValue(N, ResNo);
129 return BitConvertToInteger(N->getOperand(0));
132 SDValue DAGTypeLegalizer::SoftenFloatRes_MERGE_VALUES(SDNode *N,
134 SDValue Op = DisintegrateMERGE_VALUES(N, ResNo);
135 return BitConvertToInteger(Op);
138 SDValue DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode *N) {
139 // Convert the inputs to integers, and build a new pair out of them.
140 return DAG.getNode(ISD::BUILD_PAIR, SDLoc(N),
141 TLI.getTypeToTransformTo(*DAG.getContext(),
143 BitConvertToInteger(N->getOperand(0)),
144 BitConvertToInteger(N->getOperand(1)));
147 SDValue DAGTypeLegalizer::SoftenFloatRes_ConstantFP(SDNode *N, unsigned ResNo) {
148 // When LegalInHWReg, we can load better from the constant pool.
149 if (isLegalInHWReg(N->getValueType(ResNo)))
150 return SDValue(N, ResNo);
151 ConstantFPSDNode *CN = cast<ConstantFPSDNode>(N);
152 return DAG.getConstant(CN->getValueAPF().bitcastToAPInt(), SDLoc(CN),
153 TLI.getTypeToTransformTo(*DAG.getContext(),
154 CN->getValueType(0)));
157 SDValue DAGTypeLegalizer::SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode *N) {
158 SDValue NewOp = BitConvertVectorToIntegerVector(N->getOperand(0));
159 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(N),
160 NewOp.getValueType().getVectorElementType(),
161 NewOp, N->getOperand(1));
164 SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N, unsigned ResNo) {
165 // When LegalInHWReg, FABS can be implemented as native bitwise operations.
166 if (isLegalInHWReg(N->getValueType(ResNo)))
167 return SDValue(N, ResNo);
168 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
169 unsigned Size = NVT.getSizeInBits();
171 // Mask = ~(1 << (Size-1))
172 APInt API = APInt::getAllOnesValue(Size);
173 API.clearBit(Size - 1);
174 SDValue Mask = DAG.getConstant(API, SDLoc(N), NVT);
175 SDValue Op = GetSoftenedFloat(N->getOperand(0));
176 return DAG.getNode(ISD::AND, SDLoc(N), NVT, Op, Mask);
179 SDValue DAGTypeLegalizer::SoftenFloatRes_FMINNUM(SDNode *N) {
180 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
181 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
182 GetSoftenedFloat(N->getOperand(1)) };
183 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
188 RTLIB::FMIN_PPCF128),
189 NVT, Ops, false, SDLoc(N)).first;
192 SDValue DAGTypeLegalizer::SoftenFloatRes_FMAXNUM(SDNode *N) {
193 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
194 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
195 GetSoftenedFloat(N->getOperand(1)) };
196 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
201 RTLIB::FMAX_PPCF128),
202 NVT, Ops, false, SDLoc(N)).first;
205 SDValue DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode *N) {
206 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
207 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
208 GetSoftenedFloat(N->getOperand(1)) };
209 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
215 NVT, Ops, false, SDLoc(N)).first;
218 SDValue DAGTypeLegalizer::SoftenFloatRes_FCEIL(SDNode *N) {
219 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
220 SDValue Op = GetSoftenedFloat(N->getOperand(0));
221 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
226 RTLIB::CEIL_PPCF128),
227 NVT, Op, false, SDLoc(N)).first;
230 SDValue DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode *N, unsigned ResNo) {
231 // When LegalInHWReg, FCOPYSIGN can be implemented as native bitwise operations.
232 if (isLegalInHWReg(N->getValueType(ResNo)))
233 return SDValue(N, ResNo);
234 SDValue LHS = GetSoftenedFloat(N->getOperand(0));
235 SDValue RHS = BitConvertToInteger(N->getOperand(1));
238 EVT LVT = LHS.getValueType();
239 EVT RVT = RHS.getValueType();
241 unsigned LSize = LVT.getSizeInBits();
242 unsigned RSize = RVT.getSizeInBits();
244 // First get the sign bit of second operand.
245 SDValue SignBit = DAG.getNode(
246 ISD::SHL, dl, RVT, DAG.getConstant(1, dl, RVT),
247 DAG.getConstant(RSize - 1, dl,
248 TLI.getShiftAmountTy(RVT, DAG.getDataLayout())));
249 SignBit = DAG.getNode(ISD::AND, dl, RVT, RHS, SignBit);
251 // Shift right or sign-extend it if the two operands have different types.
252 int SizeDiff = RVT.getSizeInBits() - LVT.getSizeInBits();
255 DAG.getNode(ISD::SRL, dl, RVT, SignBit,
256 DAG.getConstant(SizeDiff, dl,
257 TLI.getShiftAmountTy(SignBit.getValueType(),
258 DAG.getDataLayout())));
259 SignBit = DAG.getNode(ISD::TRUNCATE, dl, LVT, SignBit);
260 } else if (SizeDiff < 0) {
261 SignBit = DAG.getNode(ISD::ANY_EXTEND, dl, LVT, SignBit);
263 DAG.getNode(ISD::SHL, dl, LVT, SignBit,
264 DAG.getConstant(-SizeDiff, dl,
265 TLI.getShiftAmountTy(SignBit.getValueType(),
266 DAG.getDataLayout())));
269 // Clear the sign bit of the first operand.
270 SDValue Mask = DAG.getNode(
271 ISD::SHL, dl, LVT, DAG.getConstant(1, dl, LVT),
272 DAG.getConstant(LSize - 1, dl,
273 TLI.getShiftAmountTy(LVT, DAG.getDataLayout())));
274 Mask = DAG.getNode(ISD::SUB, dl, LVT, Mask, DAG.getConstant(1, dl, LVT));
275 LHS = DAG.getNode(ISD::AND, dl, LVT, LHS, Mask);
277 // Or the value with the sign bit.
278 return DAG.getNode(ISD::OR, dl, LVT, LHS, SignBit);
281 SDValue DAGTypeLegalizer::SoftenFloatRes_FCOS(SDNode *N) {
282 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
283 SDValue Op = GetSoftenedFloat(N->getOperand(0));
284 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
290 NVT, Op, false, SDLoc(N)).first;
293 SDValue DAGTypeLegalizer::SoftenFloatRes_FDIV(SDNode *N) {
294 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
295 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
296 GetSoftenedFloat(N->getOperand(1)) };
297 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
303 NVT, Ops, false, SDLoc(N)).first;
306 SDValue DAGTypeLegalizer::SoftenFloatRes_FEXP(SDNode *N) {
307 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
308 SDValue Op = GetSoftenedFloat(N->getOperand(0));
309 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
315 NVT, Op, false, SDLoc(N)).first;
318 SDValue DAGTypeLegalizer::SoftenFloatRes_FEXP2(SDNode *N) {
319 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
320 SDValue Op = GetSoftenedFloat(N->getOperand(0));
321 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
326 RTLIB::EXP2_PPCF128),
327 NVT, Op, false, SDLoc(N)).first;
330 SDValue DAGTypeLegalizer::SoftenFloatRes_FFLOOR(SDNode *N) {
331 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
332 SDValue Op = GetSoftenedFloat(N->getOperand(0));
333 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
338 RTLIB::FLOOR_PPCF128),
339 NVT, Op, false, SDLoc(N)).first;
342 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG(SDNode *N) {
343 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
344 SDValue Op = GetSoftenedFloat(N->getOperand(0));
345 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
351 NVT, Op, false, SDLoc(N)).first;
354 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG2(SDNode *N) {
355 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
356 SDValue Op = GetSoftenedFloat(N->getOperand(0));
357 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
362 RTLIB::LOG2_PPCF128),
363 NVT, Op, false, SDLoc(N)).first;
366 SDValue DAGTypeLegalizer::SoftenFloatRes_FLOG10(SDNode *N) {
367 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
368 SDValue Op = GetSoftenedFloat(N->getOperand(0));
369 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
374 RTLIB::LOG10_PPCF128),
375 NVT, Op, false, SDLoc(N)).first;
378 SDValue DAGTypeLegalizer::SoftenFloatRes_FMA(SDNode *N) {
379 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
380 SDValue Ops[3] = { GetSoftenedFloat(N->getOperand(0)),
381 GetSoftenedFloat(N->getOperand(1)),
382 GetSoftenedFloat(N->getOperand(2)) };
383 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
389 NVT, Ops, false, SDLoc(N)).first;
392 SDValue DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode *N) {
393 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
394 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
395 GetSoftenedFloat(N->getOperand(1)) };
396 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
402 NVT, Ops, false, SDLoc(N)).first;
405 SDValue DAGTypeLegalizer::SoftenFloatRes_FNEARBYINT(SDNode *N) {
406 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
407 SDValue Op = GetSoftenedFloat(N->getOperand(0));
408 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
409 RTLIB::NEARBYINT_F32,
410 RTLIB::NEARBYINT_F64,
411 RTLIB::NEARBYINT_F80,
412 RTLIB::NEARBYINT_F128,
413 RTLIB::NEARBYINT_PPCF128),
414 NVT, Op, false, SDLoc(N)).first;
417 SDValue DAGTypeLegalizer::SoftenFloatRes_FNEG(SDNode *N, unsigned ResNo) {
418 // When LegalInHWReg, FNEG can be implemented as native bitwise operations.
419 if (isLegalInHWReg(N->getValueType(ResNo)))
420 return SDValue(N, ResNo);
421 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
423 // Expand Y = FNEG(X) -> Y = SUB -0.0, X
424 SDValue Ops[2] = { DAG.getConstantFP(-0.0, dl, N->getValueType(0)),
425 GetSoftenedFloat(N->getOperand(0)) };
426 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
432 NVT, Ops, false, dl).first;
435 SDValue DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode *N) {
436 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
437 SDValue Op = N->getOperand(0);
439 // There's only a libcall for f16 -> f32, so proceed in two stages. Also, it's
440 // entirely possible for both f16 and f32 to be legal, so use the fully
441 // hard-float FP_EXTEND rather than FP16_TO_FP.
442 if (Op.getValueType() == MVT::f16 && N->getValueType(0) != MVT::f32) {
443 Op = DAG.getNode(ISD::FP_EXTEND, SDLoc(N), MVT::f32, Op);
444 if (getTypeAction(MVT::f32) == TargetLowering::TypeSoftenFloat)
445 SoftenFloatResult(Op.getNode(), 0);
448 if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat) {
449 Op = GetPromotedFloat(Op);
450 // If the promotion did the FP_EXTEND to the destination type for us,
451 // there's nothing left to do here.
452 if (Op.getValueType() == N->getValueType(0)) {
453 return BitConvertToInteger(Op);
457 RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
458 if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftenFloat)
459 Op = GetSoftenedFloat(Op);
460 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
461 return TLI.makeLibCall(DAG, LC, NVT, Op, false, SDLoc(N)).first;
464 // FIXME: Should we just use 'normal' FP_EXTEND / FP_TRUNC instead of special
466 SDValue DAGTypeLegalizer::SoftenFloatRes_FP16_TO_FP(SDNode *N) {
467 EVT MidVT = TLI.getTypeToTransformTo(*DAG.getContext(), MVT::f32);
468 SDValue Op = N->getOperand(0);
469 SDValue Res32 = TLI.makeLibCall(DAG, RTLIB::FPEXT_F16_F32, MidVT, Op,
470 false, SDLoc(N)).first;
471 if (N->getValueType(0) == MVT::f32)
474 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
475 RTLIB::Libcall LC = RTLIB::getFPEXT(MVT::f32, N->getValueType(0));
476 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
477 return TLI.makeLibCall(DAG, LC, NVT, Res32, false, SDLoc(N)).first;
480 SDValue DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode *N) {
481 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
482 SDValue Op = N->getOperand(0);
483 if (N->getValueType(0) == MVT::f16) {
484 // Semi-soften first, to FP_TO_FP16, so that targets which support f16 as a
485 // storage-only type get a chance to select things.
486 return DAG.getNode(ISD::FP_TO_FP16, SDLoc(N), NVT, Op);
489 RTLIB::Libcall LC = RTLIB::getFPROUND(Op.getValueType(), N->getValueType(0));
490 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
491 return TLI.makeLibCall(DAG, LC, NVT, Op, false, SDLoc(N)).first;
494 SDValue DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode *N) {
495 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
496 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
497 GetSoftenedFloat(N->getOperand(1)) };
498 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
504 NVT, Ops, false, SDLoc(N)).first;
507 SDValue DAGTypeLegalizer::SoftenFloatRes_FPOWI(SDNode *N) {
508 assert(N->getOperand(1).getValueType() == MVT::i32 &&
509 "Unsupported power type!");
510 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
511 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)), N->getOperand(1) };
512 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
517 RTLIB::POWI_PPCF128),
518 NVT, Ops, false, SDLoc(N)).first;
521 SDValue DAGTypeLegalizer::SoftenFloatRes_FREM(SDNode *N) {
522 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
523 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
524 GetSoftenedFloat(N->getOperand(1)) };
525 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
531 NVT, Ops, false, SDLoc(N)).first;
534 SDValue DAGTypeLegalizer::SoftenFloatRes_FRINT(SDNode *N) {
535 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
536 SDValue Op = GetSoftenedFloat(N->getOperand(0));
537 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
542 RTLIB::RINT_PPCF128),
543 NVT, Op, false, SDLoc(N)).first;
546 SDValue DAGTypeLegalizer::SoftenFloatRes_FROUND(SDNode *N) {
547 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
548 SDValue Op = GetSoftenedFloat(N->getOperand(0));
549 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
554 RTLIB::ROUND_PPCF128),
555 NVT, Op, false, SDLoc(N)).first;
558 SDValue DAGTypeLegalizer::SoftenFloatRes_FSIN(SDNode *N) {
559 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
560 SDValue Op = GetSoftenedFloat(N->getOperand(0));
561 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
567 NVT, Op, false, SDLoc(N)).first;
570 SDValue DAGTypeLegalizer::SoftenFloatRes_FSQRT(SDNode *N) {
571 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
572 SDValue Op = GetSoftenedFloat(N->getOperand(0));
573 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
578 RTLIB::SQRT_PPCF128),
579 NVT, Op, false, SDLoc(N)).first;
582 SDValue DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode *N) {
583 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
584 SDValue Ops[2] = { GetSoftenedFloat(N->getOperand(0)),
585 GetSoftenedFloat(N->getOperand(1)) };
586 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
592 NVT, Ops, false, SDLoc(N)).first;
595 SDValue DAGTypeLegalizer::SoftenFloatRes_FTRUNC(SDNode *N) {
596 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
597 if (N->getValueType(0) == MVT::f16)
598 return DAG.getNode(ISD::FP_TO_FP16, SDLoc(N), NVT, N->getOperand(0));
600 SDValue Op = GetSoftenedFloat(N->getOperand(0));
601 return TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
606 RTLIB::TRUNC_PPCF128),
607 NVT, Op, false, SDLoc(N)).first;
610 SDValue DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode *N, unsigned ResNo) {
611 bool LegalInHWReg = isLegalInHWReg(N->getValueType(ResNo));
612 LoadSDNode *L = cast<LoadSDNode>(N);
613 EVT VT = N->getValueType(0);
614 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
618 if (L->getExtensionType() == ISD::NON_EXTLOAD) {
619 NewL = DAG.getLoad(L->getAddressingMode(), L->getExtensionType(),
620 NVT, dl, L->getChain(), L->getBasePtr(), L->getOffset(),
621 L->getPointerInfo(), NVT, L->isVolatile(),
622 L->isNonTemporal(), false, L->getAlignment(),
624 // Legalized the chain result - switch anything that used the old chain to
626 if (N != NewL.getValue(1).getNode())
627 ReplaceValueWith(SDValue(N, 1), NewL.getValue(1));
631 // Do a non-extending load followed by FP_EXTEND.
632 NewL = DAG.getLoad(L->getAddressingMode(), ISD::NON_EXTLOAD,
633 L->getMemoryVT(), dl, L->getChain(),
634 L->getBasePtr(), L->getOffset(), L->getPointerInfo(),
635 L->getMemoryVT(), L->isVolatile(),
636 L->isNonTemporal(), false, L->getAlignment(),
638 // Legalized the chain result - switch anything that used the old chain to
640 ReplaceValueWith(SDValue(N, 1), NewL.getValue(1));
641 auto ExtendNode = DAG.getNode(ISD::FP_EXTEND, dl, VT, NewL);
644 return BitConvertToInteger(ExtendNode);
647 SDValue DAGTypeLegalizer::SoftenFloatRes_SELECT(SDNode *N, unsigned ResNo) {
648 if (isLegalInHWReg(N->getValueType(ResNo)))
649 return SDValue(N, ResNo);
650 SDValue LHS = GetSoftenedFloat(N->getOperand(1));
651 SDValue RHS = GetSoftenedFloat(N->getOperand(2));
652 return DAG.getSelect(SDLoc(N),
653 LHS.getValueType(), N->getOperand(0), LHS, RHS);
656 SDValue DAGTypeLegalizer::SoftenFloatRes_SELECT_CC(SDNode *N, unsigned ResNo) {
657 if (isLegalInHWReg(N->getValueType(ResNo)))
658 return SDValue(N, ResNo);
659 SDValue LHS = GetSoftenedFloat(N->getOperand(2));
660 SDValue RHS = GetSoftenedFloat(N->getOperand(3));
661 return DAG.getNode(ISD::SELECT_CC, SDLoc(N),
662 LHS.getValueType(), N->getOperand(0),
663 N->getOperand(1), LHS, RHS, N->getOperand(4));
666 SDValue DAGTypeLegalizer::SoftenFloatRes_UNDEF(SDNode *N) {
667 return DAG.getUNDEF(TLI.getTypeToTransformTo(*DAG.getContext(),
668 N->getValueType(0)));
671 SDValue DAGTypeLegalizer::SoftenFloatRes_VAARG(SDNode *N) {
672 SDValue Chain = N->getOperand(0); // Get the chain.
673 SDValue Ptr = N->getOperand(1); // Get the pointer.
674 EVT VT = N->getValueType(0);
675 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
679 NewVAARG = DAG.getVAArg(NVT, dl, Chain, Ptr, N->getOperand(2),
680 N->getConstantOperandVal(3));
682 // Legalized the chain result - switch anything that used the old chain to
684 if (N != NewVAARG.getValue(1).getNode())
685 ReplaceValueWith(SDValue(N, 1), NewVAARG.getValue(1));
689 SDValue DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode *N) {
690 bool Signed = N->getOpcode() == ISD::SINT_TO_FP;
691 EVT SVT = N->getOperand(0).getValueType();
692 EVT RVT = N->getValueType(0);
696 // If the input is not legal, eg: i1 -> fp, then it needs to be promoted to
697 // a larger type, eg: i8 -> fp. Even if it is legal, no libcall may exactly
698 // match. Look for an appropriate libcall.
699 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
700 for (unsigned t = MVT::FIRST_INTEGER_VALUETYPE;
701 t <= MVT::LAST_INTEGER_VALUETYPE && LC == RTLIB::UNKNOWN_LIBCALL; ++t) {
702 NVT = (MVT::SimpleValueType)t;
703 // The source needs to big enough to hold the operand.
705 LC = Signed ? RTLIB::getSINTTOFP(NVT, RVT):RTLIB::getUINTTOFP (NVT, RVT);
707 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
709 // Sign/zero extend the argument if the libcall takes a larger type.
710 SDValue Op = DAG.getNode(Signed ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
711 NVT, N->getOperand(0));
712 return TLI.makeLibCall(DAG, LC,
713 TLI.getTypeToTransformTo(*DAG.getContext(), RVT),
714 Op, Signed, dl).first;
718 //===----------------------------------------------------------------------===//
719 // Convert Float Operand to Integer for Non-HW-supported Operations.
720 //===----------------------------------------------------------------------===//
722 bool DAGTypeLegalizer::SoftenFloatOperand(SDNode *N, unsigned OpNo) {
723 DEBUG(dbgs() << "Soften float operand " << OpNo << ": "; N->dump(&DAG);
725 SDValue Res = SDValue();
727 switch (N->getOpcode()) {
729 if (CanSkipSoftenFloatOperand(N, OpNo))
732 dbgs() << "SoftenFloatOperand Op #" << OpNo << ": ";
733 N->dump(&DAG); dbgs() << "\n";
735 llvm_unreachable("Do not know how to soften this operator's operand!");
737 case ISD::BITCAST: Res = SoftenFloatOp_BITCAST(N); break;
738 case ISD::BR_CC: Res = SoftenFloatOp_BR_CC(N); break;
739 case ISD::FP_EXTEND: Res = SoftenFloatOp_FP_EXTEND(N); break;
740 case ISD::FP_TO_FP16: // Same as FP_ROUND for softening purposes
741 case ISD::FP_ROUND: Res = SoftenFloatOp_FP_ROUND(N); break;
742 case ISD::FP_TO_SINT: Res = SoftenFloatOp_FP_TO_SINT(N); break;
743 case ISD::FP_TO_UINT: Res = SoftenFloatOp_FP_TO_UINT(N); break;
744 case ISD::SELECT_CC: Res = SoftenFloatOp_SELECT_CC(N); break;
745 case ISD::SETCC: Res = SoftenFloatOp_SETCC(N); break;
747 Res = SoftenFloatOp_STORE(N, OpNo);
748 // Do not try to analyze or soften this node again if the value is
749 // or can be held in a register. In that case, Res.getNode() should
751 if (Res.getNode() == N &&
752 isLegalInHWReg(N->getOperand(OpNo).getValueType()))
754 // Otherwise, we need to reanalyze and lower the new Res nodes.
758 // If the result is null, the sub-method took care of registering results etc.
759 if (!Res.getNode()) return false;
761 // If the result is N, the sub-method updated N in place. Tell the legalizer
762 // core about this to re-analyze.
763 if (Res.getNode() == N)
766 assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
767 "Invalid operand expansion");
769 ReplaceValueWith(SDValue(N, 0), Res);
773 bool DAGTypeLegalizer::CanSkipSoftenFloatOperand(SDNode *N, unsigned OpNo) {
774 if (!isLegalInHWReg(N->getOperand(OpNo).getValueType()))
776 // When the operand type can be kept in registers, SoftenFloatResult
777 // will call ReplaceValueWith to replace all references and we can
778 // skip softening this operand.
779 switch (N->getOperand(OpNo).getOpcode()) {
781 case ISD::ConstantFP:
782 case ISD::CopyFromReg:
792 // For some opcodes, SoftenFloatResult handles all conversion of softening
793 // and replacing operands, so that there is no need to soften operands
794 // again, although such opcode could be scanned for other illegal operands.
795 switch (N->getOpcode()) {
796 case ISD::ConstantFP:
797 case ISD::CopyFromReg:
808 SDValue DAGTypeLegalizer::SoftenFloatOp_BITCAST(SDNode *N) {
809 return DAG.getNode(ISD::BITCAST, SDLoc(N), N->getValueType(0),
810 GetSoftenedFloat(N->getOperand(0)));
813 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_EXTEND(SDNode *N) {
814 // If we get here, the result must be legal but the source illegal.
815 EVT SVT = N->getOperand(0).getValueType();
816 EVT RVT = N->getValueType(0);
817 SDValue Op = GetSoftenedFloat(N->getOperand(0));
820 return DAG.getNode(ISD::FP16_TO_FP, SDLoc(N), RVT, Op);
822 RTLIB::Libcall LC = RTLIB::getFPEXT(SVT, RVT);
823 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND libcall");
825 return TLI.makeLibCall(DAG, LC, RVT, Op, false, SDLoc(N)).first;
829 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode *N) {
830 // We actually deal with the partially-softened FP_TO_FP16 node too, which
831 // returns an i16 so doesn't meet the constraints necessary for FP_ROUND.
832 assert(N->getOpcode() == ISD::FP_ROUND || N->getOpcode() == ISD::FP_TO_FP16);
834 EVT SVT = N->getOperand(0).getValueType();
835 EVT RVT = N->getValueType(0);
836 EVT FloatRVT = N->getOpcode() == ISD::FP_TO_FP16 ? MVT::f16 : RVT;
838 RTLIB::Libcall LC = RTLIB::getFPROUND(SVT, FloatRVT);
839 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND libcall");
841 SDValue Op = GetSoftenedFloat(N->getOperand(0));
842 return TLI.makeLibCall(DAG, LC, RVT, Op, false, SDLoc(N)).first;
845 SDValue DAGTypeLegalizer::SoftenFloatOp_BR_CC(SDNode *N) {
846 SDValue NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
847 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
849 EVT VT = NewLHS.getValueType();
850 NewLHS = GetSoftenedFloat(NewLHS);
851 NewRHS = GetSoftenedFloat(NewRHS);
852 TLI.softenSetCCOperands(DAG, VT, NewLHS, NewRHS, CCCode, SDLoc(N));
854 // If softenSetCCOperands returned a scalar, we need to compare the result
855 // against zero to select between true and false values.
856 if (!NewRHS.getNode()) {
857 NewRHS = DAG.getConstant(0, SDLoc(N), NewLHS.getValueType());
861 // Update N to have the operands specified.
862 return SDValue(DAG.UpdateNodeOperands(N, N->getOperand(0),
863 DAG.getCondCode(CCCode), NewLHS, NewRHS,
868 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_TO_SINT(SDNode *N) {
869 EVT RVT = N->getValueType(0);
870 RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
871 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
872 SDValue Op = GetSoftenedFloat(N->getOperand(0));
873 return TLI.makeLibCall(DAG, LC, RVT, Op, false, SDLoc(N)).first;
876 SDValue DAGTypeLegalizer::SoftenFloatOp_FP_TO_UINT(SDNode *N) {
877 EVT RVT = N->getValueType(0);
878 RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
879 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
880 SDValue Op = GetSoftenedFloat(N->getOperand(0));
881 return TLI.makeLibCall(DAG, LC, RVT, Op, false, SDLoc(N)).first;
884 SDValue DAGTypeLegalizer::SoftenFloatOp_SELECT_CC(SDNode *N) {
885 SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
886 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
888 EVT VT = NewLHS.getValueType();
889 NewLHS = GetSoftenedFloat(NewLHS);
890 NewRHS = GetSoftenedFloat(NewRHS);
891 TLI.softenSetCCOperands(DAG, VT, NewLHS, NewRHS, CCCode, SDLoc(N));
893 // If softenSetCCOperands returned a scalar, we need to compare the result
894 // against zero to select between true and false values.
895 if (!NewRHS.getNode()) {
896 NewRHS = DAG.getConstant(0, SDLoc(N), NewLHS.getValueType());
900 // Update N to have the operands specified.
901 return SDValue(DAG.UpdateNodeOperands(N, NewLHS, NewRHS,
902 N->getOperand(2), N->getOperand(3),
903 DAG.getCondCode(CCCode)),
907 SDValue DAGTypeLegalizer::SoftenFloatOp_SETCC(SDNode *N) {
908 SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
909 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
911 EVT VT = NewLHS.getValueType();
912 NewLHS = GetSoftenedFloat(NewLHS);
913 NewRHS = GetSoftenedFloat(NewRHS);
914 TLI.softenSetCCOperands(DAG, VT, NewLHS, NewRHS, CCCode, SDLoc(N));
916 // If softenSetCCOperands returned a scalar, use it.
917 if (!NewRHS.getNode()) {
918 assert(NewLHS.getValueType() == N->getValueType(0) &&
919 "Unexpected setcc expansion!");
923 // Otherwise, update N to have the operands specified.
924 return SDValue(DAG.UpdateNodeOperands(N, NewLHS, NewRHS,
925 DAG.getCondCode(CCCode)),
929 SDValue DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode *N, unsigned OpNo) {
930 assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
931 assert(OpNo == 1 && "Can only soften the stored value!");
932 StoreSDNode *ST = cast<StoreSDNode>(N);
933 SDValue Val = ST->getValue();
936 if (ST->isTruncatingStore())
937 // Do an FP_ROUND followed by a non-truncating store.
938 Val = BitConvertToInteger(DAG.getNode(ISD::FP_ROUND, dl, ST->getMemoryVT(),
939 Val, DAG.getIntPtrConstant(0, dl)));
941 Val = GetSoftenedFloat(Val);
943 return DAG.getStore(ST->getChain(), dl, Val, ST->getBasePtr(),
944 ST->getMemOperand());
948 //===----------------------------------------------------------------------===//
949 // Float Result Expansion
950 //===----------------------------------------------------------------------===//
952 /// ExpandFloatResult - This method is called when the specified result of the
953 /// specified node is found to need expansion. At this point, the node may also
954 /// have invalid operands or may have other results that need promotion, we just
955 /// know that (at least) one result needs expansion.
956 void DAGTypeLegalizer::ExpandFloatResult(SDNode *N, unsigned ResNo) {
957 DEBUG(dbgs() << "Expand float result: "; N->dump(&DAG); dbgs() << "\n");
961 // See if the target wants to custom expand this node.
962 if (CustomLowerNode(N, N->getValueType(ResNo), true))
965 switch (N->getOpcode()) {
968 dbgs() << "ExpandFloatResult #" << ResNo << ": ";
969 N->dump(&DAG); dbgs() << "\n";
971 llvm_unreachable("Do not know how to expand the result of this operator!");
973 case ISD::UNDEF: SplitRes_UNDEF(N, Lo, Hi); break;
974 case ISD::SELECT: SplitRes_SELECT(N, Lo, Hi); break;
975 case ISD::SELECT_CC: SplitRes_SELECT_CC(N, Lo, Hi); break;
977 case ISD::MERGE_VALUES: ExpandRes_MERGE_VALUES(N, ResNo, Lo, Hi); break;
978 case ISD::BITCAST: ExpandRes_BITCAST(N, Lo, Hi); break;
979 case ISD::BUILD_PAIR: ExpandRes_BUILD_PAIR(N, Lo, Hi); break;
980 case ISD::EXTRACT_ELEMENT: ExpandRes_EXTRACT_ELEMENT(N, Lo, Hi); break;
981 case ISD::EXTRACT_VECTOR_ELT: ExpandRes_EXTRACT_VECTOR_ELT(N, Lo, Hi); break;
982 case ISD::VAARG: ExpandRes_VAARG(N, Lo, Hi); break;
984 case ISD::ConstantFP: ExpandFloatRes_ConstantFP(N, Lo, Hi); break;
985 case ISD::FABS: ExpandFloatRes_FABS(N, Lo, Hi); break;
986 case ISD::FMINNUM: ExpandFloatRes_FMINNUM(N, Lo, Hi); break;
987 case ISD::FMAXNUM: ExpandFloatRes_FMAXNUM(N, Lo, Hi); break;
988 case ISD::FADD: ExpandFloatRes_FADD(N, Lo, Hi); break;
989 case ISD::FCEIL: ExpandFloatRes_FCEIL(N, Lo, Hi); break;
990 case ISD::FCOPYSIGN: ExpandFloatRes_FCOPYSIGN(N, Lo, Hi); break;
991 case ISD::FCOS: ExpandFloatRes_FCOS(N, Lo, Hi); break;
992 case ISD::FDIV: ExpandFloatRes_FDIV(N, Lo, Hi); break;
993 case ISD::FEXP: ExpandFloatRes_FEXP(N, Lo, Hi); break;
994 case ISD::FEXP2: ExpandFloatRes_FEXP2(N, Lo, Hi); break;
995 case ISD::FFLOOR: ExpandFloatRes_FFLOOR(N, Lo, Hi); break;
996 case ISD::FLOG: ExpandFloatRes_FLOG(N, Lo, Hi); break;
997 case ISD::FLOG2: ExpandFloatRes_FLOG2(N, Lo, Hi); break;
998 case ISD::FLOG10: ExpandFloatRes_FLOG10(N, Lo, Hi); break;
999 case ISD::FMA: ExpandFloatRes_FMA(N, Lo, Hi); break;
1000 case ISD::FMUL: ExpandFloatRes_FMUL(N, Lo, Hi); break;
1001 case ISD::FNEARBYINT: ExpandFloatRes_FNEARBYINT(N, Lo, Hi); break;
1002 case ISD::FNEG: ExpandFloatRes_FNEG(N, Lo, Hi); break;
1003 case ISD::FP_EXTEND: ExpandFloatRes_FP_EXTEND(N, Lo, Hi); break;
1004 case ISD::FPOW: ExpandFloatRes_FPOW(N, Lo, Hi); break;
1005 case ISD::FPOWI: ExpandFloatRes_FPOWI(N, Lo, Hi); break;
1006 case ISD::FRINT: ExpandFloatRes_FRINT(N, Lo, Hi); break;
1007 case ISD::FROUND: ExpandFloatRes_FROUND(N, Lo, Hi); break;
1008 case ISD::FSIN: ExpandFloatRes_FSIN(N, Lo, Hi); break;
1009 case ISD::FSQRT: ExpandFloatRes_FSQRT(N, Lo, Hi); break;
1010 case ISD::FSUB: ExpandFloatRes_FSUB(N, Lo, Hi); break;
1011 case ISD::FTRUNC: ExpandFloatRes_FTRUNC(N, Lo, Hi); break;
1012 case ISD::LOAD: ExpandFloatRes_LOAD(N, Lo, Hi); break;
1013 case ISD::SINT_TO_FP:
1014 case ISD::UINT_TO_FP: ExpandFloatRes_XINT_TO_FP(N, Lo, Hi); break;
1015 case ISD::FREM: ExpandFloatRes_FREM(N, Lo, Hi); break;
1018 // If Lo/Hi is null, the sub-method took care of registering results etc.
1020 SetExpandedFloat(SDValue(N, ResNo), Lo, Hi);
1023 void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo,
1025 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
1026 assert(NVT.getSizeInBits() == integerPartWidth &&
1027 "Do not know how to expand this float constant!");
1028 APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().bitcastToAPInt();
1030 Lo = DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(NVT),
1031 APInt(integerPartWidth, C.getRawData()[1])),
1033 Hi = DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(NVT),
1034 APInt(integerPartWidth, C.getRawData()[0])),
1038 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDValue &Lo,
1040 assert(N->getValueType(0) == MVT::ppcf128 &&
1041 "Logic only correct for ppcf128!");
1044 GetExpandedFloat(N->getOperand(0), Lo, Tmp);
1045 Hi = DAG.getNode(ISD::FABS, dl, Tmp.getValueType(), Tmp);
1046 // Lo = Hi==fabs(Hi) ? Lo : -Lo;
1047 Lo = DAG.getSelectCC(dl, Tmp, Hi, Lo,
1048 DAG.getNode(ISD::FNEG, dl, Lo.getValueType(), Lo),
1052 void DAGTypeLegalizer::ExpandFloatRes_FMINNUM(SDNode *N, SDValue &Lo,
1054 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1055 RTLIB::FMIN_F32, RTLIB::FMIN_F64,
1056 RTLIB::FMIN_F80, RTLIB::FMIN_F128,
1057 RTLIB::FMIN_PPCF128),
1059 GetPairElements(Call, Lo, Hi);
1062 void DAGTypeLegalizer::ExpandFloatRes_FMAXNUM(SDNode *N, SDValue &Lo,
1064 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1065 RTLIB::FMAX_F32, RTLIB::FMAX_F64,
1066 RTLIB::FMAX_F80, RTLIB::FMAX_F128,
1067 RTLIB::FMAX_PPCF128),
1069 GetPairElements(Call, Lo, Hi);
1072 void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode *N, SDValue &Lo,
1074 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1075 RTLIB::ADD_F32, RTLIB::ADD_F64,
1076 RTLIB::ADD_F80, RTLIB::ADD_F128,
1077 RTLIB::ADD_PPCF128),
1079 GetPairElements(Call, Lo, Hi);
1082 void DAGTypeLegalizer::ExpandFloatRes_FCEIL(SDNode *N,
1083 SDValue &Lo, SDValue &Hi) {
1084 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1085 RTLIB::CEIL_F32, RTLIB::CEIL_F64,
1086 RTLIB::CEIL_F80, RTLIB::CEIL_F128,
1087 RTLIB::CEIL_PPCF128),
1089 GetPairElements(Call, Lo, Hi);
1092 void DAGTypeLegalizer::ExpandFloatRes_FCOPYSIGN(SDNode *N,
1093 SDValue &Lo, SDValue &Hi) {
1094 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1095 RTLIB::COPYSIGN_F32,
1096 RTLIB::COPYSIGN_F64,
1097 RTLIB::COPYSIGN_F80,
1098 RTLIB::COPYSIGN_F128,
1099 RTLIB::COPYSIGN_PPCF128),
1101 GetPairElements(Call, Lo, Hi);
1104 void DAGTypeLegalizer::ExpandFloatRes_FCOS(SDNode *N,
1105 SDValue &Lo, SDValue &Hi) {
1106 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1107 RTLIB::COS_F32, RTLIB::COS_F64,
1108 RTLIB::COS_F80, RTLIB::COS_F128,
1109 RTLIB::COS_PPCF128),
1111 GetPairElements(Call, Lo, Hi);
1114 void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode *N, SDValue &Lo,
1116 SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
1117 SDValue Call = TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
1122 RTLIB::DIV_PPCF128),
1123 N->getValueType(0), Ops, false,
1125 GetPairElements(Call, Lo, Hi);
1128 void DAGTypeLegalizer::ExpandFloatRes_FEXP(SDNode *N,
1129 SDValue &Lo, SDValue &Hi) {
1130 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1131 RTLIB::EXP_F32, RTLIB::EXP_F64,
1132 RTLIB::EXP_F80, RTLIB::EXP_F128,
1133 RTLIB::EXP_PPCF128),
1135 GetPairElements(Call, Lo, Hi);
1138 void DAGTypeLegalizer::ExpandFloatRes_FEXP2(SDNode *N,
1139 SDValue &Lo, SDValue &Hi) {
1140 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1141 RTLIB::EXP2_F32, RTLIB::EXP2_F64,
1142 RTLIB::EXP2_F80, RTLIB::EXP2_F128,
1143 RTLIB::EXP2_PPCF128),
1145 GetPairElements(Call, Lo, Hi);
1148 void DAGTypeLegalizer::ExpandFloatRes_FFLOOR(SDNode *N,
1149 SDValue &Lo, SDValue &Hi) {
1150 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1151 RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
1152 RTLIB::FLOOR_F80, RTLIB::FLOOR_F128,
1153 RTLIB::FLOOR_PPCF128),
1155 GetPairElements(Call, Lo, Hi);
1158 void DAGTypeLegalizer::ExpandFloatRes_FLOG(SDNode *N,
1159 SDValue &Lo, SDValue &Hi) {
1160 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1161 RTLIB::LOG_F32, RTLIB::LOG_F64,
1162 RTLIB::LOG_F80, RTLIB::LOG_F128,
1163 RTLIB::LOG_PPCF128),
1165 GetPairElements(Call, Lo, Hi);
1168 void DAGTypeLegalizer::ExpandFloatRes_FLOG2(SDNode *N,
1169 SDValue &Lo, SDValue &Hi) {
1170 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1171 RTLIB::LOG2_F32, RTLIB::LOG2_F64,
1172 RTLIB::LOG2_F80, RTLIB::LOG2_F128,
1173 RTLIB::LOG2_PPCF128),
1175 GetPairElements(Call, Lo, Hi);
1178 void DAGTypeLegalizer::ExpandFloatRes_FLOG10(SDNode *N,
1179 SDValue &Lo, SDValue &Hi) {
1180 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1181 RTLIB::LOG10_F32, RTLIB::LOG10_F64,
1182 RTLIB::LOG10_F80, RTLIB::LOG10_F128,
1183 RTLIB::LOG10_PPCF128),
1185 GetPairElements(Call, Lo, Hi);
1188 void DAGTypeLegalizer::ExpandFloatRes_FMA(SDNode *N, SDValue &Lo,
1190 SDValue Ops[3] = { N->getOperand(0), N->getOperand(1), N->getOperand(2) };
1191 SDValue Call = TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
1196 RTLIB::FMA_PPCF128),
1197 N->getValueType(0), Ops, false,
1199 GetPairElements(Call, Lo, Hi);
1202 void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode *N, SDValue &Lo,
1204 SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
1205 SDValue Call = TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
1210 RTLIB::MUL_PPCF128),
1211 N->getValueType(0), Ops, false,
1213 GetPairElements(Call, Lo, Hi);
1216 void DAGTypeLegalizer::ExpandFloatRes_FNEARBYINT(SDNode *N,
1217 SDValue &Lo, SDValue &Hi) {
1218 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1219 RTLIB::NEARBYINT_F32,
1220 RTLIB::NEARBYINT_F64,
1221 RTLIB::NEARBYINT_F80,
1222 RTLIB::NEARBYINT_F128,
1223 RTLIB::NEARBYINT_PPCF128),
1225 GetPairElements(Call, Lo, Hi);
1228 void DAGTypeLegalizer::ExpandFloatRes_FNEG(SDNode *N, SDValue &Lo,
1231 GetExpandedFloat(N->getOperand(0), Lo, Hi);
1232 Lo = DAG.getNode(ISD::FNEG, dl, Lo.getValueType(), Lo);
1233 Hi = DAG.getNode(ISD::FNEG, dl, Hi.getValueType(), Hi);
1236 void DAGTypeLegalizer::ExpandFloatRes_FP_EXTEND(SDNode *N, SDValue &Lo,
1238 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
1240 Hi = DAG.getNode(ISD::FP_EXTEND, dl, NVT, N->getOperand(0));
1241 Lo = DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(NVT),
1242 APInt(NVT.getSizeInBits(), 0)), dl, NVT);
1245 void DAGTypeLegalizer::ExpandFloatRes_FPOW(SDNode *N,
1246 SDValue &Lo, SDValue &Hi) {
1247 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1248 RTLIB::POW_F32, RTLIB::POW_F64,
1249 RTLIB::POW_F80, RTLIB::POW_F128,
1250 RTLIB::POW_PPCF128),
1252 GetPairElements(Call, Lo, Hi);
1255 void DAGTypeLegalizer::ExpandFloatRes_FPOWI(SDNode *N,
1256 SDValue &Lo, SDValue &Hi) {
1257 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1258 RTLIB::POWI_F32, RTLIB::POWI_F64,
1259 RTLIB::POWI_F80, RTLIB::POWI_F128,
1260 RTLIB::POWI_PPCF128),
1262 GetPairElements(Call, Lo, Hi);
1265 void DAGTypeLegalizer::ExpandFloatRes_FREM(SDNode *N,
1266 SDValue &Lo, SDValue &Hi) {
1267 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1268 RTLIB::REM_F32, RTLIB::REM_F64,
1269 RTLIB::REM_F80, RTLIB::REM_F128,
1270 RTLIB::REM_PPCF128),
1272 GetPairElements(Call, Lo, Hi);
1275 void DAGTypeLegalizer::ExpandFloatRes_FRINT(SDNode *N,
1276 SDValue &Lo, SDValue &Hi) {
1277 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1278 RTLIB::RINT_F32, RTLIB::RINT_F64,
1279 RTLIB::RINT_F80, RTLIB::RINT_F128,
1280 RTLIB::RINT_PPCF128),
1282 GetPairElements(Call, Lo, Hi);
1285 void DAGTypeLegalizer::ExpandFloatRes_FROUND(SDNode *N,
1286 SDValue &Lo, SDValue &Hi) {
1287 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1292 RTLIB::ROUND_PPCF128),
1294 GetPairElements(Call, Lo, Hi);
1297 void DAGTypeLegalizer::ExpandFloatRes_FSIN(SDNode *N,
1298 SDValue &Lo, SDValue &Hi) {
1299 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1300 RTLIB::SIN_F32, RTLIB::SIN_F64,
1301 RTLIB::SIN_F80, RTLIB::SIN_F128,
1302 RTLIB::SIN_PPCF128),
1304 GetPairElements(Call, Lo, Hi);
1307 void DAGTypeLegalizer::ExpandFloatRes_FSQRT(SDNode *N,
1308 SDValue &Lo, SDValue &Hi) {
1309 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1310 RTLIB::SQRT_F32, RTLIB::SQRT_F64,
1311 RTLIB::SQRT_F80, RTLIB::SQRT_F128,
1312 RTLIB::SQRT_PPCF128),
1314 GetPairElements(Call, Lo, Hi);
1317 void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode *N, SDValue &Lo,
1319 SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };
1320 SDValue Call = TLI.makeLibCall(DAG, GetFPLibCall(N->getValueType(0),
1325 RTLIB::SUB_PPCF128),
1326 N->getValueType(0), Ops, false,
1328 GetPairElements(Call, Lo, Hi);
1331 void DAGTypeLegalizer::ExpandFloatRes_FTRUNC(SDNode *N,
1332 SDValue &Lo, SDValue &Hi) {
1333 SDValue Call = LibCallify(GetFPLibCall(N->getValueType(0),
1334 RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
1335 RTLIB::TRUNC_F80, RTLIB::TRUNC_F128,
1336 RTLIB::TRUNC_PPCF128),
1338 GetPairElements(Call, Lo, Hi);
1341 void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode *N, SDValue &Lo,
1343 if (ISD::isNormalLoad(N)) {
1344 ExpandRes_NormalLoad(N, Lo, Hi);
1348 assert(ISD::isUNINDEXEDLoad(N) && "Indexed load during type legalization!");
1349 LoadSDNode *LD = cast<LoadSDNode>(N);
1350 SDValue Chain = LD->getChain();
1351 SDValue Ptr = LD->getBasePtr();
1354 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), LD->getValueType(0));
1355 assert(NVT.isByteSized() && "Expanded type not byte sized!");
1356 assert(LD->getMemoryVT().bitsLE(NVT) && "Float type not round?");
1358 Hi = DAG.getExtLoad(LD->getExtensionType(), dl, NVT, Chain, Ptr,
1359 LD->getMemoryVT(), LD->getMemOperand());
1361 // Remember the chain.
1362 Chain = Hi.getValue(1);
1364 // The low part is zero.
1365 Lo = DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(NVT),
1366 APInt(NVT.getSizeInBits(), 0)), dl, NVT);
1368 // Modified the chain - switch anything that used the old chain to use the
1370 ReplaceValueWith(SDValue(LD, 1), Chain);
1373 void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo,
1375 assert(N->getValueType(0) == MVT::ppcf128 && "Unsupported XINT_TO_FP!");
1376 EVT VT = N->getValueType(0);
1377 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1378 SDValue Src = N->getOperand(0);
1379 EVT SrcVT = Src.getValueType();
1380 bool isSigned = N->getOpcode() == ISD::SINT_TO_FP;
1383 // First do an SINT_TO_FP, whether the original was signed or unsigned.
1384 // When promoting partial word types to i32 we must honor the signedness,
1386 if (SrcVT.bitsLE(MVT::i32)) {
1387 // The integer can be represented exactly in an f64.
1388 Src = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
1390 Lo = DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(NVT),
1391 APInt(NVT.getSizeInBits(), 0)), dl, NVT);
1392 Hi = DAG.getNode(ISD::SINT_TO_FP, dl, NVT, Src);
1394 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1395 if (SrcVT.bitsLE(MVT::i64)) {
1396 Src = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, dl,
1398 LC = RTLIB::SINTTOFP_I64_PPCF128;
1399 } else if (SrcVT.bitsLE(MVT::i128)) {
1400 Src = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i128, Src);
1401 LC = RTLIB::SINTTOFP_I128_PPCF128;
1403 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported XINT_TO_FP!");
1405 Hi = TLI.makeLibCall(DAG, LC, VT, Src, true, dl).first;
1406 GetPairElements(Hi, Lo, Hi);
1412 // Unsigned - fix up the SINT_TO_FP value just calculated.
1413 Hi = DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi);
1414 SrcVT = Src.getValueType();
1416 // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128.
1417 static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 };
1418 static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 };
1419 static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
1420 ArrayRef<uint64_t> Parts;
1422 switch (SrcVT.getSimpleVT().SimpleTy) {
1424 llvm_unreachable("Unsupported UINT_TO_FP!");
1436 // TODO: Are there fast-math-flags to propagate to this FADD?
1437 Lo = DAG.getNode(ISD::FADD, dl, VT, Hi,
1438 DAG.getConstantFP(APFloat(APFloat::PPCDoubleDouble,
1441 Lo = DAG.getSelectCC(dl, Src, DAG.getConstant(0, dl, SrcVT),
1442 Lo, Hi, ISD::SETLT);
1443 GetPairElements(Lo, Lo, Hi);
1447 //===----------------------------------------------------------------------===//
1448 // Float Operand Expansion
1449 //===----------------------------------------------------------------------===//
1451 /// ExpandFloatOperand - This method is called when the specified operand of the
1452 /// specified node is found to need expansion. At this point, all of the result
1453 /// types of the node are known to be legal, but other operands of the node may
1454 /// need promotion or expansion as well as the specified one.
1455 bool DAGTypeLegalizer::ExpandFloatOperand(SDNode *N, unsigned OpNo) {
1456 DEBUG(dbgs() << "Expand float operand: "; N->dump(&DAG); dbgs() << "\n");
1457 SDValue Res = SDValue();
1459 // See if the target wants to custom expand this node.
1460 if (CustomLowerNode(N, N->getOperand(OpNo).getValueType(), false))
1463 switch (N->getOpcode()) {
1466 dbgs() << "ExpandFloatOperand Op #" << OpNo << ": ";
1467 N->dump(&DAG); dbgs() << "\n";
1469 llvm_unreachable("Do not know how to expand this operator's operand!");
1471 case ISD::BITCAST: Res = ExpandOp_BITCAST(N); break;
1472 case ISD::BUILD_VECTOR: Res = ExpandOp_BUILD_VECTOR(N); break;
1473 case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break;
1475 case ISD::BR_CC: Res = ExpandFloatOp_BR_CC(N); break;
1476 case ISD::FCOPYSIGN: Res = ExpandFloatOp_FCOPYSIGN(N); break;
1477 case ISD::FP_ROUND: Res = ExpandFloatOp_FP_ROUND(N); break;
1478 case ISD::FP_TO_SINT: Res = ExpandFloatOp_FP_TO_SINT(N); break;
1479 case ISD::FP_TO_UINT: Res = ExpandFloatOp_FP_TO_UINT(N); break;
1480 case ISD::SELECT_CC: Res = ExpandFloatOp_SELECT_CC(N); break;
1481 case ISD::SETCC: Res = ExpandFloatOp_SETCC(N); break;
1482 case ISD::STORE: Res = ExpandFloatOp_STORE(cast<StoreSDNode>(N),
1486 // If the result is null, the sub-method took care of registering results etc.
1487 if (!Res.getNode()) return false;
1489 // If the result is N, the sub-method updated N in place. Tell the legalizer
1491 if (Res.getNode() == N)
1494 assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
1495 "Invalid operand expansion");
1497 ReplaceValueWith(SDValue(N, 0), Res);
1501 /// FloatExpandSetCCOperands - Expand the operands of a comparison. This code
1502 /// is shared among BR_CC, SELECT_CC, and SETCC handlers.
1503 void DAGTypeLegalizer::FloatExpandSetCCOperands(SDValue &NewLHS,
1505 ISD::CondCode &CCCode,
1507 SDValue LHSLo, LHSHi, RHSLo, RHSHi;
1508 GetExpandedFloat(NewLHS, LHSLo, LHSHi);
1509 GetExpandedFloat(NewRHS, RHSLo, RHSHi);
1511 assert(NewLHS.getValueType() == MVT::ppcf128 && "Unsupported setcc type!");
1513 // FIXME: This generated code sucks. We want to generate
1514 // FCMPU crN, hi1, hi2
1516 // FCMPU crN, lo1, lo2
1517 // The following can be improved, but not that much.
1518 SDValue Tmp1, Tmp2, Tmp3;
1519 Tmp1 = DAG.getSetCC(dl, getSetCCResultType(LHSHi.getValueType()),
1520 LHSHi, RHSHi, ISD::SETOEQ);
1521 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(LHSLo.getValueType()),
1522 LHSLo, RHSLo, CCCode);
1523 Tmp3 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
1524 Tmp1 = DAG.getSetCC(dl, getSetCCResultType(LHSHi.getValueType()),
1525 LHSHi, RHSHi, ISD::SETUNE);
1526 Tmp2 = DAG.getSetCC(dl, getSetCCResultType(LHSHi.getValueType()),
1527 LHSHi, RHSHi, CCCode);
1528 Tmp1 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
1529 NewLHS = DAG.getNode(ISD::OR, dl, Tmp1.getValueType(), Tmp1, Tmp3);
1530 NewRHS = SDValue(); // LHS is the result, not a compare.
1533 SDValue DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode *N) {
1534 SDValue NewLHS = N->getOperand(2), NewRHS = N->getOperand(3);
1535 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(1))->get();
1536 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(N));
1538 // If ExpandSetCCOperands returned a scalar, we need to compare the result
1539 // against zero to select between true and false values.
1540 if (!NewRHS.getNode()) {
1541 NewRHS = DAG.getConstant(0, SDLoc(N), NewLHS.getValueType());
1542 CCCode = ISD::SETNE;
1545 // Update N to have the operands specified.
1546 return SDValue(DAG.UpdateNodeOperands(N, N->getOperand(0),
1547 DAG.getCondCode(CCCode), NewLHS, NewRHS,
1548 N->getOperand(4)), 0);
1551 SDValue DAGTypeLegalizer::ExpandFloatOp_FCOPYSIGN(SDNode *N) {
1552 assert(N->getOperand(1).getValueType() == MVT::ppcf128 &&
1553 "Logic only correct for ppcf128!");
1555 GetExpandedFloat(N->getOperand(1), Lo, Hi);
1556 // The ppcf128 value is providing only the sign; take it from the
1557 // higher-order double (which must have the larger magnitude).
1558 return DAG.getNode(ISD::FCOPYSIGN, SDLoc(N),
1559 N->getValueType(0), N->getOperand(0), Hi);
1562 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode *N) {
1563 assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
1564 "Logic only correct for ppcf128!");
1566 GetExpandedFloat(N->getOperand(0), Lo, Hi);
1567 // Round it the rest of the way (e.g. to f32) if needed.
1568 return DAG.getNode(ISD::FP_ROUND, SDLoc(N),
1569 N->getValueType(0), Hi, N->getOperand(1));
1572 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode *N) {
1573 EVT RVT = N->getValueType(0);
1576 // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on
1577 // PPC (the libcall is not available). FIXME: Do this in a less hacky way.
1578 if (RVT == MVT::i32) {
1579 assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
1580 "Logic only correct for ppcf128!");
1581 SDValue Res = DAG.getNode(ISD::FP_ROUND_INREG, dl, MVT::ppcf128,
1582 N->getOperand(0), DAG.getValueType(MVT::f64));
1583 Res = DAG.getNode(ISD::FP_ROUND, dl, MVT::f64, Res,
1584 DAG.getIntPtrConstant(1, dl));
1585 return DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32, Res);
1588 RTLIB::Libcall LC = RTLIB::getFPTOSINT(N->getOperand(0).getValueType(), RVT);
1589 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_SINT!");
1590 return TLI.makeLibCall(DAG, LC, RVT, N->getOperand(0), false, dl).first;
1593 SDValue DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
1594 EVT RVT = N->getValueType(0);
1597 // Expand ppcf128 to i32 by hand for the benefit of llvm-gcc bootstrap on
1598 // PPC (the libcall is not available). FIXME: Do this in a less hacky way.
1599 if (RVT == MVT::i32) {
1600 assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
1601 "Logic only correct for ppcf128!");
1602 const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
1603 APFloat APF = APFloat(APFloat::PPCDoubleDouble, APInt(128, TwoE31));
1604 SDValue Tmp = DAG.getConstantFP(APF, dl, MVT::ppcf128);
1605 // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
1606 // FIXME: generated code sucks.
1607 // TODO: Are there fast-math-flags to propagate to this FSUB?
1608 return DAG.getSelectCC(dl, N->getOperand(0), Tmp,
1609 DAG.getNode(ISD::ADD, dl, MVT::i32,
1610 DAG.getNode(ISD::FP_TO_SINT, dl, MVT::i32,
1611 DAG.getNode(ISD::FSUB, dl,
1615 DAG.getConstant(0x80000000, dl,
1617 DAG.getNode(ISD::FP_TO_SINT, dl,
1618 MVT::i32, N->getOperand(0)),
1622 RTLIB::Libcall LC = RTLIB::getFPTOUINT(N->getOperand(0).getValueType(), RVT);
1623 assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_TO_UINT!");
1624 return TLI.makeLibCall(DAG, LC, N->getValueType(0), N->getOperand(0),
1628 SDValue DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode *N) {
1629 SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
1630 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(4))->get();
1631 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(N));
1633 // If ExpandSetCCOperands returned a scalar, we need to compare the result
1634 // against zero to select between true and false values.
1635 if (!NewRHS.getNode()) {
1636 NewRHS = DAG.getConstant(0, SDLoc(N), NewLHS.getValueType());
1637 CCCode = ISD::SETNE;
1640 // Update N to have the operands specified.
1641 return SDValue(DAG.UpdateNodeOperands(N, NewLHS, NewRHS,
1642 N->getOperand(2), N->getOperand(3),
1643 DAG.getCondCode(CCCode)), 0);
1646 SDValue DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode *N) {
1647 SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1);
1648 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
1649 FloatExpandSetCCOperands(NewLHS, NewRHS, CCCode, SDLoc(N));
1651 // If ExpandSetCCOperands returned a scalar, use it.
1652 if (!NewRHS.getNode()) {
1653 assert(NewLHS.getValueType() == N->getValueType(0) &&
1654 "Unexpected setcc expansion!");
1658 // Otherwise, update N to have the operands specified.
1659 return SDValue(DAG.UpdateNodeOperands(N, NewLHS, NewRHS,
1660 DAG.getCondCode(CCCode)), 0);
1663 SDValue DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode *N, unsigned OpNo) {
1664 if (ISD::isNormalStore(N))
1665 return ExpandOp_NormalStore(N, OpNo);
1667 assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
1668 assert(OpNo == 1 && "Can only expand the stored value so far");
1669 StoreSDNode *ST = cast<StoreSDNode>(N);
1671 SDValue Chain = ST->getChain();
1672 SDValue Ptr = ST->getBasePtr();
1674 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(),
1675 ST->getValue().getValueType());
1676 assert(NVT.isByteSized() && "Expanded type not byte sized!");
1677 assert(ST->getMemoryVT().bitsLE(NVT) && "Float type not round?");
1681 GetExpandedOp(ST->getValue(), Lo, Hi);
1683 return DAG.getTruncStore(Chain, SDLoc(N), Hi, Ptr,
1684 ST->getMemoryVT(), ST->getMemOperand());
1687 //===----------------------------------------------------------------------===//
1688 // Float Operand Promotion
1689 //===----------------------------------------------------------------------===//
1692 static ISD::NodeType GetPromotionOpcode(EVT OpVT, EVT RetVT) {
1693 if (OpVT == MVT::f16) {
1694 return ISD::FP16_TO_FP;
1695 } else if (RetVT == MVT::f16) {
1696 return ISD::FP_TO_FP16;
1699 report_fatal_error("Attempt at an invalid promotion-related conversion");
1702 bool DAGTypeLegalizer::PromoteFloatOperand(SDNode *N, unsigned OpNo) {
1703 SDValue R = SDValue();
1705 // Nodes that use a promotion-requiring floating point operand, but doesn't
1706 // produce a promotion-requiring floating point result, need to be legalized
1707 // to use the promoted float operand. Nodes that produce at least one
1708 // promotion-requiring floating point result have their operands legalized as
1709 // a part of PromoteFloatResult.
1710 switch (N->getOpcode()) {
1712 llvm_unreachable("Do not know how to promote this operator's operand!");
1714 case ISD::BITCAST: R = PromoteFloatOp_BITCAST(N, OpNo); break;
1715 case ISD::FCOPYSIGN: R = PromoteFloatOp_FCOPYSIGN(N, OpNo); break;
1716 case ISD::FP_TO_SINT:
1717 case ISD::FP_TO_UINT: R = PromoteFloatOp_FP_TO_XINT(N, OpNo); break;
1718 case ISD::FP_EXTEND: R = PromoteFloatOp_FP_EXTEND(N, OpNo); break;
1719 case ISD::SELECT_CC: R = PromoteFloatOp_SELECT_CC(N, OpNo); break;
1720 case ISD::SETCC: R = PromoteFloatOp_SETCC(N, OpNo); break;
1721 case ISD::STORE: R = PromoteFloatOp_STORE(N, OpNo); break;
1725 ReplaceValueWith(SDValue(N, 0), R);
1729 SDValue DAGTypeLegalizer::PromoteFloatOp_BITCAST(SDNode *N, unsigned OpNo) {
1730 SDValue Op = N->getOperand(0);
1731 EVT OpVT = Op->getValueType(0);
1733 EVT IVT = EVT::getIntegerVT(*DAG.getContext(), OpVT.getSizeInBits());
1734 assert (IVT == N->getValueType(0) && "Bitcast to type of different size");
1736 SDValue Promoted = GetPromotedFloat(N->getOperand(0));
1737 EVT PromotedVT = Promoted->getValueType(0);
1739 // Convert the promoted float value to the desired IVT.
1740 return DAG.getNode(GetPromotionOpcode(PromotedVT, OpVT), SDLoc(N), IVT,
1744 // Promote Operand 1 of FCOPYSIGN. Operand 0 ought to be handled by
1745 // PromoteFloatRes_FCOPYSIGN.
1746 SDValue DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo) {
1747 assert (OpNo == 1 && "Only Operand 1 must need promotion here");
1748 SDValue Op1 = GetPromotedFloat(N->getOperand(1));
1750 return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0),
1751 N->getOperand(0), Op1);
1754 // Convert the promoted float value to the desired integer type
1755 SDValue DAGTypeLegalizer::PromoteFloatOp_FP_TO_XINT(SDNode *N, unsigned OpNo) {
1756 SDValue Op = GetPromotedFloat(N->getOperand(0));
1757 return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), Op);
1760 SDValue DAGTypeLegalizer::PromoteFloatOp_FP_EXTEND(SDNode *N, unsigned OpNo) {
1761 SDValue Op = GetPromotedFloat(N->getOperand(0));
1762 EVT VT = N->getValueType(0);
1764 // Desired VT is same as promoted type. Use promoted float directly.
1765 if (VT == Op->getValueType(0))
1768 // Else, extend the promoted float value to the desired VT.
1769 return DAG.getNode(ISD::FP_EXTEND, SDLoc(N), VT, Op);
1772 // Promote the float operands used for comparison. The true- and false-
1773 // operands have the same type as the result and are promoted, if needed, by
1774 // PromoteFloatRes_SELECT_CC
1775 SDValue DAGTypeLegalizer::PromoteFloatOp_SELECT_CC(SDNode *N, unsigned OpNo) {
1776 SDValue LHS = GetPromotedFloat(N->getOperand(0));
1777 SDValue RHS = GetPromotedFloat(N->getOperand(1));
1779 return DAG.getNode(ISD::SELECT_CC, SDLoc(N), N->getValueType(0),
1780 LHS, RHS, N->getOperand(2), N->getOperand(3),
1784 // Construct a SETCC that compares the promoted values and sets the conditional
1786 SDValue DAGTypeLegalizer::PromoteFloatOp_SETCC(SDNode *N, unsigned OpNo) {
1787 EVT VT = N->getValueType(0);
1788 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1789 SDValue Op0 = GetPromotedFloat(N->getOperand(0));
1790 SDValue Op1 = GetPromotedFloat(N->getOperand(1));
1791 ISD::CondCode CCCode = cast<CondCodeSDNode>(N->getOperand(2))->get();
1793 return DAG.getSetCC(SDLoc(N), NVT, Op0, Op1, CCCode);
1797 // Lower the promoted Float down to the integer value of same size and construct
1798 // a STORE of the integer value.
1799 SDValue DAGTypeLegalizer::PromoteFloatOp_STORE(SDNode *N, unsigned OpNo) {
1800 StoreSDNode *ST = cast<StoreSDNode>(N);
1801 SDValue Val = ST->getValue();
1804 SDValue Promoted = GetPromotedFloat(Val);
1805 EVT VT = ST->getOperand(1)->getValueType(0);
1806 EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
1809 NewVal = DAG.getNode(GetPromotionOpcode(Promoted.getValueType(), VT), DL,
1812 return DAG.getStore(ST->getChain(), DL, NewVal, ST->getBasePtr(),
1813 ST->getMemOperand());
1816 //===----------------------------------------------------------------------===//
1817 // Float Result Promotion
1818 //===----------------------------------------------------------------------===//
1820 void DAGTypeLegalizer::PromoteFloatResult(SDNode *N, unsigned ResNo) {
1821 SDValue R = SDValue();
1823 switch (N->getOpcode()) {
1824 // These opcodes cannot appear if promotion of FP16 is done in the backend
1826 case ISD::FP16_TO_FP:
1827 case ISD::FP_TO_FP16:
1829 llvm_unreachable("Do not know how to promote this operator's result!");
1831 case ISD::BITCAST: R = PromoteFloatRes_BITCAST(N); break;
1832 case ISD::ConstantFP: R = PromoteFloatRes_ConstantFP(N); break;
1833 case ISD::EXTRACT_VECTOR_ELT:
1834 R = PromoteFloatRes_EXTRACT_VECTOR_ELT(N); break;
1835 case ISD::FCOPYSIGN: R = PromoteFloatRes_FCOPYSIGN(N); break;
1837 // Unary FP Operations
1847 case ISD::FNEARBYINT:
1853 case ISD::FTRUNC: R = PromoteFloatRes_UnaryOp(N); break;
1855 // Binary FP Operations
1863 case ISD::FSUB: R = PromoteFloatRes_BinOp(N); break;
1865 case ISD::FMA: // FMA is same as FMAD
1866 case ISD::FMAD: R = PromoteFloatRes_FMAD(N); break;
1868 case ISD::FPOWI: R = PromoteFloatRes_FPOWI(N); break;
1870 case ISD::FP_ROUND: R = PromoteFloatRes_FP_ROUND(N); break;
1871 case ISD::LOAD: R = PromoteFloatRes_LOAD(N); break;
1872 case ISD::SELECT: R = PromoteFloatRes_SELECT(N); break;
1873 case ISD::SELECT_CC: R = PromoteFloatRes_SELECT_CC(N); break;
1875 case ISD::SINT_TO_FP:
1876 case ISD::UINT_TO_FP: R = PromoteFloatRes_XINT_TO_FP(N); break;
1877 case ISD::UNDEF: R = PromoteFloatRes_UNDEF(N); break;
1882 SetPromotedFloat(SDValue(N, ResNo), R);
1885 // Bitcast from i16 to f16: convert the i16 to a f32 value instead.
1886 // At this point, it is not possible to determine if the bitcast value is
1887 // eventually stored to memory or promoted to f32 or promoted to a floating
1888 // point at a higher precision. Some of these cases are handled by FP_EXTEND,
1889 // STORE promotion handlers.
1890 SDValue DAGTypeLegalizer::PromoteFloatRes_BITCAST(SDNode *N) {
1891 EVT VT = N->getValueType(0);
1892 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1893 return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT,
1897 SDValue DAGTypeLegalizer::PromoteFloatRes_ConstantFP(SDNode *N) {
1898 ConstantFPSDNode *CFPNode = cast<ConstantFPSDNode>(N);
1899 EVT VT = N->getValueType(0);
1902 // Get the (bit-cast) APInt of the APFloat and build an integer constant
1903 EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
1904 SDValue C = DAG.getConstant(CFPNode->getValueAPF().bitcastToAPInt(), DL,
1907 // Convert the Constant to the desired FP type
1908 // FIXME We might be able to do the conversion during compilation and get rid
1909 // of it from the object code
1910 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1911 return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, C);
1914 // If the Index operand is a constant, try to redirect the extract operation to
1915 // the correct legalized vector. If not, bit-convert the input vector to
1916 // equivalent integer vector. Extract the element as an (bit-cast) integer
1917 // value and convert it to the promoted type.
1918 SDValue DAGTypeLegalizer::PromoteFloatRes_EXTRACT_VECTOR_ELT(SDNode *N) {
1921 // If the index is constant, try to extract the value from the legalized
1923 if (isa<ConstantSDNode>(N->getOperand(1))) {
1924 SDValue Vec = N->getOperand(0);
1925 SDValue Idx = N->getOperand(1);
1926 EVT VecVT = Vec->getValueType(0);
1927 EVT EltVT = VecVT.getVectorElementType();
1929 uint64_t IdxVal = cast<ConstantSDNode>(Idx)->getZExtValue();
1931 switch (getTypeAction(VecVT)) {
1933 case TargetLowering::TypeScalarizeVector: {
1934 SDValue Res = GetScalarizedVector(N->getOperand(0));
1935 ReplaceValueWith(SDValue(N, 0), Res);
1938 case TargetLowering::TypeWidenVector: {
1939 Vec = GetWidenedVector(Vec);
1940 SDValue Res = DAG.getNode(N->getOpcode(), DL, EltVT, Vec, Idx);
1941 ReplaceValueWith(SDValue(N, 0), Res);
1944 case TargetLowering::TypeSplitVector: {
1946 GetSplitVector(Vec, Lo, Hi);
1948 uint64_t LoElts = Lo.getValueType().getVectorNumElements();
1950 if (IdxVal < LoElts)
1951 Res = DAG.getNode(N->getOpcode(), DL, EltVT, Lo, Idx);
1953 Res = DAG.getNode(N->getOpcode(), DL, EltVT, Hi,
1954 DAG.getConstant(IdxVal - LoElts, DL,
1955 Idx.getValueType()));
1956 ReplaceValueWith(SDValue(N, 0), Res);
1963 // Bit-convert the input vector to the equivalent integer vector
1964 SDValue NewOp = BitConvertVectorToIntegerVector(N->getOperand(0));
1965 EVT IVT = NewOp.getValueType().getVectorElementType();
1967 // Extract the element as an (bit-cast) integer value
1968 SDValue NewVal = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, IVT,
1969 NewOp, N->getOperand(1));
1971 // Convert the element to the desired FP type
1972 EVT VT = N->getValueType(0);
1973 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1974 return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, NewVal);
1977 // FCOPYSIGN(X, Y) returns the value of X with the sign of Y. If the result
1978 // needs promotion, so does the argument X. Note that Y, if needed, will be
1979 // handled during operand promotion.
1980 SDValue DAGTypeLegalizer::PromoteFloatRes_FCOPYSIGN(SDNode *N) {
1981 EVT VT = N->getValueType(0);
1982 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1983 SDValue Op0 = GetPromotedFloat(N->getOperand(0));
1985 SDValue Op1 = N->getOperand(1);
1987 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op0, Op1);
1990 // Unary operation where the result and the operand have PromoteFloat type
1991 // action. Construct a new SDNode with the promoted float value of the old
1993 SDValue DAGTypeLegalizer::PromoteFloatRes_UnaryOp(SDNode *N) {
1994 EVT VT = N->getValueType(0);
1995 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
1996 SDValue Op = GetPromotedFloat(N->getOperand(0));
1998 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op);
2001 // Binary operations where the result and both operands have PromoteFloat type
2002 // action. Construct a new SDNode with the promoted float values of the old
2004 SDValue DAGTypeLegalizer::PromoteFloatRes_BinOp(SDNode *N) {
2005 EVT VT = N->getValueType(0);
2006 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
2007 SDValue Op0 = GetPromotedFloat(N->getOperand(0));
2008 SDValue Op1 = GetPromotedFloat(N->getOperand(1));
2009 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op0, Op1, N->getFlags());
2012 SDValue DAGTypeLegalizer::PromoteFloatRes_FMAD(SDNode *N) {
2013 EVT VT = N->getValueType(0);
2014 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
2015 SDValue Op0 = GetPromotedFloat(N->getOperand(0));
2016 SDValue Op1 = GetPromotedFloat(N->getOperand(1));
2017 SDValue Op2 = GetPromotedFloat(N->getOperand(2));
2019 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op0, Op1, Op2);
2022 // Promote the Float (first) operand and retain the Integer (second) operand
2023 SDValue DAGTypeLegalizer::PromoteFloatRes_FPOWI(SDNode *N) {
2024 EVT VT = N->getValueType(0);
2025 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
2026 SDValue Op0 = GetPromotedFloat(N->getOperand(0));
2027 SDValue Op1 = N->getOperand(1);
2029 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op0, Op1);
2032 // Explicit operation to reduce precision. Reduce the value to half precision
2033 // and promote it back to the legal type.
2034 SDValue DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode *N) {
2037 SDValue Op = N->getOperand(0);
2038 EVT VT = N->getValueType(0);
2039 EVT OpVT = Op->getValueType(0);
2040 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
2041 EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
2043 // Round promoted float to desired precision
2044 SDValue Round = DAG.getNode(GetPromotionOpcode(OpVT, VT), DL, IVT, Op);
2045 // Promote it back to the legal output type
2046 return DAG.getNode(GetPromotionOpcode(VT, NVT), DL, NVT, Round);
2049 SDValue DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode *N) {
2050 LoadSDNode *L = cast<LoadSDNode>(N);
2051 EVT VT = N->getValueType(0);
2053 // Load the value as an integer value with the same number of bits
2054 EVT IVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
2055 SDValue newL = DAG.getLoad(L->getAddressingMode(), L->getExtensionType(),
2056 IVT, SDLoc(N), L->getChain(), L->getBasePtr(),
2057 L->getOffset(), L->getPointerInfo(), IVT, L->isVolatile(),
2058 L->isNonTemporal(), false, L->getAlignment(),
2060 // Legalize the chain result by replacing uses of the old value chain with the
2062 ReplaceValueWith(SDValue(N, 1), newL.getValue(1));
2064 // Convert the integer value to the desired FP type
2065 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
2066 return DAG.getNode(GetPromotionOpcode(VT, NVT), SDLoc(N), NVT, newL);
2069 // Construct a new SELECT node with the promoted true- and false- values.
2070 SDValue DAGTypeLegalizer::PromoteFloatRes_SELECT(SDNode *N) {
2071 SDValue TrueVal = GetPromotedFloat(N->getOperand(1));
2072 SDValue FalseVal = GetPromotedFloat(N->getOperand(2));
2074 return DAG.getNode(ISD::SELECT, SDLoc(N), TrueVal->getValueType(0),
2075 N->getOperand(0), TrueVal, FalseVal);
2078 // Construct a new SELECT_CC node with the promoted true- and false- values.
2079 // The operands used for comparison are promoted by PromoteFloatOp_SELECT_CC.
2080 SDValue DAGTypeLegalizer::PromoteFloatRes_SELECT_CC(SDNode *N) {
2081 SDValue TrueVal = GetPromotedFloat(N->getOperand(2));
2082 SDValue FalseVal = GetPromotedFloat(N->getOperand(3));
2084 return DAG.getNode(ISD::SELECT_CC, SDLoc(N), N->getValueType(0),
2085 N->getOperand(0), N->getOperand(1), TrueVal, FalseVal,
2089 // Construct a SDNode that transforms the SINT or UINT operand to the promoted
2091 SDValue DAGTypeLegalizer::PromoteFloatRes_XINT_TO_FP(SDNode *N) {
2092 EVT VT = N->getValueType(0);
2093 EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
2094 return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, N->getOperand(0));
2097 SDValue DAGTypeLegalizer::PromoteFloatRes_UNDEF(SDNode *N) {
2098 return DAG.getUNDEF(TLI.getTypeToTransformTo(*DAG.getContext(),
2099 N->getValueType(0)));