1 //===-------- LegalizeTypesGeneric.cpp - Generic type legalization --------===//
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 generic type expansion and splitting for LegalizeTypes.
10 // The routines here perform legalization when the details of the type (such as
11 // whether it is an integer or a float) do not matter.
12 // Expansion is the act of changing a computation in an illegal type to be a
13 // computation in two identical registers of a smaller type. The Lo/Hi part
14 // is required to be stored first in memory on little/big-endian machines.
15 // Splitting is the act of changing a computation in an illegal type to be a
16 // computation in two not necessarily identical registers of a smaller type.
17 // There are no requirements on how the type is represented in memory.
19 //===----------------------------------------------------------------------===//
21 #include "LegalizeTypes.h"
22 #include "llvm/IR/DataLayout.h"
25 #define DEBUG_TYPE "legalize-types"
27 //===----------------------------------------------------------------------===//
28 // Generic Result Expansion.
29 //===----------------------------------------------------------------------===//
31 // These routines assume that the Lo/Hi part is stored first in memory on
32 // little/big-endian machines, followed by the Hi/Lo part. This means that
33 // they cannot be used as is on vectors, for which Lo is always stored first.
34 void DAGTypeLegalizer::ExpandRes_MERGE_VALUES(SDNode
*N
, unsigned ResNo
,
35 SDValue
&Lo
, SDValue
&Hi
) {
36 SDValue Op
= DisintegrateMERGE_VALUES(N
, ResNo
);
37 GetExpandedOp(Op
, Lo
, Hi
);
40 void DAGTypeLegalizer::ExpandRes_BITCAST(SDNode
*N
, SDValue
&Lo
, SDValue
&Hi
) {
41 EVT OutVT
= N
->getValueType(0);
42 EVT NOutVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), OutVT
);
43 SDValue InOp
= N
->getOperand(0);
44 EVT InVT
= InOp
.getValueType();
47 // Handle some special cases efficiently.
48 switch (getTypeAction(InVT
)) {
49 case TargetLowering::TypeLegal
:
50 case TargetLowering::TypePromoteInteger
:
52 case TargetLowering::TypePromoteFloat
:
53 llvm_unreachable("Bitcast of a promotion-needing float should never need"
55 case TargetLowering::TypeSoftenFloat
:
56 SplitInteger(GetSoftenedFloat(InOp
), Lo
, Hi
);
57 Lo
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Lo
);
58 Hi
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Hi
);
60 case TargetLowering::TypeExpandInteger
:
61 case TargetLowering::TypeExpandFloat
: {
62 auto &DL
= DAG
.getDataLayout();
63 // Convert the expanded pieces of the input.
64 GetExpandedOp(InOp
, Lo
, Hi
);
65 if (TLI
.hasBigEndianPartOrdering(InVT
, DL
) !=
66 TLI
.hasBigEndianPartOrdering(OutVT
, DL
))
68 Lo
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Lo
);
69 Hi
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Hi
);
72 case TargetLowering::TypeSplitVector
:
73 GetSplitVector(InOp
, Lo
, Hi
);
74 if (TLI
.hasBigEndianPartOrdering(OutVT
, DAG
.getDataLayout()))
76 Lo
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Lo
);
77 Hi
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Hi
);
79 case TargetLowering::TypeScalarizeVector
:
80 // Convert the element instead.
81 SplitInteger(BitConvertToInteger(GetScalarizedVector(InOp
)), Lo
, Hi
);
82 Lo
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Lo
);
83 Hi
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Hi
);
85 case TargetLowering::TypeWidenVector
: {
86 assert(!(InVT
.getVectorNumElements() & 1) && "Unsupported BITCAST");
87 InOp
= GetWidenedVector(InOp
);
89 std::tie(LoVT
, HiVT
) = DAG
.GetSplitDestVTs(InVT
);
90 std::tie(Lo
, Hi
) = DAG
.SplitVector(InOp
, dl
, LoVT
, HiVT
);
91 if (TLI
.hasBigEndianPartOrdering(OutVT
, DAG
.getDataLayout()))
93 Lo
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Lo
);
94 Hi
= DAG
.getNode(ISD::BITCAST
, dl
, NOutVT
, Hi
);
99 if (InVT
.isVector() && OutVT
.isInteger()) {
100 // Handle cases like i64 = BITCAST v1i64 on x86, where the operand
101 // is legal but the result is not.
102 unsigned NumElems
= 2;
104 EVT NVT
= EVT::getVectorVT(*DAG
.getContext(), ElemVT
, NumElems
);
106 // If <ElemVT * N> is not a legal type, try <ElemVT/2 * (N*2)>.
107 while (!isTypeLegal(NVT
)) {
108 unsigned NewSizeInBits
= ElemVT
.getSizeInBits() / 2;
109 // If the element size is smaller than byte, bail.
110 if (NewSizeInBits
< 8)
113 ElemVT
= EVT::getIntegerVT(*DAG
.getContext(), NewSizeInBits
);
114 NVT
= EVT::getVectorVT(*DAG
.getContext(), ElemVT
, NumElems
);
117 if (isTypeLegal(NVT
)) {
118 SDValue CastInOp
= DAG
.getNode(ISD::BITCAST
, dl
, NVT
, InOp
);
120 SmallVector
<SDValue
, 8> Vals
;
121 for (unsigned i
= 0; i
< NumElems
; ++i
)
122 Vals
.push_back(DAG
.getNode(
123 ISD::EXTRACT_VECTOR_ELT
, dl
, ElemVT
, CastInOp
,
124 DAG
.getConstant(i
, dl
, TLI
.getVectorIdxTy(DAG
.getDataLayout()))));
126 // Build Lo, Hi pair by pairing extracted elements if needed.
128 for (unsigned e
= Vals
.size(); e
- Slot
> 2; Slot
+= 2, e
+= 1) {
129 // Each iteration will BUILD_PAIR two nodes and append the result until
130 // there are only two nodes left, i.e. Lo and Hi.
131 SDValue LHS
= Vals
[Slot
];
132 SDValue RHS
= Vals
[Slot
+ 1];
134 if (DAG
.getDataLayout().isBigEndian())
137 Vals
.push_back(DAG
.getNode(
139 EVT::getIntegerVT(*DAG
.getContext(), LHS
.getValueSizeInBits() << 1),
145 if (DAG
.getDataLayout().isBigEndian())
152 // Lower the bit-convert to a store/load from the stack.
153 assert(NOutVT
.isByteSized() && "Expanded type not byte sized!");
155 // Create the stack frame object. Make sure it is aligned for both
156 // the source and expanded destination types.
157 unsigned Alignment
= DAG
.getDataLayout().getPrefTypeAlignment(
158 NOutVT
.getTypeForEVT(*DAG
.getContext()));
159 SDValue StackPtr
= DAG
.CreateStackTemporary(InVT
, Alignment
);
160 int SPFI
= cast
<FrameIndexSDNode
>(StackPtr
.getNode())->getIndex();
161 MachinePointerInfo PtrInfo
=
162 MachinePointerInfo::getFixedStack(DAG
.getMachineFunction(), SPFI
);
164 // Emit a store to the stack slot.
165 SDValue Store
= DAG
.getStore(DAG
.getEntryNode(), dl
, InOp
, StackPtr
, PtrInfo
);
167 // Load the first half from the stack slot.
168 Lo
= DAG
.getLoad(NOutVT
, dl
, Store
, StackPtr
, PtrInfo
);
170 // Increment the pointer to the other half.
171 unsigned IncrementSize
= NOutVT
.getSizeInBits() / 8;
172 StackPtr
= DAG
.getNode(ISD::ADD
, dl
, StackPtr
.getValueType(), StackPtr
,
173 DAG
.getConstant(IncrementSize
, dl
,
174 StackPtr
.getValueType()));
176 // Load the second half from the stack slot.
177 Hi
= DAG
.getLoad(NOutVT
, dl
, Store
, StackPtr
,
178 PtrInfo
.getWithOffset(IncrementSize
),
179 MinAlign(Alignment
, IncrementSize
));
181 // Handle endianness of the load.
182 if (TLI
.hasBigEndianPartOrdering(OutVT
, DAG
.getDataLayout()))
186 void DAGTypeLegalizer::ExpandRes_BUILD_PAIR(SDNode
*N
, SDValue
&Lo
,
188 // Return the operands.
189 Lo
= N
->getOperand(0);
190 Hi
= N
->getOperand(1);
193 void DAGTypeLegalizer::ExpandRes_EXTRACT_ELEMENT(SDNode
*N
, SDValue
&Lo
,
195 GetExpandedOp(N
->getOperand(0), Lo
, Hi
);
196 SDValue Part
= cast
<ConstantSDNode
>(N
->getOperand(1))->getZExtValue() ?
199 assert(Part
.getValueType() == N
->getValueType(0) &&
200 "Type twice as big as expanded type not itself expanded!");
202 GetPairElements(Part
, Lo
, Hi
);
205 void DAGTypeLegalizer::ExpandRes_EXTRACT_VECTOR_ELT(SDNode
*N
, SDValue
&Lo
,
207 SDValue OldVec
= N
->getOperand(0);
208 unsigned OldElts
= OldVec
.getValueType().getVectorNumElements();
209 EVT OldEltVT
= OldVec
.getValueType().getVectorElementType();
212 // Convert to a vector of the expanded element type, for example
213 // <3 x i64> -> <6 x i32>.
214 EVT OldVT
= N
->getValueType(0);
215 EVT NewVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), OldVT
);
217 if (OldVT
!= OldEltVT
) {
218 // The result of EXTRACT_VECTOR_ELT may be larger than the element type of
219 // the input vector. If so, extend the elements of the input vector to the
220 // same bitwidth as the result before expanding.
221 assert(OldEltVT
.bitsLT(OldVT
) && "Result type smaller then element type!");
222 EVT NVecVT
= EVT::getVectorVT(*DAG
.getContext(), OldVT
, OldElts
);
223 OldVec
= DAG
.getNode(ISD::ANY_EXTEND
, dl
, NVecVT
, N
->getOperand(0));
226 SDValue NewVec
= DAG
.getNode(ISD::BITCAST
, dl
,
227 EVT::getVectorVT(*DAG
.getContext(),
231 // Extract the elements at 2 * Idx and 2 * Idx + 1 from the new vector.
232 SDValue Idx
= N
->getOperand(1);
234 Idx
= DAG
.getNode(ISD::ADD
, dl
, Idx
.getValueType(), Idx
, Idx
);
235 Lo
= DAG
.getNode(ISD::EXTRACT_VECTOR_ELT
, dl
, NewVT
, NewVec
, Idx
);
237 Idx
= DAG
.getNode(ISD::ADD
, dl
, Idx
.getValueType(), Idx
,
238 DAG
.getConstant(1, dl
, Idx
.getValueType()));
239 Hi
= DAG
.getNode(ISD::EXTRACT_VECTOR_ELT
, dl
, NewVT
, NewVec
, Idx
);
241 if (DAG
.getDataLayout().isBigEndian())
245 void DAGTypeLegalizer::ExpandRes_NormalLoad(SDNode
*N
, SDValue
&Lo
,
247 assert(ISD::isNormalLoad(N
) && "This routine only for normal loads!");
250 LoadSDNode
*LD
= cast
<LoadSDNode
>(N
);
251 EVT ValueVT
= LD
->getValueType(0);
252 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), ValueVT
);
253 SDValue Chain
= LD
->getChain();
254 SDValue Ptr
= LD
->getBasePtr();
255 unsigned Alignment
= LD
->getAlignment();
256 AAMDNodes AAInfo
= LD
->getAAInfo();
258 assert(NVT
.isByteSized() && "Expanded type not byte sized!");
260 Lo
= DAG
.getLoad(NVT
, dl
, Chain
, Ptr
, LD
->getPointerInfo(), Alignment
,
261 LD
->getMemOperand()->getFlags(), AAInfo
);
263 // Increment the pointer to the other half.
264 unsigned IncrementSize
= NVT
.getSizeInBits() / 8;
265 Ptr
= DAG
.getNode(ISD::ADD
, dl
, Ptr
.getValueType(), Ptr
,
266 DAG
.getConstant(IncrementSize
, dl
, Ptr
.getValueType()));
267 Hi
= DAG
.getLoad(NVT
, dl
, Chain
, Ptr
,
268 LD
->getPointerInfo().getWithOffset(IncrementSize
),
269 MinAlign(Alignment
, IncrementSize
),
270 LD
->getMemOperand()->getFlags(), AAInfo
);
272 // Build a factor node to remember that this load is independent of the
274 Chain
= DAG
.getNode(ISD::TokenFactor
, dl
, MVT::Other
, Lo
.getValue(1),
277 // Handle endianness of the load.
278 if (TLI
.hasBigEndianPartOrdering(ValueVT
, DAG
.getDataLayout()))
281 // Modified the chain - switch anything that used the old chain to use
283 ReplaceValueWith(SDValue(N
, 1), Chain
);
286 void DAGTypeLegalizer::ExpandRes_VAARG(SDNode
*N
, SDValue
&Lo
, SDValue
&Hi
) {
287 EVT OVT
= N
->getValueType(0);
288 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), OVT
);
289 SDValue Chain
= N
->getOperand(0);
290 SDValue Ptr
= N
->getOperand(1);
292 const unsigned Align
= N
->getConstantOperandVal(3);
294 Lo
= DAG
.getVAArg(NVT
, dl
, Chain
, Ptr
, N
->getOperand(2), Align
);
295 Hi
= DAG
.getVAArg(NVT
, dl
, Lo
.getValue(1), Ptr
, N
->getOperand(2), 0);
296 Chain
= Hi
.getValue(1);
298 // Handle endianness of the load.
299 if (TLI
.hasBigEndianPartOrdering(OVT
, DAG
.getDataLayout()))
302 // Modified the chain - switch anything that used the old chain to use
304 ReplaceValueWith(SDValue(N
, 1), Chain
);
308 //===--------------------------------------------------------------------===//
309 // Generic Operand Expansion.
310 //===--------------------------------------------------------------------===//
312 void DAGTypeLegalizer::IntegerToVector(SDValue Op
, unsigned NumElements
,
313 SmallVectorImpl
<SDValue
> &Ops
,
315 assert(Op
.getValueType().isInteger());
319 if (NumElements
> 1) {
321 SplitInteger(Op
, Parts
[0], Parts
[1]);
322 if (DAG
.getDataLayout().isBigEndian())
323 std::swap(Parts
[0], Parts
[1]);
324 IntegerToVector(Parts
[0], NumElements
, Ops
, EltVT
);
325 IntegerToVector(Parts
[1], NumElements
, Ops
, EltVT
);
327 Ops
.push_back(DAG
.getNode(ISD::BITCAST
, DL
, EltVT
, Op
));
331 SDValue
DAGTypeLegalizer::ExpandOp_BITCAST(SDNode
*N
) {
333 if (N
->getValueType(0).isVector() &&
334 N
->getOperand(0).getValueType().isInteger()) {
335 // An illegal expanding type is being converted to a legal vector type.
336 // Make a two element vector out of the expanded parts and convert that
337 // instead, but only if the new vector type is legal (otherwise there
338 // is no point, and it might create expansion loops). For example, on
339 // x86 this turns v1i64 = BITCAST i64 into v1i64 = BITCAST v2i32.
341 // FIXME: I'm not sure why we are first trying to split the input into
342 // a 2 element vector, so I'm leaving it here to maintain the current
344 unsigned NumElts
= 2;
345 EVT OVT
= N
->getOperand(0).getValueType();
346 EVT NVT
= EVT::getVectorVT(*DAG
.getContext(),
347 TLI
.getTypeToTransformTo(*DAG
.getContext(), OVT
),
349 if (!isTypeLegal(NVT
)) {
350 // If we can't find a legal type by splitting the integer in half,
351 // then we can use the node's value type.
352 NumElts
= N
->getValueType(0).getVectorNumElements();
353 NVT
= N
->getValueType(0);
356 SmallVector
<SDValue
, 8> Ops
;
357 IntegerToVector(N
->getOperand(0), NumElts
, Ops
, NVT
.getVectorElementType());
360 DAG
.getBuildVector(NVT
, dl
, makeArrayRef(Ops
.data(), NumElts
));
361 return DAG
.getNode(ISD::BITCAST
, dl
, N
->getValueType(0), Vec
);
364 // Otherwise, store to a temporary and load out again as the new type.
365 return CreateStackStoreLoad(N
->getOperand(0), N
->getValueType(0));
368 SDValue
DAGTypeLegalizer::ExpandOp_BUILD_VECTOR(SDNode
*N
) {
369 // The vector type is legal but the element type needs expansion.
370 EVT VecVT
= N
->getValueType(0);
371 unsigned NumElts
= VecVT
.getVectorNumElements();
372 EVT OldVT
= N
->getOperand(0).getValueType();
373 EVT NewVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), OldVT
);
376 assert(OldVT
== VecVT
.getVectorElementType() &&
377 "BUILD_VECTOR operand type doesn't match vector element type!");
379 // Build a vector of twice the length out of the expanded elements.
380 // For example <3 x i64> -> <6 x i32>.
381 SmallVector
<SDValue
, 16> NewElts
;
382 NewElts
.reserve(NumElts
*2);
384 for (unsigned i
= 0; i
< NumElts
; ++i
) {
386 GetExpandedOp(N
->getOperand(i
), Lo
, Hi
);
387 if (DAG
.getDataLayout().isBigEndian())
389 NewElts
.push_back(Lo
);
390 NewElts
.push_back(Hi
);
393 EVT NewVecVT
= EVT::getVectorVT(*DAG
.getContext(), NewVT
, NewElts
.size());
394 SDValue NewVec
= DAG
.getBuildVector(NewVecVT
, dl
, NewElts
);
396 // Convert the new vector to the old vector type.
397 return DAG
.getNode(ISD::BITCAST
, dl
, VecVT
, NewVec
);
400 SDValue
DAGTypeLegalizer::ExpandOp_EXTRACT_ELEMENT(SDNode
*N
) {
402 GetExpandedOp(N
->getOperand(0), Lo
, Hi
);
403 return cast
<ConstantSDNode
>(N
->getOperand(1))->getZExtValue() ? Hi
: Lo
;
406 SDValue
DAGTypeLegalizer::ExpandOp_INSERT_VECTOR_ELT(SDNode
*N
) {
407 // The vector type is legal but the element type needs expansion.
408 EVT VecVT
= N
->getValueType(0);
409 unsigned NumElts
= VecVT
.getVectorNumElements();
412 SDValue Val
= N
->getOperand(1);
413 EVT OldEVT
= Val
.getValueType();
414 EVT NewEVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), OldEVT
);
416 assert(OldEVT
== VecVT
.getVectorElementType() &&
417 "Inserted element type doesn't match vector element type!");
419 // Bitconvert to a vector of twice the length with elements of the expanded
420 // type, insert the expanded vector elements, and then convert back.
421 EVT NewVecVT
= EVT::getVectorVT(*DAG
.getContext(), NewEVT
, NumElts
*2);
422 SDValue NewVec
= DAG
.getNode(ISD::BITCAST
, dl
,
423 NewVecVT
, N
->getOperand(0));
426 GetExpandedOp(Val
, Lo
, Hi
);
427 if (DAG
.getDataLayout().isBigEndian())
430 SDValue Idx
= N
->getOperand(2);
431 Idx
= DAG
.getNode(ISD::ADD
, dl
, Idx
.getValueType(), Idx
, Idx
);
432 NewVec
= DAG
.getNode(ISD::INSERT_VECTOR_ELT
, dl
, NewVecVT
, NewVec
, Lo
, Idx
);
433 Idx
= DAG
.getNode(ISD::ADD
, dl
,
434 Idx
.getValueType(), Idx
,
435 DAG
.getConstant(1, dl
, Idx
.getValueType()));
436 NewVec
= DAG
.getNode(ISD::INSERT_VECTOR_ELT
, dl
, NewVecVT
, NewVec
, Hi
, Idx
);
438 // Convert the new vector to the old vector type.
439 return DAG
.getNode(ISD::BITCAST
, dl
, VecVT
, NewVec
);
442 SDValue
DAGTypeLegalizer::ExpandOp_SCALAR_TO_VECTOR(SDNode
*N
) {
444 EVT VT
= N
->getValueType(0);
445 assert(VT
.getVectorElementType() == N
->getOperand(0).getValueType() &&
446 "SCALAR_TO_VECTOR operand type doesn't match vector element type!");
447 unsigned NumElts
= VT
.getVectorNumElements();
448 SmallVector
<SDValue
, 16> Ops(NumElts
);
449 Ops
[0] = N
->getOperand(0);
450 SDValue UndefVal
= DAG
.getUNDEF(Ops
[0].getValueType());
451 for (unsigned i
= 1; i
< NumElts
; ++i
)
453 return DAG
.getBuildVector(VT
, dl
, Ops
);
456 SDValue
DAGTypeLegalizer::ExpandOp_NormalStore(SDNode
*N
, unsigned OpNo
) {
457 assert(ISD::isNormalStore(N
) && "This routine only for normal stores!");
458 assert(OpNo
== 1 && "Can only expand the stored value so far");
461 StoreSDNode
*St
= cast
<StoreSDNode
>(N
);
462 EVT ValueVT
= St
->getValue().getValueType();
463 EVT NVT
= TLI
.getTypeToTransformTo(*DAG
.getContext(), ValueVT
);
464 SDValue Chain
= St
->getChain();
465 SDValue Ptr
= St
->getBasePtr();
466 unsigned Alignment
= St
->getAlignment();
467 AAMDNodes AAInfo
= St
->getAAInfo();
469 assert(NVT
.isByteSized() && "Expanded type not byte sized!");
470 unsigned IncrementSize
= NVT
.getSizeInBits() / 8;
473 GetExpandedOp(St
->getValue(), Lo
, Hi
);
475 if (TLI
.hasBigEndianPartOrdering(ValueVT
, DAG
.getDataLayout()))
478 Lo
= DAG
.getStore(Chain
, dl
, Lo
, Ptr
, St
->getPointerInfo(), Alignment
,
479 St
->getMemOperand()->getFlags(), AAInfo
);
481 Ptr
= DAG
.getObjectPtrOffset(dl
, Ptr
, IncrementSize
);
482 Hi
= DAG
.getStore(Chain
, dl
, Hi
, Ptr
,
483 St
->getPointerInfo().getWithOffset(IncrementSize
),
484 MinAlign(Alignment
, IncrementSize
),
485 St
->getMemOperand()->getFlags(), AAInfo
);
487 return DAG
.getNode(ISD::TokenFactor
, dl
, MVT::Other
, Lo
, Hi
);
491 //===--------------------------------------------------------------------===//
492 // Generic Result Splitting.
493 //===--------------------------------------------------------------------===//
495 // Be careful to make no assumptions about which of Lo/Hi is stored first in
496 // memory (for vectors it is always Lo first followed by Hi in the following
497 // bytes; for integers and floats it is Lo first if and only if the machine is
500 void DAGTypeLegalizer::SplitRes_MERGE_VALUES(SDNode
*N
, unsigned ResNo
,
501 SDValue
&Lo
, SDValue
&Hi
) {
502 SDValue Op
= DisintegrateMERGE_VALUES(N
, ResNo
);
503 GetSplitOp(Op
, Lo
, Hi
);
506 void DAGTypeLegalizer::SplitRes_SELECT(SDNode
*N
, SDValue
&Lo
, SDValue
&Hi
) {
507 SDValue LL
, LH
, RL
, RH
, CL
, CH
;
509 GetSplitOp(N
->getOperand(1), LL
, LH
);
510 GetSplitOp(N
->getOperand(2), RL
, RH
);
512 SDValue Cond
= N
->getOperand(0);
514 if (Cond
.getValueType().isVector()) {
515 if (SDValue Res
= WidenVSELECTAndMask(N
))
516 std::tie(CL
, CH
) = DAG
.SplitVector(Res
->getOperand(0), dl
);
517 // Check if there are already splitted versions of the vector available and
518 // use those instead of splitting the mask operand again.
519 else if (getTypeAction(Cond
.getValueType()) ==
520 TargetLowering::TypeSplitVector
)
521 GetSplitVector(Cond
, CL
, CH
);
522 // It seems to improve code to generate two narrow SETCCs as opposed to
523 // splitting a wide result vector.
524 else if (Cond
.getOpcode() == ISD::SETCC
) {
525 // If the condition is a vXi1 vector, and the LHS of the setcc is a legal
526 // type and the setcc result type is the same vXi1, then leave the setcc
528 EVT CondLHSVT
= Cond
.getOperand(0).getValueType();
529 if (Cond
.getValueType().getVectorElementType() == MVT::i1
&&
530 isTypeLegal(CondLHSVT
) &&
531 getSetCCResultType(CondLHSVT
) == Cond
.getValueType())
532 std::tie(CL
, CH
) = DAG
.SplitVector(Cond
, dl
);
534 SplitVecRes_SETCC(Cond
.getNode(), CL
, CH
);
536 std::tie(CL
, CH
) = DAG
.SplitVector(Cond
, dl
);
539 Lo
= DAG
.getNode(N
->getOpcode(), dl
, LL
.getValueType(), CL
, LL
, RL
);
540 Hi
= DAG
.getNode(N
->getOpcode(), dl
, LH
.getValueType(), CH
, LH
, RH
);
543 void DAGTypeLegalizer::SplitRes_SELECT_CC(SDNode
*N
, SDValue
&Lo
,
545 SDValue LL
, LH
, RL
, RH
;
547 GetSplitOp(N
->getOperand(2), LL
, LH
);
548 GetSplitOp(N
->getOperand(3), RL
, RH
);
550 Lo
= DAG
.getNode(ISD::SELECT_CC
, dl
, LL
.getValueType(), N
->getOperand(0),
551 N
->getOperand(1), LL
, RL
, N
->getOperand(4));
552 Hi
= DAG
.getNode(ISD::SELECT_CC
, dl
, LH
.getValueType(), N
->getOperand(0),
553 N
->getOperand(1), LH
, RH
, N
->getOperand(4));
556 void DAGTypeLegalizer::SplitRes_UNDEF(SDNode
*N
, SDValue
&Lo
, SDValue
&Hi
) {
558 std::tie(LoVT
, HiVT
) = DAG
.GetSplitDestVTs(N
->getValueType(0));
559 Lo
= DAG
.getUNDEF(LoVT
);
560 Hi
= DAG
.getUNDEF(HiVT
);