1 //===-------- LegalizeFloatTypes.cpp - Legalization of float types --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements float type expansion and softening for LegalizeTypes.
10 // Softening is the act of turning a computation in an illegal floating point
11 // type into a computation in an integer type of the same size; also known as
12 // "soft float". For example, turning f32 arithmetic into operations using i32.
13 // The resulting integer value is the same as what you would get by performing
14 // the floating point operation and bitcasting the result to the integer type.
15 // Expansion is the act of changing a computation in an illegal type to be a
16 // computation in two identical registers of a smaller type. For example,
17 // implementing ppcf128 arithmetic in two f64 registers.
19 //===----------------------------------------------------------------------===//
21 #include "LegalizeTypes.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/raw_ostream.h"
26 #define DEBUG_TYPE "legalize-types"
28 /// GetFPLibCall - Return the right libcall for the given floating point type.
29 static RTLIB::Libcall
GetFPLibCall(EVT VT
,
30 RTLIB::Libcall Call_F32
,
31 RTLIB::Libcall Call_F64
,
32 RTLIB::Libcall Call_F80
,
33 RTLIB::Libcall Call_F128
,
34 RTLIB::Libcall Call_PPCF128
) {
36 VT
== MVT::f32
? Call_F32
:
37 VT
== MVT::f64
? Call_F64
:
38 VT
== MVT::f80
? Call_F80
:
39 VT
== MVT::f128
? Call_F128
:
40 VT
== MVT::ppcf128
? Call_PPCF128
:
41 RTLIB::UNKNOWN_LIBCALL
;
44 //===----------------------------------------------------------------------===//
45 // Convert Float Results to Integer
46 //===----------------------------------------------------------------------===//
48 void DAGTypeLegalizer::SoftenFloatResult(SDNode
*N
, unsigned ResNo
) {
49 LLVM_DEBUG(dbgs() << "Soften float result " << ResNo
<< ": "; N
->dump(&DAG
);
51 SDValue R
= SDValue();
53 switch (N
->getOpcode()) {
56 dbgs() << "SoftenFloatResult #" << ResNo
<< ": ";
57 N
->dump(&DAG
); dbgs() << "\n";
59 llvm_unreachable("Do not know how to soften the result of this operator!");
61 case ISD::MERGE_VALUES
:R
= SoftenFloatRes_MERGE_VALUES(N
, ResNo
); break;
62 case ISD::BITCAST
: R
= SoftenFloatRes_BITCAST(N
); break;
63 case ISD::BUILD_PAIR
: R
= SoftenFloatRes_BUILD_PAIR(N
); break;
64 case ISD::ConstantFP
: R
= SoftenFloatRes_ConstantFP(N
); break;
65 case ISD::EXTRACT_VECTOR_ELT
:
66 R
= SoftenFloatRes_EXTRACT_VECTOR_ELT(N
, ResNo
); break;
67 case ISD::FABS
: R
= SoftenFloatRes_FABS(N
); break;
68 case ISD::FMINNUM
: R
= SoftenFloatRes_FMINNUM(N
); break;
69 case ISD::FMAXNUM
: R
= SoftenFloatRes_FMAXNUM(N
); break;
70 case ISD::FADD
: R
= SoftenFloatRes_FADD(N
); break;
71 case ISD::FCEIL
: R
= SoftenFloatRes_FCEIL(N
); break;
72 case ISD::FCOPYSIGN
: R
= SoftenFloatRes_FCOPYSIGN(N
); break;
73 case ISD::FCOS
: R
= SoftenFloatRes_FCOS(N
); break;
74 case ISD::FDIV
: R
= SoftenFloatRes_FDIV(N
); break;
75 case ISD::FEXP
: R
= SoftenFloatRes_FEXP(N
); break;
76 case ISD::FEXP2
: R
= SoftenFloatRes_FEXP2(N
); break;
77 case ISD::FFLOOR
: R
= SoftenFloatRes_FFLOOR(N
); break;
78 case ISD::FLOG
: R
= SoftenFloatRes_FLOG(N
); break;
79 case ISD::FLOG2
: R
= SoftenFloatRes_FLOG2(N
); break;
80 case ISD::FLOG10
: R
= SoftenFloatRes_FLOG10(N
); break;
81 case ISD::FMA
: R
= SoftenFloatRes_FMA(N
); break;
82 case ISD::FMUL
: R
= SoftenFloatRes_FMUL(N
); break;
83 case ISD::FNEARBYINT
: R
= SoftenFloatRes_FNEARBYINT(N
); break;
84 case ISD::FNEG
: R
= SoftenFloatRes_FNEG(N
); break;
85 case ISD::FP_EXTEND
: R
= SoftenFloatRes_FP_EXTEND(N
); break;
86 case ISD::FP_ROUND
: R
= SoftenFloatRes_FP_ROUND(N
); break;
87 case ISD::FP16_TO_FP
: R
= SoftenFloatRes_FP16_TO_FP(N
); break;
88 case ISD::FPOW
: R
= SoftenFloatRes_FPOW(N
); break;
89 case ISD::FPOWI
: R
= SoftenFloatRes_FPOWI(N
); break;
90 case ISD::FREM
: R
= SoftenFloatRes_FREM(N
); break;
91 case ISD::FRINT
: R
= SoftenFloatRes_FRINT(N
); break;
92 case ISD::FROUND
: R
= SoftenFloatRes_FROUND(N
); break;
93 case ISD::FSIN
: R
= SoftenFloatRes_FSIN(N
); break;
94 case ISD::FSQRT
: R
= SoftenFloatRes_FSQRT(N
); break;
95 case ISD::FSUB
: R
= SoftenFloatRes_FSUB(N
); break;
96 case ISD::FTRUNC
: R
= SoftenFloatRes_FTRUNC(N
); break;
97 case ISD::LOAD
: R
= SoftenFloatRes_LOAD(N
); break;
98 case ISD::ATOMIC_SWAP
: R
= BitcastToInt_ATOMIC_SWAP(N
); break;
99 case ISD::SELECT
: R
= SoftenFloatRes_SELECT(N
); break;
100 case ISD::SELECT_CC
: R
= SoftenFloatRes_SELECT_CC(N
); break;
101 case ISD::SINT_TO_FP
:
102 case ISD::UINT_TO_FP
: R
= SoftenFloatRes_XINT_TO_FP(N
); break;
103 case ISD::UNDEF
: R
= SoftenFloatRes_UNDEF(N
); break;
104 case ISD::VAARG
: R
= SoftenFloatRes_VAARG(N
); break;
107 // If R is null, the sub-method took care of registering the result.
109 assert(R
.getNode() != N
);
110 SetSoftenedFloat(SDValue(N
, ResNo
), R
);
114 SDValue
DAGTypeLegalizer::SoftenFloatRes_BITCAST(SDNode
*N
) {
115 return BitConvertToInteger(N
->getOperand(0));
118 SDValue
DAGTypeLegalizer::SoftenFloatRes_MERGE_VALUES(SDNode
*N
,
120 SDValue Op
= DisintegrateMERGE_VALUES(N
, ResNo
);
121 return BitConvertToInteger(Op
);
124 SDValue
DAGTypeLegalizer::SoftenFloatRes_BUILD_PAIR(SDNode
*N
) {
125 // Convert the inputs to integers, and build a new pair out of them.
126 return DAG
.getNode(ISD::BUILD_PAIR
, SDLoc(N
),
127 TLI
.getTypeToTransformTo(*DAG
.getContext(),
129 BitConvertToInteger(N
->getOperand(0)),
130 BitConvertToInteger(N
->getOperand(1)));
133 SDValue
DAGTypeLegalizer::SoftenFloatRes_ConstantFP(SDNode
*N
) {
134 ConstantFPSDNode
*CN
= cast
<ConstantFPSDNode
>(N
);
135 // In ppcf128, the high 64 bits are always first in memory regardless
136 // of Endianness. LLVM's APFloat representation is not Endian sensitive,
137 // and so always converts into a 128-bit APInt in a non-Endian-sensitive
138 // way. However, APInt's are serialized in an Endian-sensitive fashion,
139 // so on big-Endian targets, the two doubles are output in the wrong
140 // order. Fix this by manually flipping the order of the high 64 bits
141 // and the low 64 bits here.
142 if (DAG
.getDataLayout().isBigEndian() &&
143 CN
->getValueType(0).getSimpleVT() == llvm::MVT::ppcf128
) {
144 uint64_t words
[2] = { CN
->getValueAPF().bitcastToAPInt().getRawData()[1],
145 CN
->getValueAPF().bitcastToAPInt().getRawData()[0] };
146 APInt
Val(128, words
);
147 return DAG
.getConstant(Val
, SDLoc(CN
),
148 TLI
.getTypeToTransformTo(*DAG
.getContext(),
149 CN
->getValueType(0)));
151 return DAG
.getConstant(CN
->getValueAPF().bitcastToAPInt(), SDLoc(CN
),
152 TLI
.getTypeToTransformTo(*DAG
.getContext(),
153 CN
->getValueType(0)));
157 SDValue
DAGTypeLegalizer::SoftenFloatRes_EXTRACT_VECTOR_ELT(SDNode
*N
, unsigned ResNo
) {
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
) {
165 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
166 unsigned Size
= NVT
.getSizeInBits();
168 // Mask = ~(1 << (Size-1))
169 APInt API
= APInt::getAllOnesValue(Size
);
170 API
.clearBit(Size
- 1);
171 SDValue Mask
= DAG
.getConstant(API
, SDLoc(N
), NVT
);
172 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
173 return DAG
.getNode(ISD::AND
, SDLoc(N
), NVT
, Op
, Mask
);
176 SDValue
DAGTypeLegalizer::SoftenFloatRes_FMINNUM(SDNode
*N
) {
177 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
178 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
179 GetSoftenedFloat(N
->getOperand(1)) };
180 TargetLowering::MakeLibCallOptions CallOptions
;
181 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
182 N
->getOperand(1).getValueType() };
183 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
184 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
189 RTLIB::FMIN_PPCF128
),
190 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
193 SDValue
DAGTypeLegalizer::SoftenFloatRes_FMAXNUM(SDNode
*N
) {
194 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
195 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
196 GetSoftenedFloat(N
->getOperand(1)) };
197 TargetLowering::MakeLibCallOptions CallOptions
;
198 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
199 N
->getOperand(1).getValueType() };
200 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
201 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
206 RTLIB::FMAX_PPCF128
),
207 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
210 SDValue
DAGTypeLegalizer::SoftenFloatRes_FADD(SDNode
*N
) {
211 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
212 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
213 GetSoftenedFloat(N
->getOperand(1)) };
214 TargetLowering::MakeLibCallOptions CallOptions
;
215 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
216 N
->getOperand(1).getValueType() };
217 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
218 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
224 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
227 SDValue
DAGTypeLegalizer::SoftenFloatRes_FCEIL(SDNode
*N
) {
228 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
229 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
230 TargetLowering::MakeLibCallOptions CallOptions
;
231 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
232 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
233 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
238 RTLIB::CEIL_PPCF128
),
239 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
242 SDValue
DAGTypeLegalizer::SoftenFloatRes_FCOPYSIGN(SDNode
*N
) {
243 SDValue LHS
= GetSoftenedFloat(N
->getOperand(0));
244 SDValue RHS
= BitConvertToInteger(N
->getOperand(1));
247 EVT LVT
= LHS
.getValueType();
248 EVT RVT
= RHS
.getValueType();
250 unsigned LSize
= LVT
.getSizeInBits();
251 unsigned RSize
= RVT
.getSizeInBits();
253 // First get the sign bit of second operand.
254 SDValue SignBit
= DAG
.getNode(
255 ISD::SHL
, dl
, RVT
, DAG
.getConstant(1, dl
, RVT
),
256 DAG
.getConstant(RSize
- 1, dl
,
257 TLI
.getShiftAmountTy(RVT
, DAG
.getDataLayout())));
258 SignBit
= DAG
.getNode(ISD::AND
, dl
, RVT
, RHS
, SignBit
);
260 // Shift right or sign-extend it if the two operands have different types.
261 int SizeDiff
= RVT
.getSizeInBits() - LVT
.getSizeInBits();
264 DAG
.getNode(ISD::SRL
, dl
, RVT
, SignBit
,
265 DAG
.getConstant(SizeDiff
, dl
,
266 TLI
.getShiftAmountTy(SignBit
.getValueType(),
267 DAG
.getDataLayout())));
268 SignBit
= DAG
.getNode(ISD::TRUNCATE
, dl
, LVT
, SignBit
);
269 } else if (SizeDiff
< 0) {
270 SignBit
= DAG
.getNode(ISD::ANY_EXTEND
, dl
, LVT
, SignBit
);
272 DAG
.getNode(ISD::SHL
, dl
, LVT
, SignBit
,
273 DAG
.getConstant(-SizeDiff
, dl
,
274 TLI
.getShiftAmountTy(SignBit
.getValueType(),
275 DAG
.getDataLayout())));
278 // Clear the sign bit of the first operand.
279 SDValue Mask
= DAG
.getNode(
280 ISD::SHL
, dl
, LVT
, DAG
.getConstant(1, dl
, LVT
),
281 DAG
.getConstant(LSize
- 1, dl
,
282 TLI
.getShiftAmountTy(LVT
, DAG
.getDataLayout())));
283 Mask
= DAG
.getNode(ISD::SUB
, dl
, LVT
, Mask
, DAG
.getConstant(1, dl
, LVT
));
284 LHS
= DAG
.getNode(ISD::AND
, dl
, LVT
, LHS
, Mask
);
286 // Or the value with the sign bit.
287 return DAG
.getNode(ISD::OR
, dl
, LVT
, LHS
, SignBit
);
290 SDValue
DAGTypeLegalizer::SoftenFloatRes_FCOS(SDNode
*N
) {
291 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
292 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
293 TargetLowering::MakeLibCallOptions CallOptions
;
294 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
295 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
296 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
302 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
305 SDValue
DAGTypeLegalizer::SoftenFloatRes_FDIV(SDNode
*N
) {
306 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
307 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
308 GetSoftenedFloat(N
->getOperand(1)) };
309 TargetLowering::MakeLibCallOptions CallOptions
;
310 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
311 N
->getOperand(1).getValueType() };
312 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
313 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
319 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
322 SDValue
DAGTypeLegalizer::SoftenFloatRes_FEXP(SDNode
*N
) {
323 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
324 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
325 TargetLowering::MakeLibCallOptions CallOptions
;
326 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
327 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
328 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
334 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
337 SDValue
DAGTypeLegalizer::SoftenFloatRes_FEXP2(SDNode
*N
) {
338 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
339 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
340 TargetLowering::MakeLibCallOptions CallOptions
;
341 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
342 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
343 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
348 RTLIB::EXP2_PPCF128
),
349 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
352 SDValue
DAGTypeLegalizer::SoftenFloatRes_FFLOOR(SDNode
*N
) {
353 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
354 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
355 TargetLowering::MakeLibCallOptions CallOptions
;
356 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
357 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
358 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
363 RTLIB::FLOOR_PPCF128
),
364 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
367 SDValue
DAGTypeLegalizer::SoftenFloatRes_FLOG(SDNode
*N
) {
368 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
369 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
370 TargetLowering::MakeLibCallOptions CallOptions
;
371 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
372 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
373 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
379 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
382 SDValue
DAGTypeLegalizer::SoftenFloatRes_FLOG2(SDNode
*N
) {
383 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
384 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
385 TargetLowering::MakeLibCallOptions CallOptions
;
386 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
387 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
388 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
393 RTLIB::LOG2_PPCF128
),
394 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
397 SDValue
DAGTypeLegalizer::SoftenFloatRes_FLOG10(SDNode
*N
) {
398 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
399 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
400 TargetLowering::MakeLibCallOptions CallOptions
;
401 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
402 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
403 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
408 RTLIB::LOG10_PPCF128
),
409 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
412 SDValue
DAGTypeLegalizer::SoftenFloatRes_FMA(SDNode
*N
) {
413 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
414 SDValue Ops
[3] = { GetSoftenedFloat(N
->getOperand(0)),
415 GetSoftenedFloat(N
->getOperand(1)),
416 GetSoftenedFloat(N
->getOperand(2)) };
417 TargetLowering::MakeLibCallOptions CallOptions
;
418 EVT OpsVT
[3] = { N
->getOperand(0).getValueType(),
419 N
->getOperand(1).getValueType(),
420 N
->getOperand(2).getValueType() };
421 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
422 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
428 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
431 SDValue
DAGTypeLegalizer::SoftenFloatRes_FMUL(SDNode
*N
) {
432 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
433 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
434 GetSoftenedFloat(N
->getOperand(1)) };
435 TargetLowering::MakeLibCallOptions CallOptions
;
436 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
437 N
->getOperand(1).getValueType() };
438 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
439 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
445 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
448 SDValue
DAGTypeLegalizer::SoftenFloatRes_FNEARBYINT(SDNode
*N
) {
449 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
450 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
451 TargetLowering::MakeLibCallOptions CallOptions
;
452 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
453 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
454 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
455 RTLIB::NEARBYINT_F32
,
456 RTLIB::NEARBYINT_F64
,
457 RTLIB::NEARBYINT_F80
,
458 RTLIB::NEARBYINT_F128
,
459 RTLIB::NEARBYINT_PPCF128
),
460 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
463 SDValue
DAGTypeLegalizer::SoftenFloatRes_FNEG(SDNode
*N
) {
464 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
467 EVT FloatVT
= N
->getValueType(0);
468 if (FloatVT
== MVT::f32
|| FloatVT
== MVT::f64
|| FloatVT
== MVT::f128
) {
469 // Expand Y = FNEG(X) -> Y = X ^ sign mask
470 APInt SignMask
= APInt::getSignMask(NVT
.getSizeInBits());
471 return DAG
.getNode(ISD::XOR
, dl
, NVT
, GetSoftenedFloat(N
->getOperand(0)),
472 DAG
.getConstant(SignMask
, dl
, NVT
));
475 // Expand Y = FNEG(X) -> Y = SUB -0.0, X
476 SDValue Ops
[2] = { DAG
.getConstantFP(-0.0, dl
, N
->getValueType(0)),
477 GetSoftenedFloat(N
->getOperand(0)) };
478 TargetLowering::MakeLibCallOptions CallOptions
;
479 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
485 NVT
, Ops
, CallOptions
, dl
).first
;
488 SDValue
DAGTypeLegalizer::SoftenFloatRes_FP_EXTEND(SDNode
*N
) {
489 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
490 SDValue Op
= N
->getOperand(0);
492 // There's only a libcall for f16 -> f32, so proceed in two stages. Also, it's
493 // entirely possible for both f16 and f32 to be legal, so use the fully
494 // hard-float FP_EXTEND rather than FP16_TO_FP.
495 if (Op
.getValueType() == MVT::f16
&& N
->getValueType(0) != MVT::f32
) {
496 Op
= DAG
.getNode(ISD::FP_EXTEND
, SDLoc(N
), MVT::f32
, Op
);
497 if (getTypeAction(MVT::f32
) == TargetLowering::TypeSoftenFloat
)
498 AddToWorklist(Op
.getNode());
501 if (getTypeAction(Op
.getValueType()) == TargetLowering::TypePromoteFloat
) {
502 Op
= GetPromotedFloat(Op
);
503 // If the promotion did the FP_EXTEND to the destination type for us,
504 // there's nothing left to do here.
505 if (Op
.getValueType() == N
->getValueType(0)) {
506 return BitConvertToInteger(Op
);
510 RTLIB::Libcall LC
= RTLIB::getFPEXT(Op
.getValueType(), N
->getValueType(0));
511 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_EXTEND!");
512 TargetLowering::MakeLibCallOptions CallOptions
;
513 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
514 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
515 return TLI
.makeLibCall(DAG
, LC
, NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
518 // FIXME: Should we just use 'normal' FP_EXTEND / FP_TRUNC instead of special
520 SDValue
DAGTypeLegalizer::SoftenFloatRes_FP16_TO_FP(SDNode
*N
) {
521 EVT MidVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), MVT::f32
);
522 SDValue Op
= N
->getOperand(0);
523 TargetLowering::MakeLibCallOptions CallOptions
;
524 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
525 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
526 SDValue Res32
= TLI
.makeLibCall(DAG
, RTLIB::FPEXT_F16_F32
, MidVT
, Op
,
527 CallOptions
, SDLoc(N
)).first
;
528 if (N
->getValueType(0) == MVT::f32
)
531 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
532 RTLIB::Libcall LC
= RTLIB::getFPEXT(MVT::f32
, N
->getValueType(0));
533 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_EXTEND!");
534 return TLI
.makeLibCall(DAG
, LC
, NVT
, Res32
, CallOptions
, SDLoc(N
)).first
;
537 SDValue
DAGTypeLegalizer::SoftenFloatRes_FP_ROUND(SDNode
*N
) {
538 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
539 SDValue Op
= N
->getOperand(0);
540 if (N
->getValueType(0) == MVT::f16
) {
541 // Semi-soften first, to FP_TO_FP16, so that targets which support f16 as a
542 // storage-only type get a chance to select things.
543 return DAG
.getNode(ISD::FP_TO_FP16
, SDLoc(N
), NVT
, Op
);
546 RTLIB::Libcall LC
= RTLIB::getFPROUND(Op
.getValueType(), N
->getValueType(0));
547 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_ROUND!");
548 TargetLowering::MakeLibCallOptions CallOptions
;
549 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
550 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
551 return TLI
.makeLibCall(DAG
, LC
, NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
554 SDValue
DAGTypeLegalizer::SoftenFloatRes_FPOW(SDNode
*N
) {
555 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
556 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
557 GetSoftenedFloat(N
->getOperand(1)) };
558 TargetLowering::MakeLibCallOptions CallOptions
;
559 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
560 N
->getOperand(1).getValueType() };
561 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
562 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
568 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
571 SDValue
DAGTypeLegalizer::SoftenFloatRes_FPOWI(SDNode
*N
) {
572 assert(N
->getOperand(1).getValueType() == MVT::i32
&&
573 "Unsupported power type!");
574 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
575 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)), N
->getOperand(1) };
576 TargetLowering::MakeLibCallOptions CallOptions
;
577 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
578 N
->getOperand(1).getValueType() };
579 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
580 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
585 RTLIB::POWI_PPCF128
),
586 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
589 SDValue
DAGTypeLegalizer::SoftenFloatRes_FREM(SDNode
*N
) {
590 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
591 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
592 GetSoftenedFloat(N
->getOperand(1)) };
593 TargetLowering::MakeLibCallOptions CallOptions
;
594 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
595 N
->getOperand(1).getValueType() };
596 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
597 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
603 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
606 SDValue
DAGTypeLegalizer::SoftenFloatRes_FRINT(SDNode
*N
) {
607 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
608 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
609 TargetLowering::MakeLibCallOptions CallOptions
;
610 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
611 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
612 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
617 RTLIB::RINT_PPCF128
),
618 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
621 SDValue
DAGTypeLegalizer::SoftenFloatRes_FROUND(SDNode
*N
) {
622 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
623 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
624 TargetLowering::MakeLibCallOptions CallOptions
;
625 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
626 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
627 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
632 RTLIB::ROUND_PPCF128
),
633 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
636 SDValue
DAGTypeLegalizer::SoftenFloatRes_FSIN(SDNode
*N
) {
637 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
638 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
639 TargetLowering::MakeLibCallOptions CallOptions
;
640 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
641 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
642 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
648 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
651 SDValue
DAGTypeLegalizer::SoftenFloatRes_FSQRT(SDNode
*N
) {
652 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
653 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
654 TargetLowering::MakeLibCallOptions CallOptions
;
655 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
656 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
657 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
662 RTLIB::SQRT_PPCF128
),
663 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
666 SDValue
DAGTypeLegalizer::SoftenFloatRes_FSUB(SDNode
*N
) {
667 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
668 SDValue Ops
[2] = { GetSoftenedFloat(N
->getOperand(0)),
669 GetSoftenedFloat(N
->getOperand(1)) };
670 TargetLowering::MakeLibCallOptions CallOptions
;
671 EVT OpsVT
[2] = { N
->getOperand(0).getValueType(),
672 N
->getOperand(1).getValueType() };
673 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
674 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
680 NVT
, Ops
, CallOptions
, SDLoc(N
)).first
;
683 SDValue
DAGTypeLegalizer::SoftenFloatRes_FTRUNC(SDNode
*N
) {
684 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
685 if (N
->getValueType(0) == MVT::f16
)
686 return DAG
.getNode(ISD::FP_TO_FP16
, SDLoc(N
), NVT
, N
->getOperand(0));
688 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
689 TargetLowering::MakeLibCallOptions CallOptions
;
690 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
691 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
692 return TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
697 RTLIB::TRUNC_PPCF128
),
698 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
701 SDValue
DAGTypeLegalizer::SoftenFloatRes_LOAD(SDNode
*N
) {
702 LoadSDNode
*L
= cast
<LoadSDNode
>(N
);
703 EVT VT
= N
->getValueType(0);
704 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
708 L
->getMemOperand()->getFlags() &
709 ~(MachineMemOperand::MOInvariant
| MachineMemOperand::MODereferenceable
);
711 if (L
->getExtensionType() == ISD::NON_EXTLOAD
) {
712 NewL
= DAG
.getLoad(L
->getAddressingMode(), L
->getExtensionType(), NVT
, dl
,
713 L
->getChain(), L
->getBasePtr(), L
->getOffset(),
714 L
->getPointerInfo(), NVT
, L
->getAlignment(), MMOFlags
,
716 // Legalized the chain result - switch anything that used the old chain to
718 if (N
!= NewL
.getValue(1).getNode())
719 ReplaceValueWith(SDValue(N
, 1), NewL
.getValue(1));
723 // Do a non-extending load followed by FP_EXTEND.
724 NewL
= DAG
.getLoad(L
->getAddressingMode(), ISD::NON_EXTLOAD
, L
->getMemoryVT(),
725 dl
, L
->getChain(), L
->getBasePtr(), L
->getOffset(),
726 L
->getPointerInfo(), L
->getMemoryVT(), L
->getAlignment(),
727 MMOFlags
, L
->getAAInfo());
728 // Legalized the chain result - switch anything that used the old chain to
730 ReplaceValueWith(SDValue(N
, 1), NewL
.getValue(1));
731 auto ExtendNode
= DAG
.getNode(ISD::FP_EXTEND
, dl
, VT
, NewL
);
732 return BitConvertToInteger(ExtendNode
);
735 SDValue
DAGTypeLegalizer::SoftenFloatRes_SELECT(SDNode
*N
) {
736 SDValue LHS
= GetSoftenedFloat(N
->getOperand(1));
737 SDValue RHS
= GetSoftenedFloat(N
->getOperand(2));
738 return DAG
.getSelect(SDLoc(N
),
739 LHS
.getValueType(), N
->getOperand(0), LHS
, RHS
);
742 SDValue
DAGTypeLegalizer::SoftenFloatRes_SELECT_CC(SDNode
*N
) {
743 SDValue LHS
= GetSoftenedFloat(N
->getOperand(2));
744 SDValue RHS
= GetSoftenedFloat(N
->getOperand(3));
745 return DAG
.getNode(ISD::SELECT_CC
, SDLoc(N
),
746 LHS
.getValueType(), N
->getOperand(0),
747 N
->getOperand(1), LHS
, RHS
, N
->getOperand(4));
750 SDValue
DAGTypeLegalizer::SoftenFloatRes_UNDEF(SDNode
*N
) {
751 return DAG
.getUNDEF(TLI
.getTypeToTransformTo(*DAG
.getContext(),
752 N
->getValueType(0)));
755 SDValue
DAGTypeLegalizer::SoftenFloatRes_VAARG(SDNode
*N
) {
756 SDValue Chain
= N
->getOperand(0); // Get the chain.
757 SDValue Ptr
= N
->getOperand(1); // Get the pointer.
758 EVT VT
= N
->getValueType(0);
759 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
763 NewVAARG
= DAG
.getVAArg(NVT
, dl
, Chain
, Ptr
, N
->getOperand(2),
764 N
->getConstantOperandVal(3));
766 // Legalized the chain result - switch anything that used the old chain to
768 if (N
!= NewVAARG
.getValue(1).getNode())
769 ReplaceValueWith(SDValue(N
, 1), NewVAARG
.getValue(1));
773 SDValue
DAGTypeLegalizer::SoftenFloatRes_XINT_TO_FP(SDNode
*N
) {
774 bool Signed
= N
->getOpcode() == ISD::SINT_TO_FP
;
775 EVT SVT
= N
->getOperand(0).getValueType();
776 EVT RVT
= N
->getValueType(0);
780 // If the input is not legal, eg: i1 -> fp, then it needs to be promoted to
781 // a larger type, eg: i8 -> fp. Even if it is legal, no libcall may exactly
782 // match. Look for an appropriate libcall.
783 RTLIB::Libcall LC
= RTLIB::UNKNOWN_LIBCALL
;
784 for (unsigned t
= MVT::FIRST_INTEGER_VALUETYPE
;
785 t
<= MVT::LAST_INTEGER_VALUETYPE
&& LC
== RTLIB::UNKNOWN_LIBCALL
; ++t
) {
786 NVT
= (MVT::SimpleValueType
)t
;
787 // The source needs to big enough to hold the operand.
789 LC
= Signed
? RTLIB::getSINTTOFP(NVT
, RVT
):RTLIB::getUINTTOFP (NVT
, RVT
);
791 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported XINT_TO_FP!");
793 // Sign/zero extend the argument if the libcall takes a larger type.
794 SDValue Op
= DAG
.getNode(Signed
? ISD::SIGN_EXTEND
: ISD::ZERO_EXTEND
, dl
,
795 NVT
, N
->getOperand(0));
796 TargetLowering::MakeLibCallOptions CallOptions
;
797 CallOptions
.setSExt(Signed
);
798 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
799 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
800 return TLI
.makeLibCall(DAG
, LC
,
801 TLI
.getTypeToTransformTo(*DAG
.getContext(), RVT
),
802 Op
, CallOptions
, dl
).first
;
806 //===----------------------------------------------------------------------===//
807 // Convert Float Operand to Integer
808 //===----------------------------------------------------------------------===//
810 bool DAGTypeLegalizer::SoftenFloatOperand(SDNode
*N
, unsigned OpNo
) {
811 LLVM_DEBUG(dbgs() << "Soften float operand " << OpNo
<< ": "; N
->dump(&DAG
);
813 SDValue Res
= SDValue();
815 switch (N
->getOpcode()) {
818 dbgs() << "SoftenFloatOperand Op #" << OpNo
<< ": ";
819 N
->dump(&DAG
); dbgs() << "\n";
821 llvm_unreachable("Do not know how to soften this operator's operand!");
823 case ISD::BITCAST
: Res
= SoftenFloatOp_BITCAST(N
); break;
824 case ISD::BR_CC
: Res
= SoftenFloatOp_BR_CC(N
); break;
825 case ISD::FP_EXTEND
: Res
= SoftenFloatOp_FP_EXTEND(N
); break;
826 case ISD::FP_TO_FP16
: // Same as FP_ROUND for softening purposes
827 case ISD::FP_ROUND
: Res
= SoftenFloatOp_FP_ROUND(N
); break;
828 case ISD::FP_TO_SINT
:
829 case ISD::FP_TO_UINT
: Res
= SoftenFloatOp_FP_TO_XINT(N
); break;
830 case ISD::LROUND
: Res
= SoftenFloatOp_LROUND(N
); break;
831 case ISD::LLROUND
: Res
= SoftenFloatOp_LLROUND(N
); break;
832 case ISD::LRINT
: Res
= SoftenFloatOp_LRINT(N
); break;
833 case ISD::LLRINT
: Res
= SoftenFloatOp_LLRINT(N
); break;
834 case ISD::SELECT_CC
: Res
= SoftenFloatOp_SELECT_CC(N
); break;
835 case ISD::SETCC
: Res
= SoftenFloatOp_SETCC(N
); break;
836 case ISD::STORE
: Res
= SoftenFloatOp_STORE(N
, OpNo
); break;
839 // If the result is null, the sub-method took care of registering results etc.
840 if (!Res
.getNode()) return false;
842 // If the result is N, the sub-method updated N in place. Tell the legalizer
843 // core about this to re-analyze.
844 if (Res
.getNode() == N
)
847 assert(Res
.getValueType() == N
->getValueType(0) && N
->getNumValues() == 1 &&
848 "Invalid operand promotion");
850 ReplaceValueWith(SDValue(N
, 0), Res
);
854 SDValue
DAGTypeLegalizer::SoftenFloatOp_BITCAST(SDNode
*N
) {
855 SDValue Op0
= GetSoftenedFloat(N
->getOperand(0));
857 return DAG
.getNode(ISD::BITCAST
, SDLoc(N
), N
->getValueType(0), Op0
);
860 SDValue
DAGTypeLegalizer::SoftenFloatOp_FP_EXTEND(SDNode
*N
) {
861 // If we get here, the result must be legal but the source illegal.
862 EVT SVT
= N
->getOperand(0).getValueType();
863 EVT RVT
= N
->getValueType(0);
864 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
867 return DAG
.getNode(ISD::FP16_TO_FP
, SDLoc(N
), RVT
, Op
);
869 RTLIB::Libcall LC
= RTLIB::getFPEXT(SVT
, RVT
);
870 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_EXTEND libcall");
872 TargetLowering::MakeLibCallOptions CallOptions
;
873 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
874 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
875 return TLI
.makeLibCall(DAG
, LC
, RVT
, Op
, CallOptions
, SDLoc(N
)).first
;
879 SDValue
DAGTypeLegalizer::SoftenFloatOp_FP_ROUND(SDNode
*N
) {
880 // We actually deal with the partially-softened FP_TO_FP16 node too, which
881 // returns an i16 so doesn't meet the constraints necessary for FP_ROUND.
882 assert(N
->getOpcode() == ISD::FP_ROUND
|| N
->getOpcode() == ISD::FP_TO_FP16
);
884 EVT SVT
= N
->getOperand(0).getValueType();
885 EVT RVT
= N
->getValueType(0);
886 EVT FloatRVT
= N
->getOpcode() == ISD::FP_TO_FP16
? MVT::f16
: RVT
;
888 RTLIB::Libcall LC
= RTLIB::getFPROUND(SVT
, FloatRVT
);
889 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_ROUND libcall");
891 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
892 TargetLowering::MakeLibCallOptions CallOptions
;
893 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
894 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
895 return TLI
.makeLibCall(DAG
, LC
, RVT
, Op
, CallOptions
, SDLoc(N
)).first
;
898 SDValue
DAGTypeLegalizer::SoftenFloatOp_BR_CC(SDNode
*N
) {
899 SDValue NewLHS
= N
->getOperand(2), NewRHS
= N
->getOperand(3);
900 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(1))->get();
902 EVT VT
= NewLHS
.getValueType();
903 NewLHS
= GetSoftenedFloat(NewLHS
);
904 NewRHS
= GetSoftenedFloat(NewRHS
);
905 TLI
.softenSetCCOperands(DAG
, VT
, NewLHS
, NewRHS
, CCCode
, SDLoc(N
),
906 N
->getOperand(2), N
->getOperand(3));
908 // If softenSetCCOperands returned a scalar, we need to compare the result
909 // against zero to select between true and false values.
910 if (!NewRHS
.getNode()) {
911 NewRHS
= DAG
.getConstant(0, SDLoc(N
), NewLHS
.getValueType());
915 // Update N to have the operands specified.
916 return SDValue(DAG
.UpdateNodeOperands(N
, N
->getOperand(0),
917 DAG
.getCondCode(CCCode
), NewLHS
, NewRHS
,
922 SDValue
DAGTypeLegalizer::SoftenFloatOp_FP_TO_XINT(SDNode
*N
) {
923 bool Signed
= N
->getOpcode() == ISD::FP_TO_SINT
;
924 EVT SVT
= N
->getOperand(0).getValueType();
925 EVT RVT
= N
->getValueType(0);
929 // If the result is not legal, eg: fp -> i1, then it needs to be promoted to
930 // a larger type, eg: fp -> i32. Even if it is legal, no libcall may exactly
931 // match, eg. we don't have fp -> i8 conversions.
932 // Look for an appropriate libcall.
933 RTLIB::Libcall LC
= RTLIB::UNKNOWN_LIBCALL
;
934 for (unsigned IntVT
= MVT::FIRST_INTEGER_VALUETYPE
;
935 IntVT
<= MVT::LAST_INTEGER_VALUETYPE
&& LC
== RTLIB::UNKNOWN_LIBCALL
;
937 NVT
= (MVT::SimpleValueType
)IntVT
;
938 // The type needs to big enough to hold the result.
940 LC
= Signed
? RTLIB::getFPTOSINT(SVT
, NVT
):RTLIB::getFPTOUINT(SVT
, NVT
);
942 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_TO_XINT!");
944 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
945 TargetLowering::MakeLibCallOptions CallOptions
;
946 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
947 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
948 SDValue Res
= TLI
.makeLibCall(DAG
, LC
, NVT
, Op
, CallOptions
, dl
).first
;
950 // Truncate the result if the libcall returns a larger type.
951 return DAG
.getNode(ISD::TRUNCATE
, dl
, RVT
, Res
);
954 SDValue
DAGTypeLegalizer::SoftenFloatOp_SELECT_CC(SDNode
*N
) {
955 SDValue NewLHS
= N
->getOperand(0), NewRHS
= N
->getOperand(1);
956 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(4))->get();
958 EVT VT
= NewLHS
.getValueType();
959 NewLHS
= GetSoftenedFloat(NewLHS
);
960 NewRHS
= GetSoftenedFloat(NewRHS
);
961 TLI
.softenSetCCOperands(DAG
, VT
, NewLHS
, NewRHS
, CCCode
, SDLoc(N
),
962 N
->getOperand(0), N
->getOperand(1));
964 // If softenSetCCOperands returned a scalar, we need to compare the result
965 // against zero to select between true and false values.
966 if (!NewRHS
.getNode()) {
967 NewRHS
= DAG
.getConstant(0, SDLoc(N
), NewLHS
.getValueType());
971 // Update N to have the operands specified.
972 return SDValue(DAG
.UpdateNodeOperands(N
, NewLHS
, NewRHS
,
973 N
->getOperand(2), N
->getOperand(3),
974 DAG
.getCondCode(CCCode
)),
978 SDValue
DAGTypeLegalizer::SoftenFloatOp_SETCC(SDNode
*N
) {
979 SDValue NewLHS
= N
->getOperand(0), NewRHS
= N
->getOperand(1);
980 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(2))->get();
982 EVT VT
= NewLHS
.getValueType();
983 NewLHS
= GetSoftenedFloat(NewLHS
);
984 NewRHS
= GetSoftenedFloat(NewRHS
);
985 TLI
.softenSetCCOperands(DAG
, VT
, NewLHS
, NewRHS
, CCCode
, SDLoc(N
),
986 N
->getOperand(0), N
->getOperand(1));
988 // If softenSetCCOperands returned a scalar, use it.
989 if (!NewRHS
.getNode()) {
990 assert(NewLHS
.getValueType() == N
->getValueType(0) &&
991 "Unexpected setcc expansion!");
995 // Otherwise, update N to have the operands specified.
996 return SDValue(DAG
.UpdateNodeOperands(N
, NewLHS
, NewRHS
,
997 DAG
.getCondCode(CCCode
)),
1001 SDValue
DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode
*N
, unsigned OpNo
) {
1002 assert(ISD::isUNINDEXEDStore(N
) && "Indexed store during type legalization!");
1003 assert(OpNo
== 1 && "Can only soften the stored value!");
1004 StoreSDNode
*ST
= cast
<StoreSDNode
>(N
);
1005 SDValue Val
= ST
->getValue();
1008 if (ST
->isTruncatingStore())
1009 // Do an FP_ROUND followed by a non-truncating store.
1010 Val
= BitConvertToInteger(DAG
.getNode(ISD::FP_ROUND
, dl
, ST
->getMemoryVT(),
1011 Val
, DAG
.getIntPtrConstant(0, dl
)));
1013 Val
= GetSoftenedFloat(Val
);
1015 return DAG
.getStore(ST
->getChain(), dl
, Val
, ST
->getBasePtr(),
1016 ST
->getMemOperand());
1019 SDValue
DAGTypeLegalizer::SoftenFloatOp_LROUND(SDNode
*N
) {
1020 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1022 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
1023 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1024 TargetLowering::MakeLibCallOptions CallOptions
;
1025 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
1026 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
1027 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1032 RTLIB::LROUND_PPCF128
),
1033 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
1036 SDValue
DAGTypeLegalizer::SoftenFloatOp_LLROUND(SDNode
*N
) {
1037 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1039 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
1040 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1041 TargetLowering::MakeLibCallOptions CallOptions
;
1042 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
1043 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
1044 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1048 RTLIB::LLROUND_F128
,
1049 RTLIB::LLROUND_PPCF128
),
1050 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
1053 SDValue
DAGTypeLegalizer::SoftenFloatOp_LRINT(SDNode
*N
) {
1054 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1056 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
1057 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1058 TargetLowering::MakeLibCallOptions CallOptions
;
1059 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
1060 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
1061 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1066 RTLIB::LRINT_PPCF128
),
1067 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
1070 SDValue
DAGTypeLegalizer::SoftenFloatOp_LLRINT(SDNode
*N
) {
1071 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1073 SDValue Op
= GetSoftenedFloat(N
->getOperand(0));
1074 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1075 TargetLowering::MakeLibCallOptions CallOptions
;
1076 EVT OpsVT
[1] = { N
->getOperand(0).getValueType() };
1077 CallOptions
.setTypeListBeforeSoften(OpsVT
, N
->getValueType(0), true);
1078 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1083 RTLIB::LLRINT_PPCF128
),
1084 NVT
, Op
, CallOptions
, SDLoc(N
)).first
;
1087 //===----------------------------------------------------------------------===//
1088 // Float Result Expansion
1089 //===----------------------------------------------------------------------===//
1091 /// ExpandFloatResult - This method is called when the specified result of the
1092 /// specified node is found to need expansion. At this point, the node may also
1093 /// have invalid operands or may have other results that need promotion, we just
1094 /// know that (at least) one result needs expansion.
1095 void DAGTypeLegalizer::ExpandFloatResult(SDNode
*N
, unsigned ResNo
) {
1096 LLVM_DEBUG(dbgs() << "Expand float result: "; N
->dump(&DAG
); dbgs() << "\n");
1098 Lo
= Hi
= SDValue();
1100 // See if the target wants to custom expand this node.
1101 if (CustomLowerNode(N
, N
->getValueType(ResNo
), true))
1104 switch (N
->getOpcode()) {
1107 dbgs() << "ExpandFloatResult #" << ResNo
<< ": ";
1108 N
->dump(&DAG
); dbgs() << "\n";
1110 llvm_unreachable("Do not know how to expand the result of this operator!");
1112 case ISD::UNDEF
: SplitRes_UNDEF(N
, Lo
, Hi
); break;
1113 case ISD::SELECT
: SplitRes_SELECT(N
, Lo
, Hi
); break;
1114 case ISD::SELECT_CC
: SplitRes_SELECT_CC(N
, Lo
, Hi
); break;
1116 case ISD::MERGE_VALUES
: ExpandRes_MERGE_VALUES(N
, ResNo
, Lo
, Hi
); break;
1117 case ISD::BITCAST
: ExpandRes_BITCAST(N
, Lo
, Hi
); break;
1118 case ISD::BUILD_PAIR
: ExpandRes_BUILD_PAIR(N
, Lo
, Hi
); break;
1119 case ISD::EXTRACT_ELEMENT
: ExpandRes_EXTRACT_ELEMENT(N
, Lo
, Hi
); break;
1120 case ISD::EXTRACT_VECTOR_ELT
: ExpandRes_EXTRACT_VECTOR_ELT(N
, Lo
, Hi
); break;
1121 case ISD::VAARG
: ExpandRes_VAARG(N
, Lo
, Hi
); break;
1123 case ISD::ConstantFP
: ExpandFloatRes_ConstantFP(N
, Lo
, Hi
); break;
1124 case ISD::FABS
: ExpandFloatRes_FABS(N
, Lo
, Hi
); break;
1125 case ISD::FMINNUM
: ExpandFloatRes_FMINNUM(N
, Lo
, Hi
); break;
1126 case ISD::FMAXNUM
: ExpandFloatRes_FMAXNUM(N
, Lo
, Hi
); break;
1127 case ISD::FADD
: ExpandFloatRes_FADD(N
, Lo
, Hi
); break;
1128 case ISD::FCEIL
: ExpandFloatRes_FCEIL(N
, Lo
, Hi
); break;
1129 case ISD::FCOPYSIGN
: ExpandFloatRes_FCOPYSIGN(N
, Lo
, Hi
); break;
1130 case ISD::FCOS
: ExpandFloatRes_FCOS(N
, Lo
, Hi
); break;
1131 case ISD::FDIV
: ExpandFloatRes_FDIV(N
, Lo
, Hi
); break;
1132 case ISD::FEXP
: ExpandFloatRes_FEXP(N
, Lo
, Hi
); break;
1133 case ISD::FEXP2
: ExpandFloatRes_FEXP2(N
, Lo
, Hi
); break;
1134 case ISD::FFLOOR
: ExpandFloatRes_FFLOOR(N
, Lo
, Hi
); break;
1135 case ISD::FLOG
: ExpandFloatRes_FLOG(N
, Lo
, Hi
); break;
1136 case ISD::FLOG2
: ExpandFloatRes_FLOG2(N
, Lo
, Hi
); break;
1137 case ISD::FLOG10
: ExpandFloatRes_FLOG10(N
, Lo
, Hi
); break;
1138 case ISD::FMA
: ExpandFloatRes_FMA(N
, Lo
, Hi
); break;
1139 case ISD::FMUL
: ExpandFloatRes_FMUL(N
, Lo
, Hi
); break;
1140 case ISD::FNEARBYINT
: ExpandFloatRes_FNEARBYINT(N
, Lo
, Hi
); break;
1141 case ISD::FNEG
: ExpandFloatRes_FNEG(N
, Lo
, Hi
); break;
1142 case ISD::FP_EXTEND
: ExpandFloatRes_FP_EXTEND(N
, Lo
, Hi
); break;
1143 case ISD::FPOW
: ExpandFloatRes_FPOW(N
, Lo
, Hi
); break;
1144 case ISD::FPOWI
: ExpandFloatRes_FPOWI(N
, Lo
, Hi
); break;
1145 case ISD::FRINT
: ExpandFloatRes_FRINT(N
, Lo
, Hi
); break;
1146 case ISD::FROUND
: ExpandFloatRes_FROUND(N
, Lo
, Hi
); break;
1147 case ISD::FSIN
: ExpandFloatRes_FSIN(N
, Lo
, Hi
); break;
1148 case ISD::FSQRT
: ExpandFloatRes_FSQRT(N
, Lo
, Hi
); break;
1149 case ISD::FSUB
: ExpandFloatRes_FSUB(N
, Lo
, Hi
); break;
1150 case ISD::FTRUNC
: ExpandFloatRes_FTRUNC(N
, Lo
, Hi
); break;
1151 case ISD::LOAD
: ExpandFloatRes_LOAD(N
, Lo
, Hi
); break;
1152 case ISD::SINT_TO_FP
:
1153 case ISD::UINT_TO_FP
: ExpandFloatRes_XINT_TO_FP(N
, Lo
, Hi
); break;
1154 case ISD::FREM
: ExpandFloatRes_FREM(N
, Lo
, Hi
); break;
1157 // If Lo/Hi is null, the sub-method took care of registering results etc.
1159 SetExpandedFloat(SDValue(N
, ResNo
), Lo
, Hi
);
1162 void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode
*N
, SDValue
&Lo
,
1164 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1165 assert(NVT
.getSizeInBits() == 64 &&
1166 "Do not know how to expand this float constant!");
1167 APInt C
= cast
<ConstantFPSDNode
>(N
)->getValueAPF().bitcastToAPInt();
1169 Lo
= DAG
.getConstantFP(APFloat(DAG
.EVTToAPFloatSemantics(NVT
),
1170 APInt(64, C
.getRawData()[1])),
1172 Hi
= DAG
.getConstantFP(APFloat(DAG
.EVTToAPFloatSemantics(NVT
),
1173 APInt(64, C
.getRawData()[0])),
1177 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode
*N
, SDValue
&Lo
,
1179 assert(N
->getValueType(0) == MVT::ppcf128
&&
1180 "Logic only correct for ppcf128!");
1183 GetExpandedFloat(N
->getOperand(0), Lo
, Tmp
);
1184 Hi
= DAG
.getNode(ISD::FABS
, dl
, Tmp
.getValueType(), Tmp
);
1185 // Lo = Hi==fabs(Hi) ? Lo : -Lo;
1186 Lo
= DAG
.getSelectCC(dl
, Tmp
, Hi
, Lo
,
1187 DAG
.getNode(ISD::FNEG
, dl
, Lo
.getValueType(), Lo
),
1191 void DAGTypeLegalizer::ExpandFloatRes_FMINNUM(SDNode
*N
, SDValue
&Lo
,
1193 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1194 RTLIB::FMIN_F32
, RTLIB::FMIN_F64
,
1195 RTLIB::FMIN_F80
, RTLIB::FMIN_F128
,
1196 RTLIB::FMIN_PPCF128
),
1198 GetPairElements(Call
, Lo
, Hi
);
1201 void DAGTypeLegalizer::ExpandFloatRes_FMAXNUM(SDNode
*N
, SDValue
&Lo
,
1203 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1204 RTLIB::FMAX_F32
, RTLIB::FMAX_F64
,
1205 RTLIB::FMAX_F80
, RTLIB::FMAX_F128
,
1206 RTLIB::FMAX_PPCF128
),
1208 GetPairElements(Call
, Lo
, Hi
);
1211 void DAGTypeLegalizer::ExpandFloatRes_FADD(SDNode
*N
, SDValue
&Lo
,
1213 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1214 RTLIB::ADD_F32
, RTLIB::ADD_F64
,
1215 RTLIB::ADD_F80
, RTLIB::ADD_F128
,
1216 RTLIB::ADD_PPCF128
),
1218 GetPairElements(Call
, Lo
, Hi
);
1221 void DAGTypeLegalizer::ExpandFloatRes_FCEIL(SDNode
*N
,
1222 SDValue
&Lo
, SDValue
&Hi
) {
1223 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1224 RTLIB::CEIL_F32
, RTLIB::CEIL_F64
,
1225 RTLIB::CEIL_F80
, RTLIB::CEIL_F128
,
1226 RTLIB::CEIL_PPCF128
),
1228 GetPairElements(Call
, Lo
, Hi
);
1231 void DAGTypeLegalizer::ExpandFloatRes_FCOPYSIGN(SDNode
*N
,
1232 SDValue
&Lo
, SDValue
&Hi
) {
1233 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1234 RTLIB::COPYSIGN_F32
,
1235 RTLIB::COPYSIGN_F64
,
1236 RTLIB::COPYSIGN_F80
,
1237 RTLIB::COPYSIGN_F128
,
1238 RTLIB::COPYSIGN_PPCF128
),
1240 GetPairElements(Call
, Lo
, Hi
);
1243 void DAGTypeLegalizer::ExpandFloatRes_FCOS(SDNode
*N
,
1244 SDValue
&Lo
, SDValue
&Hi
) {
1245 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1246 RTLIB::COS_F32
, RTLIB::COS_F64
,
1247 RTLIB::COS_F80
, RTLIB::COS_F128
,
1248 RTLIB::COS_PPCF128
),
1250 GetPairElements(Call
, Lo
, Hi
);
1253 void DAGTypeLegalizer::ExpandFloatRes_FDIV(SDNode
*N
, SDValue
&Lo
,
1255 SDValue Ops
[2] = { N
->getOperand(0), N
->getOperand(1) };
1256 TargetLowering::MakeLibCallOptions CallOptions
;
1257 SDValue Call
= TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
1262 RTLIB::DIV_PPCF128
),
1263 N
->getValueType(0), Ops
, CallOptions
,
1265 GetPairElements(Call
, Lo
, Hi
);
1268 void DAGTypeLegalizer::ExpandFloatRes_FEXP(SDNode
*N
,
1269 SDValue
&Lo
, SDValue
&Hi
) {
1270 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1271 RTLIB::EXP_F32
, RTLIB::EXP_F64
,
1272 RTLIB::EXP_F80
, RTLIB::EXP_F128
,
1273 RTLIB::EXP_PPCF128
),
1275 GetPairElements(Call
, Lo
, Hi
);
1278 void DAGTypeLegalizer::ExpandFloatRes_FEXP2(SDNode
*N
,
1279 SDValue
&Lo
, SDValue
&Hi
) {
1280 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1281 RTLIB::EXP2_F32
, RTLIB::EXP2_F64
,
1282 RTLIB::EXP2_F80
, RTLIB::EXP2_F128
,
1283 RTLIB::EXP2_PPCF128
),
1285 GetPairElements(Call
, Lo
, Hi
);
1288 void DAGTypeLegalizer::ExpandFloatRes_FFLOOR(SDNode
*N
,
1289 SDValue
&Lo
, SDValue
&Hi
) {
1290 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1291 RTLIB::FLOOR_F32
, RTLIB::FLOOR_F64
,
1292 RTLIB::FLOOR_F80
, RTLIB::FLOOR_F128
,
1293 RTLIB::FLOOR_PPCF128
),
1295 GetPairElements(Call
, Lo
, Hi
);
1298 void DAGTypeLegalizer::ExpandFloatRes_FLOG(SDNode
*N
,
1299 SDValue
&Lo
, SDValue
&Hi
) {
1300 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1301 RTLIB::LOG_F32
, RTLIB::LOG_F64
,
1302 RTLIB::LOG_F80
, RTLIB::LOG_F128
,
1303 RTLIB::LOG_PPCF128
),
1305 GetPairElements(Call
, Lo
, Hi
);
1308 void DAGTypeLegalizer::ExpandFloatRes_FLOG2(SDNode
*N
,
1309 SDValue
&Lo
, SDValue
&Hi
) {
1310 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1311 RTLIB::LOG2_F32
, RTLIB::LOG2_F64
,
1312 RTLIB::LOG2_F80
, RTLIB::LOG2_F128
,
1313 RTLIB::LOG2_PPCF128
),
1315 GetPairElements(Call
, Lo
, Hi
);
1318 void DAGTypeLegalizer::ExpandFloatRes_FLOG10(SDNode
*N
,
1319 SDValue
&Lo
, SDValue
&Hi
) {
1320 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1321 RTLIB::LOG10_F32
, RTLIB::LOG10_F64
,
1322 RTLIB::LOG10_F80
, RTLIB::LOG10_F128
,
1323 RTLIB::LOG10_PPCF128
),
1325 GetPairElements(Call
, Lo
, Hi
);
1328 void DAGTypeLegalizer::ExpandFloatRes_FMA(SDNode
*N
, SDValue
&Lo
,
1330 SDValue Ops
[3] = { N
->getOperand(0), N
->getOperand(1), N
->getOperand(2) };
1331 TargetLowering::MakeLibCallOptions CallOptions
;
1332 SDValue Call
= TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
1337 RTLIB::FMA_PPCF128
),
1338 N
->getValueType(0), Ops
, CallOptions
,
1340 GetPairElements(Call
, Lo
, Hi
);
1343 void DAGTypeLegalizer::ExpandFloatRes_FMUL(SDNode
*N
, SDValue
&Lo
,
1345 SDValue Ops
[2] = { N
->getOperand(0), N
->getOperand(1) };
1346 TargetLowering::MakeLibCallOptions CallOptions
;
1347 SDValue Call
= TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
1352 RTLIB::MUL_PPCF128
),
1353 N
->getValueType(0), Ops
, CallOptions
,
1355 GetPairElements(Call
, Lo
, Hi
);
1358 void DAGTypeLegalizer::ExpandFloatRes_FNEARBYINT(SDNode
*N
,
1359 SDValue
&Lo
, SDValue
&Hi
) {
1360 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1361 RTLIB::NEARBYINT_F32
,
1362 RTLIB::NEARBYINT_F64
,
1363 RTLIB::NEARBYINT_F80
,
1364 RTLIB::NEARBYINT_F128
,
1365 RTLIB::NEARBYINT_PPCF128
),
1367 GetPairElements(Call
, Lo
, Hi
);
1370 void DAGTypeLegalizer::ExpandFloatRes_FNEG(SDNode
*N
, SDValue
&Lo
,
1373 GetExpandedFloat(N
->getOperand(0), Lo
, Hi
);
1374 Lo
= DAG
.getNode(ISD::FNEG
, dl
, Lo
.getValueType(), Lo
);
1375 Hi
= DAG
.getNode(ISD::FNEG
, dl
, Hi
.getValueType(), Hi
);
1378 void DAGTypeLegalizer::ExpandFloatRes_FP_EXTEND(SDNode
*N
, SDValue
&Lo
,
1380 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
1382 Hi
= DAG
.getNode(ISD::FP_EXTEND
, dl
, NVT
, N
->getOperand(0));
1383 Lo
= DAG
.getConstantFP(APFloat(DAG
.EVTToAPFloatSemantics(NVT
),
1384 APInt(NVT
.getSizeInBits(), 0)), dl
, NVT
);
1387 void DAGTypeLegalizer::ExpandFloatRes_FPOW(SDNode
*N
,
1388 SDValue
&Lo
, SDValue
&Hi
) {
1389 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1390 RTLIB::POW_F32
, RTLIB::POW_F64
,
1391 RTLIB::POW_F80
, RTLIB::POW_F128
,
1392 RTLIB::POW_PPCF128
),
1394 GetPairElements(Call
, Lo
, Hi
);
1397 void DAGTypeLegalizer::ExpandFloatRes_FPOWI(SDNode
*N
,
1398 SDValue
&Lo
, SDValue
&Hi
) {
1399 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1400 RTLIB::POWI_F32
, RTLIB::POWI_F64
,
1401 RTLIB::POWI_F80
, RTLIB::POWI_F128
,
1402 RTLIB::POWI_PPCF128
),
1404 GetPairElements(Call
, Lo
, Hi
);
1407 void DAGTypeLegalizer::ExpandFloatRes_FREM(SDNode
*N
,
1408 SDValue
&Lo
, SDValue
&Hi
) {
1409 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1410 RTLIB::REM_F32
, RTLIB::REM_F64
,
1411 RTLIB::REM_F80
, RTLIB::REM_F128
,
1412 RTLIB::REM_PPCF128
),
1414 GetPairElements(Call
, Lo
, Hi
);
1417 void DAGTypeLegalizer::ExpandFloatRes_FRINT(SDNode
*N
,
1418 SDValue
&Lo
, SDValue
&Hi
) {
1419 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1420 RTLIB::RINT_F32
, RTLIB::RINT_F64
,
1421 RTLIB::RINT_F80
, RTLIB::RINT_F128
,
1422 RTLIB::RINT_PPCF128
),
1424 GetPairElements(Call
, Lo
, Hi
);
1427 void DAGTypeLegalizer::ExpandFloatRes_FROUND(SDNode
*N
,
1428 SDValue
&Lo
, SDValue
&Hi
) {
1429 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1434 RTLIB::ROUND_PPCF128
),
1436 GetPairElements(Call
, Lo
, Hi
);
1439 void DAGTypeLegalizer::ExpandFloatRes_FSIN(SDNode
*N
,
1440 SDValue
&Lo
, SDValue
&Hi
) {
1441 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1442 RTLIB::SIN_F32
, RTLIB::SIN_F64
,
1443 RTLIB::SIN_F80
, RTLIB::SIN_F128
,
1444 RTLIB::SIN_PPCF128
),
1446 GetPairElements(Call
, Lo
, Hi
);
1449 void DAGTypeLegalizer::ExpandFloatRes_FSQRT(SDNode
*N
,
1450 SDValue
&Lo
, SDValue
&Hi
) {
1451 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1452 RTLIB::SQRT_F32
, RTLIB::SQRT_F64
,
1453 RTLIB::SQRT_F80
, RTLIB::SQRT_F128
,
1454 RTLIB::SQRT_PPCF128
),
1456 GetPairElements(Call
, Lo
, Hi
);
1459 void DAGTypeLegalizer::ExpandFloatRes_FSUB(SDNode
*N
, SDValue
&Lo
,
1461 SDValue Ops
[2] = { N
->getOperand(0), N
->getOperand(1) };
1462 TargetLowering::MakeLibCallOptions CallOptions
;
1463 SDValue Call
= TLI
.makeLibCall(DAG
, GetFPLibCall(N
->getValueType(0),
1468 RTLIB::SUB_PPCF128
),
1469 N
->getValueType(0), Ops
, CallOptions
,
1471 GetPairElements(Call
, Lo
, Hi
);
1474 void DAGTypeLegalizer::ExpandFloatRes_FTRUNC(SDNode
*N
,
1475 SDValue
&Lo
, SDValue
&Hi
) {
1476 SDValue Call
= LibCallify(GetFPLibCall(N
->getValueType(0),
1477 RTLIB::TRUNC_F32
, RTLIB::TRUNC_F64
,
1478 RTLIB::TRUNC_F80
, RTLIB::TRUNC_F128
,
1479 RTLIB::TRUNC_PPCF128
),
1481 GetPairElements(Call
, Lo
, Hi
);
1484 void DAGTypeLegalizer::ExpandFloatRes_LOAD(SDNode
*N
, SDValue
&Lo
,
1486 if (ISD::isNormalLoad(N
)) {
1487 ExpandRes_NormalLoad(N
, Lo
, Hi
);
1491 assert(ISD::isUNINDEXEDLoad(N
) && "Indexed load during type legalization!");
1492 LoadSDNode
*LD
= cast
<LoadSDNode
>(N
);
1493 SDValue Chain
= LD
->getChain();
1494 SDValue Ptr
= LD
->getBasePtr();
1497 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), LD
->getValueType(0));
1498 assert(NVT
.isByteSized() && "Expanded type not byte sized!");
1499 assert(LD
->getMemoryVT().bitsLE(NVT
) && "Float type not round?");
1501 Hi
= DAG
.getExtLoad(LD
->getExtensionType(), dl
, NVT
, Chain
, Ptr
,
1502 LD
->getMemoryVT(), LD
->getMemOperand());
1504 // Remember the chain.
1505 Chain
= Hi
.getValue(1);
1507 // The low part is zero.
1508 Lo
= DAG
.getConstantFP(APFloat(DAG
.EVTToAPFloatSemantics(NVT
),
1509 APInt(NVT
.getSizeInBits(), 0)), dl
, NVT
);
1511 // Modified the chain - switch anything that used the old chain to use the
1513 ReplaceValueWith(SDValue(LD
, 1), Chain
);
1516 void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode
*N
, SDValue
&Lo
,
1518 assert(N
->getValueType(0) == MVT::ppcf128
&& "Unsupported XINT_TO_FP!");
1519 EVT VT
= N
->getValueType(0);
1520 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
1521 SDValue Src
= N
->getOperand(0);
1522 EVT SrcVT
= Src
.getValueType();
1523 bool isSigned
= N
->getOpcode() == ISD::SINT_TO_FP
;
1526 // First do an SINT_TO_FP, whether the original was signed or unsigned.
1527 // When promoting partial word types to i32 we must honor the signedness,
1529 if (SrcVT
.bitsLE(MVT::i32
)) {
1530 // The integer can be represented exactly in an f64.
1531 Src
= DAG
.getNode(isSigned
? ISD::SIGN_EXTEND
: ISD::ZERO_EXTEND
, dl
,
1533 Lo
= DAG
.getConstantFP(APFloat(DAG
.EVTToAPFloatSemantics(NVT
),
1534 APInt(NVT
.getSizeInBits(), 0)), dl
, NVT
);
1535 Hi
= DAG
.getNode(ISD::SINT_TO_FP
, dl
, NVT
, Src
);
1537 RTLIB::Libcall LC
= RTLIB::UNKNOWN_LIBCALL
;
1538 if (SrcVT
.bitsLE(MVT::i64
)) {
1539 Src
= DAG
.getNode(isSigned
? ISD::SIGN_EXTEND
: ISD::ZERO_EXTEND
, dl
,
1541 LC
= RTLIB::SINTTOFP_I64_PPCF128
;
1542 } else if (SrcVT
.bitsLE(MVT::i128
)) {
1543 Src
= DAG
.getNode(ISD::SIGN_EXTEND
, dl
, MVT::i128
, Src
);
1544 LC
= RTLIB::SINTTOFP_I128_PPCF128
;
1546 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported XINT_TO_FP!");
1548 TargetLowering::MakeLibCallOptions CallOptions
;
1549 CallOptions
.setSExt(true);
1550 Hi
= TLI
.makeLibCall(DAG
, LC
, VT
, Src
, CallOptions
, dl
).first
;
1551 GetPairElements(Hi
, Lo
, Hi
);
1557 // Unsigned - fix up the SINT_TO_FP value just calculated.
1558 Hi
= DAG
.getNode(ISD::BUILD_PAIR
, dl
, VT
, Lo
, Hi
);
1559 SrcVT
= Src
.getValueType();
1561 // x>=0 ? (ppcf128)(iN)x : (ppcf128)(iN)x + 2^N; N=32,64,128.
1562 static const uint64_t TwoE32
[] = { 0x41f0000000000000LL
, 0 };
1563 static const uint64_t TwoE64
[] = { 0x43f0000000000000LL
, 0 };
1564 static const uint64_t TwoE128
[] = { 0x47f0000000000000LL
, 0 };
1565 ArrayRef
<uint64_t> Parts
;
1567 switch (SrcVT
.getSimpleVT().SimpleTy
) {
1569 llvm_unreachable("Unsupported UINT_TO_FP!");
1581 // TODO: Are there fast-math-flags to propagate to this FADD?
1582 Lo
= DAG
.getNode(ISD::FADD
, dl
, VT
, Hi
,
1583 DAG
.getConstantFP(APFloat(APFloat::PPCDoubleDouble(),
1586 Lo
= DAG
.getSelectCC(dl
, Src
, DAG
.getConstant(0, dl
, SrcVT
),
1587 Lo
, Hi
, ISD::SETLT
);
1588 GetPairElements(Lo
, Lo
, Hi
);
1592 //===----------------------------------------------------------------------===//
1593 // Float Operand Expansion
1594 //===----------------------------------------------------------------------===//
1596 /// ExpandFloatOperand - This method is called when the specified operand of the
1597 /// specified node is found to need expansion. At this point, all of the result
1598 /// types of the node are known to be legal, but other operands of the node may
1599 /// need promotion or expansion as well as the specified one.
1600 bool DAGTypeLegalizer::ExpandFloatOperand(SDNode
*N
, unsigned OpNo
) {
1601 LLVM_DEBUG(dbgs() << "Expand float operand: "; N
->dump(&DAG
); dbgs() << "\n");
1602 SDValue Res
= SDValue();
1604 // See if the target wants to custom expand this node.
1605 if (CustomLowerNode(N
, N
->getOperand(OpNo
).getValueType(), false))
1608 switch (N
->getOpcode()) {
1611 dbgs() << "ExpandFloatOperand Op #" << OpNo
<< ": ";
1612 N
->dump(&DAG
); dbgs() << "\n";
1614 llvm_unreachable("Do not know how to expand this operator's operand!");
1616 case ISD::BITCAST
: Res
= ExpandOp_BITCAST(N
); break;
1617 case ISD::BUILD_VECTOR
: Res
= ExpandOp_BUILD_VECTOR(N
); break;
1618 case ISD::EXTRACT_ELEMENT
: Res
= ExpandOp_EXTRACT_ELEMENT(N
); break;
1620 case ISD::BR_CC
: Res
= ExpandFloatOp_BR_CC(N
); break;
1621 case ISD::FCOPYSIGN
: Res
= ExpandFloatOp_FCOPYSIGN(N
); break;
1622 case ISD::FP_ROUND
: Res
= ExpandFloatOp_FP_ROUND(N
); break;
1623 case ISD::FP_TO_SINT
: Res
= ExpandFloatOp_FP_TO_SINT(N
); break;
1624 case ISD::FP_TO_UINT
: Res
= ExpandFloatOp_FP_TO_UINT(N
); break;
1625 case ISD::LROUND
: Res
= ExpandFloatOp_LROUND(N
); break;
1626 case ISD::LLROUND
: Res
= ExpandFloatOp_LLROUND(N
); break;
1627 case ISD::LRINT
: Res
= ExpandFloatOp_LRINT(N
); break;
1628 case ISD::LLRINT
: Res
= ExpandFloatOp_LLRINT(N
); break;
1629 case ISD::SELECT_CC
: Res
= ExpandFloatOp_SELECT_CC(N
); break;
1630 case ISD::SETCC
: Res
= ExpandFloatOp_SETCC(N
); break;
1631 case ISD::STORE
: Res
= ExpandFloatOp_STORE(cast
<StoreSDNode
>(N
),
1635 // If the result is null, the sub-method took care of registering results etc.
1636 if (!Res
.getNode()) return false;
1638 // If the result is N, the sub-method updated N in place. Tell the legalizer
1640 if (Res
.getNode() == N
)
1643 assert(Res
.getValueType() == N
->getValueType(0) && N
->getNumValues() == 1 &&
1644 "Invalid operand expansion");
1646 ReplaceValueWith(SDValue(N
, 0), Res
);
1650 /// FloatExpandSetCCOperands - Expand the operands of a comparison. This code
1651 /// is shared among BR_CC, SELECT_CC, and SETCC handlers.
1652 void DAGTypeLegalizer::FloatExpandSetCCOperands(SDValue
&NewLHS
,
1654 ISD::CondCode
&CCCode
,
1656 SDValue LHSLo
, LHSHi
, RHSLo
, RHSHi
;
1657 GetExpandedFloat(NewLHS
, LHSLo
, LHSHi
);
1658 GetExpandedFloat(NewRHS
, RHSLo
, RHSHi
);
1660 assert(NewLHS
.getValueType() == MVT::ppcf128
&& "Unsupported setcc type!");
1662 // FIXME: This generated code sucks. We want to generate
1663 // FCMPU crN, hi1, hi2
1665 // FCMPU crN, lo1, lo2
1666 // The following can be improved, but not that much.
1667 SDValue Tmp1
, Tmp2
, Tmp3
;
1668 Tmp1
= DAG
.getSetCC(dl
, getSetCCResultType(LHSHi
.getValueType()),
1669 LHSHi
, RHSHi
, ISD::SETOEQ
);
1670 Tmp2
= DAG
.getSetCC(dl
, getSetCCResultType(LHSLo
.getValueType()),
1671 LHSLo
, RHSLo
, CCCode
);
1672 Tmp3
= DAG
.getNode(ISD::AND
, dl
, Tmp1
.getValueType(), Tmp1
, Tmp2
);
1673 Tmp1
= DAG
.getSetCC(dl
, getSetCCResultType(LHSHi
.getValueType()),
1674 LHSHi
, RHSHi
, ISD::SETUNE
);
1675 Tmp2
= DAG
.getSetCC(dl
, getSetCCResultType(LHSHi
.getValueType()),
1676 LHSHi
, RHSHi
, CCCode
);
1677 Tmp1
= DAG
.getNode(ISD::AND
, dl
, Tmp1
.getValueType(), Tmp1
, Tmp2
);
1678 NewLHS
= DAG
.getNode(ISD::OR
, dl
, Tmp1
.getValueType(), Tmp1
, Tmp3
);
1679 NewRHS
= SDValue(); // LHS is the result, not a compare.
1682 SDValue
DAGTypeLegalizer::ExpandFloatOp_BR_CC(SDNode
*N
) {
1683 SDValue NewLHS
= N
->getOperand(2), NewRHS
= N
->getOperand(3);
1684 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(1))->get();
1685 FloatExpandSetCCOperands(NewLHS
, NewRHS
, CCCode
, SDLoc(N
));
1687 // If ExpandSetCCOperands returned a scalar, we need to compare the result
1688 // against zero to select between true and false values.
1689 if (!NewRHS
.getNode()) {
1690 NewRHS
= DAG
.getConstant(0, SDLoc(N
), NewLHS
.getValueType());
1691 CCCode
= ISD::SETNE
;
1694 // Update N to have the operands specified.
1695 return SDValue(DAG
.UpdateNodeOperands(N
, N
->getOperand(0),
1696 DAG
.getCondCode(CCCode
), NewLHS
, NewRHS
,
1697 N
->getOperand(4)), 0);
1700 SDValue
DAGTypeLegalizer::ExpandFloatOp_FCOPYSIGN(SDNode
*N
) {
1701 assert(N
->getOperand(1).getValueType() == MVT::ppcf128
&&
1702 "Logic only correct for ppcf128!");
1704 GetExpandedFloat(N
->getOperand(1), Lo
, Hi
);
1705 // The ppcf128 value is providing only the sign; take it from the
1706 // higher-order double (which must have the larger magnitude).
1707 return DAG
.getNode(ISD::FCOPYSIGN
, SDLoc(N
),
1708 N
->getValueType(0), N
->getOperand(0), Hi
);
1711 SDValue
DAGTypeLegalizer::ExpandFloatOp_FP_ROUND(SDNode
*N
) {
1712 assert(N
->getOperand(0).getValueType() == MVT::ppcf128
&&
1713 "Logic only correct for ppcf128!");
1715 GetExpandedFloat(N
->getOperand(0), Lo
, Hi
);
1716 // Round it the rest of the way (e.g. to f32) if needed.
1717 return DAG
.getNode(ISD::FP_ROUND
, SDLoc(N
),
1718 N
->getValueType(0), Hi
, N
->getOperand(1));
1721 SDValue
DAGTypeLegalizer::ExpandFloatOp_FP_TO_SINT(SDNode
*N
) {
1722 EVT RVT
= N
->getValueType(0);
1725 RTLIB::Libcall LC
= RTLIB::getFPTOSINT(N
->getOperand(0).getValueType(), RVT
);
1726 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_TO_SINT!");
1727 TargetLowering::MakeLibCallOptions CallOptions
;
1728 return TLI
.makeLibCall(DAG
, LC
, RVT
, N
->getOperand(0), CallOptions
, dl
).first
;
1731 SDValue
DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode
*N
) {
1732 EVT RVT
= N
->getValueType(0);
1735 RTLIB::Libcall LC
= RTLIB::getFPTOUINT(N
->getOperand(0).getValueType(), RVT
);
1736 assert(LC
!= RTLIB::UNKNOWN_LIBCALL
&& "Unsupported FP_TO_UINT!");
1737 TargetLowering::MakeLibCallOptions CallOptions
;
1738 return TLI
.makeLibCall(DAG
, LC
, N
->getValueType(0), N
->getOperand(0),
1739 CallOptions
, dl
).first
;
1742 SDValue
DAGTypeLegalizer::ExpandFloatOp_SELECT_CC(SDNode
*N
) {
1743 SDValue NewLHS
= N
->getOperand(0), NewRHS
= N
->getOperand(1);
1744 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(4))->get();
1745 FloatExpandSetCCOperands(NewLHS
, NewRHS
, CCCode
, SDLoc(N
));
1747 // If ExpandSetCCOperands returned a scalar, we need to compare the result
1748 // against zero to select between true and false values.
1749 if (!NewRHS
.getNode()) {
1750 NewRHS
= DAG
.getConstant(0, SDLoc(N
), NewLHS
.getValueType());
1751 CCCode
= ISD::SETNE
;
1754 // Update N to have the operands specified.
1755 return SDValue(DAG
.UpdateNodeOperands(N
, NewLHS
, NewRHS
,
1756 N
->getOperand(2), N
->getOperand(3),
1757 DAG
.getCondCode(CCCode
)), 0);
1760 SDValue
DAGTypeLegalizer::ExpandFloatOp_SETCC(SDNode
*N
) {
1761 SDValue NewLHS
= N
->getOperand(0), NewRHS
= N
->getOperand(1);
1762 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(2))->get();
1763 FloatExpandSetCCOperands(NewLHS
, NewRHS
, CCCode
, SDLoc(N
));
1765 // If ExpandSetCCOperands returned a scalar, use it.
1766 if (!NewRHS
.getNode()) {
1767 assert(NewLHS
.getValueType() == N
->getValueType(0) &&
1768 "Unexpected setcc expansion!");
1772 // Otherwise, update N to have the operands specified.
1773 return SDValue(DAG
.UpdateNodeOperands(N
, NewLHS
, NewRHS
,
1774 DAG
.getCondCode(CCCode
)), 0);
1777 SDValue
DAGTypeLegalizer::ExpandFloatOp_STORE(SDNode
*N
, unsigned OpNo
) {
1778 if (ISD::isNormalStore(N
))
1779 return ExpandOp_NormalStore(N
, OpNo
);
1781 assert(ISD::isUNINDEXEDStore(N
) && "Indexed store during type legalization!");
1782 assert(OpNo
== 1 && "Can only expand the stored value so far");
1783 StoreSDNode
*ST
= cast
<StoreSDNode
>(N
);
1785 SDValue Chain
= ST
->getChain();
1786 SDValue Ptr
= ST
->getBasePtr();
1788 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(),
1789 ST
->getValue().getValueType());
1790 assert(NVT
.isByteSized() && "Expanded type not byte sized!");
1791 assert(ST
->getMemoryVT().bitsLE(NVT
) && "Float type not round?");
1795 GetExpandedOp(ST
->getValue(), Lo
, Hi
);
1797 return DAG
.getTruncStore(Chain
, SDLoc(N
), Hi
, Ptr
,
1798 ST
->getMemoryVT(), ST
->getMemOperand());
1801 SDValue
DAGTypeLegalizer::ExpandFloatOp_LROUND(SDNode
*N
) {
1802 EVT RVT
= N
->getValueType(0);
1803 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1804 TargetLowering::MakeLibCallOptions CallOptions
;
1805 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1810 RTLIB::LROUND_PPCF128
),
1811 RVT
, N
->getOperand(0), CallOptions
, SDLoc(N
)).first
;
1814 SDValue
DAGTypeLegalizer::ExpandFloatOp_LLROUND(SDNode
*N
) {
1815 EVT RVT
= N
->getValueType(0);
1816 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1817 TargetLowering::MakeLibCallOptions CallOptions
;
1818 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1822 RTLIB::LLROUND_F128
,
1823 RTLIB::LLROUND_PPCF128
),
1824 RVT
, N
->getOperand(0), CallOptions
, SDLoc(N
)).first
;
1827 SDValue
DAGTypeLegalizer::ExpandFloatOp_LRINT(SDNode
*N
) {
1828 EVT RVT
= N
->getValueType(0);
1829 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1830 TargetLowering::MakeLibCallOptions CallOptions
;
1831 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1836 RTLIB::LRINT_PPCF128
),
1837 RVT
, N
->getOperand(0), CallOptions
, SDLoc(N
)).first
;
1840 SDValue
DAGTypeLegalizer::ExpandFloatOp_LLRINT(SDNode
*N
) {
1841 EVT RVT
= N
->getValueType(0);
1842 EVT RetVT
= N
->getOperand(0).getValueType().getSimpleVT().SimpleTy
;
1843 TargetLowering::MakeLibCallOptions CallOptions
;
1844 return TLI
.makeLibCall(DAG
, GetFPLibCall(RetVT
,
1849 RTLIB::LLRINT_PPCF128
),
1850 RVT
, N
->getOperand(0), CallOptions
, SDLoc(N
)).first
;
1853 //===----------------------------------------------------------------------===//
1854 // Float Operand Promotion
1855 //===----------------------------------------------------------------------===//
1858 static ISD::NodeType
GetPromotionOpcode(EVT OpVT
, EVT RetVT
) {
1859 if (OpVT
== MVT::f16
) {
1860 return ISD::FP16_TO_FP
;
1861 } else if (RetVT
== MVT::f16
) {
1862 return ISD::FP_TO_FP16
;
1865 report_fatal_error("Attempt at an invalid promotion-related conversion");
1868 bool DAGTypeLegalizer::PromoteFloatOperand(SDNode
*N
, unsigned OpNo
) {
1869 LLVM_DEBUG(dbgs() << "Promote float operand " << OpNo
<< ": "; N
->dump(&DAG
);
1871 SDValue R
= SDValue();
1873 if (CustomLowerNode(N
, N
->getOperand(OpNo
).getValueType(), false)) {
1874 LLVM_DEBUG(dbgs() << "Node has been custom lowered, done\n");
1878 // Nodes that use a promotion-requiring floating point operand, but doesn't
1879 // produce a promotion-requiring floating point result, need to be legalized
1880 // to use the promoted float operand. Nodes that produce at least one
1881 // promotion-requiring floating point result have their operands legalized as
1882 // a part of PromoteFloatResult.
1883 switch (N
->getOpcode()) {
1886 dbgs() << "PromoteFloatOperand Op #" << OpNo
<< ": ";
1887 N
->dump(&DAG
); dbgs() << "\n";
1889 llvm_unreachable("Do not know how to promote this operator's operand!");
1891 case ISD::BITCAST
: R
= PromoteFloatOp_BITCAST(N
, OpNo
); break;
1892 case ISD::FCOPYSIGN
: R
= PromoteFloatOp_FCOPYSIGN(N
, OpNo
); break;
1893 case ISD::FP_TO_SINT
:
1894 case ISD::FP_TO_UINT
: R
= PromoteFloatOp_FP_TO_XINT(N
, OpNo
); break;
1895 case ISD::FP_EXTEND
: R
= PromoteFloatOp_FP_EXTEND(N
, OpNo
); break;
1896 case ISD::SELECT_CC
: R
= PromoteFloatOp_SELECT_CC(N
, OpNo
); break;
1897 case ISD::SETCC
: R
= PromoteFloatOp_SETCC(N
, OpNo
); break;
1898 case ISD::STORE
: R
= PromoteFloatOp_STORE(N
, OpNo
); break;
1902 ReplaceValueWith(SDValue(N
, 0), R
);
1906 SDValue
DAGTypeLegalizer::PromoteFloatOp_BITCAST(SDNode
*N
, unsigned OpNo
) {
1907 SDValue Op
= N
->getOperand(0);
1908 EVT OpVT
= Op
->getValueType(0);
1910 SDValue Promoted
= GetPromotedFloat(N
->getOperand(0));
1911 EVT PromotedVT
= Promoted
->getValueType(0);
1913 // Convert the promoted float value to the desired IVT.
1914 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(), OpVT
.getSizeInBits());
1915 SDValue Convert
= DAG
.getNode(GetPromotionOpcode(PromotedVT
, OpVT
), SDLoc(N
),
1917 // The final result type might not be an scalar so we need a bitcast. The
1918 // bitcast will be further legalized if needed.
1919 return DAG
.getBitcast(N
->getValueType(0), Convert
);
1922 // Promote Operand 1 of FCOPYSIGN. Operand 0 ought to be handled by
1923 // PromoteFloatRes_FCOPYSIGN.
1924 SDValue
DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode
*N
, unsigned OpNo
) {
1925 assert (OpNo
== 1 && "Only Operand 1 must need promotion here");
1926 SDValue Op1
= GetPromotedFloat(N
->getOperand(1));
1928 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), N
->getValueType(0),
1929 N
->getOperand(0), Op1
);
1932 // Convert the promoted float value to the desired integer type
1933 SDValue
DAGTypeLegalizer::PromoteFloatOp_FP_TO_XINT(SDNode
*N
, unsigned OpNo
) {
1934 SDValue Op
= GetPromotedFloat(N
->getOperand(0));
1935 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), N
->getValueType(0), Op
);
1938 SDValue
DAGTypeLegalizer::PromoteFloatOp_FP_EXTEND(SDNode
*N
, unsigned OpNo
) {
1939 SDValue Op
= GetPromotedFloat(N
->getOperand(0));
1940 EVT VT
= N
->getValueType(0);
1942 // Desired VT is same as promoted type. Use promoted float directly.
1943 if (VT
== Op
->getValueType(0))
1946 // Else, extend the promoted float value to the desired VT.
1947 return DAG
.getNode(ISD::FP_EXTEND
, SDLoc(N
), VT
, Op
);
1950 // Promote the float operands used for comparison. The true- and false-
1951 // operands have the same type as the result and are promoted, if needed, by
1952 // PromoteFloatRes_SELECT_CC
1953 SDValue
DAGTypeLegalizer::PromoteFloatOp_SELECT_CC(SDNode
*N
, unsigned OpNo
) {
1954 SDValue LHS
= GetPromotedFloat(N
->getOperand(0));
1955 SDValue RHS
= GetPromotedFloat(N
->getOperand(1));
1957 return DAG
.getNode(ISD::SELECT_CC
, SDLoc(N
), N
->getValueType(0),
1958 LHS
, RHS
, N
->getOperand(2), N
->getOperand(3),
1962 // Construct a SETCC that compares the promoted values and sets the conditional
1964 SDValue
DAGTypeLegalizer::PromoteFloatOp_SETCC(SDNode
*N
, unsigned OpNo
) {
1965 EVT VT
= N
->getValueType(0);
1966 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
1967 SDValue Op0
= GetPromotedFloat(N
->getOperand(0));
1968 SDValue Op1
= GetPromotedFloat(N
->getOperand(1));
1969 ISD::CondCode CCCode
= cast
<CondCodeSDNode
>(N
->getOperand(2))->get();
1971 return DAG
.getSetCC(SDLoc(N
), NVT
, Op0
, Op1
, CCCode
);
1975 // Lower the promoted Float down to the integer value of same size and construct
1976 // a STORE of the integer value.
1977 SDValue
DAGTypeLegalizer::PromoteFloatOp_STORE(SDNode
*N
, unsigned OpNo
) {
1978 StoreSDNode
*ST
= cast
<StoreSDNode
>(N
);
1979 SDValue Val
= ST
->getValue();
1982 SDValue Promoted
= GetPromotedFloat(Val
);
1983 EVT VT
= ST
->getOperand(1).getValueType();
1984 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(), VT
.getSizeInBits());
1987 NewVal
= DAG
.getNode(GetPromotionOpcode(Promoted
.getValueType(), VT
), DL
,
1990 return DAG
.getStore(ST
->getChain(), DL
, NewVal
, ST
->getBasePtr(),
1991 ST
->getMemOperand());
1994 //===----------------------------------------------------------------------===//
1995 // Float Result Promotion
1996 //===----------------------------------------------------------------------===//
1998 void DAGTypeLegalizer::PromoteFloatResult(SDNode
*N
, unsigned ResNo
) {
1999 LLVM_DEBUG(dbgs() << "Promote float result " << ResNo
<< ": "; N
->dump(&DAG
);
2001 SDValue R
= SDValue();
2003 // See if the target wants to custom expand this node.
2004 if (CustomLowerNode(N
, N
->getValueType(ResNo
), true)) {
2005 LLVM_DEBUG(dbgs() << "Node has been custom expanded, done\n");
2009 switch (N
->getOpcode()) {
2010 // These opcodes cannot appear if promotion of FP16 is done in the backend
2012 case ISD::FP16_TO_FP
:
2013 case ISD::FP_TO_FP16
:
2016 dbgs() << "PromoteFloatResult #" << ResNo
<< ": ";
2017 N
->dump(&DAG
); dbgs() << "\n";
2019 llvm_unreachable("Do not know how to promote this operator's result!");
2021 case ISD::BITCAST
: R
= PromoteFloatRes_BITCAST(N
); break;
2022 case ISD::ConstantFP
: R
= PromoteFloatRes_ConstantFP(N
); break;
2023 case ISD::EXTRACT_VECTOR_ELT
:
2024 R
= PromoteFloatRes_EXTRACT_VECTOR_ELT(N
); break;
2025 case ISD::FCOPYSIGN
: R
= PromoteFloatRes_FCOPYSIGN(N
); break;
2027 // Unary FP Operations
2037 case ISD::FNEARBYINT
:
2044 case ISD::FCANONICALIZE
: R
= PromoteFloatRes_UnaryOp(N
); break;
2046 // Binary FP Operations
2056 case ISD::FSUB
: R
= PromoteFloatRes_BinOp(N
); break;
2058 case ISD::FMA
: // FMA is same as FMAD
2059 case ISD::FMAD
: R
= PromoteFloatRes_FMAD(N
); break;
2061 case ISD::FPOWI
: R
= PromoteFloatRes_FPOWI(N
); break;
2063 case ISD::FP_ROUND
: R
= PromoteFloatRes_FP_ROUND(N
); break;
2064 case ISD::LOAD
: R
= PromoteFloatRes_LOAD(N
); break;
2065 case ISD::SELECT
: R
= PromoteFloatRes_SELECT(N
); break;
2066 case ISD::SELECT_CC
: R
= PromoteFloatRes_SELECT_CC(N
); break;
2068 case ISD::SINT_TO_FP
:
2069 case ISD::UINT_TO_FP
: R
= PromoteFloatRes_XINT_TO_FP(N
); break;
2070 case ISD::UNDEF
: R
= PromoteFloatRes_UNDEF(N
); break;
2071 case ISD::ATOMIC_SWAP
: R
= BitcastToInt_ATOMIC_SWAP(N
); break;
2075 SetPromotedFloat(SDValue(N
, ResNo
), R
);
2078 // Bitcast from i16 to f16: convert the i16 to a f32 value instead.
2079 // At this point, it is not possible to determine if the bitcast value is
2080 // eventually stored to memory or promoted to f32 or promoted to a floating
2081 // point at a higher precision. Some of these cases are handled by FP_EXTEND,
2082 // STORE promotion handlers.
2083 SDValue
DAGTypeLegalizer::PromoteFloatRes_BITCAST(SDNode
*N
) {
2084 EVT VT
= N
->getValueType(0);
2085 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2086 // Input type isn't guaranteed to be a scalar int so bitcast if not. The
2087 // bitcast will be legalized further if necessary.
2088 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(),
2089 N
->getOperand(0).getValueType().getSizeInBits());
2090 SDValue Cast
= DAG
.getBitcast(IVT
, N
->getOperand(0));
2091 return DAG
.getNode(GetPromotionOpcode(VT
, NVT
), SDLoc(N
), NVT
, Cast
);
2094 SDValue
DAGTypeLegalizer::PromoteFloatRes_ConstantFP(SDNode
*N
) {
2095 ConstantFPSDNode
*CFPNode
= cast
<ConstantFPSDNode
>(N
);
2096 EVT VT
= N
->getValueType(0);
2099 // Get the (bit-cast) APInt of the APFloat and build an integer constant
2100 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(), VT
.getSizeInBits());
2101 SDValue C
= DAG
.getConstant(CFPNode
->getValueAPF().bitcastToAPInt(), DL
,
2104 // Convert the Constant to the desired FP type
2105 // FIXME We might be able to do the conversion during compilation and get rid
2106 // of it from the object code
2107 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2108 return DAG
.getNode(GetPromotionOpcode(VT
, NVT
), DL
, NVT
, C
);
2111 // If the Index operand is a constant, try to redirect the extract operation to
2112 // the correct legalized vector. If not, bit-convert the input vector to
2113 // equivalent integer vector. Extract the element as an (bit-cast) integer
2114 // value and convert it to the promoted type.
2115 SDValue
DAGTypeLegalizer::PromoteFloatRes_EXTRACT_VECTOR_ELT(SDNode
*N
) {
2118 // If the index is constant, try to extract the value from the legalized
2120 if (isa
<ConstantSDNode
>(N
->getOperand(1))) {
2121 SDValue Vec
= N
->getOperand(0);
2122 SDValue Idx
= N
->getOperand(1);
2123 EVT VecVT
= Vec
->getValueType(0);
2124 EVT EltVT
= VecVT
.getVectorElementType();
2126 uint64_t IdxVal
= cast
<ConstantSDNode
>(Idx
)->getZExtValue();
2128 switch (getTypeAction(VecVT
)) {
2130 case TargetLowering::TypeScalarizeVector
: {
2131 SDValue Res
= GetScalarizedVector(N
->getOperand(0));
2132 ReplaceValueWith(SDValue(N
, 0), Res
);
2135 case TargetLowering::TypeWidenVector
: {
2136 Vec
= GetWidenedVector(Vec
);
2137 SDValue Res
= DAG
.getNode(N
->getOpcode(), DL
, EltVT
, Vec
, Idx
);
2138 ReplaceValueWith(SDValue(N
, 0), Res
);
2141 case TargetLowering::TypeSplitVector
: {
2143 GetSplitVector(Vec
, Lo
, Hi
);
2145 uint64_t LoElts
= Lo
.getValueType().getVectorNumElements();
2147 if (IdxVal
< LoElts
)
2148 Res
= DAG
.getNode(N
->getOpcode(), DL
, EltVT
, Lo
, Idx
);
2150 Res
= DAG
.getNode(N
->getOpcode(), DL
, EltVT
, Hi
,
2151 DAG
.getConstant(IdxVal
- LoElts
, DL
,
2152 Idx
.getValueType()));
2153 ReplaceValueWith(SDValue(N
, 0), Res
);
2160 // Bit-convert the input vector to the equivalent integer vector
2161 SDValue NewOp
= BitConvertVectorToIntegerVector(N
->getOperand(0));
2162 EVT IVT
= NewOp
.getValueType().getVectorElementType();
2164 // Extract the element as an (bit-cast) integer value
2165 SDValue NewVal
= DAG
.getNode(ISD::EXTRACT_VECTOR_ELT
, DL
, IVT
,
2166 NewOp
, N
->getOperand(1));
2168 // Convert the element to the desired FP type
2169 EVT VT
= N
->getValueType(0);
2170 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2171 return DAG
.getNode(GetPromotionOpcode(VT
, NVT
), SDLoc(N
), NVT
, NewVal
);
2174 // FCOPYSIGN(X, Y) returns the value of X with the sign of Y. If the result
2175 // needs promotion, so does the argument X. Note that Y, if needed, will be
2176 // handled during operand promotion.
2177 SDValue
DAGTypeLegalizer::PromoteFloatRes_FCOPYSIGN(SDNode
*N
) {
2178 EVT VT
= N
->getValueType(0);
2179 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2180 SDValue Op0
= GetPromotedFloat(N
->getOperand(0));
2182 SDValue Op1
= N
->getOperand(1);
2184 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), NVT
, Op0
, Op1
);
2187 // Unary operation where the result and the operand have PromoteFloat type
2188 // action. Construct a new SDNode with the promoted float value of the old
2190 SDValue
DAGTypeLegalizer::PromoteFloatRes_UnaryOp(SDNode
*N
) {
2191 EVT VT
= N
->getValueType(0);
2192 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2193 SDValue Op
= GetPromotedFloat(N
->getOperand(0));
2195 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), NVT
, Op
);
2198 // Binary operations where the result and both operands have PromoteFloat type
2199 // action. Construct a new SDNode with the promoted float values of the old
2201 SDValue
DAGTypeLegalizer::PromoteFloatRes_BinOp(SDNode
*N
) {
2202 EVT VT
= N
->getValueType(0);
2203 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2204 SDValue Op0
= GetPromotedFloat(N
->getOperand(0));
2205 SDValue Op1
= GetPromotedFloat(N
->getOperand(1));
2206 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), NVT
, Op0
, Op1
, N
->getFlags());
2209 SDValue
DAGTypeLegalizer::PromoteFloatRes_FMAD(SDNode
*N
) {
2210 EVT VT
= N
->getValueType(0);
2211 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2212 SDValue Op0
= GetPromotedFloat(N
->getOperand(0));
2213 SDValue Op1
= GetPromotedFloat(N
->getOperand(1));
2214 SDValue Op2
= GetPromotedFloat(N
->getOperand(2));
2216 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), NVT
, Op0
, Op1
, Op2
);
2219 // Promote the Float (first) operand and retain the Integer (second) operand
2220 SDValue
DAGTypeLegalizer::PromoteFloatRes_FPOWI(SDNode
*N
) {
2221 EVT VT
= N
->getValueType(0);
2222 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2223 SDValue Op0
= GetPromotedFloat(N
->getOperand(0));
2224 SDValue Op1
= N
->getOperand(1);
2226 return DAG
.getNode(N
->getOpcode(), SDLoc(N
), NVT
, Op0
, Op1
);
2229 // Explicit operation to reduce precision. Reduce the value to half precision
2230 // and promote it back to the legal type.
2231 SDValue
DAGTypeLegalizer::PromoteFloatRes_FP_ROUND(SDNode
*N
) {
2234 SDValue Op
= N
->getOperand(0);
2235 EVT VT
= N
->getValueType(0);
2236 EVT OpVT
= Op
->getValueType(0);
2237 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), N
->getValueType(0));
2238 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(), VT
.getSizeInBits());
2240 // Round promoted float to desired precision
2241 SDValue Round
= DAG
.getNode(GetPromotionOpcode(OpVT
, VT
), DL
, IVT
, Op
);
2242 // Promote it back to the legal output type
2243 return DAG
.getNode(GetPromotionOpcode(VT
, NVT
), DL
, NVT
, Round
);
2246 SDValue
DAGTypeLegalizer::PromoteFloatRes_LOAD(SDNode
*N
) {
2247 LoadSDNode
*L
= cast
<LoadSDNode
>(N
);
2248 EVT VT
= N
->getValueType(0);
2250 // Load the value as an integer value with the same number of bits.
2251 EVT IVT
= EVT::getIntegerVT(*DAG
.getContext(), VT
.getSizeInBits());
2252 SDValue newL
= DAG
.getLoad(L
->getAddressingMode(), L
->getExtensionType(), IVT
,
2253 SDLoc(N
), L
->getChain(), L
->getBasePtr(),
2254 L
->getOffset(), L
->getPointerInfo(), IVT
,
2256 L
->getMemOperand()->getFlags(),
2258 // Legalize the chain result by replacing uses of the old value chain with the
2260 ReplaceValueWith(SDValue(N
, 1), newL
.getValue(1));
2262 // Convert the integer value to the desired FP type
2263 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2264 return DAG
.getNode(GetPromotionOpcode(VT
, NVT
), SDLoc(N
), NVT
, newL
);
2267 // Construct a new SELECT node with the promoted true- and false- values.
2268 SDValue
DAGTypeLegalizer::PromoteFloatRes_SELECT(SDNode
*N
) {
2269 SDValue TrueVal
= GetPromotedFloat(N
->getOperand(1));
2270 SDValue FalseVal
= GetPromotedFloat(N
->getOperand(2));
2272 return DAG
.getNode(ISD::SELECT
, SDLoc(N
), TrueVal
->getValueType(0),
2273 N
->getOperand(0), TrueVal
, FalseVal
);
2276 // Construct a new SELECT_CC node with the promoted true- and false- values.
2277 // The operands used for comparison are promoted by PromoteFloatOp_SELECT_CC.
2278 SDValue
DAGTypeLegalizer::PromoteFloatRes_SELECT_CC(SDNode
*N
) {
2279 SDValue TrueVal
= GetPromotedFloat(N
->getOperand(2));
2280 SDValue FalseVal
= GetPromotedFloat(N
->getOperand(3));
2282 return DAG
.getNode(ISD::SELECT_CC
, SDLoc(N
),
2283 TrueVal
.getNode()->getValueType(0), N
->getOperand(0),
2284 N
->getOperand(1), TrueVal
, FalseVal
, N
->getOperand(4));
2287 // Construct a SDNode that transforms the SINT or UINT operand to the promoted
2289 SDValue
DAGTypeLegalizer::PromoteFloatRes_XINT_TO_FP(SDNode
*N
) {
2291 EVT VT
= N
->getValueType(0);
2292 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2293 SDValue NV
= DAG
.getNode(N
->getOpcode(), DL
, NVT
, N
->getOperand(0));
2294 // Round the value to the desired precision (that of the source type).
2296 ISD::FP_EXTEND
, DL
, NVT
,
2297 DAG
.getNode(ISD::FP_ROUND
, DL
, VT
, NV
, DAG
.getIntPtrConstant(0, DL
)));
2300 SDValue
DAGTypeLegalizer::PromoteFloatRes_UNDEF(SDNode
*N
) {
2301 return DAG
.getUNDEF(TLI
.getTypeToTransformTo(*DAG
.getContext(),
2302 N
->getValueType(0)));
2305 SDValue
DAGTypeLegalizer::BitcastToInt_ATOMIC_SWAP(SDNode
*N
) {
2306 EVT VT
= N
->getValueType(0);
2307 EVT NFPVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), VT
);
2309 AtomicSDNode
*AM
= cast
<AtomicSDNode
>(N
);
2312 SDValue CastVal
= BitConvertToInteger(AM
->getVal());
2313 EVT CastVT
= CastVal
.getValueType();
2316 = DAG
.getAtomic(ISD::ATOMIC_SWAP
, SL
, CastVT
,
2317 DAG
.getVTList(CastVT
, MVT::Other
),
2318 { AM
->getChain(), AM
->getBasePtr(), CastVal
},
2319 AM
->getMemOperand());
2321 SDValue ResultCast
= DAG
.getNode(GetPromotionOpcode(VT
, NFPVT
), SL
, NFPVT
,
2323 // Legalize the chain result by replacing uses of the old value chain with the
2325 ReplaceValueWith(SDValue(N
, 1), NewAtomic
.getValue(1));