LLVM 19.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 ExpandSELECT(SDNode *Node);
139 std::pair<SDValue, SDValue> ExpandLoad(SDNode *N);
140 SDValue ExpandStore(SDNode *N);
141 SDValue ExpandFNEG(SDNode *Node);
142 void ExpandFSUB(SDNode *Node, SmallVectorImpl<SDValue> &Results);
143 void ExpandSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
144 void ExpandBITREVERSE(SDNode *Node, SmallVectorImpl<SDValue> &Results);
145 void ExpandUADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
146 void ExpandSADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
147 void ExpandMULO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
148 void ExpandFixedPointDiv(SDNode *Node, SmallVectorImpl<SDValue> &Results);
149 void ExpandStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
150 void ExpandREM(SDNode *Node, SmallVectorImpl<SDValue> &Results);
151
152 bool tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
154 bool tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall Call_F32,
155 RTLIB::Libcall Call_F64, RTLIB::Libcall Call_F80,
156 RTLIB::Libcall Call_F128,
157 RTLIB::Libcall Call_PPCF128,
159
160 void UnrollStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
161
162 /// Implements vector promotion.
163 ///
164 /// This is essentially just bitcasting the operands to a different type and
165 /// bitcasting the result back to the original type.
167
168 /// Implements [SU]INT_TO_FP vector promotion.
169 ///
170 /// This is a [zs]ext of the input operand to a larger integer type.
171 void PromoteINT_TO_FP(SDNode *Node, SmallVectorImpl<SDValue> &Results);
172
173 /// Implements FP_TO_[SU]INT vector promotion of the result type.
174 ///
175 /// It is promoted to a larger integer type. The result is then
176 /// truncated back to the original type.
177 void PromoteFP_TO_INT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
178
179 /// Implements vector setcc operation promotion.
180 ///
181 /// All vector operands are promoted to a vector type with larger element
182 /// type.
183 void PromoteSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
184
185 void PromoteSTRICT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
186
187public:
188 VectorLegalizer(SelectionDAG& dag) :
189 DAG(dag), TLI(dag.getTargetLoweringInfo()) {}
190
191 /// Begin legalizer the vector operations in the DAG.
192 bool Run();
193};
194
195} // end anonymous namespace
196
197bool VectorLegalizer::Run() {
198 // Before we start legalizing vector nodes, check if there are any vectors.
199 bool HasVectors = false;
200 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
201 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) {
202 // Check if the values of the nodes contain vectors. We don't need to check
203 // the operands because we are going to check their values at some point.
204 HasVectors = llvm::any_of(I->values(), [](EVT T) { return T.isVector(); });
205
206 // If we found a vector node we can start the legalization.
207 if (HasVectors)
208 break;
209 }
210
211 // If this basic block has no vectors then no need to legalize vectors.
212 if (!HasVectors)
213 return false;
214
215 // The legalize process is inherently a bottom-up recursive process (users
216 // legalize their uses before themselves). Given infinite stack space, we
217 // could just start legalizing on the root and traverse the whole graph. In
218 // practice however, this causes us to run out of stack space on large basic
219 // blocks. To avoid this problem, compute an ordering of the nodes where each
220 // node is only legalized after all of its operands are legalized.
221 DAG.AssignTopologicalOrder();
222 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
223 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I)
224 LegalizeOp(SDValue(&*I, 0));
225
226 // Finally, it's possible the root changed. Get the new root.
227 SDValue OldRoot = DAG.getRoot();
228 assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
229 DAG.setRoot(LegalizedNodes[OldRoot]);
230
231 LegalizedNodes.clear();
232
233 // Remove dead nodes now.
234 DAG.RemoveDeadNodes();
235
236 return Changed;
237}
238
239SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDNode *Result) {
240 assert(Op->getNumValues() == Result->getNumValues() &&
241 "Unexpected number of results");
242 // Generic legalization: just pass the operand through.
243 for (unsigned i = 0, e = Op->getNumValues(); i != e; ++i)
244 AddLegalizedOperand(Op.getValue(i), SDValue(Result, i));
245 return SDValue(Result, Op.getResNo());
246}
247
249VectorLegalizer::RecursivelyLegalizeResults(SDValue Op,
251 assert(Results.size() == Op->getNumValues() &&
252 "Unexpected number of results");
253 // Make sure that the generated code is itself legal.
254 for (unsigned i = 0, e = Results.size(); i != e; ++i) {
255 Results[i] = LegalizeOp(Results[i]);
256 AddLegalizedOperand(Op.getValue(i), Results[i]);
257 }
258
259 return Results[Op.getResNo()];
260}
261
262SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
263 // Note that LegalizeOp may be reentered even from single-use nodes, which
264 // means that we always must cache transformed nodes.
265 DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
266 if (I != LegalizedNodes.end()) return I->second;
267
268 // Legalize the operands
270 for (const SDValue &Oper : Op->op_values())
271 Ops.push_back(LegalizeOp(Oper));
272
273 SDNode *Node = DAG.UpdateNodeOperands(Op.getNode(), Ops);
274
275 bool HasVectorValueOrOp =
276 llvm::any_of(Node->values(), [](EVT T) { return T.isVector(); }) ||
277 llvm::any_of(Node->op_values(),
278 [](SDValue O) { return O.getValueType().isVector(); });
279 if (!HasVectorValueOrOp)
280 return TranslateLegalizeResults(Op, Node);
281
282 TargetLowering::LegalizeAction Action = TargetLowering::Legal;
283 EVT ValVT;
284 switch (Op.getOpcode()) {
285 default:
286 return TranslateLegalizeResults(Op, Node);
287 case ISD::LOAD: {
288 LoadSDNode *LD = cast<LoadSDNode>(Node);
289 ISD::LoadExtType ExtType = LD->getExtensionType();
290 EVT LoadedVT = LD->getMemoryVT();
291 if (LoadedVT.isVector() && ExtType != ISD::NON_EXTLOAD)
292 Action = TLI.getLoadExtAction(ExtType, LD->getValueType(0), LoadedVT);
293 break;
294 }
295 case ISD::STORE: {
296 StoreSDNode *ST = cast<StoreSDNode>(Node);
297 EVT StVT = ST->getMemoryVT();
298 MVT ValVT = ST->getValue().getSimpleValueType();
299 if (StVT.isVector() && ST->isTruncatingStore())
300 Action = TLI.getTruncStoreAction(ValVT, StVT);
301 break;
302 }
304 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
305 // This operation lies about being legal: when it claims to be legal,
306 // it should actually be expanded.
307 if (Action == TargetLowering::Legal)
308 Action = TargetLowering::Expand;
309 break;
310#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
311 case ISD::STRICT_##DAGN:
312#include "llvm/IR/ConstrainedOps.def"
313 ValVT = Node->getValueType(0);
314 if (Op.getOpcode() == ISD::STRICT_SINT_TO_FP ||
315 Op.getOpcode() == ISD::STRICT_UINT_TO_FP)
316 ValVT = Node->getOperand(1).getValueType();
317 if (Op.getOpcode() == ISD::STRICT_FSETCC ||
318 Op.getOpcode() == ISD::STRICT_FSETCCS) {
319 MVT OpVT = Node->getOperand(1).getSimpleValueType();
320 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(3))->get();
321 Action = TLI.getCondCodeAction(CCCode, OpVT);
322 if (Action == TargetLowering::Legal)
323 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
324 } else {
325 Action = TLI.getOperationAction(Node->getOpcode(), ValVT);
326 }
327 // If we're asked to expand a strict vector floating-point operation,
328 // by default we're going to simply unroll it. That is usually the
329 // best approach, except in the case where the resulting strict (scalar)
330 // operations would themselves use the fallback mutation to non-strict.
331 // In that specific case, just do the fallback on the vector op.
332 if (Action == TargetLowering::Expand && !TLI.isStrictFPEnabled() &&
333 TLI.getStrictFPOperationAction(Node->getOpcode(), ValVT) ==
334 TargetLowering::Legal) {
335 EVT EltVT = ValVT.getVectorElementType();
336 if (TLI.getOperationAction(Node->getOpcode(), EltVT)
337 == TargetLowering::Expand &&
338 TLI.getStrictFPOperationAction(Node->getOpcode(), EltVT)
339 == TargetLowering::Legal)
340 Action = TargetLowering::Legal;
341 }
342 break;
343 case ISD::ADD:
344 case ISD::SUB:
345 case ISD::MUL:
346 case ISD::MULHS:
347 case ISD::MULHU:
348 case ISD::SDIV:
349 case ISD::UDIV:
350 case ISD::SREM:
351 case ISD::UREM:
352 case ISD::SDIVREM:
353 case ISD::UDIVREM:
354 case ISD::FADD:
355 case ISD::FSUB:
356 case ISD::FMUL:
357 case ISD::FDIV:
358 case ISD::FREM:
359 case ISD::AND:
360 case ISD::OR:
361 case ISD::XOR:
362 case ISD::SHL:
363 case ISD::SRA:
364 case ISD::SRL:
365 case ISD::FSHL:
366 case ISD::FSHR:
367 case ISD::ROTL:
368 case ISD::ROTR:
369 case ISD::ABS:
370 case ISD::ABDS:
371 case ISD::ABDU:
372 case ISD::BSWAP:
373 case ISD::BITREVERSE:
374 case ISD::CTLZ:
375 case ISD::CTTZ:
378 case ISD::CTPOP:
379 case ISD::SELECT:
380 case ISD::VSELECT:
381 case ISD::SELECT_CC:
382 case ISD::ZERO_EXTEND:
383 case ISD::ANY_EXTEND:
384 case ISD::TRUNCATE:
385 case ISD::SIGN_EXTEND:
386 case ISD::FP_TO_SINT:
387 case ISD::FP_TO_UINT:
388 case ISD::FNEG:
389 case ISD::FABS:
390 case ISD::FMINNUM:
391 case ISD::FMAXNUM:
394 case ISD::FMINIMUM:
395 case ISD::FMAXIMUM:
396 case ISD::FCOPYSIGN:
397 case ISD::FSQRT:
398 case ISD::FSIN:
399 case ISD::FCOS:
400 case ISD::FTAN:
401 case ISD::FLDEXP:
402 case ISD::FPOWI:
403 case ISD::FPOW:
404 case ISD::FLOG:
405 case ISD::FLOG2:
406 case ISD::FLOG10:
407 case ISD::FEXP:
408 case ISD::FEXP2:
409 case ISD::FEXP10:
410 case ISD::FCEIL:
411 case ISD::FTRUNC:
412 case ISD::FRINT:
413 case ISD::FNEARBYINT:
414 case ISD::FROUND:
415 case ISD::FROUNDEVEN:
416 case ISD::FFLOOR:
417 case ISD::FP_ROUND:
418 case ISD::FP_EXTEND:
420 case ISD::FMA:
425 case ISD::SMIN:
426 case ISD::SMAX:
427 case ISD::UMIN:
428 case ISD::UMAX:
429 case ISD::SMUL_LOHI:
430 case ISD::UMUL_LOHI:
431 case ISD::SADDO:
432 case ISD::UADDO:
433 case ISD::SSUBO:
434 case ISD::USUBO:
435 case ISD::SMULO:
436 case ISD::UMULO:
438 case ISD::FFREXP:
439 case ISD::SADDSAT:
440 case ISD::UADDSAT:
441 case ISD::SSUBSAT:
442 case ISD::USUBSAT:
443 case ISD::SSHLSAT:
444 case ISD::USHLSAT:
447 case ISD::MGATHER:
448 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
449 break;
450 case ISD::SMULFIX:
451 case ISD::SMULFIXSAT:
452 case ISD::UMULFIX:
453 case ISD::UMULFIXSAT:
454 case ISD::SDIVFIX:
455 case ISD::SDIVFIXSAT:
456 case ISD::UDIVFIX:
457 case ISD::UDIVFIXSAT: {
458 unsigned Scale = Node->getConstantOperandVal(2);
459 Action = TLI.getFixedPointOperationAction(Node->getOpcode(),
460 Node->getValueType(0), Scale);
461 break;
462 }
463 case ISD::LRINT:
464 case ISD::LLRINT:
465 case ISD::SINT_TO_FP:
466 case ISD::UINT_TO_FP:
482 Action = TLI.getOperationAction(Node->getOpcode(),
483 Node->getOperand(0).getValueType());
484 break;
487 Action = TLI.getOperationAction(Node->getOpcode(),
488 Node->getOperand(1).getValueType());
489 break;
490 case ISD::SETCC: {
491 MVT OpVT = Node->getOperand(0).getSimpleValueType();
492 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get();
493 Action = TLI.getCondCodeAction(CCCode, OpVT);
494 if (Action == TargetLowering::Legal)
495 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
496 break;
497 }
498
499#define BEGIN_REGISTER_VP_SDNODE(VPID, LEGALPOS, ...) \
500 case ISD::VPID: { \
501 EVT LegalizeVT = LEGALPOS < 0 ? Node->getValueType(-(1 + LEGALPOS)) \
502 : Node->getOperand(LEGALPOS).getValueType(); \
503 if (ISD::VPID == ISD::VP_SETCC) { \
504 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get(); \
505 Action = TLI.getCondCodeAction(CCCode, LegalizeVT.getSimpleVT()); \
506 if (Action != TargetLowering::Legal) \
507 break; \
508 } \
509 /* Defer non-vector results to LegalizeDAG. */ \
510 if (!Node->getValueType(0).isVector() && \
511 Node->getValueType(0) != MVT::Other) { \
512 Action = TargetLowering::Legal; \
513 break; \
514 } \
515 Action = TLI.getOperationAction(Node->getOpcode(), LegalizeVT); \
516 } break;
517#include "llvm/IR/VPIntrinsics.def"
518 }
519
520 LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG));
521
522 SmallVector<SDValue, 8> ResultVals;
523 switch (Action) {
524 default: llvm_unreachable("This action is not supported yet!");
525 case TargetLowering::Promote:
526 assert((Op.getOpcode() != ISD::LOAD && Op.getOpcode() != ISD::STORE) &&
527 "This action is not supported yet!");
528 LLVM_DEBUG(dbgs() << "Promoting\n");
529 Promote(Node, ResultVals);
530 assert(!ResultVals.empty() && "No results for promotion?");
531 break;
532 case TargetLowering::Legal:
533 LLVM_DEBUG(dbgs() << "Legal node: nothing to do\n");
534 break;
535 case TargetLowering::Custom:
536 LLVM_DEBUG(dbgs() << "Trying custom legalization\n");
537 if (LowerOperationWrapper(Node, ResultVals))
538 break;
539 LLVM_DEBUG(dbgs() << "Could not custom legalize node\n");
540 [[fallthrough]];
541 case TargetLowering::Expand:
542 LLVM_DEBUG(dbgs() << "Expanding\n");
543 Expand(Node, ResultVals);
544 break;
545 }
546
547 if (ResultVals.empty())
548 return TranslateLegalizeResults(Op, Node);
549
550 Changed = true;
551 return RecursivelyLegalizeResults(Op, ResultVals);
552}
553
554// FIXME: This is very similar to TargetLowering::LowerOperationWrapper. Can we
555// merge them somehow?
556bool VectorLegalizer::LowerOperationWrapper(SDNode *Node,
558 SDValue Res = TLI.LowerOperation(SDValue(Node, 0), DAG);
559
560 if (!Res.getNode())
561 return false;
562
563 if (Res == SDValue(Node, 0))
564 return true;
565
566 // If the original node has one result, take the return value from
567 // LowerOperation as is. It might not be result number 0.
568 if (Node->getNumValues() == 1) {
569 Results.push_back(Res);
570 return true;
571 }
572
573 // If the original node has multiple results, then the return node should
574 // have the same number of results.
575 assert((Node->getNumValues() == Res->getNumValues()) &&
576 "Lowering returned the wrong number of results!");
577
578 // Places new result values base on N result number.
579 for (unsigned I = 0, E = Node->getNumValues(); I != E; ++I)
580 Results.push_back(Res.getValue(I));
581
582 return true;
583}
584
585void VectorLegalizer::PromoteSETCC(SDNode *Node,
587 MVT VecVT = Node->getOperand(0).getSimpleValueType();
588 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
589
590 unsigned ExtOp = VecVT.isFloatingPoint() ? ISD::FP_EXTEND : ISD::ANY_EXTEND;
591
592 SDLoc DL(Node);
593 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
594
595 Operands[0] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(0));
596 Operands[1] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(1));
597 Operands[2] = Node->getOperand(2);
598
599 if (Node->getOpcode() == ISD::VP_SETCC) {
600 Operands[3] = Node->getOperand(3); // mask
601 Operands[4] = Node->getOperand(4); // evl
602 }
603
604 SDValue Res = DAG.getNode(Node->getOpcode(), DL, Node->getSimpleValueType(0),
605 Operands, Node->getFlags());
606
607 Results.push_back(Res);
608}
609
610void VectorLegalizer::PromoteSTRICT(SDNode *Node,
612 MVT VecVT = Node->getOperand(1).getSimpleValueType();
613 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
614
615 assert(VecVT.isFloatingPoint());
616
617 SDLoc DL(Node);
618 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
620
621 for (unsigned j = 1; j != Node->getNumOperands(); ++j)
622 if (Node->getOperand(j).getValueType().isVector() &&
623 !(ISD::isVPOpcode(Node->getOpcode()) &&
624 ISD::getVPMaskIdx(Node->getOpcode()) == j)) // Skip mask operand.
625 {
626 // promote the vector operand.
627 SDValue Ext =
628 DAG.getNode(ISD::STRICT_FP_EXTEND, DL, {NewVecVT, MVT::Other},
629 {Node->getOperand(0), Node->getOperand(j)});
630 Operands[j] = Ext.getValue(0);
631 Chains.push_back(Ext.getValue(1));
632 } else
633 Operands[j] = Node->getOperand(j); // Skip no vector operand.
634
635 SDVTList VTs = DAG.getVTList(NewVecVT, Node->getValueType(1));
636
637 Operands[0] = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
638
639 SDValue Res =
640 DAG.getNode(Node->getOpcode(), DL, VTs, Operands, Node->getFlags());
641
642 SDValue Round =
643 DAG.getNode(ISD::STRICT_FP_ROUND, DL, {VecVT, MVT::Other},
644 {Res.getValue(1), Res.getValue(0),
645 DAG.getIntPtrConstant(0, DL, /*isTarget=*/true)});
646
647 Results.push_back(Round.getValue(0));
648 Results.push_back(Round.getValue(1));
649}
650
651void VectorLegalizer::Promote(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
652 // For a few operations there is a specific concept for promotion based on
653 // the operand's type.
654 switch (Node->getOpcode()) {
655 case ISD::SINT_TO_FP:
656 case ISD::UINT_TO_FP:
659 // "Promote" the operation by extending the operand.
660 PromoteINT_TO_FP(Node, Results);
661 return;
662 case ISD::FP_TO_UINT:
663 case ISD::FP_TO_SINT:
666 // Promote the operation by extending the operand.
667 PromoteFP_TO_INT(Node, Results);
668 return;
669 case ISD::VP_SETCC:
670 case ISD::SETCC:
671 // Promote the operation by extending the operand.
672 PromoteSETCC(Node, Results);
673 return;
674 case ISD::STRICT_FADD:
675 case ISD::STRICT_FSUB:
676 case ISD::STRICT_FMUL:
677 case ISD::STRICT_FDIV:
679 case ISD::STRICT_FMA:
680 PromoteSTRICT(Node, Results);
681 return;
682 case ISD::FP_ROUND:
683 case ISD::FP_EXTEND:
684 // These operations are used to do promotion so they can't be promoted
685 // themselves.
686 llvm_unreachable("Don't know how to promote this operation!");
687 }
688
689 // There are currently two cases of vector promotion:
690 // 1) Bitcasting a vector of integers to a different type to a vector of the
691 // same overall length. For example, x86 promotes ISD::AND v2i32 to v1i64.
692 // 2) Extending a vector of floats to a vector of the same number of larger
693 // floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32.
694 assert(Node->getNumValues() == 1 &&
695 "Can't promote a vector with multiple results!");
696 MVT VT = Node->getSimpleValueType(0);
697 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
698 SDLoc dl(Node);
699 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
700
701 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
702 // Do not promote the mask operand of a VP OP.
703 bool SkipPromote = ISD::isVPOpcode(Node->getOpcode()) &&
704 ISD::getVPMaskIdx(Node->getOpcode()) == j;
705 if (Node->getOperand(j).getValueType().isVector() && !SkipPromote)
706 if (Node->getOperand(j)
707 .getValueType()
708 .getVectorElementType()
709 .isFloatingPoint() &&
711 Operands[j] = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(j));
712 else
713 Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Node->getOperand(j));
714 else
715 Operands[j] = Node->getOperand(j);
716 }
717
718 SDValue Res =
719 DAG.getNode(Node->getOpcode(), dl, NVT, Operands, Node->getFlags());
720
721 if ((VT.isFloatingPoint() && NVT.isFloatingPoint()) ||
724 Res = DAG.getNode(ISD::FP_ROUND, dl, VT, Res,
725 DAG.getIntPtrConstant(0, dl, /*isTarget=*/true));
726 else
727 Res = DAG.getNode(ISD::BITCAST, dl, VT, Res);
728
729 Results.push_back(Res);
730}
731
732void VectorLegalizer::PromoteINT_TO_FP(SDNode *Node,
734 // INT_TO_FP operations may require the input operand be promoted even
735 // when the type is otherwise legal.
736 bool IsStrict = Node->isStrictFPOpcode();
737 MVT VT = Node->getOperand(IsStrict ? 1 : 0).getSimpleValueType();
738 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
740 "Vectors have different number of elements!");
741
742 SDLoc dl(Node);
743 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
744
745 unsigned Opc = (Node->getOpcode() == ISD::UINT_TO_FP ||
746 Node->getOpcode() == ISD::STRICT_UINT_TO_FP)
749 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
750 if (Node->getOperand(j).getValueType().isVector())
751 Operands[j] = DAG.getNode(Opc, dl, NVT, Node->getOperand(j));
752 else
753 Operands[j] = Node->getOperand(j);
754 }
755
756 if (IsStrict) {
757 SDValue Res = DAG.getNode(Node->getOpcode(), dl,
758 {Node->getValueType(0), MVT::Other}, Operands);
759 Results.push_back(Res);
760 Results.push_back(Res.getValue(1));
761 return;
762 }
763
764 SDValue Res =
765 DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Operands);
766 Results.push_back(Res);
767}
768
769// For FP_TO_INT we promote the result type to a vector type with wider
770// elements and then truncate the result. This is different from the default
771// PromoteVector which uses bitcast to promote thus assumning that the
772// promoted vector type has the same overall size.
773void VectorLegalizer::PromoteFP_TO_INT(SDNode *Node,
775 MVT VT = Node->getSimpleValueType(0);
776 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
777 bool IsStrict = Node->isStrictFPOpcode();
779 "Vectors have different number of elements!");
780
781 unsigned NewOpc = Node->getOpcode();
782 // Change FP_TO_UINT to FP_TO_SINT if possible.
783 // TODO: Should we only do this if FP_TO_UINT itself isn't legal?
784 if (NewOpc == ISD::FP_TO_UINT &&
785 TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT))
786 NewOpc = ISD::FP_TO_SINT;
787
788 if (NewOpc == ISD::STRICT_FP_TO_UINT &&
789 TLI.isOperationLegalOrCustom(ISD::STRICT_FP_TO_SINT, NVT))
790 NewOpc = ISD::STRICT_FP_TO_SINT;
791
792 SDLoc dl(Node);
793 SDValue Promoted, Chain;
794 if (IsStrict) {
795 Promoted = DAG.getNode(NewOpc, dl, {NVT, MVT::Other},
796 {Node->getOperand(0), Node->getOperand(1)});
797 Chain = Promoted.getValue(1);
798 } else
799 Promoted = DAG.getNode(NewOpc, dl, NVT, Node->getOperand(0));
800
801 // Assert that the converted value fits in the original type. If it doesn't
802 // (eg: because the value being converted is too big), then the result of the
803 // original operation was undefined anyway, so the assert is still correct.
804 if (Node->getOpcode() == ISD::FP_TO_UINT ||
805 Node->getOpcode() == ISD::STRICT_FP_TO_UINT)
806 NewOpc = ISD::AssertZext;
807 else
808 NewOpc = ISD::AssertSext;
809
810 Promoted = DAG.getNode(NewOpc, dl, NVT, Promoted,
811 DAG.getValueType(VT.getScalarType()));
812 Promoted = DAG.getNode(ISD::TRUNCATE, dl, VT, Promoted);
813 Results.push_back(Promoted);
814 if (IsStrict)
815 Results.push_back(Chain);
816}
817
818std::pair<SDValue, SDValue> VectorLegalizer::ExpandLoad(SDNode *N) {
819 LoadSDNode *LD = cast<LoadSDNode>(N);
820 return TLI.scalarizeVectorLoad(LD, DAG);
821}
822
823SDValue VectorLegalizer::ExpandStore(SDNode *N) {
824 StoreSDNode *ST = cast<StoreSDNode>(N);
825 SDValue TF = TLI.scalarizeVectorStore(ST, DAG);
826 return TF;
827}
828
829void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
830 switch (Node->getOpcode()) {
831 case ISD::LOAD: {
832 std::pair<SDValue, SDValue> Tmp = ExpandLoad(Node);
833 Results.push_back(Tmp.first);
834 Results.push_back(Tmp.second);
835 return;
836 }
837 case ISD::STORE:
838 Results.push_back(ExpandStore(Node));
839 return;
841 for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
842 Results.push_back(Node->getOperand(i));
843 return;
845 Results.push_back(ExpandSEXTINREG(Node));
846 return;
848 Results.push_back(ExpandANY_EXTEND_VECTOR_INREG(Node));
849 return;
851 Results.push_back(ExpandSIGN_EXTEND_VECTOR_INREG(Node));
852 return;
854 Results.push_back(ExpandZERO_EXTEND_VECTOR_INREG(Node));
855 return;
856 case ISD::BSWAP:
857 Results.push_back(ExpandBSWAP(Node));
858 return;
859 case ISD::VP_BSWAP:
860 Results.push_back(TLI.expandVPBSWAP(Node, DAG));
861 return;
862 case ISD::VSELECT:
863 Results.push_back(ExpandVSELECT(Node));
864 return;
865 case ISD::VP_SELECT:
866 Results.push_back(ExpandVP_SELECT(Node));
867 return;
868 case ISD::VP_SREM:
869 case ISD::VP_UREM:
870 if (SDValue Expanded = ExpandVP_REM(Node)) {
871 Results.push_back(Expanded);
872 return;
873 }
874 break;
875 case ISD::SELECT:
876 Results.push_back(ExpandSELECT(Node));
877 return;
878 case ISD::SELECT_CC: {
879 if (Node->getValueType(0).isScalableVector()) {
880 EVT CondVT = TLI.getSetCCResultType(
881 DAG.getDataLayout(), *DAG.getContext(), Node->getValueType(0));
882 SDValue SetCC =
883 DAG.getNode(ISD::SETCC, SDLoc(Node), CondVT, Node->getOperand(0),
884 Node->getOperand(1), Node->getOperand(4));
885 Results.push_back(DAG.getSelect(SDLoc(Node), Node->getValueType(0), SetCC,
886 Node->getOperand(2),
887 Node->getOperand(3)));
888 return;
889 }
890 break;
891 }
892 case ISD::FP_TO_UINT:
893 ExpandFP_TO_UINT(Node, Results);
894 return;
895 case ISD::UINT_TO_FP:
896 ExpandUINT_TO_FLOAT(Node, Results);
897 return;
898 case ISD::FNEG:
899 Results.push_back(ExpandFNEG(Node));
900 return;
901 case ISD::FSUB:
902 ExpandFSUB(Node, Results);
903 return;
904 case ISD::SETCC:
905 case ISD::VP_SETCC:
906 ExpandSETCC(Node, Results);
907 return;
908 case ISD::ABS:
909 if (SDValue Expanded = TLI.expandABS(Node, DAG)) {
910 Results.push_back(Expanded);
911 return;
912 }
913 break;
914 case ISD::ABDS:
915 case ISD::ABDU:
916 if (SDValue Expanded = TLI.expandABD(Node, DAG)) {
917 Results.push_back(Expanded);
918 return;
919 }
920 break;
921 case ISD::BITREVERSE:
922 ExpandBITREVERSE(Node, Results);
923 return;
924 case ISD::VP_BITREVERSE:
925 if (SDValue Expanded = TLI.expandVPBITREVERSE(Node, DAG)) {
926 Results.push_back(Expanded);
927 return;
928 }
929 break;
930 case ISD::CTPOP:
931 if (SDValue Expanded = TLI.expandCTPOP(Node, DAG)) {
932 Results.push_back(Expanded);
933 return;
934 }
935 break;
936 case ISD::VP_CTPOP:
937 if (SDValue Expanded = TLI.expandVPCTPOP(Node, DAG)) {
938 Results.push_back(Expanded);
939 return;
940 }
941 break;
942 case ISD::CTLZ:
944 if (SDValue Expanded = TLI.expandCTLZ(Node, DAG)) {
945 Results.push_back(Expanded);
946 return;
947 }
948 break;
949 case ISD::VP_CTLZ:
950 case ISD::VP_CTLZ_ZERO_UNDEF:
951 if (SDValue Expanded = TLI.expandVPCTLZ(Node, DAG)) {
952 Results.push_back(Expanded);
953 return;
954 }
955 break;
956 case ISD::CTTZ:
958 if (SDValue Expanded = TLI.expandCTTZ(Node, DAG)) {
959 Results.push_back(Expanded);
960 return;
961 }
962 break;
963 case ISD::VP_CTTZ:
964 case ISD::VP_CTTZ_ZERO_UNDEF:
965 if (SDValue Expanded = TLI.expandVPCTTZ(Node, DAG)) {
966 Results.push_back(Expanded);
967 return;
968 }
969 break;
970 case ISD::FSHL:
971 case ISD::VP_FSHL:
972 case ISD::FSHR:
973 case ISD::VP_FSHR:
974 if (SDValue Expanded = TLI.expandFunnelShift(Node, DAG)) {
975 Results.push_back(Expanded);
976 return;
977 }
978 break;
979 case ISD::ROTL:
980 case ISD::ROTR:
981 if (SDValue Expanded = TLI.expandROT(Node, false /*AllowVectorOps*/, DAG)) {
982 Results.push_back(Expanded);
983 return;
984 }
985 break;
986 case ISD::FMINNUM:
987 case ISD::FMAXNUM:
988 if (SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Node, DAG)) {
989 Results.push_back(Expanded);
990 return;
991 }
992 break;
993 case ISD::FMINIMUM:
994 case ISD::FMAXIMUM:
995 Results.push_back(TLI.expandFMINIMUM_FMAXIMUM(Node, DAG));
996 return;
997 case ISD::SMIN:
998 case ISD::SMAX:
999 case ISD::UMIN:
1000 case ISD::UMAX:
1001 if (SDValue Expanded = TLI.expandIntMINMAX(Node, DAG)) {
1002 Results.push_back(Expanded);
1003 return;
1004 }
1005 break;
1006 case ISD::UADDO:
1007 case ISD::USUBO:
1008 ExpandUADDSUBO(Node, Results);
1009 return;
1010 case ISD::SADDO:
1011 case ISD::SSUBO:
1012 ExpandSADDSUBO(Node, Results);
1013 return;
1014 case ISD::UMULO:
1015 case ISD::SMULO:
1016 ExpandMULO(Node, Results);
1017 return;
1018 case ISD::USUBSAT:
1019 case ISD::SSUBSAT:
1020 case ISD::UADDSAT:
1021 case ISD::SADDSAT:
1022 if (SDValue Expanded = TLI.expandAddSubSat(Node, DAG)) {
1023 Results.push_back(Expanded);
1024 return;
1025 }
1026 break;
1027 case ISD::USHLSAT:
1028 case ISD::SSHLSAT:
1029 if (SDValue Expanded = TLI.expandShlSat(Node, DAG)) {
1030 Results.push_back(Expanded);
1031 return;
1032 }
1033 break;
1036 // Expand the fpsosisat if it is scalable to prevent it from unrolling below.
1037 if (Node->getValueType(0).isScalableVector()) {
1038 if (SDValue Expanded = TLI.expandFP_TO_INT_SAT(Node, DAG)) {
1039 Results.push_back(Expanded);
1040 return;
1041 }
1042 }
1043 break;
1044 case ISD::SMULFIX:
1045 case ISD::UMULFIX:
1046 if (SDValue Expanded = TLI.expandFixedPointMul(Node, DAG)) {
1047 Results.push_back(Expanded);
1048 return;
1049 }
1050 break;
1051 case ISD::SMULFIXSAT:
1052 case ISD::UMULFIXSAT:
1053 // FIXME: We do not expand SMULFIXSAT/UMULFIXSAT here yet, not sure exactly
1054 // why. Maybe it results in worse codegen compared to the unroll for some
1055 // targets? This should probably be investigated. And if we still prefer to
1056 // unroll an explanation could be helpful.
1057 break;
1058 case ISD::SDIVFIX:
1059 case ISD::UDIVFIX:
1060 ExpandFixedPointDiv(Node, Results);
1061 return;
1062 case ISD::SDIVFIXSAT:
1063 case ISD::UDIVFIXSAT:
1064 break;
1065#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1066 case ISD::STRICT_##DAGN:
1067#include "llvm/IR/ConstrainedOps.def"
1068 ExpandStrictFPOp(Node, Results);
1069 return;
1070 case ISD::VECREDUCE_ADD:
1071 case ISD::VECREDUCE_MUL:
1072 case ISD::VECREDUCE_AND:
1073 case ISD::VECREDUCE_OR:
1074 case ISD::VECREDUCE_XOR:
1085 Results.push_back(TLI.expandVecReduce(Node, DAG));
1086 return;
1089 Results.push_back(TLI.expandVecReduceSeq(Node, DAG));
1090 return;
1091 case ISD::SREM:
1092 case ISD::UREM:
1093 ExpandREM(Node, Results);
1094 return;
1095 case ISD::VP_MERGE:
1096 Results.push_back(ExpandVP_MERGE(Node));
1097 return;
1098 case ISD::FREM:
1099 if (tryExpandVecMathCall(Node, RTLIB::REM_F32, RTLIB::REM_F64,
1100 RTLIB::REM_F80, RTLIB::REM_F128,
1101 RTLIB::REM_PPCF128, Results))
1102 return;
1103
1104 break;
1105 }
1106
1107 SDValue Unrolled = DAG.UnrollVectorOp(Node);
1108 if (Node->getNumValues() == 1) {
1109 Results.push_back(Unrolled);
1110 } else {
1111 assert(Node->getNumValues() == Unrolled->getNumValues() &&
1112 "VectorLegalizer Expand returned wrong number of results!");
1113 for (unsigned I = 0, E = Unrolled->getNumValues(); I != E; ++I)
1114 Results.push_back(Unrolled.getValue(I));
1115 }
1116}
1117
1118SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
1119 // Lower a select instruction where the condition is a scalar and the
1120 // operands are vectors. Lower this select to VSELECT and implement it
1121 // using XOR AND OR. The selector bit is broadcasted.
1122 EVT VT = Node->getValueType(0);
1123 SDLoc DL(Node);
1124
1125 SDValue Mask = Node->getOperand(0);
1126 SDValue Op1 = Node->getOperand(1);
1127 SDValue Op2 = Node->getOperand(2);
1128
1129 assert(VT.isVector() && !Mask.getValueType().isVector()
1130 && Op1.getValueType() == Op2.getValueType() && "Invalid type");
1131
1132 // If we can't even use the basic vector operations of
1133 // AND,OR,XOR, we will have to scalarize the op.
1134 // Notice that the operation may be 'promoted' which means that it is
1135 // 'bitcasted' to another type which is handled.
1136 // Also, we need to be able to construct a splat vector using either
1137 // BUILD_VECTOR or SPLAT_VECTOR.
1138 // FIXME: Should we also permit fixed-length SPLAT_VECTOR as a fallback to
1139 // BUILD_VECTOR?
1140 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1141 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1142 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
1143 TLI.getOperationAction(VT.isFixedLengthVector() ? ISD::BUILD_VECTOR
1145 VT) == TargetLowering::Expand)
1146 return DAG.UnrollVectorOp(Node);
1147
1148 // Generate a mask operand.
1150
1151 // What is the size of each element in the vector mask.
1152 EVT BitTy = MaskTy.getScalarType();
1153
1154 Mask = DAG.getSelect(DL, BitTy, Mask, DAG.getAllOnesConstant(DL, BitTy),
1155 DAG.getConstant(0, DL, BitTy));
1156
1157 // Broadcast the mask so that the entire vector is all one or all zero.
1158 Mask = DAG.getSplat(MaskTy, DL, Mask);
1159
1160 // Bitcast the operands to be the same type as the mask.
1161 // This is needed when we select between FP types because
1162 // the mask is a vector of integers.
1163 Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
1164 Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);
1165
1166 SDValue NotMask = DAG.getNOT(DL, Mask, MaskTy);
1167
1168 Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
1169 Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask);
1170 SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2);
1171 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1172}
1173
1174SDValue VectorLegalizer::ExpandSEXTINREG(SDNode *Node) {
1175 EVT VT = Node->getValueType(0);
1176
1177 // Make sure that the SRA and SHL instructions are available.
1178 if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
1179 TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
1180 return DAG.UnrollVectorOp(Node);
1181
1182 SDLoc DL(Node);
1183 EVT OrigTy = cast<VTSDNode>(Node->getOperand(1))->getVT();
1184
1185 unsigned BW = VT.getScalarSizeInBits();
1186 unsigned OrigBW = OrigTy.getScalarSizeInBits();
1187 SDValue ShiftSz = DAG.getConstant(BW - OrigBW, DL, VT);
1188
1189 SDValue Op = DAG.getNode(ISD::SHL, DL, VT, Node->getOperand(0), ShiftSz);
1190 return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz);
1191}
1192
1193// Generically expand a vector anyext in register to a shuffle of the relevant
1194// lanes into the appropriate locations, with other lanes left undef.
1195SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node) {
1196 SDLoc DL(Node);
1197 EVT VT = Node->getValueType(0);
1198 int NumElements = VT.getVectorNumElements();
1199 SDValue Src = Node->getOperand(0);
1200 EVT SrcVT = Src.getValueType();
1201 int NumSrcElements = SrcVT.getVectorNumElements();
1202
1203 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1204 // into a larger vector type.
1205 if (SrcVT.bitsLE(VT)) {
1206 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1207 "ANY_EXTEND_VECTOR_INREG vector size mismatch");
1208 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1209 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1210 NumSrcElements);
1211 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT),
1212 Src, DAG.getVectorIdxConstant(0, DL));
1213 }
1214
1215 // Build a base mask of undef shuffles.
1216 SmallVector<int, 16> ShuffleMask;
1217 ShuffleMask.resize(NumSrcElements, -1);
1218
1219 // Place the extended lanes into the correct locations.
1220 int ExtLaneScale = NumSrcElements / NumElements;
1221 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1222 for (int i = 0; i < NumElements; ++i)
1223 ShuffleMask[i * ExtLaneScale + EndianOffset] = i;
1224
1225 return DAG.getNode(
1226 ISD::BITCAST, DL, VT,
1227 DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask));
1228}
1229
1230SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node) {
1231 SDLoc DL(Node);
1232 EVT VT = Node->getValueType(0);
1233 SDValue Src = Node->getOperand(0);
1234 EVT SrcVT = Src.getValueType();
1235
1236 // First build an any-extend node which can be legalized above when we
1237 // recurse through it.
1238 SDValue Op = DAG.getNode(ISD::ANY_EXTEND_VECTOR_INREG, DL, VT, Src);
1239
1240 // Now we need sign extend. Do this by shifting the elements. Even if these
1241 // aren't legal operations, they have a better chance of being legalized
1242 // without full scalarization than the sign extension does.
1243 unsigned EltWidth = VT.getScalarSizeInBits();
1244 unsigned SrcEltWidth = SrcVT.getScalarSizeInBits();
1245 SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, DL, VT);
1246 return DAG.getNode(ISD::SRA, DL, VT,
1247 DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount),
1248 ShiftAmount);
1249}
1250
1251// Generically expand a vector zext in register to a shuffle of the relevant
1252// lanes into the appropriate locations, a blend of zero into the high bits,
1253// and a bitcast to the wider element type.
1254SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node) {
1255 SDLoc DL(Node);
1256 EVT VT = Node->getValueType(0);
1257 int NumElements = VT.getVectorNumElements();
1258 SDValue Src = Node->getOperand(0);
1259 EVT SrcVT = Src.getValueType();
1260 int NumSrcElements = SrcVT.getVectorNumElements();
1261
1262 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1263 // into a larger vector type.
1264 if (SrcVT.bitsLE(VT)) {
1265 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1266 "ZERO_EXTEND_VECTOR_INREG vector size mismatch");
1267 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1268 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1269 NumSrcElements);
1270 Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT),
1271 Src, DAG.getVectorIdxConstant(0, DL));
1272 }
1273
1274 // Build up a zero vector to blend into this one.
1275 SDValue Zero = DAG.getConstant(0, DL, SrcVT);
1276
1277 // Shuffle the incoming lanes into the correct position, and pull all other
1278 // lanes from the zero vector.
1279 auto ShuffleMask = llvm::to_vector<16>(llvm::seq<int>(0, NumSrcElements));
1280
1281 int ExtLaneScale = NumSrcElements / NumElements;
1282 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1283 for (int i = 0; i < NumElements; ++i)
1284 ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i;
1285
1286 return DAG.getNode(ISD::BITCAST, DL, VT,
1287 DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask));
1288}
1289
1290static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
1291 int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
1292 for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
1293 for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
1294 ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
1295}
1296
1297SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) {
1298 EVT VT = Node->getValueType(0);
1299
1300 // Scalable vectors can't use shuffle expansion.
1301 if (VT.isScalableVector())
1302 return TLI.expandBSWAP(Node, DAG);
1303
1304 // Generate a byte wise shuffle mask for the BSWAP.
1305 SmallVector<int, 16> ShuffleMask;
1306 createBSWAPShuffleMask(VT, ShuffleMask);
1307 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
1308
1309 // Only emit a shuffle if the mask is legal.
1310 if (TLI.isShuffleMaskLegal(ShuffleMask, ByteVT)) {
1311 SDLoc DL(Node);
1312 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1313 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), ShuffleMask);
1314 return DAG.getNode(ISD::BITCAST, DL, VT, Op);
1315 }
1316
1317 // If we have the appropriate vector bit operations, it is better to use them
1318 // than unrolling and expanding each component.
1319 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1320 TLI.isOperationLegalOrCustom(ISD::SRL, VT) &&
1321 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
1322 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
1323 return TLI.expandBSWAP(Node, DAG);
1324
1325 // Otherwise unroll.
1326 return DAG.UnrollVectorOp(Node);
1327}
1328
1329void VectorLegalizer::ExpandBITREVERSE(SDNode *Node,
1331 EVT VT = Node->getValueType(0);
1332
1333 // We can't unroll or use shuffles for scalable vectors.
1334 if (VT.isScalableVector()) {
1335 Results.push_back(TLI.expandBITREVERSE(Node, DAG));
1336 return;
1337 }
1338
1339 // If we have the scalar operation, it's probably cheaper to unroll it.
1340 if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType())) {
1341 SDValue Tmp = DAG.UnrollVectorOp(Node);
1342 Results.push_back(Tmp);
1343 return;
1344 }
1345
1346 // If the vector element width is a whole number of bytes, test if its legal
1347 // to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte
1348 // vector. This greatly reduces the number of bit shifts necessary.
1349 unsigned ScalarSizeInBits = VT.getScalarSizeInBits();
1350 if (ScalarSizeInBits > 8 && (ScalarSizeInBits % 8) == 0) {
1351 SmallVector<int, 16> BSWAPMask;
1352 createBSWAPShuffleMask(VT, BSWAPMask);
1353
1354 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, BSWAPMask.size());
1355 if (TLI.isShuffleMaskLegal(BSWAPMask, ByteVT) &&
1356 (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, ByteVT) ||
1357 (TLI.isOperationLegalOrCustom(ISD::SHL, ByteVT) &&
1358 TLI.isOperationLegalOrCustom(ISD::SRL, ByteVT) &&
1359 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, ByteVT) &&
1360 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, ByteVT)))) {
1361 SDLoc DL(Node);
1362 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1363 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT),
1364 BSWAPMask);
1365 Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op);
1366 Op = DAG.getNode(ISD::BITCAST, DL, VT, Op);
1367 Results.push_back(Op);
1368 return;
1369 }
1370 }
1371
1372 // If we have the appropriate vector bit operations, it is better to use them
1373 // than unrolling and expanding each component.
1374 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1375 TLI.isOperationLegalOrCustom(ISD::SRL, VT) &&
1376 TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
1377 TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT)) {
1378 Results.push_back(TLI.expandBITREVERSE(Node, DAG));
1379 return;
1380 }
1381
1382 // Otherwise unroll.
1383 SDValue Tmp = DAG.UnrollVectorOp(Node);
1384 Results.push_back(Tmp);
1385}
1386
1387SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
1388 // Implement VSELECT in terms of XOR, AND, OR
1389 // on platforms which do not support blend natively.
1390 SDLoc DL(Node);
1391
1392 SDValue Mask = Node->getOperand(0);
1393 SDValue Op1 = Node->getOperand(1);
1394 SDValue Op2 = Node->getOperand(2);
1395
1396 EVT VT = Mask.getValueType();
1397
1398 // If we can't even use the basic vector operations of
1399 // AND,OR,XOR, we will have to scalarize the op.
1400 // Notice that the operation may be 'promoted' which means that it is
1401 // 'bitcasted' to another type which is handled.
1402 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1403 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1404 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand)
1405 return DAG.UnrollVectorOp(Node);
1406
1407 // This operation also isn't safe with AND, OR, XOR when the boolean type is
1408 // 0/1 and the select operands aren't also booleans, as we need an all-ones
1409 // vector constant to mask with.
1410 // FIXME: Sign extend 1 to all ones if that's legal on the target.
1411 auto BoolContents = TLI.getBooleanContents(Op1.getValueType());
1412 if (BoolContents != TargetLowering::ZeroOrNegativeOneBooleanContent &&
1413 !(BoolContents == TargetLowering::ZeroOrOneBooleanContent &&
1414 Op1.getValueType().getVectorElementType() == MVT::i1))
1415 return DAG.UnrollVectorOp(Node);
1416
1417 // If the mask and the type are different sizes, unroll the vector op. This
1418 // can occur when getSetCCResultType returns something that is different in
1419 // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
1420 if (VT.getSizeInBits() != Op1.getValueSizeInBits())
1421 return DAG.UnrollVectorOp(Node);
1422
1423 // Bitcast the operands to be the same type as the mask.
1424 // This is needed when we select between FP types because
1425 // the mask is a vector of integers.
1426 Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
1427 Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);
1428
1429 SDValue NotMask = DAG.getNOT(DL, Mask, VT);
1430
1431 Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
1432 Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask);
1433 SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2);
1434 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1435}
1436
1437SDValue VectorLegalizer::ExpandVP_SELECT(SDNode *Node) {
1438 // Implement VP_SELECT in terms of VP_XOR, VP_AND and VP_OR on platforms which
1439 // do not support it natively.
1440 SDLoc DL(Node);
1441
1442 SDValue Mask = Node->getOperand(0);
1443 SDValue Op1 = Node->getOperand(1);
1444 SDValue Op2 = Node->getOperand(2);
1445 SDValue EVL = Node->getOperand(3);
1446
1447 EVT VT = Mask.getValueType();
1448
1449 // If we can't even use the basic vector operations of
1450 // VP_AND,VP_OR,VP_XOR, we will have to scalarize the op.
1451 if (TLI.getOperationAction(ISD::VP_AND, VT) == TargetLowering::Expand ||
1452 TLI.getOperationAction(ISD::VP_XOR, VT) == TargetLowering::Expand ||
1453 TLI.getOperationAction(ISD::VP_OR, VT) == TargetLowering::Expand)
1454 return DAG.UnrollVectorOp(Node);
1455
1456 // This operation also isn't safe when the operands aren't also booleans.
1457 if (Op1.getValueType().getVectorElementType() != MVT::i1)
1458 return DAG.UnrollVectorOp(Node);
1459
1460 SDValue Ones = DAG.getAllOnesConstant(DL, VT);
1461 SDValue NotMask = DAG.getNode(ISD::VP_XOR, DL, VT, Mask, Ones, Ones, EVL);
1462
1463 Op1 = DAG.getNode(ISD::VP_AND, DL, VT, Op1, Mask, Ones, EVL);
1464 Op2 = DAG.getNode(ISD::VP_AND, DL, VT, Op2, NotMask, Ones, EVL);
1465 return DAG.getNode(ISD::VP_OR, DL, VT, Op1, Op2, Ones, EVL);
1466}
1467
1468SDValue VectorLegalizer::ExpandVP_MERGE(SDNode *Node) {
1469 // Implement VP_MERGE in terms of VSELECT. Construct a mask where vector
1470 // indices less than the EVL/pivot are true. Combine that with the original
1471 // mask for a full-length mask. Use a full-length VSELECT to select between
1472 // the true and false values.
1473 SDLoc DL(Node);
1474
1475 SDValue Mask = Node->getOperand(0);
1476 SDValue Op1 = Node->getOperand(1);
1477 SDValue Op2 = Node->getOperand(2);
1478 SDValue EVL = Node->getOperand(3);
1479
1480 EVT MaskVT = Mask.getValueType();
1481 bool IsFixedLen = MaskVT.isFixedLengthVector();
1482
1483 EVT EVLVecVT = EVT::getVectorVT(*DAG.getContext(), EVL.getValueType(),
1484 MaskVT.getVectorElementCount());
1485
1486 // If we can't construct the EVL mask efficiently, it's better to unroll.
1487 if ((IsFixedLen &&
1488 !TLI.isOperationLegalOrCustom(ISD::BUILD_VECTOR, EVLVecVT)) ||
1489 (!IsFixedLen &&
1490 (!TLI.isOperationLegalOrCustom(ISD::STEP_VECTOR, EVLVecVT) ||
1491 !TLI.isOperationLegalOrCustom(ISD::SPLAT_VECTOR, EVLVecVT))))
1492 return DAG.UnrollVectorOp(Node);
1493
1494 // If using a SETCC would result in a different type than the mask type,
1495 // unroll.
1496 if (TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
1497 EVLVecVT) != MaskVT)
1498 return DAG.UnrollVectorOp(Node);
1499
1500 SDValue StepVec = DAG.getStepVector(DL, EVLVecVT);
1501 SDValue SplatEVL = DAG.getSplat(EVLVecVT, DL, EVL);
1502 SDValue EVLMask =
1503 DAG.getSetCC(DL, MaskVT, StepVec, SplatEVL, ISD::CondCode::SETULT);
1504
1505 SDValue FullMask = DAG.getNode(ISD::AND, DL, MaskVT, Mask, EVLMask);
1506 return DAG.getSelect(DL, Node->getValueType(0), FullMask, Op1, Op2);
1507}
1508
1509SDValue VectorLegalizer::ExpandVP_REM(SDNode *Node) {
1510 // Implement VP_SREM/UREM in terms of VP_SDIV/VP_UDIV, VP_MUL, VP_SUB.
1511 EVT VT = Node->getValueType(0);
1512
1513 unsigned DivOpc = Node->getOpcode() == ISD::VP_SREM ? ISD::VP_SDIV : ISD::VP_UDIV;
1514
1515 if (!TLI.isOperationLegalOrCustom(DivOpc, VT) ||
1516 !TLI.isOperationLegalOrCustom(ISD::VP_MUL, VT) ||
1517 !TLI.isOperationLegalOrCustom(ISD::VP_SUB, VT))
1518 return SDValue();
1519
1520 SDLoc DL(Node);
1521
1522 SDValue Dividend = Node->getOperand(0);
1523 SDValue Divisor = Node->getOperand(1);
1524 SDValue Mask = Node->getOperand(2);
1525 SDValue EVL = Node->getOperand(3);
1526
1527 // X % Y -> X-X/Y*Y
1528 SDValue Div = DAG.getNode(DivOpc, DL, VT, Dividend, Divisor, Mask, EVL);
1529 SDValue Mul = DAG.getNode(ISD::VP_MUL, DL, VT, Divisor, Div, Mask, EVL);
1530 return DAG.getNode(ISD::VP_SUB, DL, VT, Dividend, Mul, Mask, EVL);
1531}
1532
1533void VectorLegalizer::ExpandFP_TO_UINT(SDNode *Node,
1535 // Attempt to expand using TargetLowering.
1536 SDValue Result, Chain;
1537 if (TLI.expandFP_TO_UINT(Node, Result, Chain, DAG)) {
1538 Results.push_back(Result);
1539 if (Node->isStrictFPOpcode())
1540 Results.push_back(Chain);
1541 return;
1542 }
1543
1544 // Otherwise go ahead and unroll.
1545 if (Node->isStrictFPOpcode()) {
1546 UnrollStrictFPOp(Node, Results);
1547 return;
1548 }
1549
1550 Results.push_back(DAG.UnrollVectorOp(Node));
1551}
1552
1553void VectorLegalizer::ExpandUINT_TO_FLOAT(SDNode *Node,
1555 bool IsStrict = Node->isStrictFPOpcode();
1556 unsigned OpNo = IsStrict ? 1 : 0;
1557 SDValue Src = Node->getOperand(OpNo);
1558 EVT VT = Src.getValueType();
1559 SDLoc DL(Node);
1560
1561 // Attempt to expand using TargetLowering.
1563 SDValue Chain;
1564 if (TLI.expandUINT_TO_FP(Node, Result, Chain, DAG)) {
1565 Results.push_back(Result);
1566 if (IsStrict)
1567 Results.push_back(Chain);
1568 return;
1569 }
1570
1571 // Make sure that the SINT_TO_FP and SRL instructions are available.
1572 if (((!IsStrict && TLI.getOperationAction(ISD::SINT_TO_FP, VT) ==
1573 TargetLowering::Expand) ||
1574 (IsStrict && TLI.getOperationAction(ISD::STRICT_SINT_TO_FP, VT) ==
1575 TargetLowering::Expand)) ||
1576 TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Expand) {
1577 if (IsStrict) {
1578 UnrollStrictFPOp(Node, Results);
1579 return;
1580 }
1581
1582 Results.push_back(DAG.UnrollVectorOp(Node));
1583 return;
1584 }
1585
1586 unsigned BW = VT.getScalarSizeInBits();
1587 assert((BW == 64 || BW == 32) &&
1588 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
1589
1590 SDValue HalfWord = DAG.getConstant(BW / 2, DL, VT);
1591
1592 // Constants to clear the upper part of the word.
1593 // Notice that we can also use SHL+SHR, but using a constant is slightly
1594 // faster on x86.
1595 uint64_t HWMask = (BW == 64) ? 0x00000000FFFFFFFF : 0x0000FFFF;
1596 SDValue HalfWordMask = DAG.getConstant(HWMask, DL, VT);
1597
1598 // Two to the power of half-word-size.
1599 SDValue TWOHW =
1600 DAG.getConstantFP(1ULL << (BW / 2), DL, Node->getValueType(0));
1601
1602 // Clear upper part of LO, lower HI
1603 SDValue HI = DAG.getNode(ISD::SRL, DL, VT, Src, HalfWord);
1604 SDValue LO = DAG.getNode(ISD::AND, DL, VT, Src, HalfWordMask);
1605
1606 if (IsStrict) {
1607 // Convert hi and lo to floats
1608 // Convert the hi part back to the upper values
1609 // TODO: Can any fast-math-flags be set on these nodes?
1611 {Node->getValueType(0), MVT::Other},
1612 {Node->getOperand(0), HI});
1613 fHI = DAG.getNode(ISD::STRICT_FMUL, DL, {Node->getValueType(0), MVT::Other},
1614 {fHI.getValue(1), fHI, TWOHW});
1616 {Node->getValueType(0), MVT::Other},
1617 {Node->getOperand(0), LO});
1618
1619 SDValue TF = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, fHI.getValue(1),
1620 fLO.getValue(1));
1621
1622 // Add the two halves
1623 SDValue Result =
1624 DAG.getNode(ISD::STRICT_FADD, DL, {Node->getValueType(0), MVT::Other},
1625 {TF, fHI, fLO});
1626
1627 Results.push_back(Result);
1628 Results.push_back(Result.getValue(1));
1629 return;
1630 }
1631
1632 // Convert hi and lo to floats
1633 // Convert the hi part back to the upper values
1634 // TODO: Can any fast-math-flags be set on these nodes?
1635 SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, Node->getValueType(0), HI);
1636 fHI = DAG.getNode(ISD::FMUL, DL, Node->getValueType(0), fHI, TWOHW);
1637 SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, Node->getValueType(0), LO);
1638
1639 // Add the two halves
1640 Results.push_back(
1641 DAG.getNode(ISD::FADD, DL, Node->getValueType(0), fHI, fLO));
1642}
1643
1644SDValue VectorLegalizer::ExpandFNEG(SDNode *Node) {
1645 if (TLI.isOperationLegalOrCustom(ISD::FSUB, Node->getValueType(0))) {
1646 SDLoc DL(Node);
1647 SDValue Zero = DAG.getConstantFP(-0.0, DL, Node->getValueType(0));
1648 // TODO: If FNEG had fast-math-flags, they'd get propagated to this FSUB.
1649 return DAG.getNode(ISD::FSUB, DL, Node->getValueType(0), Zero,
1650 Node->getOperand(0));
1651 }
1652 return DAG.UnrollVectorOp(Node);
1653}
1654
1655void VectorLegalizer::ExpandFSUB(SDNode *Node,
1657 // For floating-point values, (a-b) is the same as a+(-b). If FNEG is legal,
1658 // we can defer this to operation legalization where it will be lowered as
1659 // a+(-b).
1660 EVT VT = Node->getValueType(0);
1661 if (TLI.isOperationLegalOrCustom(ISD::FNEG, VT) &&
1662 TLI.isOperationLegalOrCustom(ISD::FADD, VT))
1663 return; // Defer to LegalizeDAG
1664
1665 SDValue Tmp = DAG.UnrollVectorOp(Node);
1666 Results.push_back(Tmp);
1667}
1668
1669void VectorLegalizer::ExpandSETCC(SDNode *Node,
1671 bool NeedInvert = false;
1672 bool IsVP = Node->getOpcode() == ISD::VP_SETCC;
1673 bool IsStrict = Node->getOpcode() == ISD::STRICT_FSETCC ||
1674 Node->getOpcode() == ISD::STRICT_FSETCCS;
1675 bool IsSignaling = Node->getOpcode() == ISD::STRICT_FSETCCS;
1676 unsigned Offset = IsStrict ? 1 : 0;
1677
1678 SDValue Chain = IsStrict ? Node->getOperand(0) : SDValue();
1679 SDValue LHS = Node->getOperand(0 + Offset);
1680 SDValue RHS = Node->getOperand(1 + Offset);
1681 SDValue CC = Node->getOperand(2 + Offset);
1682
1683 MVT OpVT = LHS.getSimpleValueType();
1684 ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
1685
1686 if (TLI.getCondCodeAction(CCCode, OpVT) != TargetLowering::Expand) {
1687 if (IsStrict) {
1688 UnrollStrictFPOp(Node, Results);
1689 return;
1690 }
1691 Results.push_back(UnrollVSETCC(Node));
1692 return;
1693 }
1694
1695 SDValue Mask, EVL;
1696 if (IsVP) {
1697 Mask = Node->getOperand(3 + Offset);
1698 EVL = Node->getOperand(4 + Offset);
1699 }
1700
1701 SDLoc dl(Node);
1702 bool Legalized =
1703 TLI.LegalizeSetCCCondCode(DAG, Node->getValueType(0), LHS, RHS, CC, Mask,
1704 EVL, NeedInvert, dl, Chain, IsSignaling);
1705
1706 if (Legalized) {
1707 // If we expanded the SETCC by swapping LHS and RHS, or by inverting the
1708 // condition code, create a new SETCC node.
1709 if (CC.getNode()) {
1710 if (IsStrict) {
1711 LHS = DAG.getNode(Node->getOpcode(), dl, Node->getVTList(),
1712 {Chain, LHS, RHS, CC}, Node->getFlags());
1713 Chain = LHS.getValue(1);
1714 } else if (IsVP) {
1715 LHS = DAG.getNode(ISD::VP_SETCC, dl, Node->getValueType(0),
1716 {LHS, RHS, CC, Mask, EVL}, Node->getFlags());
1717 } else {
1718 LHS = DAG.getNode(ISD::SETCC, dl, Node->getValueType(0), LHS, RHS, CC,
1719 Node->getFlags());
1720 }
1721 }
1722
1723 // If we expanded the SETCC by inverting the condition code, then wrap
1724 // the existing SETCC in a NOT to restore the intended condition.
1725 if (NeedInvert) {
1726 if (!IsVP)
1727 LHS = DAG.getLogicalNOT(dl, LHS, LHS->getValueType(0));
1728 else
1729 LHS = DAG.getVPLogicalNOT(dl, LHS, Mask, EVL, LHS->getValueType(0));
1730 }
1731 } else {
1732 assert(!IsStrict && "Don't know how to expand for strict nodes.");
1733
1734 // Otherwise, SETCC for the given comparison type must be completely
1735 // illegal; expand it into a SELECT_CC.
1736 EVT VT = Node->getValueType(0);
1737 LHS =
1738 DAG.getNode(ISD::SELECT_CC, dl, VT, LHS, RHS,
1739 DAG.getBoolConstant(true, dl, VT, LHS.getValueType()),
1740 DAG.getBoolConstant(false, dl, VT, LHS.getValueType()), CC);
1741 LHS->setFlags(Node->getFlags());
1742 }
1743
1744 Results.push_back(LHS);
1745 if (IsStrict)
1746 Results.push_back(Chain);
1747}
1748
1749void VectorLegalizer::ExpandUADDSUBO(SDNode *Node,
1751 SDValue Result, Overflow;
1752 TLI.expandUADDSUBO(Node, Result, Overflow, DAG);
1753 Results.push_back(Result);
1754 Results.push_back(Overflow);
1755}
1756
1757void VectorLegalizer::ExpandSADDSUBO(SDNode *Node,
1759 SDValue Result, Overflow;
1760 TLI.expandSADDSUBO(Node, Result, Overflow, DAG);
1761 Results.push_back(Result);
1762 Results.push_back(Overflow);
1763}
1764
1765void VectorLegalizer::ExpandMULO(SDNode *Node,
1767 SDValue Result, Overflow;
1768 if (!TLI.expandMULO(Node, Result, Overflow, DAG))
1769 std::tie(Result, Overflow) = DAG.UnrollVectorOverflowOp(Node);
1770
1771 Results.push_back(Result);
1772 Results.push_back(Overflow);
1773}
1774
1775void VectorLegalizer::ExpandFixedPointDiv(SDNode *Node,
1777 SDNode *N = Node;
1778 if (SDValue Expanded = TLI.expandFixedPointDiv(N->getOpcode(), SDLoc(N),
1779 N->getOperand(0), N->getOperand(1), N->getConstantOperandVal(2), DAG))
1780 Results.push_back(Expanded);
1781}
1782
1783void VectorLegalizer::ExpandStrictFPOp(SDNode *Node,
1785 if (Node->getOpcode() == ISD::STRICT_UINT_TO_FP) {
1786 ExpandUINT_TO_FLOAT(Node, Results);
1787 return;
1788 }
1789 if (Node->getOpcode() == ISD::STRICT_FP_TO_UINT) {
1790 ExpandFP_TO_UINT(Node, Results);
1791 return;
1792 }
1793
1794 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
1795 Node->getOpcode() == ISD::STRICT_FSETCCS) {
1796 ExpandSETCC(Node, Results);
1797 return;
1798 }
1799
1800 UnrollStrictFPOp(Node, Results);
1801}
1802
1803void VectorLegalizer::ExpandREM(SDNode *Node,
1805 assert((Node->getOpcode() == ISD::SREM || Node->getOpcode() == ISD::UREM) &&
1806 "Expected REM node");
1807
1809 if (!TLI.expandREM(Node, Result, DAG))
1810 Result = DAG.UnrollVectorOp(Node);
1811 Results.push_back(Result);
1812}
1813
1814// Try to expand libm nodes into vector math routine calls. Callers provide the
1815// LibFunc equivalent of the passed in Node, which is used to lookup mappings
1816// within TargetLibraryInfo. The only mappings considered are those where the
1817// result and all operands are the same vector type. While predicated nodes are
1818// not supported, we will emit calls to masked routines by passing in an all
1819// true mask.
1820bool VectorLegalizer::tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
1822 // Chain must be propagated but currently strict fp operations are down
1823 // converted to their none strict counterpart.
1824 assert(!Node->isStrictFPOpcode() && "Unexpected strict fp operation!");
1825
1826 const char *LCName = TLI.getLibcallName(LC);
1827 if (!LCName)
1828 return false;
1829 LLVM_DEBUG(dbgs() << "Looking for vector variant of " << LCName << "\n");
1830
1831 EVT VT = Node->getValueType(0);
1833
1834 // Lookup a vector function equivalent to the specified libcall. Prefer
1835 // unmasked variants but we will generate a mask if need be.
1836 const TargetLibraryInfo &TLibInfo = DAG.getLibInfo();
1837 const VecDesc *VD = TLibInfo.getVectorMappingInfo(LCName, VL, false);
1838 if (!VD)
1839 VD = TLibInfo.getVectorMappingInfo(LCName, VL, /*Masked=*/true);
1840 if (!VD)
1841 return false;
1842
1843 LLVMContext *Ctx = DAG.getContext();
1844 Type *Ty = VT.getTypeForEVT(*Ctx);
1845 Type *ScalarTy = Ty->getScalarType();
1846
1847 // Construct a scalar function type based on Node's operands.
1849 for (unsigned i = 0; i < Node->getNumOperands(); ++i) {
1850 assert(Node->getOperand(i).getValueType() == VT &&
1851 "Expected matching vector types!");
1852 ArgTys.push_back(ScalarTy);
1853 }
1854 FunctionType *ScalarFTy = FunctionType::get(ScalarTy, ArgTys, false);
1855
1856 // Generate call information for the vector function.
1857 const std::string MangledName = VD->getVectorFunctionABIVariantString();
1858 auto OptVFInfo = VFABI::tryDemangleForVFABI(MangledName, ScalarFTy);
1859 if (!OptVFInfo)
1860 return false;
1861
1862 LLVM_DEBUG(dbgs() << "Found vector variant " << VD->getVectorFnName()
1863 << "\n");
1864
1865 // Sanity check just in case OptVFInfo has unexpected parameters.
1866 if (OptVFInfo->Shape.Parameters.size() !=
1867 Node->getNumOperands() + VD->isMasked())
1868 return false;
1869
1870 // Collect vector call operands.
1871
1872 SDLoc DL(Node);
1875 Entry.IsSExt = false;
1876 Entry.IsZExt = false;
1877
1878 unsigned OpNum = 0;
1879 for (auto &VFParam : OptVFInfo->Shape.Parameters) {
1880 if (VFParam.ParamKind == VFParamKind::GlobalPredicate) {
1881 EVT MaskVT = TLI.getSetCCResultType(DAG.getDataLayout(), *Ctx, VT);
1882 Entry.Node = DAG.getBoolConstant(true, DL, MaskVT, VT);
1883 Entry.Ty = MaskVT.getTypeForEVT(*Ctx);
1884 Args.push_back(Entry);
1885 continue;
1886 }
1887
1888 // Only vector operands are supported.
1889 if (VFParam.ParamKind != VFParamKind::Vector)
1890 return false;
1891
1892 Entry.Node = Node->getOperand(OpNum++);
1893 Entry.Ty = Ty;
1894 Args.push_back(Entry);
1895 }
1896
1897 // Emit a call to the vector function.
1898 SDValue Callee = DAG.getExternalSymbol(VD->getVectorFnName().data(),
1899 TLI.getPointerTy(DAG.getDataLayout()));
1901 CLI.setDebugLoc(DL)
1902 .setChain(DAG.getEntryNode())
1903 .setLibCallee(CallingConv::C, Ty, Callee, std::move(Args));
1904
1905 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
1906 Results.push_back(CallResult.first);
1907 return true;
1908}
1909
1910/// Try to expand the node to a vector libcall based on the result type.
1911bool VectorLegalizer::tryExpandVecMathCall(
1912 SDNode *Node, RTLIB::Libcall Call_F32, RTLIB::Libcall Call_F64,
1913 RTLIB::Libcall Call_F80, RTLIB::Libcall Call_F128,
1916 Node->getValueType(0).getVectorElementType(), Call_F32, Call_F64,
1917 Call_F80, Call_F128, Call_PPCF128);
1918
1919 if (LC == RTLIB::UNKNOWN_LIBCALL)
1920 return false;
1921
1922 return tryExpandVecMathCall(Node, LC, Results);
1923}
1924
1925void VectorLegalizer::UnrollStrictFPOp(SDNode *Node,
1927 EVT VT = Node->getValueType(0);
1928 EVT EltVT = VT.getVectorElementType();
1929 unsigned NumElems = VT.getVectorNumElements();
1930 unsigned NumOpers = Node->getNumOperands();
1931 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1932
1933 EVT TmpEltVT = EltVT;
1934 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
1935 Node->getOpcode() == ISD::STRICT_FSETCCS)
1936 TmpEltVT = TLI.getSetCCResultType(DAG.getDataLayout(),
1937 *DAG.getContext(), TmpEltVT);
1938
1939 EVT ValueVTs[] = {TmpEltVT, MVT::Other};
1940 SDValue Chain = Node->getOperand(0);
1941 SDLoc dl(Node);
1942
1943 SmallVector<SDValue, 32> OpValues;
1944 SmallVector<SDValue, 32> OpChains;
1945 for (unsigned i = 0; i < NumElems; ++i) {
1947 SDValue Idx = DAG.getVectorIdxConstant(i, dl);
1948
1949 // The Chain is the first operand.
1950 Opers.push_back(Chain);
1951
1952 // Now process the remaining operands.
1953 for (unsigned j = 1; j < NumOpers; ++j) {
1954 SDValue Oper = Node->getOperand(j);
1955 EVT OperVT = Oper.getValueType();
1956
1957 if (OperVT.isVector())
1958 Oper = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
1959 OperVT.getVectorElementType(), Oper, Idx);
1960
1961 Opers.push_back(Oper);
1962 }
1963
1964 SDValue ScalarOp = DAG.getNode(Node->getOpcode(), dl, ValueVTs, Opers);
1965 SDValue ScalarResult = ScalarOp.getValue(0);
1966 SDValue ScalarChain = ScalarOp.getValue(1);
1967
1968 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
1969 Node->getOpcode() == ISD::STRICT_FSETCCS)
1970 ScalarResult = DAG.getSelect(dl, EltVT, ScalarResult,
1971 DAG.getAllOnesConstant(dl, EltVT),
1972 DAG.getConstant(0, dl, EltVT));
1973
1974 OpValues.push_back(ScalarResult);
1975 OpChains.push_back(ScalarChain);
1976 }
1977
1978 SDValue Result = DAG.getBuildVector(VT, dl, OpValues);
1979 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OpChains);
1980
1981 Results.push_back(Result);
1982 Results.push_back(NewChain);
1983}
1984
1985SDValue VectorLegalizer::UnrollVSETCC(SDNode *Node) {
1986 EVT VT = Node->getValueType(0);
1987 unsigned NumElems = VT.getVectorNumElements();
1988 EVT EltVT = VT.getVectorElementType();
1989 SDValue LHS = Node->getOperand(0);
1990 SDValue RHS = Node->getOperand(1);
1991 SDValue CC = Node->getOperand(2);
1992 EVT TmpEltVT = LHS.getValueType().getVectorElementType();
1993 SDLoc dl(Node);
1994 SmallVector<SDValue, 8> Ops(NumElems);
1995 for (unsigned i = 0; i < NumElems; ++i) {
1996 SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS,
1997 DAG.getVectorIdxConstant(i, dl));
1998 SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS,
1999 DAG.getVectorIdxConstant(i, dl));
2000 Ops[i] = DAG.getNode(ISD::SETCC, dl,
2001 TLI.getSetCCResultType(DAG.getDataLayout(),
2002 *DAG.getContext(), TmpEltVT),
2003 LHSElem, RHSElem, CC);
2004 Ops[i] = DAG.getSelect(dl, EltVT, Ops[i], DAG.getAllOnesConstant(dl, EltVT),
2005 DAG.getConstant(0, dl, EltVT));
2006 }
2007 return DAG.getBuildVector(VT, dl, Ops);
2008}
2009
2011 return VectorLegalizer(*this).Run();
2012}
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(X)
Definition: Debug.h:101
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
This class represents an Operation in the Expression.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
size_t size() const
Definition: Function.h:811
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:307
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:227
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:492
ilist< SDNode >::iterator allnodes_iterator
Definition: SelectionDAG.h:548
bool empty() const
Definition: SmallVector.h:94
size_t size() const
Definition: SmallVector.h:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void resize(size_type N)
Definition: SmallVector.h:651
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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:131
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:348
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:121
@ 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:752
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:237
@ CTLZ_ZERO_UNDEF
Definition: ISDOpcodes.h:725
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition: ISDOpcodes.h:478
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
Definition: ISDOpcodes.h:1348
@ VECREDUCE_SMIN
Definition: ISDOpcodes.h:1379
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:251
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
Definition: ISDOpcodes.h:561
@ BSWAP
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:716
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition: ISDOpcodes.h:368
@ FMAXNUM_IEEE
Definition: ISDOpcodes.h:988
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:240
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1040
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:374
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:785
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:485
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:792
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:1364
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:391
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
Definition: ISDOpcodes.h:1368
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:690
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:822
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:256
@ VECREDUCE_SMAX
Definition: ISDOpcodes.h:1378
@ STRICT_FSETCCS
Definition: ISDOpcodes.h:479
@ FPTRUNC_ROUND
Definition: ISDOpcodes.h:482
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:905
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:942
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition: ISDOpcodes.h:381
@ STRICT_FSQRT
Constrained versions of libm-equivalent floating point intrinsics.
Definition: ISDOpcodes.h:412
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:776
@ STRICT_UINT_TO_FP
Definition: ISDOpcodes.h:452
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
Definition: ISDOpcodes.h:1361
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:724
@ VECREDUCE_FMIN
Definition: ISDOpcodes.h:1365
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:932
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:328
@ STEP_VECTOR
STEP_VECTOR(IMM) - Returns a scalable vector whose lanes are comprised of a linear sequence of unsign...
Definition: ISDOpcodes.h:648
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition: ISDOpcodes.h:502
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition: ISDOpcodes.h:350
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:729
@ VECREDUCE_UMAX
Definition: ISDOpcodes.h:1380
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:629
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:324
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
Definition: ISDOpcodes.h:1373
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:653
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:707
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:987
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:537
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:782
@ FP_TO_UINT_SAT
Definition: ISDOpcodes.h:858
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:744
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:974
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition: ISDOpcodes.h:360
@ SMULO
Same for multiplication.
Definition: ISDOpcodes.h:332
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:811
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:800
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:676
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:387
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:890
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:738
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
Definition: ISDOpcodes.h:451
@ VECREDUCE_UMIN
Definition: ISDOpcodes.h:1381
@ STRICT_FP_TO_UINT
Definition: ISDOpcodes.h:445
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
Definition: ISDOpcodes.h:467
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:444
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:993
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:838
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:472
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:682
@ VECREDUCE_FMUL
Definition: ISDOpcodes.h:1362
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition: ISDOpcodes.h:401
@ 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:947
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:871
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:833
@ 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:857
@ VECREDUCE_FMINIMUM
Definition: ISDOpcodes.h:1369
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:788
@ VECREDUCE_SEQ_FMUL
Definition: ISDOpcodes.h:1349
@ 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:495
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:341
@ AssertZext
Definition: ISDOpcodes.h:62
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition: ISDOpcodes.h:517
std::optional< unsigned > getVPMaskIdx(unsigned Opcode)
The operand position of the vector mask.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1542
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:1522
bool isVPOpcode(unsigned Opcode)
Whether this is a vector-predicated Opcode.
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,...
ManagedStatic< cl::opt< FnT >, OptCreatorT > Action
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:456
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:1729
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
#define N
Extended Value Type.
Definition: ValueTypes.h:34
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:93
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:73
ElementCount getVectorElementCount() const
Definition: ValueTypes.h:340
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:358
uint64_t getScalarSizeInBits() const
Definition: ValueTypes.h:370
bool isFixedLengthVector() const
Definition: ValueTypes.h:177
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:167
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:313
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:203
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition: ValueTypes.h:173
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:318
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:326
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:298
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.