LLVM 20.0.0git
LegalizeVectorOps.cpp
Go to the documentation of this file.
1//===- LegalizeVectorOps.cpp - Implement SelectionDAG::LegalizeVectors ----===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the SelectionDAG::LegalizeVectors method.
10//
11// The vector legalizer looks for vector operations which might need to be
12// scalarized and legalizes them. This is a separate step from Legalize because
13// scalarizing can introduce illegal types. For example, suppose we have an
14// ISD::SDIV of type v2i64 on x86-32. The type is legal (for example, addition
15// on a v2i64 is legal), but ISD::SDIV isn't legal, so we have to unroll the
16// operation, which introduces nodes with the illegal type i64 which must be
17// expanded. Similarly, suppose we have an ISD::SRA of type v16i8 on PowerPC;
18// the operation must be unrolled, which introduces nodes with the illegal
19// type i8 which must be promoted.
20//
21// This does not legalize vector manipulations like ISD::BUILD_VECTOR,
22// or operations that happen to take a vector which are custom-lowered;
23// the legalization for such operations never produces nodes
24// with illegal types, so it's okay to put off legalizing them until
25// SelectionDAG::Legalize runs.
26//
27//===----------------------------------------------------------------------===//
28
29#include "llvm/ADT/DenseMap.h"
39#include "llvm/IR/DataLayout.h"
42#include "llvm/Support/Debug.h"
44#include <cassert>
45#include <cstdint>
46#include <iterator>
47#include <utility>
48
49using namespace llvm;
50
51#define DEBUG_TYPE "legalizevectorops"
52
53namespace {
54
55class VectorLegalizer {
56 SelectionDAG& DAG;
57 const TargetLowering &TLI;
58 bool Changed = false; // Keep track of whether anything changed
59
60 /// For nodes that are of legal width, and that have more than one use, this
61 /// map indicates what regularized operand to use. This allows us to avoid
62 /// legalizing the same thing more than once.
64
65 /// Adds a node to the translation cache.
66 void AddLegalizedOperand(SDValue From, SDValue To) {
67 LegalizedNodes.insert(std::make_pair(From, To));
68 // If someone requests legalization of the new node, return itself.
69 if (From != To)
70 LegalizedNodes.insert(std::make_pair(To, To));
71 }
72
73 /// Legalizes the given node.
74 SDValue LegalizeOp(SDValue Op);
75
76 /// Assuming the node is legal, "legalize" the results.
77 SDValue TranslateLegalizeResults(SDValue Op, SDNode *Result);
78
79 /// Make sure Results are legal and update the translation cache.
80 SDValue RecursivelyLegalizeResults(SDValue Op,
82
83 /// Wrapper to interface LowerOperation with a vector of Results.
84 /// Returns false if the target wants to use default expansion. Otherwise
85 /// returns true. If return is true and the Results are empty, then the
86 /// target wants to keep the input node as is.
87 bool LowerOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results);
88
89 /// Implements unrolling a VSETCC.
90 SDValue UnrollVSETCC(SDNode *Node);
91
92 /// Implement expand-based legalization of vector operations.
93 ///
94 /// This is just a high-level routine to dispatch to specific code paths for
95 /// operations to legalize them.
97
98 /// Implements expansion for FP_TO_UINT; falls back to UnrollVectorOp if
99 /// FP_TO_SINT isn't legal.
100 void ExpandFP_TO_UINT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
101
102 /// Implements expansion for UINT_TO_FLOAT; falls back to UnrollVectorOp if
103 /// SINT_TO_FLOAT and SHR on vectors isn't legal.
104 void ExpandUINT_TO_FLOAT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
105
106 /// Implement expansion for SIGN_EXTEND_INREG using SRL and SRA.
107 SDValue ExpandSEXTINREG(SDNode *Node);
108
109 /// Implement expansion for ANY_EXTEND_VECTOR_INREG.
110 ///
111 /// Shuffles the low lanes of the operand into place and bitcasts to the proper
112 /// type. The contents of the bits in the extended part of each element are
113 /// undef.
114 SDValue ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node);
115
116 /// Implement expansion for SIGN_EXTEND_VECTOR_INREG.
117 ///
118 /// Shuffles the low lanes of the operand into place, bitcasts to the proper
119 /// type, then shifts left and arithmetic shifts right to introduce a sign
120 /// extension.
121 SDValue ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node);
122
123 /// Implement expansion for ZERO_EXTEND_VECTOR_INREG.
124 ///
125 /// Shuffles the low lanes of the operand into place and blends zeros into
126 /// the remaining lanes, finally bitcasting to the proper type.
127 SDValue ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node);
128
129 /// Expand bswap of vectors into a shuffle if legal.
130 SDValue ExpandBSWAP(SDNode *Node);
131
132 /// Implement vselect in terms of XOR, AND, OR when blend is not
133 /// supported by the target.
134 SDValue ExpandVSELECT(SDNode *Node);
135 SDValue ExpandVP_SELECT(SDNode *Node);
136 SDValue ExpandVP_MERGE(SDNode *Node);
137 SDValue ExpandVP_REM(SDNode *Node);
138 SDValue ExpandVP_FNEG(SDNode *Node);
139 SDValue ExpandVP_FABS(SDNode *Node);
140 SDValue ExpandVP_FCOPYSIGN(SDNode *Node);
141 SDValue ExpandSELECT(SDNode *Node);
142 std::pair<SDValue, SDValue> ExpandLoad(SDNode *N);
143 SDValue ExpandStore(SDNode *N);
144 SDValue ExpandFNEG(SDNode *Node);
145 SDValue ExpandFABS(SDNode *Node);
146 SDValue ExpandFCOPYSIGN(SDNode *Node);
147 void ExpandFSUB(SDNode *Node, SmallVectorImpl<SDValue> &Results);
148 void ExpandSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
149 SDValue ExpandBITREVERSE(SDNode *Node);
150 void ExpandUADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
151 void ExpandSADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
152 void ExpandMULO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
153 void ExpandFixedPointDiv(SDNode *Node, SmallVectorImpl<SDValue> &Results);
154 void ExpandStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
155 void ExpandREM(SDNode *Node, SmallVectorImpl<SDValue> &Results);
156
157 bool tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
159 bool tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall Call_F32,
160 RTLIB::Libcall Call_F64, RTLIB::Libcall Call_F80,
161 RTLIB::Libcall Call_F128,
162 RTLIB::Libcall Call_PPCF128,
164
165 void UnrollStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
166
167 /// Implements vector promotion.
168 ///
169 /// This is essentially just bitcasting the operands to a different type and
170 /// bitcasting the result back to the original type.
172
173 /// Implements [SU]INT_TO_FP vector promotion.
174 ///
175 /// This is a [zs]ext of the input operand to a larger integer type.
176 void PromoteINT_TO_FP(SDNode *Node, SmallVectorImpl<SDValue> &Results);
177
178 /// Implements FP_TO_[SU]INT vector promotion of the result type.
179 ///
180 /// It is promoted to a larger integer type. The result is then
181 /// truncated back to the original type.
182 void PromoteFP_TO_INT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
183
184 /// Implements vector setcc operation promotion.
185 ///
186 /// All vector operands are promoted to a vector type with larger element
187 /// type.
188 void PromoteSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
189
190 void PromoteSTRICT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
191
192public:
193 VectorLegalizer(SelectionDAG& dag) :
194 DAG(dag), TLI(dag.getTargetLoweringInfo()) {}
195
196 /// Begin legalizer the vector operations in the DAG.
197 bool Run();
198};
199
200} // end anonymous namespace
201
202bool VectorLegalizer::Run() {
203 // Before we start legalizing vector nodes, check if there are any vectors.
204 bool HasVectors = false;
205 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
206 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) {
207 // Check if the values of the nodes contain vectors. We don't need to check
208 // the operands because we are going to check their values at some point.
209 HasVectors = llvm::any_of(I->values(), [](EVT T) { return T.isVector(); });
210
211 // If we found a vector node we can start the legalization.
212 if (HasVectors)
213 break;
214 }
215
216 // If this basic block has no vectors then no need to legalize vectors.
217 if (!HasVectors)
218 return false;
219
220 // The legalize process is inherently a bottom-up recursive process (users
221 // legalize their uses before themselves). Given infinite stack space, we
222 // could just start legalizing on the root and traverse the whole graph. In
223 // practice however, this causes us to run out of stack space on large basic
224 // blocks. To avoid this problem, compute an ordering of the nodes where each
225 // node is only legalized after all of its operands are legalized.
226 DAG.AssignTopologicalOrder();
227 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
228 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I)
229 LegalizeOp(SDValue(&*I, 0));
230
231 // Finally, it's possible the root changed. Get the new root.
232 SDValue OldRoot = DAG.getRoot();
233 assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
234 DAG.setRoot(LegalizedNodes[OldRoot]);
235
236 LegalizedNodes.clear();
237
238 // Remove dead nodes now.
239 DAG.RemoveDeadNodes();
240
241 return Changed;
242}
243
244SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDNode *Result) {
245 assert(Op->getNumValues() == Result->getNumValues() &&
246 "Unexpected number of results");
247 // Generic legalization: just pass the operand through.
248 for (unsigned i = 0, e = Op->getNumValues(); i != e; ++i)
249 AddLegalizedOperand(Op.getValue(i), SDValue(Result, i));
250 return SDValue(Result, Op.getResNo());
251}
252
254VectorLegalizer::RecursivelyLegalizeResults(SDValue Op,
256 assert(Results.size() == Op->getNumValues() &&
257 "Unexpected number of results");
258 // Make sure that the generated code is itself legal.
259 for (unsigned i = 0, e = Results.size(); i != e; ++i) {
260 Results[i] = LegalizeOp(Results[i]);
261 AddLegalizedOperand(Op.getValue(i), Results[i]);
262 }
263
264 return Results[Op.getResNo()];
265}
266
267SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
268 // Note that LegalizeOp may be reentered even from single-use nodes, which
269 // means that we always must cache transformed nodes.
270 DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
271 if (I != LegalizedNodes.end()) return I->second;
272
273 // Legalize the operands
275 for (const SDValue &Oper : Op->op_values())
276 Ops.push_back(LegalizeOp(Oper));
277
278 SDNode *Node = DAG.UpdateNodeOperands(Op.getNode(), Ops);
279
280 bool HasVectorValueOrOp =
281 llvm::any_of(Node->values(), [](EVT T) { return T.isVector(); }) ||
282 llvm::any_of(Node->op_values(),
283 [](SDValue O) { return O.getValueType().isVector(); });
284 if (!HasVectorValueOrOp)
285 return TranslateLegalizeResults(Op, Node);
286
287 TargetLowering::LegalizeAction Action = TargetLowering::Legal;
288 EVT ValVT;
289 switch (Op.getOpcode()) {
290 default:
291 return TranslateLegalizeResults(Op, Node);
292 case ISD::LOAD: {
293 LoadSDNode *LD = cast<LoadSDNode>(Node);
294 ISD::LoadExtType ExtType = LD->getExtensionType();
295 EVT LoadedVT = LD->getMemoryVT();
296 if (LoadedVT.isVector() && ExtType != ISD::NON_EXTLOAD)
297 Action = TLI.getLoadExtAction(ExtType, LD->getValueType(0), LoadedVT);
298 break;
299 }
300 case ISD::STORE: {
301 StoreSDNode *ST = cast<StoreSDNode>(Node);
302 EVT StVT = ST->getMemoryVT();
303 MVT ValVT = ST->getValue().getSimpleValueType();
304 if (StVT.isVector() && ST->isTruncatingStore())
305 Action = TLI.getTruncStoreAction(ValVT, StVT);
306 break;
307 }
309 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
310 // This operation lies about being legal: when it claims to be legal,
311 // it should actually be expanded.
312 if (Action == TargetLowering::Legal)
313 Action = TargetLowering::Expand;
314 break;
315#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
316 case ISD::STRICT_##DAGN:
317#include "llvm/IR/ConstrainedOps.def"
318 ValVT = Node->getValueType(0);
319 if (Op.getOpcode() == ISD::STRICT_SINT_TO_FP ||
320 Op.getOpcode() == ISD::STRICT_UINT_TO_FP)
321 ValVT = Node->getOperand(1).getValueType();
322 if (Op.getOpcode() == ISD::STRICT_FSETCC ||
323 Op.getOpcode() == ISD::STRICT_FSETCCS) {
324 MVT OpVT = Node->getOperand(1).getSimpleValueType();
325 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(3))->get();
326 Action = TLI.getCondCodeAction(CCCode, OpVT);
327 if (Action == TargetLowering::Legal)
328 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
329 } else {
330 Action = TLI.getOperationAction(Node->getOpcode(), ValVT);
331 }
332 // If we're asked to expand a strict vector floating-point operation,
333 // by default we're going to simply unroll it. That is usually the
334 // best approach, except in the case where the resulting strict (scalar)
335 // operations would themselves use the fallback mutation to non-strict.
336 // In that specific case, just do the fallback on the vector op.
337 if (Action == TargetLowering::Expand && !TLI.isStrictFPEnabled() &&
338 TLI.getStrictFPOperationAction(Node->getOpcode(), ValVT) ==
339 TargetLowering::Legal) {
340 EVT EltVT = ValVT.getVectorElementType();
341 if (TLI.getOperationAction(Node->getOpcode(), EltVT)
342 == TargetLowering::Expand &&
343 TLI.getStrictFPOperationAction(Node->getOpcode(), EltVT)
344 == TargetLowering::Legal)
345 Action = TargetLowering::Legal;
346 }
347 break;
348 case ISD::ADD:
349 case ISD::SUB:
350 case ISD::MUL:
351 case ISD::MULHS:
352 case ISD::MULHU:
353 case ISD::SDIV:
354 case ISD::UDIV:
355 case ISD::SREM:
356 case ISD::UREM:
357 case ISD::SDIVREM:
358 case ISD::UDIVREM:
359 case ISD::FADD:
360 case ISD::FSUB:
361 case ISD::FMUL:
362 case ISD::FDIV:
363 case ISD::FREM:
364 case ISD::AND:
365 case ISD::OR:
366 case ISD::XOR:
367 case ISD::SHL:
368 case ISD::SRA:
369 case ISD::SRL:
370 case ISD::FSHL:
371 case ISD::FSHR:
372 case ISD::ROTL:
373 case ISD::ROTR:
374 case ISD::ABS:
375 case ISD::ABDS:
376 case ISD::ABDU:
377 case ISD::AVGCEILS:
378 case ISD::AVGCEILU:
379 case ISD::AVGFLOORS:
380 case ISD::AVGFLOORU:
381 case ISD::BSWAP:
382 case ISD::BITREVERSE:
383 case ISD::CTLZ:
384 case ISD::CTTZ:
387 case ISD::CTPOP:
388 case ISD::SELECT:
389 case ISD::VSELECT:
390 case ISD::SELECT_CC:
391 case ISD::ZERO_EXTEND:
392 case ISD::ANY_EXTEND:
393 case ISD::TRUNCATE:
394 case ISD::SIGN_EXTEND:
395 case ISD::FP_TO_SINT:
396 case ISD::FP_TO_UINT:
397 case ISD::FNEG:
398 case ISD::FABS:
399 case ISD::FMINNUM:
400 case ISD::FMAXNUM:
403 case ISD::FMINIMUM:
404 case ISD::FMAXIMUM:
405 case ISD::FMINIMUMNUM:
406 case ISD::FMAXIMUMNUM:
407 case ISD::FCOPYSIGN:
408 case ISD::FSQRT:
409 case ISD::FSIN:
410 case ISD::FCOS:
411 case ISD::FTAN:
412 case ISD::FASIN:
413 case ISD::FACOS:
414 case ISD::FATAN:
415 case ISD::FATAN2:
416 case ISD::FSINH:
417 case ISD::FCOSH:
418 case ISD::FTANH:
419 case ISD::FLDEXP:
420 case ISD::FPOWI:
421 case ISD::FPOW:
422 case ISD::FLOG:
423 case ISD::FLOG2:
424 case ISD::FLOG10:
425 case ISD::FEXP:
426 case ISD::FEXP2:
427 case ISD::FEXP10:
428 case ISD::FCEIL:
429 case ISD::FTRUNC:
430 case ISD::FRINT:
431 case ISD::FNEARBYINT:
432 case ISD::FROUND:
433 case ISD::FROUNDEVEN:
434 case ISD::FFLOOR:
435 case ISD::FP_ROUND:
436 case ISD::FP_EXTEND:
438 case ISD::FMA:
443 case ISD::SMIN:
444 case ISD::SMAX:
445 case ISD::UMIN:
446 case ISD::UMAX:
447 case ISD::SMUL_LOHI:
448 case ISD::UMUL_LOHI:
449 case ISD::SADDO:
450 case ISD::UADDO:
451 case ISD::SSUBO:
452 case ISD::USUBO:
453 case ISD::SMULO:
454 case ISD::UMULO:
456 case ISD::FFREXP:
457 case ISD::FSINCOS:
458 case ISD::SADDSAT:
459 case ISD::UADDSAT:
460 case ISD::SSUBSAT:
461 case ISD::USUBSAT:
462 case ISD::SSHLSAT:
463 case ISD::USHLSAT:
466 case ISD::MGATHER:
468 case ISD::SCMP:
469 case ISD::UCMP:
470 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
471 break;
472 case ISD::SMULFIX:
473 case ISD::SMULFIXSAT:
474 case ISD::UMULFIX:
475 case ISD::UMULFIXSAT:
476 case ISD::SDIVFIX:
477 case ISD::SDIVFIXSAT:
478 case ISD::UDIVFIX:
479 case ISD::UDIVFIXSAT: {
480 unsigned Scale = Node->getConstantOperandVal(2);
481 Action = TLI.getFixedPointOperationAction(Node->getOpcode(),
482 Node->getValueType(0), Scale);
483 break;
484 }
485 case ISD::LROUND:
486 case ISD::LLROUND:
487 case ISD::LRINT:
488 case ISD::LLRINT:
489 case ISD::SINT_TO_FP:
490 case ISD::UINT_TO_FP:
506 Action = TLI.getOperationAction(Node->getOpcode(),
507 Node->getOperand(0).getValueType());
508 break;
511 Action = TLI.getOperationAction(Node->getOpcode(),
512 Node->getOperand(1).getValueType());
513 break;
514 case ISD::SETCC: {
515 MVT OpVT = Node->getOperand(0).getSimpleValueType();
516 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get();
517 Action = TLI.getCondCodeAction(CCCode, OpVT);
518 if (Action == TargetLowering::Legal)
519 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
520 break;
521 }
522
523#define BEGIN_REGISTER_VP_SDNODE(VPID, LEGALPOS, ...) \
524 case ISD::VPID: { \
525 EVT LegalizeVT = LEGALPOS < 0 ? Node->getValueType(-(1 + LEGALPOS)) \
526 : Node->getOperand(LEGALPOS).getValueType(); \
527 if (ISD::VPID == ISD::VP_SETCC) { \
528 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get(); \
529 Action = TLI.getCondCodeAction(CCCode, LegalizeVT.getSimpleVT()); \
530 if (Action != TargetLowering::Legal) \
531 break; \
532 } \
533 /* Defer non-vector results to LegalizeDAG. */ \
534 if (!Node->getValueType(0).isVector() && \
535 Node->getValueType(0) != MVT::Other) { \
536 Action = TargetLowering::Legal; \
537 break; \
538 } \
539 Action = TLI.getOperationAction(Node->getOpcode(), LegalizeVT); \
540 } break;
541#include "llvm/IR/VPIntrinsics.def"
542 }
543
544 LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG));
545
546 SmallVector<SDValue, 8> ResultVals;
547 switch (Action) {
548 default: llvm_unreachable("This action is not supported yet!");
549 case TargetLowering::Promote:
550 assert((Op.getOpcode() != ISD::LOAD && Op.getOpcode() != ISD::STORE) &&
551 "This action is not supported yet!");
552 LLVM_DEBUG(dbgs() << "Promoting\n");
553 Promote(Node, ResultVals);
554 assert(!ResultVals.empty() && "No results for promotion?");
555 break;
556 case TargetLowering::Legal:
557 LLVM_DEBUG(dbgs() << "Legal node: nothing to do\n");
558 break;
559 case TargetLowering::Custom:
560 LLVM_DEBUG(dbgs() << "Trying custom legalization\n");
561 if (LowerOperationWrapper(Node, ResultVals))
562 break;
563 LLVM_DEBUG(dbgs() << "Could not custom legalize node\n");
564 [[fallthrough]];
565 case TargetLowering::Expand:
566 LLVM_DEBUG(dbgs() << "Expanding\n");
567 Expand(Node, ResultVals);
568 break;
569 }
570
571 if (ResultVals.empty())
572 return TranslateLegalizeResults(Op, Node);
573
574 Changed = true;
575 return RecursivelyLegalizeResults(Op, ResultVals);
576}
577
578// FIXME: This is very similar to TargetLowering::LowerOperationWrapper. Can we
579// merge them somehow?
580bool VectorLegalizer::LowerOperationWrapper(SDNode *Node,
582 SDValue Res = TLI.LowerOperation(SDValue(Node, 0), DAG);
583
584 if (!Res.getNode())
585 return false;
586
587 if (Res == SDValue(Node, 0))
588 return true;
589
590 // If the original node has one result, take the return value from
591 // LowerOperation as is. It might not be result number 0.
592 if (Node->getNumValues() == 1) {
593 Results.push_back(Res);
594 return true;
595 }
596
597 // If the original node has multiple results, then the return node should
598 // have the same number of results.
599 assert((Node->getNumValues() == Res->getNumValues()) &&
600 "Lowering returned the wrong number of results!");
601
602 // Places new result values base on N result number.
603 for (unsigned I = 0, E = Node->getNumValues(); I != E; ++I)
604 Results.push_back(Res.getValue(I));
605
606 return true;
607}
608
609void VectorLegalizer::PromoteSETCC(SDNode *Node,
611 MVT VecVT = Node->getOperand(0).getSimpleValueType();
612 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
613
614 unsigned ExtOp = VecVT.isFloatingPoint() ? ISD::FP_EXTEND : ISD::ANY_EXTEND;
615
616 SDLoc DL(Node);
617 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
618
619 Operands[0] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(0));
620 Operands[1] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(1));
621 Operands[2] = Node->getOperand(2);
622
623 if (Node->getOpcode() == ISD::VP_SETCC) {
624 Operands[3] = Node->getOperand(3); // mask
625 Operands[4] = Node->getOperand(4); // evl
626 }
627
628 SDValue Res = DAG.getNode(Node->getOpcode(), DL, Node->getSimpleValueType(0),
629 Operands, Node->getFlags());
630
631 Results.push_back(Res);
632}
633
634void VectorLegalizer::PromoteSTRICT(SDNode *Node,
636 MVT VecVT = Node->getOperand(1).getSimpleValueType();
637 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
638
639 assert(VecVT.isFloatingPoint());
640
641 SDLoc DL(Node);
642 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
644
645 for (unsigned j = 1; j != Node->getNumOperands(); ++j)
646 if (Node->getOperand(j).getValueType().isVector() &&
647 !(ISD::isVPOpcode(Node->getOpcode()) &&
648 ISD::getVPMaskIdx(Node->getOpcode()) == j)) // Skip mask operand.
649 {
650 // promote the vector operand.
651 SDValue Ext =
652 DAG.getNode(ISD::STRICT_FP_EXTEND, DL, {NewVecVT, MVT::Other},
653 {Node->getOperand(0), Node->getOperand(j)});
654 Operands[j] = Ext.getValue(0);
655 Chains.push_back(Ext.getValue(1));
656 } else
657 Operands[j] = Node->getOperand(j); // Skip no vector operand.
658
659 SDVTList VTs = DAG.getVTList(NewVecVT, Node->getValueType(1));
660
661 Operands[0] = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
662
663 SDValue Res =
664 DAG.getNode(Node->getOpcode(), DL, VTs, Operands, Node->getFlags());
665
666 SDValue Round =
667 DAG.getNode(ISD::STRICT_FP_ROUND, DL, {VecVT, MVT::Other},
668 {Res.getValue(1), Res.getValue(0),
669 DAG.getIntPtrConstant(0, DL, /*isTarget=*/true)});
670
671 Results.push_back(Round.getValue(0));
672 Results.push_back(Round.getValue(1));
673}
674
675void VectorLegalizer::Promote(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
676 // For a few operations there is a specific concept for promotion based on
677 // the operand's type.
678 switch (Node->getOpcode()) {
679 case ISD::SINT_TO_FP:
680 case ISD::UINT_TO_FP:
683 // "Promote" the operation by extending the operand.
684 PromoteINT_TO_FP(Node, Results);
685 return;
686 case ISD::FP_TO_UINT:
687 case ISD::FP_TO_SINT:
690 // Promote the operation by extending the operand.
691 PromoteFP_TO_INT(Node, Results);
692 return;
693 case ISD::VP_SETCC:
694 case ISD::SETCC:
695 // Promote the operation by extending the operand.
696 PromoteSETCC(Node, Results);
697 return;
698 case ISD::STRICT_FADD:
699 case ISD::STRICT_FSUB:
700 case ISD::STRICT_FMUL:
701 case ISD::STRICT_FDIV:
703 case ISD::STRICT_FMA:
704 PromoteSTRICT(Node, Results);
705 return;
706 case ISD::FP_ROUND:
707 case ISD::FP_EXTEND:
708 // These operations are used to do promotion so they can't be promoted
709 // themselves.
710 llvm_unreachable("Don't know how to promote this operation!");
711 case ISD::VP_FABS:
712 case ISD::VP_FCOPYSIGN:
713 case ISD::VP_FNEG:
714 // Promoting fabs, fneg, and fcopysign changes their semantics.
715 llvm_unreachable("These operations should not be promoted");
716 }
717
718 // There are currently two cases of vector promotion:
719 // 1) Bitcasting a vector of integers to a different type to a vector of the
720 // same overall length. For example, x86 promotes ISD::AND v2i32 to v1i64.
721 // 2) Extending a vector of floats to a vector of the same number of larger
722 // floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32.
723 assert(Node->getNumValues() == 1 &&
724 "Can't promote a vector with multiple results!");
725 MVT VT = Node->getSimpleValueType(0);
726 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
727 SDLoc dl(Node);
728 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
729
730 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
731 // Do not promote the mask operand of a VP OP.
732 bool SkipPromote = ISD::isVPOpcode(Node->getOpcode()) &&
733 ISD::getVPMaskIdx(Node->getOpcode()) == j;
734 if (Node->getOperand(j).getValueType().isVector() && !SkipPromote)
735 if (Node->getOperand(j)
736 .getValueType()
737 .getVectorElementType()
738 .isFloatingPoint() &&
740 if (ISD::isVPOpcode(Node->getOpcode())) {
741 unsigned EVLIdx =
743 unsigned MaskIdx = *ISD::getVPMaskIdx(Node->getOpcode());
744 Operands[j] =
745 DAG.getNode(ISD::VP_FP_EXTEND, dl, NVT, Node->getOperand(j),
746 Node->getOperand(MaskIdx), Node->getOperand(EVLIdx));
747 } else {
748 Operands[j] =
749 DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(j));
750 }
751 else
752 Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Node->getOperand(j));
753 else
754 Operands[j] = Node->getOperand(j);
755 }
756
757 SDValue Res =
758 DAG.getNode(Node->getOpcode(), dl, NVT, Operands, Node->getFlags());
759
760 if ((VT.isFloatingPoint() && NVT.isFloatingPoint()) ||
763 if (ISD::isVPOpcode(Node->getOpcode())) {
764 unsigned EVLIdx = *ISD::getVPExplicitVectorLengthIdx(Node->getOpcode());
765 unsigned MaskIdx = *ISD::getVPMaskIdx(Node->getOpcode());
766 Res = DAG.getNode(ISD::VP_FP_ROUND, dl, VT, Res,
767 Node->getOperand(MaskIdx), Node->getOperand(EVLIdx));
768 } else {
769 Res = DAG.getNode(ISD::FP_ROUND, dl, VT, Res,
770 DAG.getIntPtrConstant(0, dl, /*isTarget=*/true));
771 }
772 else
773 Res = DAG.getNode(ISD::BITCAST, dl, VT, Res);
774
775 Results.push_back(Res);
776}
777
778void VectorLegalizer::PromoteINT_TO_FP(SDNode *Node,
780 // INT_TO_FP operations may require the input operand be promoted even
781 // when the type is otherwise legal.
782 bool IsStrict = Node->isStrictFPOpcode();
783 MVT VT = Node->getOperand(IsStrict ? 1 : 0).getSimpleValueType();
784 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
786 "Vectors have different number of elements!");
787
788 SDLoc dl(Node);
789 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
790
791 unsigned Opc = (Node->getOpcode() == ISD::UINT_TO_FP ||
792 Node->getOpcode() == ISD::STRICT_UINT_TO_FP)
795 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
796 if (Node->getOperand(j).getValueType().isVector())
797 Operands[j] = DAG.getNode(Opc, dl, NVT, Node->getOperand(j));
798 else
799 Operands[j] = Node->getOperand(j);
800 }
801
802 if (IsStrict) {
803 SDValue Res = DAG.getNode(Node->getOpcode(), dl,
804 {Node->getValueType(0), MVT::Other}, Operands);
805 Results.push_back(Res);
806 Results.push_back(Res.getValue(1));
807 return;
808 }
809
810 SDValue Res =
811 DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Operands);
812 Results.push_back(Res);
813}
814
815// For FP_TO_INT we promote the result type to a vector type with wider
816// elements and then truncate the result. This is different from the default
817// PromoteVector which uses bitcast to promote thus assumning that the
818// promoted vector type has the same overall size.
819void VectorLegalizer::PromoteFP_TO_INT(SDNode *Node,
821 MVT VT = Node->getSimpleValueType(0);
822 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
823 bool IsStrict = Node->isStrictFPOpcode();
825 "Vectors have different number of elements!");
826
827 unsigned NewOpc = Node->getOpcode();
828 // Change FP_TO_UINT to FP_TO_SINT if possible.
829 // TODO: Should we only do this if FP_TO_UINT itself isn't legal?
830 if (NewOpc == ISD::FP_TO_UINT &&
831 TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT))
832 NewOpc = ISD::FP_TO_SINT;
833
834 if (NewOpc == ISD::STRICT_FP_TO_UINT &&
835 TLI.isOperationLegalOrCustom(ISD::STRICT_FP_TO_SINT, NVT))
836 NewOpc = ISD::STRICT_FP_TO_SINT;
837
838 SDLoc dl(Node);
839 SDValue Promoted, Chain;
840 if (IsStrict) {
841 Promoted = DAG.getNode(NewOpc, dl, {NVT, MVT::Other},
842 {Node->getOperand(0), Node->getOperand(1)});
843 Chain = Promoted.getValue(1);
844 } else
845 Promoted = DAG.getNode(NewOpc, dl, NVT, Node->getOperand(0));
846
847 // Assert that the converted value fits in the original type. If it doesn't
848 // (eg: because the value being converted is too big), then the result of the
849 // original operation was undefined anyway, so the assert is still correct.
850 if (Node->getOpcode() == ISD::FP_TO_UINT ||
851 Node->getOpcode() == ISD::STRICT_FP_TO_UINT)
852 NewOpc = ISD::AssertZext;
853 else
854 NewOpc = ISD::AssertSext;
855
856 Promoted = DAG.getNode(NewOpc, dl, NVT, Promoted,
857 DAG.getValueType(VT.getScalarType()));
858 Promoted = DAG.getNode(ISD::TRUNCATE, dl, VT, Promoted);
859 Results.push_back(Promoted);
860 if (IsStrict)
861 Results.push_back(Chain);
862}
863
864std::pair<SDValue, SDValue> VectorLegalizer::ExpandLoad(SDNode *N) {
865 LoadSDNode *LD = cast<LoadSDNode>(N);
866 return TLI.scalarizeVectorLoad(LD, DAG);
867}
868
869SDValue VectorLegalizer::ExpandStore(SDNode *N) {
870 StoreSDNode *ST = cast<StoreSDNode>(N);
871 SDValue TF = TLI.scalarizeVectorStore(ST, DAG);
872 return TF;
873}
874
875void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
876 switch (Node->getOpcode()) {
877 case ISD::LOAD: {
878 std::pair<SDValue, SDValue> Tmp = ExpandLoad(Node);
879 Results.push_back(Tmp.first);
880 Results.push_back(Tmp.second);
881 return;
882 }
883 case ISD::STORE:
884 Results.push_back(ExpandStore(Node));
885 return;
887 for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
888 Results.push_back(Node->getOperand(i));
889 return;
891 if (SDValue Expanded = ExpandSEXTINREG(Node)) {
892 Results.push_back(Expanded);
893 return;
894 }
895 break;
897 Results.push_back(ExpandANY_EXTEND_VECTOR_INREG(Node));
898 return;
900 Results.push_back(ExpandSIGN_EXTEND_VECTOR_INREG(Node));
901 return;
903 Results.push_back(ExpandZERO_EXTEND_VECTOR_INREG(Node));
904 return;
905 case ISD::BSWAP:
906 if (SDValue Expanded = ExpandBSWAP(Node)) {
907 Results.push_back(Expanded);
908 return;
909 }
910 break;
911 case ISD::VP_BSWAP:
912 Results.push_back(TLI.expandVPBSWAP(Node, DAG));
913 return;
914 case ISD::VSELECT:
915 if (SDValue Expanded = ExpandVSELECT(Node)) {
916 Results.push_back(Expanded);
917 return;
918 }
919 break;
920 case ISD::VP_SELECT:
921 if (SDValue Expanded = ExpandVP_SELECT(Node)) {
922 Results.push_back(Expanded);
923 return;
924 }
925 break;
926 case ISD::VP_SREM:
927 case ISD::VP_UREM:
928 if (SDValue Expanded = ExpandVP_REM(Node)) {
929 Results.push_back(Expanded);
930 return;
931 }
932 break;
933 case ISD::VP_FNEG:
934 if (SDValue Expanded = ExpandVP_FNEG(Node)) {
935 Results.push_back(Expanded);
936 return;
937 }
938 break;
939 case ISD::VP_FABS:
940 if (SDValue Expanded = ExpandVP_FABS(Node)) {
941 Results.push_back(Expanded);
942 return;
943 }
944 break;
945 case ISD::VP_FCOPYSIGN:
946 if (SDValue Expanded = ExpandVP_FCOPYSIGN(Node)) {
947 Results.push_back(Expanded);
948 return;
949 }
950 break;
951 case ISD::SELECT:
952 if (SDValue Expanded = ExpandSELECT(Node)) {
953 Results.push_back(Expanded);
954 return;
955 }
956 break;
957 case ISD::SELECT_CC: {
958 if (Node->getValueType(0).isScalableVector()) {
959 EVT CondVT = TLI.getSetCCResultType(
960 DAG.getDataLayout(), *DAG.getContext(), Node->getValueType(0));
961 SDValue SetCC =
962 DAG.getNode(ISD::SETCC, SDLoc(Node), CondVT, Node->getOperand(0),
963 Node->getOperand(1), Node->getOperand(4));
964 Results.push_back(DAG.getSelect(SDLoc(Node), Node->getValueType(0), SetCC,
965 Node->getOperand(2),
966 Node->getOperand(3)));
967 return;
968 }
969 break;
970 }
971 case ISD::FP_TO_UINT:
972 ExpandFP_TO_UINT(Node, Results);
973 return;
974 case ISD::UINT_TO_FP:
975 ExpandUINT_TO_FLOAT(Node, Results);
976 return;
977 case ISD::FNEG:
978 if (SDValue Expanded = ExpandFNEG(Node)) {
979 Results.push_back(Expanded);
980 return;
981 }
982 break;
983 case ISD::FABS:
984 if (SDValue Expanded = ExpandFABS(Node)) {
985 Results.push_back(Expanded);
986 return;
987 }
988 break;
989 case ISD::FCOPYSIGN:
990 if (SDValue Expanded = ExpandFCOPYSIGN(Node)) {
991 Results.push_back(Expanded);
992 return;
993 }
994 break;
995 case ISD::FSUB:
996 ExpandFSUB(Node, Results);
997 return;
998 case ISD::SETCC:
999 case ISD::VP_SETCC:
1000 ExpandSETCC(Node, Results);
1001 return;
1002 case ISD::ABS:
1003 if (SDValue Expanded = TLI.expandABS(Node, DAG)) {
1004 Results.push_back(Expanded);
1005 return;
1006 }
1007 break;
1008 case ISD::ABDS:
1009 case ISD::ABDU:
1010 if (SDValue Expanded = TLI.expandABD(Node, DAG)) {
1011 Results.push_back(Expanded);
1012 return;
1013 }
1014 break;
1015 case ISD::AVGCEILS:
1016 case ISD::AVGCEILU:
1017 case ISD::AVGFLOORS:
1018 case ISD::AVGFLOORU:
1019 if (SDValue Expanded = TLI.expandAVG(Node, DAG)) {
1020 Results.push_back(Expanded);
1021 return;
1022 }
1023 break;
1024 case ISD::BITREVERSE:
1025 if (SDValue Expanded = ExpandBITREVERSE(Node)) {
1026 Results.push_back(Expanded);
1027 return;
1028 }
1029 break;
1030 case ISD::VP_BITREVERSE:
1031 if (SDValue Expanded = TLI.expandVPBITREVERSE(Node, DAG)) {
1032 Results.push_back(Expanded);
1033 return;
1034 }
1035 break;
1036 case ISD::CTPOP:
1037 if (SDValue Expanded = TLI.expandCTPOP(Node, DAG)) {
1038 Results.push_back(Expanded);
1039 return;
1040 }
1041 break;
1042 case ISD::VP_CTPOP:
1043 if (SDValue Expanded = TLI.expandVPCTPOP(Node, DAG)) {
1044 Results.push_back(Expanded);
1045 return;
1046 }
1047 break;
1048 case ISD::CTLZ:
1050 if (SDValue Expanded = TLI.expandCTLZ(Node, DAG)) {
1051 Results.push_back(Expanded);
1052 return;
1053 }
1054 break;
1055 case ISD::VP_CTLZ:
1056 case ISD::VP_CTLZ_ZERO_UNDEF:
1057 if (SDValue Expanded = TLI.expandVPCTLZ(Node, DAG)) {
1058 Results.push_back(Expanded);
1059 return;
1060 }
1061 break;
1062 case ISD::CTTZ:
1064 if (SDValue Expanded = TLI.expandCTTZ(Node, DAG)) {
1065 Results.push_back(Expanded);
1066 return;
1067 }
1068 break;
1069 case ISD::VP_CTTZ:
1070 case ISD::VP_CTTZ_ZERO_UNDEF:
1071 if (SDValue Expanded = TLI.expandVPCTTZ(Node, DAG)) {
1072 Results.push_back(Expanded);
1073 return;
1074 }
1075 break;
1076 case ISD::FSHL:
1077 case ISD::VP_FSHL:
1078 case ISD::FSHR:
1079 case ISD::VP_FSHR:
1080 if (SDValue Expanded = TLI.expandFunnelShift(Node, DAG)) {
1081 Results.push_back(Expanded);
1082 return;
1083 }
1084 break;
1085 case ISD::ROTL:
1086 case ISD::ROTR:
1087 if (SDValue Expanded = TLI.expandROT(Node, false /*AllowVectorOps*/, DAG)) {
1088 Results.push_back(Expanded);
1089 return;
1090 }
1091 break;
1092 case ISD::FMINNUM:
1093 case ISD::FMAXNUM:
1094 if (SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Node, DAG)) {
1095 Results.push_back(Expanded);
1096 return;
1097 }
1098 break;
1099 case ISD::FMINIMUM:
1100 case ISD::FMAXIMUM:
1101 Results.push_back(TLI.expandFMINIMUM_FMAXIMUM(Node, DAG));
1102 return;
1103 case ISD::FMINIMUMNUM:
1104 case ISD::FMAXIMUMNUM:
1105 Results.push_back(TLI.expandFMINIMUMNUM_FMAXIMUMNUM(Node, DAG));
1106 return;
1107 case ISD::SMIN:
1108 case ISD::SMAX:
1109 case ISD::UMIN:
1110 case ISD::UMAX:
1111 if (SDValue Expanded = TLI.expandIntMINMAX(Node, DAG)) {
1112 Results.push_back(Expanded);
1113 return;
1114 }
1115 break;
1116 case ISD::UADDO:
1117 case ISD::USUBO:
1118 ExpandUADDSUBO(Node, Results);
1119 return;
1120 case ISD::SADDO:
1121 case ISD::SSUBO:
1122 ExpandSADDSUBO(Node, Results);
1123 return;
1124 case ISD::UMULO:
1125 case ISD::SMULO:
1126 ExpandMULO(Node, Results);
1127 return;
1128 case ISD::USUBSAT:
1129 case ISD::SSUBSAT:
1130 case ISD::UADDSAT:
1131 case ISD::SADDSAT:
1132 if (SDValue Expanded = TLI.expandAddSubSat(Node, DAG)) {
1133 Results.push_back(Expanded);
1134 return;
1135 }
1136 break;
1137 case ISD::USHLSAT:
1138 case ISD::SSHLSAT:
1139 if (SDValue Expanded = TLI.expandShlSat(Node, DAG)) {
1140 Results.push_back(Expanded);
1141 return;
1142 }
1143 break;
1146 // Expand the fpsosisat if it is scalable to prevent it from unrolling below.
1147 if (Node->getValueType(0).isScalableVector()) {
1148 if (SDValue Expanded = TLI.expandFP_TO_INT_SAT(Node, DAG)) {
1149 Results.push_back(Expanded);
1150 return;
1151 }
1152 }
1153 break;
1154 case ISD::SMULFIX:
1155 case ISD::UMULFIX:
1156 if (SDValue Expanded = TLI.expandFixedPointMul(Node, DAG)) {
1157 Results.push_back(Expanded);
1158 return;
1159 }
1160 break;
1161 case ISD::SMULFIXSAT:
1162 case ISD::UMULFIXSAT:
1163 // FIXME: We do not expand SMULFIXSAT/UMULFIXSAT here yet, not sure exactly
1164 // why. Maybe it results in worse codegen compared to the unroll for some
1165 // targets? This should probably be investigated. And if we still prefer to
1166 // unroll an explanation could be helpful.
1167 break;
1168 case ISD::SDIVFIX:
1169 case ISD::UDIVFIX:
1170 ExpandFixedPointDiv(Node, Results);
1171 return;
1172 case ISD::SDIVFIXSAT:
1173 case ISD::UDIVFIXSAT:
1174 break;
1175#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1176 case ISD::STRICT_##DAGN:
1177#include "llvm/IR/ConstrainedOps.def"
1178 ExpandStrictFPOp(Node, Results);
1179 return;
1180 case ISD::VECREDUCE_ADD:
1181 case ISD::VECREDUCE_MUL:
1182 case ISD::VECREDUCE_AND:
1183 case ISD::VECREDUCE_OR:
1184 case ISD::VECREDUCE_XOR:
1195 Results.push_back(TLI.expandVecReduce(Node, DAG));
1196 return;
1199 Results.push_back(TLI.expandVecReduceSeq(Node, DAG));
1200 return;
1201 case ISD::SREM:
1202 case ISD::UREM:
1203 ExpandREM(Node, Results);
1204 return;
1205 case ISD::VP_MERGE:
1206 if (SDValue Expanded = ExpandVP_MERGE(Node)) {
1207 Results.push_back(Expanded);
1208 return;
1209 }
1210 break;
1211 case ISD::FREM:
1212 if (tryExpandVecMathCall(Node, RTLIB::REM_F32, RTLIB::REM_F64,
1213 RTLIB::REM_F80, RTLIB::REM_F128,
1214 RTLIB::REM_PPCF128, Results))
1215 return;
1216
1217 break;
1218 case ISD::FSINCOS: {
1219 RTLIB::Libcall LC =
1220 RTLIB::getFSINCOS(Node->getValueType(0).getVectorElementType());
1221 if (DAG.expandMultipleResultFPLibCall(LC, Node, Results))
1222 return;
1223 break;
1224 }
1226 Results.push_back(TLI.expandVECTOR_COMPRESS(Node, DAG));
1227 return;
1228 case ISD::SCMP:
1229 case ISD::UCMP:
1230 Results.push_back(TLI.expandCMP(Node, DAG));
1231 return;
1232
1233 case ISD::FADD:
1234 case ISD::FMUL:
1235 case ISD::FMA:
1236 case ISD::FDIV:
1237 case ISD::FCEIL:
1238 case ISD::FFLOOR:
1239 case ISD::FNEARBYINT:
1240 case ISD::FRINT:
1241 case ISD::FROUND:
1242 case ISD::FROUNDEVEN:
1243 case ISD::FTRUNC:
1244 case ISD::FSQRT:
1245 if (SDValue Expanded = TLI.expandVectorNaryOpBySplitting(Node, DAG)) {
1246 Results.push_back(Expanded);
1247 return;
1248 }
1249 break;
1250 }
1251
1252 SDValue Unrolled = DAG.UnrollVectorOp(Node);
1253 if (Node->getNumValues() == 1) {
1254 Results.push_back(Unrolled);
1255 } else {
1256 assert(Node->getNumValues() == Unrolled->getNumValues() &&
1257 "VectorLegalizer Expand returned wrong number of results!");
1258 for (unsigned I = 0, E = Unrolled->getNumValues(); I != E; ++I)
1259 Results.push_back(Unrolled.getValue(I));
1260 }
1261}
1262
1263SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
1264 // Lower a select instruction where the condition is a scalar and the
1265 // operands are vectors. Lower this select to VSELECT and implement it
1266 // using XOR AND OR. The selector bit is broadcasted.
1267 EVT VT = Node->getValueType(0);
1268 SDLoc DL(Node);
1269
1270 SDValue Mask = Node->getOperand(0);
1271 SDValue Op1 = Node->getOperand(1);
1272 SDValue Op2 = Node->getOperand(2);
1273
1274 assert(VT.isVector() && !Mask.getValueType().isVector()
1275 && Op1.getValueType() == Op2.getValueType() && "Invalid type");
1276
1277 // If we can't even use the basic vector operations of
1278 // AND,OR,XOR, we will have to scalarize the op.
1279 // Notice that the operation may be 'promoted' which means that it is
1280 // 'bitcasted' to another type which is handled.
1281 // Also, we need to be able to construct a splat vector using either
1282 // BUILD_VECTOR or SPLAT_VECTOR.
1283 // FIXME: Should we also permit fixed-length SPLAT_VECTOR as a fallback to
1284 // BUILD_VECTOR?
1285 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1286 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1287 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
1288 TLI.getOperationAction(VT.isFixedLengthVector() ? ISD::BUILD_VECTOR
1290 VT) == TargetLowering::Expand)
1291 return SDValue();
1292
1293 // Generate a mask operand.
1295
1296 // What is the size of each element in the vector mask.
1297 EVT BitTy = MaskTy.getScalarType();
1298
1299 Mask = DAG.getSelect(DL, BitTy, Mask, DAG.getAllOnesConstant(DL, BitTy),
1300 DAG.getConstant(0, DL, BitTy));
1301
1302 // Broadcast the mask so that the entire vector is all one or all zero.
1303 Mask = DAG.getSplat(MaskTy, DL, Mask);
1304
1305 // Bitcast the operands to be the same type as the mask.
1306 // This is needed when we select between FP types because
1307 // the mask is a vector of integers.
1308 Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
1309 Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);
1310
1311 SDValue NotMask = DAG.getNOT(DL, Mask, MaskTy);
1312
1313 Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
1314 Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask);
1315 SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2);
1316 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1317}
1318
1319SDValue VectorLegalizer::ExpandSEXTINREG(SDNode *Node) {
1320 EVT VT = Node->getValueType(0);
1321
1322 // Make sure that the SRA and SHL instructions are available.
1323 if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
1324 TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
1325 return SDValue();
1326
1327 SDLoc DL(Node);
1328 EVT OrigTy = cast<VTSDNode>(Node->getOperand(1))->getVT();
1329
1330 unsigned BW = VT.getScalarSizeInBits();
1331 unsigned OrigBW = OrigTy.getScalarSizeInBits();
1332 SDValue ShiftSz = DAG.getConstant(BW - OrigBW, DL, VT);
1333
1334 SDValue Op = DAG.getNode(ISD::SHL, DL, VT, Node->getOperand(0), ShiftSz);
1335 return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz);
1336}
1337
1338// Generically expand a vector anyext in register to a shuffle of the relevant
1339// lanes into the appropriate locations, with other lanes left undef.
1340SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node) {
1341 SDLoc DL(Node);
1342 EVT VT = Node->getValueType(0);
1343 int NumElements = VT.getVectorNumElements();
1344 SDValue Src = Node->getOperand(0);
1345 EVT SrcVT = Src.getValueType();
1346 int NumSrcElements = SrcVT.getVectorNumElements();
1347
1348 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1349 // into a larger vector type.
1350 if (SrcVT.bitsLE(VT)) {
1351 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1352 "ANY_EXTEND_VECTOR_INREG vector size mismatch");
1353 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1354 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1355 NumSrcElements);
1356 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT),
1357 Src, DAG.getVectorIdxConstant(0, DL));
1358 }
1359
1360 // Build a base mask of undef shuffles.
1361 SmallVector<int, 16> ShuffleMask;
1362 ShuffleMask.resize(NumSrcElements, -1);
1363
1364 // Place the extended lanes into the correct locations.
1365 int ExtLaneScale = NumSrcElements / NumElements;
1366 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1367 for (int i = 0; i < NumElements; ++i)
1368 ShuffleMask[i * ExtLaneScale + EndianOffset] = i;
1369
1370 return DAG.getNode(
1371 ISD::BITCAST, DL, VT,
1372 DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask));
1373}
1374
1375SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node) {
1376 SDLoc DL(Node);
1377 EVT VT = Node->getValueType(0);
1378 SDValue Src = Node->getOperand(0);
1379 EVT SrcVT = Src.getValueType();
1380
1381 // First build an any-extend node which can be legalized above when we
1382 // recurse through it.
1383 SDValue Op = DAG.getNode(ISD::ANY_EXTEND_VECTOR_INREG, DL, VT, Src);
1384
1385 // Now we need sign extend. Do this by shifting the elements. Even if these
1386 // aren't legal operations, they have a better chance of being legalized
1387 // without full scalarization than the sign extension does.
1388 unsigned EltWidth = VT.getScalarSizeInBits();
1389 unsigned SrcEltWidth = SrcVT.getScalarSizeInBits();
1390 SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, DL, VT);
1391 return DAG.getNode(ISD::SRA, DL, VT,
1392 DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount),
1393 ShiftAmount);
1394}
1395
1396// Generically expand a vector zext in register to a shuffle of the relevant
1397// lanes into the appropriate locations, a blend of zero into the high bits,
1398// and a bitcast to the wider element type.
1399SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node) {
1400 SDLoc DL(Node);
1401 EVT VT = Node->getValueType(0);
1402 int NumElements = VT.getVectorNumElements();
1403 SDValue Src = Node->getOperand(0);
1404 EVT SrcVT = Src.getValueType();
1405 int NumSrcElements = SrcVT.getVectorNumElements();
1406
1407 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1408 // into a larger vector type.
1409 if (SrcVT.bitsLE(VT)) {
1410 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1411 "ZERO_EXTEND_VECTOR_INREG vector size mismatch");
1412 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1413 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1414 NumSrcElements);
1415 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT),
1416 Src, DAG.getVectorIdxConstant(0, DL));
1417 }
1418
1419 // Build up a zero vector to blend into this one.
1420 SDValue Zero = DAG.getConstant(0, DL, SrcVT);
1421
1422 // Shuffle the incoming lanes into the correct position, and pull all other
1423 // lanes from the zero vector.
1424 auto ShuffleMask = llvm::to_vector<16>(llvm::seq<int>(0, NumSrcElements));
1425
1426 int ExtLaneScale = NumSrcElements / NumElements;
1427 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1428 for (int i = 0; i < NumElements; ++i)
1429 ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i;
1430
1431 return DAG.getNode(ISD::BITCAST, DL, VT,
1432 DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask));
1433}
1434
1435static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
1436 int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
1437 for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
1438 for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
1439 ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
1440}
1441
1442SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) {
1443 EVT VT = Node->getValueType(0);
1444
1445 // Scalable vectors can't use shuffle expansion.
1446 if (VT.isScalableVector())
1447 return TLI.expandBSWAP(Node, DAG);
1448
1449 // Generate a byte wise shuffle mask for the BSWAP.
1450 SmallVector<int, 16> ShuffleMask;
1451 createBSWAPShuffleMask(VT, ShuffleMask);
1452 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
1453
1454 // Only emit a shuffle if the mask is legal.
1455 if (TLI.isShuffleMaskLegal(ShuffleMask, ByteVT)) {
1456 SDLoc DL(Node);
1457 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1458 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), ShuffleMask);
1459 return DAG.getNode(ISD::BITCAST, DL, VT, Op);
1460 }
1461
1462 // If we have the appropriate vector bit operations, it is better to use them
1463 // than unrolling and expanding each component.
1464 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1465 TLI.isOperationLegalOrCustom(ISD::SRL, VT) &&
1466 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
1467 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
1468 return TLI.expandBSWAP(Node, DAG);
1469
1470 // Otherwise let the caller unroll.
1471 return SDValue();
1472}
1473
1474SDValue VectorLegalizer::ExpandBITREVERSE(SDNode *Node) {
1475 EVT VT = Node->getValueType(0);
1476
1477 // We can't unroll or use shuffles for scalable vectors.
1478 if (VT.isScalableVector())
1479 return TLI.expandBITREVERSE(Node, DAG);
1480
1481 // If we have the scalar operation, it's probably cheaper to unroll it.
1482 if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType()))
1483 return SDValue();
1484
1485 // If the vector element width is a whole number of bytes, test if its legal
1486 // to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte
1487 // vector. This greatly reduces the number of bit shifts necessary.
1488 unsigned ScalarSizeInBits = VT.getScalarSizeInBits();
1489 if (ScalarSizeInBits > 8 && (ScalarSizeInBits % 8) == 0) {
1490 SmallVector<int, 16> BSWAPMask;
1491 createBSWAPShuffleMask(VT, BSWAPMask);
1492
1493 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, BSWAPMask.size());
1494 if (TLI.isShuffleMaskLegal(BSWAPMask, ByteVT) &&
1495 (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, ByteVT) ||
1496 (TLI.isOperationLegalOrCustom(ISD::SHL, ByteVT) &&
1497 TLI.isOperationLegalOrCustom(ISD::SRL, ByteVT) &&
1498 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, ByteVT) &&
1499 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, ByteVT)))) {
1500 SDLoc DL(Node);
1501 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1502 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT),
1503 BSWAPMask);
1504 Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op);
1505 Op = DAG.getNode(ISD::BITCAST, DL, VT, Op);
1506 return Op;
1507 }
1508 }
1509
1510 // If we have the appropriate vector bit operations, it is better to use them
1511 // than unrolling and expanding each component.
1512 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1513 TLI.isOperationLegalOrCustom(ISD::SRL, VT) &&
1514 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
1515 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
1516 return TLI.expandBITREVERSE(Node, DAG);
1517
1518 // Otherwise unroll.
1519 return SDValue();
1520}
1521
1522SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
1523 // Implement VSELECT in terms of XOR, AND, OR
1524 // on platforms which do not support blend natively.
1525 SDLoc DL(Node);
1526
1527 SDValue Mask = Node->getOperand(0);
1528 SDValue Op1 = Node->getOperand(1);
1529 SDValue Op2 = Node->getOperand(2);
1530
1531 EVT VT = Mask.getValueType();
1532
1533 // If we can't even use the basic vector operations of
1534 // AND,OR,XOR, we will have to scalarize the op.
1535 // Notice that the operation may be 'promoted' which means that it is
1536 // 'bitcasted' to another type which is handled.
1537 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1538 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1539 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand)
1540 return SDValue();
1541
1542 // This operation also isn't safe with AND, OR, XOR when the boolean type is
1543 // 0/1 and the select operands aren't also booleans, as we need an all-ones
1544 // vector constant to mask with.
1545 // FIXME: Sign extend 1 to all ones if that's legal on the target.
1546 auto BoolContents = TLI.getBooleanContents(Op1.getValueType());
1547 if (BoolContents != TargetLowering::ZeroOrNegativeOneBooleanContent &&
1548 !(BoolContents == TargetLowering::ZeroOrOneBooleanContent &&
1549 Op1.getValueType().getVectorElementType() == MVT::i1))
1550 return SDValue();
1551
1552 // If the mask and the type are different sizes, unroll the vector op. This
1553 // can occur when getSetCCResultType returns something that is different in
1554 // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
1555 if (VT.getSizeInBits() != Op1.getValueSizeInBits())
1556 return SDValue();
1557
1558 // Bitcast the operands to be the same type as the mask.
1559 // This is needed when we select between FP types because
1560 // the mask is a vector of integers.
1561 Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
1562 Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);
1563
1564 SDValue NotMask = DAG.getNOT(DL, Mask, VT);
1565
1566 Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
1567 Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask);
1568 SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2);
1569 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1570}
1571
1572SDValue VectorLegalizer::ExpandVP_SELECT(SDNode *Node) {
1573 // Implement VP_SELECT in terms of VP_XOR, VP_AND and VP_OR on platforms which
1574 // do not support it natively.
1575 SDLoc DL(Node);
1576
1577 SDValue Mask = Node->getOperand(0);
1578 SDValue Op1 = Node->getOperand(1);
1579 SDValue Op2 = Node->getOperand(2);
1580 SDValue EVL = Node->getOperand(3);
1581
1582 EVT VT = Mask.getValueType();
1583
1584 // If we can't even use the basic vector operations of
1585 // VP_AND,VP_OR,VP_XOR, we will have to scalarize the op.
1586 if (TLI.getOperationAction(ISD::VP_AND, VT) == TargetLowering::Expand ||
1587 TLI.getOperationAction(ISD::VP_XOR, VT) == TargetLowering::Expand ||
1588 TLI.getOperationAction(ISD::VP_OR, VT) == TargetLowering::Expand)
1589 return SDValue();
1590
1591 // This operation also isn't safe when the operands aren't also booleans.
1592 if (Op1.getValueType().getVectorElementType() != MVT::i1)
1593 return SDValue();
1594
1595 SDValue Ones = DAG.getAllOnesConstant(DL, VT);
1596 SDValue NotMask = DAG.getNode(ISD::VP_XOR, DL, VT, Mask, Ones, Ones, EVL);
1597
1598 Op1 = DAG.getNode(ISD::VP_AND, DL, VT, Op1, Mask, Ones, EVL);
1599 Op2 = DAG.getNode(ISD::VP_AND, DL, VT, Op2, NotMask, Ones, EVL);
1600 return DAG.getNode(ISD::VP_OR, DL, VT, Op1, Op2, Ones, EVL);
1601}
1602
1603SDValue VectorLegalizer::ExpandVP_MERGE(SDNode *Node) {
1604 // Implement VP_MERGE in terms of VSELECT. Construct a mask where vector
1605 // indices less than the EVL/pivot are true. Combine that with the original
1606 // mask for a full-length mask. Use a full-length VSELECT to select between
1607 // the true and false values.
1608 SDLoc DL(Node);
1609
1610 SDValue Mask = Node->getOperand(0);
1611 SDValue Op1 = Node->getOperand(1);
1612 SDValue Op2 = Node->getOperand(2);
1613 SDValue EVL = Node->getOperand(3);
1614
1615 EVT MaskVT = Mask.getValueType();
1616 bool IsFixedLen = MaskVT.isFixedLengthVector();
1617
1618 EVT EVLVecVT = EVT::getVectorVT(*DAG.getContext(), EVL.getValueType(),
1619 MaskVT.getVectorElementCount());
1620
1621 // If we can't construct the EVL mask efficiently, it's better to unroll.
1622 if ((IsFixedLen &&
1623 !TLI.isOperationLegalOrCustom(ISD::BUILD_VECTOR, EVLVecVT)) ||
1624 (!IsFixedLen &&
1625 (!TLI.isOperationLegalOrCustom(ISD::STEP_VECTOR, EVLVecVT) ||
1626 !TLI.isOperationLegalOrCustom(ISD::SPLAT_VECTOR, EVLVecVT))))
1627 return SDValue();
1628
1629 // If using a SETCC would result in a different type than the mask type,
1630 // unroll.
1631 if (TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
1632 EVLVecVT) != MaskVT)
1633 return SDValue();
1634
1635 SDValue StepVec = DAG.getStepVector(DL, EVLVecVT);
1636 SDValue SplatEVL = DAG.getSplat(EVLVecVT, DL, EVL);
1637 SDValue EVLMask =
1638 DAG.getSetCC(DL, MaskVT, StepVec, SplatEVL, ISD::CondCode::SETULT);
1639
1640 SDValue FullMask = DAG.getNode(ISD::AND, DL, MaskVT, Mask, EVLMask);
1641 return DAG.getSelect(DL, Node->getValueType(0), FullMask, Op1, Op2);
1642}
1643
1644SDValue VectorLegalizer::ExpandVP_REM(SDNode *Node) {
1645 // Implement VP_SREM/UREM in terms of VP_SDIV/VP_UDIV, VP_MUL, VP_SUB.
1646 EVT VT = Node->getValueType(0);
1647
1648 unsigned DivOpc = Node->getOpcode() == ISD::VP_SREM ? ISD::VP_SDIV : ISD::VP_UDIV;
1649
1650 if (!TLI.isOperationLegalOrCustom(DivOpc, VT) ||
1651 !TLI.isOperationLegalOrCustom(ISD::VP_MUL, VT) ||
1652 !TLI.isOperationLegalOrCustom(ISD::VP_SUB, VT))
1653 return SDValue();
1654
1655 SDLoc DL(Node);
1656
1657 SDValue Dividend = Node->getOperand(0);
1658 SDValue Divisor = Node->getOperand(1);
1659 SDValue Mask = Node->getOperand(2);
1660 SDValue EVL = Node->getOperand(3);
1661
1662 // X % Y -> X-X/Y*Y
1663 SDValue Div = DAG.getNode(DivOpc, DL, VT, Dividend, Divisor, Mask, EVL);
1664 SDValue Mul = DAG.getNode(ISD::VP_MUL, DL, VT, Divisor, Div, Mask, EVL);
1665 return DAG.getNode(ISD::VP_SUB, DL, VT, Dividend, Mul, Mask, EVL);
1666}
1667
1668SDValue VectorLegalizer::ExpandVP_FNEG(SDNode *Node) {
1669 EVT VT = Node->getValueType(0);
1671
1672 if (!TLI.isOperationLegalOrCustom(ISD::VP_XOR, IntVT))
1673 return SDValue();
1674
1675 SDValue Mask = Node->getOperand(1);
1676 SDValue EVL = Node->getOperand(2);
1677
1678 SDLoc DL(Node);
1679 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1680 SDValue SignMask = DAG.getConstant(
1681 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1682 SDValue Xor = DAG.getNode(ISD::VP_XOR, DL, IntVT, Cast, SignMask, Mask, EVL);
1683 return DAG.getNode(ISD::BITCAST, DL, VT, Xor);
1684}
1685
1686SDValue VectorLegalizer::ExpandVP_FABS(SDNode *Node) {
1687 EVT VT = Node->getValueType(0);
1689
1690 if (!TLI.isOperationLegalOrCustom(ISD::VP_AND, IntVT))
1691 return SDValue();
1692
1693 SDValue Mask = Node->getOperand(1);
1694 SDValue EVL = Node->getOperand(2);
1695
1696 SDLoc DL(Node);
1697 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1698 SDValue ClearSignMask = DAG.getConstant(
1700 SDValue ClearSign =
1701 DAG.getNode(ISD::VP_AND, DL, IntVT, Cast, ClearSignMask, Mask, EVL);
1702 return DAG.getNode(ISD::BITCAST, DL, VT, ClearSign);
1703}
1704
1705SDValue VectorLegalizer::ExpandVP_FCOPYSIGN(SDNode *Node) {
1706 EVT VT = Node->getValueType(0);
1707
1708 if (VT != Node->getOperand(1).getValueType())
1709 return SDValue();
1710
1712 if (!TLI.isOperationLegalOrCustom(ISD::VP_AND, IntVT) ||
1713 !TLI.isOperationLegalOrCustom(ISD::VP_XOR, IntVT))
1714 return SDValue();
1715
1716 SDValue Mask = Node->getOperand(2);
1717 SDValue EVL = Node->getOperand(3);
1718
1719 SDLoc DL(Node);
1720 SDValue Mag = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1721 SDValue Sign = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(1));
1722
1723 SDValue SignMask = DAG.getConstant(
1724 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1725 SDValue SignBit =
1726 DAG.getNode(ISD::VP_AND, DL, IntVT, Sign, SignMask, Mask, EVL);
1727
1728 SDValue ClearSignMask = DAG.getConstant(
1730 SDValue ClearedSign =
1731 DAG.getNode(ISD::VP_AND, DL, IntVT, Mag, ClearSignMask, Mask, EVL);
1732
1733 SDValue CopiedSign = DAG.getNode(ISD::VP_OR, DL, IntVT, ClearedSign, SignBit,
1734 Mask, EVL, SDNodeFlags::Disjoint);
1735
1736 return DAG.getNode(ISD::BITCAST, DL, VT, CopiedSign);
1737}
1738
1739void VectorLegalizer::ExpandFP_TO_UINT(SDNode *Node,
1741 // Attempt to expand using TargetLowering.
1742 SDValue Result, Chain;
1743 if (TLI.expandFP_TO_UINT(Node, Result, Chain, DAG)) {
1744 Results.push_back(Result);
1745 if (Node->isStrictFPOpcode())
1746 Results.push_back(Chain);
1747 return;
1748 }
1749
1750 // Otherwise go ahead and unroll.
1751 if (Node->isStrictFPOpcode()) {
1752 UnrollStrictFPOp(Node, Results);
1753 return;
1754 }
1755
1756 Results.push_back(DAG.UnrollVectorOp(Node));
1757}
1758
1759void VectorLegalizer::ExpandUINT_TO_FLOAT(SDNode *Node,
1761 bool IsStrict = Node->isStrictFPOpcode();
1762 unsigned OpNo = IsStrict ? 1 : 0;
1763 SDValue Src = Node->getOperand(OpNo);
1764 EVT SrcVT = Src.getValueType();
1765 EVT DstVT = Node->getValueType(0);
1766 SDLoc DL(Node);
1767
1768 // Attempt to expand using TargetLowering.
1770 SDValue Chain;
1771 if (TLI.expandUINT_TO_FP(Node, Result, Chain, DAG)) {
1772 Results.push_back(Result);
1773 if (IsStrict)
1774 Results.push_back(Chain);
1775 return;
1776 }
1777
1778 // Make sure that the SINT_TO_FP and SRL instructions are available.
1779 if (((!IsStrict && TLI.getOperationAction(ISD::SINT_TO_FP, SrcVT) ==
1780 TargetLowering::Expand) ||
1781 (IsStrict && TLI.getOperationAction(ISD::STRICT_SINT_TO_FP, SrcVT) ==
1782 TargetLowering::Expand)) ||
1783 TLI.getOperationAction(ISD::SRL, SrcVT) == TargetLowering::Expand) {
1784 if (IsStrict) {
1785 UnrollStrictFPOp(Node, Results);
1786 return;
1787 }
1788
1789 Results.push_back(DAG.UnrollVectorOp(Node));
1790 return;
1791 }
1792
1793 unsigned BW = SrcVT.getScalarSizeInBits();
1794 assert((BW == 64 || BW == 32) &&
1795 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
1796
1797 // If STRICT_/FMUL is not supported by the target (in case of f16) replace the
1798 // UINT_TO_FP with a larger float and round to the smaller type
1799 if ((!IsStrict && !TLI.isOperationLegalOrCustom(ISD::FMUL, DstVT)) ||
1800 (IsStrict && !TLI.isOperationLegalOrCustom(ISD::STRICT_FMUL, DstVT))) {
1801 EVT FPVT = BW == 32 ? MVT::f32 : MVT::f64;
1802 SDValue UIToFP;
1804 SDValue TargetZero = DAG.getIntPtrConstant(0, DL, /*isTarget=*/true);
1805 EVT FloatVecVT = SrcVT.changeVectorElementType(FPVT);
1806 if (IsStrict) {
1807 UIToFP = DAG.getNode(ISD::STRICT_UINT_TO_FP, DL, {FloatVecVT, MVT::Other},
1808 {Node->getOperand(0), Src});
1809 Result = DAG.getNode(ISD::STRICT_FP_ROUND, DL, {DstVT, MVT::Other},
1810 {Node->getOperand(0), UIToFP, TargetZero});
1811 Results.push_back(Result);
1812 Results.push_back(Result.getValue(1));
1813 } else {
1814 UIToFP = DAG.getNode(ISD::UINT_TO_FP, DL, FloatVecVT, Src);
1815 Result = DAG.getNode(ISD::FP_ROUND, DL, DstVT, UIToFP, TargetZero);
1816 Results.push_back(Result);
1817 }
1818
1819 return;
1820 }
1821
1822 SDValue HalfWord = DAG.getConstant(BW / 2, DL, SrcVT);
1823
1824 // Constants to clear the upper part of the word.
1825 // Notice that we can also use SHL+SHR, but using a constant is slightly
1826 // faster on x86.
1827 uint64_t HWMask = (BW == 64) ? 0x00000000FFFFFFFF : 0x0000FFFF;
1828 SDValue HalfWordMask = DAG.getConstant(HWMask, DL, SrcVT);
1829
1830 // Two to the power of half-word-size.
1831 SDValue TWOHW = DAG.getConstantFP(1ULL << (BW / 2), DL, DstVT);
1832
1833 // Clear upper part of LO, lower HI
1834 SDValue HI = DAG.getNode(ISD::SRL, DL, SrcVT, Src, HalfWord);
1835 SDValue LO = DAG.getNode(ISD::AND, DL, SrcVT, Src, HalfWordMask);
1836
1837 if (IsStrict) {
1838 // Convert hi and lo to floats
1839 // Convert the hi part back to the upper values
1840 // TODO: Can any fast-math-flags be set on these nodes?
1841 SDValue fHI = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, {DstVT, MVT::Other},
1842 {Node->getOperand(0), HI});
1843 fHI = DAG.getNode(ISD::STRICT_FMUL, DL, {DstVT, MVT::Other},
1844 {fHI.getValue(1), fHI, TWOHW});
1845 SDValue fLO = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, {DstVT, MVT::Other},
1846 {Node->getOperand(0), LO});
1847
1848 SDValue TF = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, fHI.getValue(1),
1849 fLO.getValue(1));
1850
1851 // Add the two halves
1852 SDValue Result =
1853 DAG.getNode(ISD::STRICT_FADD, DL, {DstVT, MVT::Other}, {TF, fHI, fLO});
1854
1855 Results.push_back(Result);
1856 Results.push_back(Result.getValue(1));
1857 return;
1858 }
1859
1860 // Convert hi and lo to floats
1861 // Convert the hi part back to the upper values
1862 // TODO: Can any fast-math-flags be set on these nodes?
1863 SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, DstVT, HI);
1864 fHI = DAG.getNode(ISD::FMUL, DL, DstVT, fHI, TWOHW);
1865 SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, DstVT, LO);
1866
1867 // Add the two halves
1868 Results.push_back(DAG.getNode(ISD::FADD, DL, DstVT, fHI, fLO));
1869}
1870
1871SDValue VectorLegalizer::ExpandFNEG(SDNode *Node) {
1872 EVT VT = Node->getValueType(0);
1874
1875 if (!TLI.isOperationLegalOrCustom(ISD::XOR, IntVT))
1876 return SDValue();
1877
1878 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
1879 if (!TLI.isOperationLegalOrCustomOrPromote(ISD::FSUB, VT) &&
1880 !VT.isScalableVector())
1881 return SDValue();
1882
1883 SDLoc DL(Node);
1884 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1885 SDValue SignMask = DAG.getConstant(
1886 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1887 SDValue Xor = DAG.getNode(ISD::XOR, DL, IntVT, Cast, SignMask);
1888 return DAG.getNode(ISD::BITCAST, DL, VT, Xor);
1889}
1890
1891SDValue VectorLegalizer::ExpandFABS(SDNode *Node) {
1892 EVT VT = Node->getValueType(0);
1894
1895 if (!TLI.isOperationLegalOrCustom(ISD::AND, IntVT))
1896 return SDValue();
1897
1898 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
1899 if (!TLI.isOperationLegalOrCustomOrPromote(ISD::FSUB, VT) &&
1900 !VT.isScalableVector())
1901 return SDValue();
1902
1903 SDLoc DL(Node);
1904 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1905 SDValue ClearSignMask = DAG.getConstant(
1907 SDValue ClearedSign = DAG.getNode(ISD::AND, DL, IntVT, Cast, ClearSignMask);
1908 return DAG.getNode(ISD::BITCAST, DL, VT, ClearedSign);
1909}
1910
1911SDValue VectorLegalizer::ExpandFCOPYSIGN(SDNode *Node) {
1912 EVT VT = Node->getValueType(0);
1914
1915 if (VT != Node->getOperand(1).getValueType() ||
1916 !TLI.isOperationLegalOrCustom(ISD::AND, IntVT) ||
1917 !TLI.isOperationLegalOrCustom(ISD::OR, IntVT))
1918 return SDValue();
1919
1920 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
1921 if (!TLI.isOperationLegalOrCustomOrPromote(ISD::FSUB, VT) &&
1922 !VT.isScalableVector())
1923 return SDValue();
1924
1925 SDLoc DL(Node);
1926 SDValue Mag = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1927 SDValue Sign = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(1));
1928
1929 SDValue SignMask = DAG.getConstant(
1930 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1931 SDValue SignBit = DAG.getNode(ISD::AND, DL, IntVT, Sign, SignMask);
1932
1933 SDValue ClearSignMask = DAG.getConstant(
1935 SDValue ClearedSign = DAG.getNode(ISD::AND, DL, IntVT, Mag, ClearSignMask);
1936
1937 SDValue CopiedSign = DAG.getNode(ISD::OR, DL, IntVT, ClearedSign, SignBit,
1939
1940 return DAG.getNode(ISD::BITCAST, DL, VT, CopiedSign);
1941}
1942
1943void VectorLegalizer::ExpandFSUB(SDNode *Node,
1945 // For floating-point values, (a-b) is the same as a+(-b). If FNEG is legal,
1946 // we can defer this to operation legalization where it will be lowered as
1947 // a+(-b).
1948 EVT VT = Node->getValueType(0);
1949 if (TLI.isOperationLegalOrCustom(ISD::FNEG, VT) &&
1950 TLI.isOperationLegalOrCustom(ISD::FADD, VT))
1951 return; // Defer to LegalizeDAG
1952
1953 if (SDValue Expanded = TLI.expandVectorNaryOpBySplitting(Node, DAG)) {
1954 Results.push_back(Expanded);
1955 return;
1956 }
1957
1958 SDValue Tmp = DAG.UnrollVectorOp(Node);
1959 Results.push_back(Tmp);
1960}
1961
1962void VectorLegalizer::ExpandSETCC(SDNode *Node,
1964 bool NeedInvert = false;
1965 bool IsVP = Node->getOpcode() == ISD::VP_SETCC;
1966 bool IsStrict = Node->getOpcode() == ISD::STRICT_FSETCC ||
1967 Node->getOpcode() == ISD::STRICT_FSETCCS;
1968 bool IsSignaling = Node->getOpcode() == ISD::STRICT_FSETCCS;
1969 unsigned Offset = IsStrict ? 1 : 0;
1970
1971 SDValue Chain = IsStrict ? Node->getOperand(0) : SDValue();
1972 SDValue LHS = Node->getOperand(0 + Offset);
1973 SDValue RHS = Node->getOperand(1 + Offset);
1974 SDValue CC = Node->getOperand(2 + Offset);
1975
1976 MVT OpVT = LHS.getSimpleValueType();
1977 ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
1978
1979 if (TLI.getCondCodeAction(CCCode, OpVT) != TargetLowering::Expand) {
1980 if (IsStrict) {
1981 UnrollStrictFPOp(Node, Results);
1982 return;
1983 }
1984 Results.push_back(UnrollVSETCC(Node));
1985 return;
1986 }
1987
1988 SDValue Mask, EVL;
1989 if (IsVP) {
1990 Mask = Node->getOperand(3 + Offset);
1991 EVL = Node->getOperand(4 + Offset);
1992 }
1993
1994 SDLoc dl(Node);
1995 bool Legalized =
1996 TLI.LegalizeSetCCCondCode(DAG, Node->getValueType(0), LHS, RHS, CC, Mask,
1997 EVL, NeedInvert, dl, Chain, IsSignaling);
1998
1999 if (Legalized) {
2000 // If we expanded the SETCC by swapping LHS and RHS, or by inverting the
2001 // condition code, create a new SETCC node.
2002 if (CC.getNode()) {
2003 if (IsStrict) {
2004 LHS = DAG.getNode(Node->getOpcode(), dl, Node->getVTList(),
2005 {Chain, LHS, RHS, CC}, Node->getFlags());
2006 Chain = LHS.getValue(1);
2007 } else if (IsVP) {
2008 LHS = DAG.getNode(ISD::VP_SETCC, dl, Node->getValueType(0),
2009 {LHS, RHS, CC, Mask, EVL}, Node->getFlags());
2010 } else {
2011 LHS = DAG.getNode(ISD::SETCC, dl, Node->getValueType(0), LHS, RHS, CC,
2012 Node->getFlags());
2013 }
2014 }
2015
2016 // If we expanded the SETCC by inverting the condition code, then wrap
2017 // the existing SETCC in a NOT to restore the intended condition.
2018 if (NeedInvert) {
2019 if (!IsVP)
2020 LHS = DAG.getLogicalNOT(dl, LHS, LHS->getValueType(0));
2021 else
2022 LHS = DAG.getVPLogicalNOT(dl, LHS, Mask, EVL, LHS->getValueType(0));
2023 }
2024 } else {
2025 assert(!IsStrict && "Don't know how to expand for strict nodes.");
2026
2027 // Otherwise, SETCC for the given comparison type must be completely
2028 // illegal; expand it into a SELECT_CC.
2029 EVT VT = Node->getValueType(0);
2030 LHS =
2031 DAG.getNode(ISD::SELECT_CC, dl, VT, LHS, RHS,
2032 DAG.getBoolConstant(true, dl, VT, LHS.getValueType()),
2033 DAG.getBoolConstant(false, dl, VT, LHS.getValueType()), CC);
2034 LHS->setFlags(Node->getFlags());
2035 }
2036
2037 Results.push_back(LHS);
2038 if (IsStrict)
2039 Results.push_back(Chain);
2040}
2041
2042void VectorLegalizer::ExpandUADDSUBO(SDNode *Node,
2044 SDValue Result, Overflow;
2045 TLI.expandUADDSUBO(Node, Result, Overflow, DAG);
2046 Results.push_back(Result);
2047 Results.push_back(Overflow);
2048}
2049
2050void VectorLegalizer::ExpandSADDSUBO(SDNode *Node,
2052 SDValue Result, Overflow;
2053 TLI.expandSADDSUBO(Node, Result, Overflow, DAG);
2054 Results.push_back(Result);
2055 Results.push_back(Overflow);
2056}
2057
2058void VectorLegalizer::ExpandMULO(SDNode *Node,
2060 SDValue Result, Overflow;
2061 if (!TLI.expandMULO(Node, Result, Overflow, DAG))
2062 std::tie(Result, Overflow) = DAG.UnrollVectorOverflowOp(Node);
2063
2064 Results.push_back(Result);
2065 Results.push_back(Overflow);
2066}
2067
2068void VectorLegalizer::ExpandFixedPointDiv(SDNode *Node,
2070 SDNode *N = Node;
2071 if (SDValue Expanded = TLI.expandFixedPointDiv(N->getOpcode(), SDLoc(N),
2072 N->getOperand(0), N->getOperand(1), N->getConstantOperandVal(2), DAG))
2073 Results.push_back(Expanded);
2074}
2075
2076void VectorLegalizer::ExpandStrictFPOp(SDNode *Node,
2078 if (Node->getOpcode() == ISD::STRICT_UINT_TO_FP) {
2079 ExpandUINT_TO_FLOAT(Node, Results);
2080 return;
2081 }
2082 if (Node->getOpcode() == ISD::STRICT_FP_TO_UINT) {
2083 ExpandFP_TO_UINT(Node, Results);
2084 return;
2085 }
2086
2087 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2088 Node->getOpcode() == ISD::STRICT_FSETCCS) {
2089 ExpandSETCC(Node, Results);
2090 return;
2091 }
2092
2093 UnrollStrictFPOp(Node, Results);
2094}
2095
2096void VectorLegalizer::ExpandREM(SDNode *Node,
2098 assert((Node->getOpcode() == ISD::SREM || Node->getOpcode() == ISD::UREM) &&
2099 "Expected REM node");
2100
2102 if (!TLI.expandREM(Node, Result, DAG))
2103 Result = DAG.UnrollVectorOp(Node);
2104 Results.push_back(Result);
2105}
2106
2107// Try to expand libm nodes into vector math routine calls. Callers provide the
2108// LibFunc equivalent of the passed in Node, which is used to lookup mappings
2109// within TargetLibraryInfo. The only mappings considered are those where the
2110// result and all operands are the same vector type. While predicated nodes are
2111// not supported, we will emit calls to masked routines by passing in an all
2112// true mask.
2113bool VectorLegalizer::tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
2115 // Chain must be propagated but currently strict fp operations are down
2116 // converted to their none strict counterpart.
2117 assert(!Node->isStrictFPOpcode() && "Unexpected strict fp operation!");
2118
2119 const char *LCName = TLI.getLibcallName(LC);
2120 if (!LCName)
2121 return false;
2122 LLVM_DEBUG(dbgs() << "Looking for vector variant of " << LCName << "\n");
2123
2124 EVT VT = Node->getValueType(0);
2126
2127 // Lookup a vector function equivalent to the specified libcall. Prefer
2128 // unmasked variants but we will generate a mask if need be.
2129 const TargetLibraryInfo &TLibInfo = DAG.getLibInfo();
2130 const VecDesc *VD = TLibInfo.getVectorMappingInfo(LCName, VL, false);
2131 if (!VD)
2132 VD = TLibInfo.getVectorMappingInfo(LCName, VL, /*Masked=*/true);
2133 if (!VD)
2134 return false;
2135
2136 LLVMContext *Ctx = DAG.getContext();
2137 Type *Ty = VT.getTypeForEVT(*Ctx);
2138 Type *ScalarTy = Ty->getScalarType();
2139
2140 // Construct a scalar function type based on Node's operands.
2142 for (unsigned i = 0; i < Node->getNumOperands(); ++i) {
2143 assert(Node->getOperand(i).getValueType() == VT &&
2144 "Expected matching vector types!");
2145 ArgTys.push_back(ScalarTy);
2146 }
2147 FunctionType *ScalarFTy = FunctionType::get(ScalarTy, ArgTys, false);
2148
2149 // Generate call information for the vector function.
2150 const std::string MangledName = VD->getVectorFunctionABIVariantString();
2151 auto OptVFInfo = VFABI::tryDemangleForVFABI(MangledName, ScalarFTy);
2152 if (!OptVFInfo)
2153 return false;
2154
2155 LLVM_DEBUG(dbgs() << "Found vector variant " << VD->getVectorFnName()
2156 << "\n");
2157
2158 // Sanity check just in case OptVFInfo has unexpected parameters.
2159 if (OptVFInfo->Shape.Parameters.size() !=
2160 Node->getNumOperands() + VD->isMasked())
2161 return false;
2162
2163 // Collect vector call operands.
2164
2165 SDLoc DL(Node);
2168 Entry.IsSExt = false;
2169 Entry.IsZExt = false;
2170
2171 unsigned OpNum = 0;
2172 for (auto &VFParam : OptVFInfo->Shape.Parameters) {
2173 if (VFParam.ParamKind == VFParamKind::GlobalPredicate) {
2174 EVT MaskVT = TLI.getSetCCResultType(DAG.getDataLayout(), *Ctx, VT);
2175 Entry.Node = DAG.getBoolConstant(true, DL, MaskVT, VT);
2176 Entry.Ty = MaskVT.getTypeForEVT(*Ctx);
2177 Args.push_back(Entry);
2178 continue;
2179 }
2180
2181 // Only vector operands are supported.
2182 if (VFParam.ParamKind != VFParamKind::Vector)
2183 return false;
2184
2185 Entry.Node = Node->getOperand(OpNum++);
2186 Entry.Ty = Ty;
2187 Args.push_back(Entry);
2188 }
2189
2190 // Emit a call to the vector function.
2191 SDValue Callee = DAG.getExternalSymbol(VD->getVectorFnName().data(),
2192 TLI.getPointerTy(DAG.getDataLayout()));
2194 CLI.setDebugLoc(DL)
2195 .setChain(DAG.getEntryNode())
2196 .setLibCallee(CallingConv::C, Ty, Callee, std::move(Args));
2197
2198 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
2199 Results.push_back(CallResult.first);
2200 return true;
2201}
2202
2203/// Try to expand the node to a vector libcall based on the result type.
2204bool VectorLegalizer::tryExpandVecMathCall(
2205 SDNode *Node, RTLIB::Libcall Call_F32, RTLIB::Libcall Call_F64,
2206 RTLIB::Libcall Call_F80, RTLIB::Libcall Call_F128,
2209 Node->getValueType(0).getVectorElementType(), Call_F32, Call_F64,
2210 Call_F80, Call_F128, Call_PPCF128);
2211
2212 if (LC == RTLIB::UNKNOWN_LIBCALL)
2213 return false;
2214
2215 return tryExpandVecMathCall(Node, LC, Results);
2216}
2217
2218void VectorLegalizer::UnrollStrictFPOp(SDNode *Node,
2220 EVT VT = Node->getValueType(0);
2221 EVT EltVT = VT.getVectorElementType();
2222 unsigned NumElems = VT.getVectorNumElements();
2223 unsigned NumOpers = Node->getNumOperands();
2224 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
2225
2226 EVT TmpEltVT = EltVT;
2227 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2228 Node->getOpcode() == ISD::STRICT_FSETCCS)
2229 TmpEltVT = TLI.getSetCCResultType(DAG.getDataLayout(),
2230 *DAG.getContext(), TmpEltVT);
2231
2232 EVT ValueVTs[] = {TmpEltVT, MVT::Other};
2233 SDValue Chain = Node->getOperand(0);
2234 SDLoc dl(Node);
2235
2236 SmallVector<SDValue, 32> OpValues;
2237 SmallVector<SDValue, 32> OpChains;
2238 for (unsigned i = 0; i < NumElems; ++i) {
2240 SDValue Idx = DAG.getVectorIdxConstant(i, dl);
2241
2242 // The Chain is the first operand.
2243 Opers.push_back(Chain);
2244
2245 // Now process the remaining operands.
2246 for (unsigned j = 1; j < NumOpers; ++j) {
2247 SDValue Oper = Node->getOperand(j);
2248 EVT OperVT = Oper.getValueType();
2249
2250 if (OperVT.isVector())
2251 Oper = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
2252 OperVT.getVectorElementType(), Oper, Idx);
2253
2254 Opers.push_back(Oper);
2255 }
2256
2257 SDValue ScalarOp = DAG.getNode(Node->getOpcode(), dl, ValueVTs, Opers);
2258 SDValue ScalarResult = ScalarOp.getValue(0);
2259 SDValue ScalarChain = ScalarOp.getValue(1);
2260
2261 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2262 Node->getOpcode() == ISD::STRICT_FSETCCS)
2263 ScalarResult = DAG.getSelect(dl, EltVT, ScalarResult,
2264 DAG.getAllOnesConstant(dl, EltVT),
2265 DAG.getConstant(0, dl, EltVT));
2266
2267 OpValues.push_back(ScalarResult);
2268 OpChains.push_back(ScalarChain);
2269 }
2270
2271 SDValue Result = DAG.getBuildVector(VT, dl, OpValues);
2272 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OpChains);
2273
2274 Results.push_back(Result);
2275 Results.push_back(NewChain);
2276}
2277
2278SDValue VectorLegalizer::UnrollVSETCC(SDNode *Node) {
2279 EVT VT = Node->getValueType(0);
2280 unsigned NumElems = VT.getVectorNumElements();
2281 EVT EltVT = VT.getVectorElementType();
2282 SDValue LHS = Node->getOperand(0);
2283 SDValue RHS = Node->getOperand(1);
2284 SDValue CC = Node->getOperand(2);
2285 EVT TmpEltVT = LHS.getValueType().getVectorElementType();
2286 SDLoc dl(Node);
2287 SmallVector<SDValue, 8> Ops(NumElems);
2288 for (unsigned i = 0; i < NumElems; ++i) {
2289 SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS,
2290 DAG.getVectorIdxConstant(i, dl));
2291 SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS,
2292 DAG.getVectorIdxConstant(i, dl));
2293 // FIXME: We should use i1 setcc + boolext here, but it causes regressions.
2294 Ops[i] = DAG.getNode(ISD::SETCC, dl,
2295 TLI.getSetCCResultType(DAG.getDataLayout(),
2296 *DAG.getContext(), TmpEltVT),
2297 LHSElem, RHSElem, CC);
2298 Ops[i] = DAG.getSelect(dl, EltVT, Ops[i],
2299 DAG.getBoolConstant(true, dl, EltVT, VT),
2300 DAG.getConstant(0, dl, EltVT));
2301 }
2302 return DAG.getBuildVector(VT, dl, Ops);
2303}
2304
2306 return VectorLegalizer(*this).Run();
2307}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
BlockVerifier::State From
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(...)
Definition: Debug.h:106
This file defines the DenseMap class.
static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl< int > &ShuffleMask)
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file describes how to lower LLVM code to machine code.
Value * RHS
Value * LHS
BinaryOperator * Mul
DEMANGLE_DUMP_METHOD void dump() const
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition: APInt.h:229
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition: APInt.h:209
This class represents an Operation in the Expression.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
size_t size() const
Definition: Function.h:858
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
This class is used to represent ISD::LOAD nodes.
Machine Value Type.
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
MVT getVectorElementType() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:310
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:228
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:503
ilist< SDNode >::iterator allnodes_iterator
Definition: SelectionDAG.h:560
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void resize(size_type N)
Definition: SmallVector.h:638
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
This class is used to represent ISD::STORE nodes.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:144
Provides information about what library functions are available for the current target.
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
std::vector< ArgListEntry > ArgListTy
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:355
Provides info so a possible vectorization of a function can be computed.
bool isMasked() const
std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getVectorFnName() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:125
@ Entry
Definition: COFF.h:844
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:780
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:243
@ CTLZ_ZERO_UNDEF
Definition: ISDOpcodes.h:753
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition: ISDOpcodes.h:491
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition: ISDOpcodes.h:1417
@ VECREDUCE_SMIN
Definition: ISDOpcodes.h:1450
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:257
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
Definition: ISDOpcodes.h:574
@ BSWAP
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:744
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition: ISDOpcodes.h:374
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:246
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1102
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:380
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:814
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:498
@ FATAN2
FATAN2 - atan2, inspired by libm.
Definition: ISDOpcodes.h:999
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:841
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:1435
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:397
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
Definition: ISDOpcodes.h:1439
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:717
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:871
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:262
@ VECREDUCE_SMAX
Definition: ISDOpcodes.h:1449
@ STRICT_FSETCCS
Definition: ISDOpcodes.h:492
@ FPTRUNC_ROUND
FPTRUNC_ROUND - This corresponds to the fptrunc_round intrinsic.
Definition: ISDOpcodes.h:495
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:954
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:997
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition: ISDOpcodes.h:387
@ STRICT_FSQRT
Constrained versions of libm-equivalent floating point intrinsics.
Definition: ISDOpcodes.h:418
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:805
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition: ISDOpcodes.h:685
@ STRICT_UINT_TO_FP
Definition: ISDOpcodes.h:465
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition: ISDOpcodes.h:1432
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:752
@ VECREDUCE_FMIN
Definition: ISDOpcodes.h:1436
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:1059
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:981
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:334
@ STEP_VECTOR
STEP_VECTOR(IMM) - Returns a scalable vector whose lanes are comprised of a linear sequence of unsign...
Definition: ISDOpcodes.h:661
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition: ISDOpcodes.h:515
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition: ISDOpcodes.h:356
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:757
@ VECREDUCE_UMAX
Definition: ISDOpcodes.h:1451
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:642
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:330
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
Definition: ISDOpcodes.h:1444
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:674
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:735
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:1044
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:550
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:811
@ FP_TO_UINT_SAT
Definition: ISDOpcodes.h:907
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:772
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:1031
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition: ISDOpcodes.h:366
@ SMULO
Same for multiplication.
Definition: ISDOpcodes.h:338
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:860
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:849
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:697
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:393
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:939
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:766
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
Definition: ISDOpcodes.h:464
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
Definition: ISDOpcodes.h:1372
@ VECREDUCE_UMIN
Definition: ISDOpcodes.h:1452
@ STRICT_FP_TO_UINT
Definition: ISDOpcodes.h:458
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
Definition: ISDOpcodes.h:480
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:457
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:1050
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:887
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:485
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:709
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition: ISDOpcodes.h:705
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition: ISDOpcodes.h:680
@ VECREDUCE_FMUL
Definition: ISDOpcodes.h:1433
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition: ISDOpcodes.h:407
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:52
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
Definition: ISDOpcodes.h:1004
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:920
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition: ISDOpcodes.h:669
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:882
@ FP_TO_SINT_SAT
FP_TO_[US]INT_SAT - Convert floating point value in operand 0 to a signed or unsigned scalar integer ...
Definition: ISDOpcodes.h:906
@ VECREDUCE_FMINIMUM
Definition: ISDOpcodes.h:1440
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:817
@ VECREDUCE_SEQ_FMUL
Definition: ISDOpcodes.h:1418
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:61
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:508
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:347
@ AssertZext
Definition: ISDOpcodes.h:62
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
Definition: ISDOpcodes.h:1055
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition: ISDOpcodes.h:692
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition: ISDOpcodes.h:530
std::optional< unsigned > getVPMaskIdx(unsigned Opcode)
The operand position of the vector mask.
std::optional< unsigned > getVPExplicitVectorLengthIdx(unsigned Opcode)
The operand position of the explicit vector length parameter.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1606
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:1586
bool isVPOpcode(unsigned Opcode)
Whether this is a vector-predicated Opcode.
Libcall getFSINCOS(EVT RetVT)
getFSINCOS - Return the FSINCOS_* value for the given types, or UNKNOWN_LIBCALL if there is none.
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
Libcall getFPLibCall(EVT VT, Libcall Call_F32, Libcall Call_F64, Libcall Call_F80, Libcall Call_F128, Libcall Call_PPCF128)
GetFPLibCall - Helper to return the right libcall for the given floating point type,...
std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)
Function to construct a VFInfo out of a mangled names in the following format:
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1746
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
@ Xor
Bitwise or logical XOR of integers.
DWARFExpression::Operation Op
#define N
Extended Value Type.
Definition: ValueTypes.h:35
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:94
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition: ValueTypes.h:74
ElementCount getVectorElementCount() const
Definition: ValueTypes.h:345
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
uint64_t getScalarSizeInBits() const
Definition: ValueTypes.h:380
bool isFixedLengthVector() const
Definition: ValueTypes.h:181
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:168
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:318
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:210
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition: ValueTypes.h:174
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:323
EVT changeVectorElementType(EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
Definition: ValueTypes.h:102
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:331
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:303
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This structure contains all information that is necessary for lowering calls.