LLVM 22.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 ExpandLOOP_DEPENDENCE_MASK(SDNode *N);
142 SDValue ExpandSELECT(SDNode *Node);
143 std::pair<SDValue, SDValue> ExpandLoad(SDNode *N);
144 SDValue ExpandStore(SDNode *N);
145 SDValue ExpandFNEG(SDNode *Node);
146 SDValue ExpandFABS(SDNode *Node);
147 SDValue ExpandFCOPYSIGN(SDNode *Node);
148 void ExpandFSUB(SDNode *Node, SmallVectorImpl<SDValue> &Results);
149 void ExpandSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
150 SDValue ExpandBITREVERSE(SDNode *Node);
151 void ExpandUADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
152 void ExpandSADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
153 void ExpandMULO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
154 void ExpandFixedPointDiv(SDNode *Node, SmallVectorImpl<SDValue> &Results);
155 void ExpandStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
156 void ExpandREM(SDNode *Node, SmallVectorImpl<SDValue> &Results);
157
158 bool tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
160
161 void UnrollStrictFPOp(SDNode *Node, SmallVectorImpl<SDValue> &Results);
162
163 /// Implements vector promotion.
164 ///
165 /// This is essentially just bitcasting the operands to a different type and
166 /// bitcasting the result back to the original type.
168
169 /// Implements [SU]INT_TO_FP vector promotion.
170 ///
171 /// This is a [zs]ext of the input operand to a larger integer type.
172 void PromoteINT_TO_FP(SDNode *Node, SmallVectorImpl<SDValue> &Results);
173
174 /// Implements FP_TO_[SU]INT vector promotion of the result type.
175 ///
176 /// It is promoted to a larger integer type. The result is then
177 /// truncated back to the original type.
178 void PromoteFP_TO_INT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
179
180 /// Implements vector setcc operation promotion.
181 ///
182 /// All vector operands are promoted to a vector type with larger element
183 /// type.
184 void PromoteSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
185
186 void PromoteSTRICT(SDNode *Node, SmallVectorImpl<SDValue> &Results);
187
188 /// Calculate the reduction using a type of higher precision and round the
189 /// result to match the original type. Setting NonArithmetic signifies the
190 /// rounding of the result does not affect its value.
191 void PromoteFloatVECREDUCE(SDNode *Node, SmallVectorImpl<SDValue> &Results,
192 bool NonArithmetic);
193
194public:
195 VectorLegalizer(SelectionDAG& dag) :
196 DAG(dag), TLI(dag.getTargetLoweringInfo()) {}
197
198 /// Begin legalizer the vector operations in the DAG.
199 bool Run();
200};
201
202} // end anonymous namespace
203
204bool VectorLegalizer::Run() {
205 // Before we start legalizing vector nodes, check if there are any vectors.
206 bool HasVectors = false;
208 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) {
209 // Check if the values of the nodes contain vectors. We don't need to check
210 // the operands because we are going to check their values at some point.
211 HasVectors = llvm::any_of(I->values(), [](EVT T) { return T.isVector(); });
212
213 // If we found a vector node we can start the legalization.
214 if (HasVectors)
215 break;
216 }
217
218 // If this basic block has no vectors then no need to legalize vectors.
219 if (!HasVectors)
220 return false;
221
222 // The legalize process is inherently a bottom-up recursive process (users
223 // legalize their uses before themselves). Given infinite stack space, we
224 // could just start legalizing on the root and traverse the whole graph. In
225 // practice however, this causes us to run out of stack space on large basic
226 // blocks. To avoid this problem, compute an ordering of the nodes where each
227 // node is only legalized after all of its operands are legalized.
230 E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I)
231 LegalizeOp(SDValue(&*I, 0));
232
233 // Finally, it's possible the root changed. Get the new root.
234 SDValue OldRoot = DAG.getRoot();
235 assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
236 DAG.setRoot(LegalizedNodes[OldRoot]);
237
238 LegalizedNodes.clear();
239
240 // Remove dead nodes now.
241 DAG.RemoveDeadNodes();
242
243 return Changed;
244}
245
246SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDNode *Result) {
247 assert(Op->getNumValues() == Result->getNumValues() &&
248 "Unexpected number of results");
249 // Generic legalization: just pass the operand through.
250 for (unsigned i = 0, e = Op->getNumValues(); i != e; ++i)
251 AddLegalizedOperand(Op.getValue(i), SDValue(Result, i));
252 return SDValue(Result, Op.getResNo());
253}
254
256VectorLegalizer::RecursivelyLegalizeResults(SDValue Op,
258 assert(Results.size() == Op->getNumValues() &&
259 "Unexpected number of results");
260 // Make sure that the generated code is itself legal.
261 for (unsigned i = 0, e = Results.size(); i != e; ++i) {
262 Results[i] = LegalizeOp(Results[i]);
263 AddLegalizedOperand(Op.getValue(i), Results[i]);
264 }
265
266 return Results[Op.getResNo()];
267}
268
269SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
270 // Note that LegalizeOp may be reentered even from single-use nodes, which
271 // means that we always must cache transformed nodes.
272 DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
273 if (I != LegalizedNodes.end()) return I->second;
274
275 // Legalize the operands
277 for (const SDValue &Oper : Op->op_values())
278 Ops.push_back(LegalizeOp(Oper));
279
280 SDNode *Node = DAG.UpdateNodeOperands(Op.getNode(), Ops);
281
282 bool HasVectorValueOrOp =
283 llvm::any_of(Node->values(), [](EVT T) { return T.isVector(); }) ||
284 llvm::any_of(Node->op_values(),
285 [](SDValue O) { return O.getValueType().isVector(); });
286 if (!HasVectorValueOrOp)
287 return TranslateLegalizeResults(Op, Node);
288
289 TargetLowering::LegalizeAction Action = TargetLowering::Legal;
290 EVT ValVT;
291 switch (Op.getOpcode()) {
292 default:
293 return TranslateLegalizeResults(Op, Node);
294 case ISD::LOAD: {
295 LoadSDNode *LD = cast<LoadSDNode>(Node);
296 ISD::LoadExtType ExtType = LD->getExtensionType();
297 EVT LoadedVT = LD->getMemoryVT();
298 if (LoadedVT.isVector() && ExtType != ISD::NON_EXTLOAD)
299 Action = TLI.getLoadExtAction(ExtType, LD->getValueType(0), LoadedVT);
300 break;
301 }
302 case ISD::STORE: {
303 StoreSDNode *ST = cast<StoreSDNode>(Node);
304 EVT StVT = ST->getMemoryVT();
305 MVT ValVT = ST->getValue().getSimpleValueType();
306 if (StVT.isVector() && ST->isTruncatingStore())
307 Action = TLI.getTruncStoreAction(ValVT, StVT);
308 break;
309 }
311 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
312 // This operation lies about being legal: when it claims to be legal,
313 // it should actually be expanded.
314 if (Action == TargetLowering::Legal)
315 Action = TargetLowering::Expand;
316 break;
317#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
318 case ISD::STRICT_##DAGN:
319#include "llvm/IR/ConstrainedOps.def"
320 ValVT = Node->getValueType(0);
321 if (Op.getOpcode() == ISD::STRICT_SINT_TO_FP ||
322 Op.getOpcode() == ISD::STRICT_UINT_TO_FP)
323 ValVT = Node->getOperand(1).getValueType();
324 if (Op.getOpcode() == ISD::STRICT_FSETCC ||
325 Op.getOpcode() == ISD::STRICT_FSETCCS) {
326 MVT OpVT = Node->getOperand(1).getSimpleValueType();
327 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(3))->get();
328 Action = TLI.getCondCodeAction(CCCode, OpVT);
329 if (Action == TargetLowering::Legal)
330 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
331 } else {
332 Action = TLI.getOperationAction(Node->getOpcode(), ValVT);
333 }
334 // If we're asked to expand a strict vector floating-point operation,
335 // by default we're going to simply unroll it. That is usually the
336 // best approach, except in the case where the resulting strict (scalar)
337 // operations would themselves use the fallback mutation to non-strict.
338 // In that specific case, just do the fallback on the vector op.
339 if (Action == TargetLowering::Expand && !TLI.isStrictFPEnabled() &&
340 TLI.getStrictFPOperationAction(Node->getOpcode(), ValVT) ==
341 TargetLowering::Legal) {
342 EVT EltVT = ValVT.getVectorElementType();
343 if (TLI.getOperationAction(Node->getOpcode(), EltVT)
344 == TargetLowering::Expand &&
345 TLI.getStrictFPOperationAction(Node->getOpcode(), EltVT)
346 == TargetLowering::Legal)
347 Action = TargetLowering::Legal;
348 }
349 break;
350 case ISD::ADD:
351 case ISD::SUB:
352 case ISD::MUL:
353 case ISD::MULHS:
354 case ISD::MULHU:
355 case ISD::SDIV:
356 case ISD::UDIV:
357 case ISD::SREM:
358 case ISD::UREM:
359 case ISD::SDIVREM:
360 case ISD::UDIVREM:
361 case ISD::FADD:
362 case ISD::FSUB:
363 case ISD::FMUL:
364 case ISD::FDIV:
365 case ISD::FREM:
366 case ISD::AND:
367 case ISD::OR:
368 case ISD::XOR:
369 case ISD::SHL:
370 case ISD::SRA:
371 case ISD::SRL:
372 case ISD::FSHL:
373 case ISD::FSHR:
374 case ISD::ROTL:
375 case ISD::ROTR:
376 case ISD::ABS:
377 case ISD::ABDS:
378 case ISD::ABDU:
379 case ISD::AVGCEILS:
380 case ISD::AVGCEILU:
381 case ISD::AVGFLOORS:
382 case ISD::AVGFLOORU:
383 case ISD::BSWAP:
384 case ISD::BITREVERSE:
385 case ISD::CTLZ:
386 case ISD::CTTZ:
389 case ISD::CTPOP:
390 case ISD::SELECT:
391 case ISD::VSELECT:
392 case ISD::SELECT_CC:
393 case ISD::ZERO_EXTEND:
394 case ISD::ANY_EXTEND:
395 case ISD::TRUNCATE:
396 case ISD::SIGN_EXTEND:
397 case ISD::FP_TO_SINT:
398 case ISD::FP_TO_UINT:
399 case ISD::FNEG:
400 case ISD::FABS:
401 case ISD::FMINNUM:
402 case ISD::FMAXNUM:
405 case ISD::FMINIMUM:
406 case ISD::FMAXIMUM:
407 case ISD::FMINIMUMNUM:
408 case ISD::FMAXIMUMNUM:
409 case ISD::FCOPYSIGN:
410 case ISD::FSQRT:
411 case ISD::FSIN:
412 case ISD::FCOS:
413 case ISD::FTAN:
414 case ISD::FASIN:
415 case ISD::FACOS:
416 case ISD::FATAN:
417 case ISD::FATAN2:
418 case ISD::FSINH:
419 case ISD::FCOSH:
420 case ISD::FTANH:
421 case ISD::FLDEXP:
422 case ISD::FPOWI:
423 case ISD::FPOW:
424 case ISD::FLOG:
425 case ISD::FLOG2:
426 case ISD::FLOG10:
427 case ISD::FEXP:
428 case ISD::FEXP2:
429 case ISD::FEXP10:
430 case ISD::FCEIL:
431 case ISD::FTRUNC:
432 case ISD::FRINT:
433 case ISD::FNEARBYINT:
434 case ISD::FROUND:
435 case ISD::FROUNDEVEN:
436 case ISD::FFLOOR:
437 case ISD::FP_ROUND:
438 case ISD::FP_EXTEND:
440 case ISD::FMA:
445 case ISD::SMIN:
446 case ISD::SMAX:
447 case ISD::UMIN:
448 case ISD::UMAX:
449 case ISD::SMUL_LOHI:
450 case ISD::UMUL_LOHI:
451 case ISD::SADDO:
452 case ISD::UADDO:
453 case ISD::SSUBO:
454 case ISD::USUBO:
455 case ISD::SMULO:
456 case ISD::UMULO:
458 case ISD::FFREXP:
459 case ISD::FMODF:
460 case ISD::FSINCOS:
461 case ISD::FSINCOSPI:
462 case ISD::SADDSAT:
463 case ISD::UADDSAT:
464 case ISD::SSUBSAT:
465 case ISD::USUBSAT:
466 case ISD::SSHLSAT:
467 case ISD::USHLSAT:
470 case ISD::MGATHER:
472 case ISD::SCMP:
473 case ISD::UCMP:
476 Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
477 break;
478 case ISD::SMULFIX:
479 case ISD::SMULFIXSAT:
480 case ISD::UMULFIX:
481 case ISD::UMULFIXSAT:
482 case ISD::SDIVFIX:
483 case ISD::SDIVFIXSAT:
484 case ISD::UDIVFIX:
485 case ISD::UDIVFIXSAT: {
486 unsigned Scale = Node->getConstantOperandVal(2);
487 Action = TLI.getFixedPointOperationAction(Node->getOpcode(),
488 Node->getValueType(0), Scale);
489 break;
490 }
491 case ISD::LROUND:
492 case ISD::LLROUND:
493 case ISD::LRINT:
494 case ISD::LLRINT:
495 case ISD::SINT_TO_FP:
496 case ISD::UINT_TO_FP:
513 Action = TLI.getOperationAction(Node->getOpcode(),
514 Node->getOperand(0).getValueType());
515 break;
518 Action = TLI.getOperationAction(Node->getOpcode(),
519 Node->getOperand(1).getValueType());
520 break;
521 case ISD::SETCC: {
522 MVT OpVT = Node->getOperand(0).getSimpleValueType();
523 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get();
524 Action = TLI.getCondCodeAction(CCCode, OpVT);
525 if (Action == TargetLowering::Legal)
526 Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
527 break;
528 }
533 Action =
534 TLI.getPartialReduceMLAAction(Op.getOpcode(), Node->getValueType(0),
535 Node->getOperand(1).getValueType());
536 break;
537
538#define BEGIN_REGISTER_VP_SDNODE(VPID, LEGALPOS, ...) \
539 case ISD::VPID: { \
540 EVT LegalizeVT = LEGALPOS < 0 ? Node->getValueType(-(1 + LEGALPOS)) \
541 : Node->getOperand(LEGALPOS).getValueType(); \
542 if (ISD::VPID == ISD::VP_SETCC) { \
543 ISD::CondCode CCCode = cast<CondCodeSDNode>(Node->getOperand(2))->get(); \
544 Action = TLI.getCondCodeAction(CCCode, LegalizeVT.getSimpleVT()); \
545 if (Action != TargetLowering::Legal) \
546 break; \
547 } \
548 /* Defer non-vector results to LegalizeDAG. */ \
549 if (!Node->getValueType(0).isVector() && \
550 Node->getValueType(0) != MVT::Other) { \
551 Action = TargetLowering::Legal; \
552 break; \
553 } \
554 Action = TLI.getOperationAction(Node->getOpcode(), LegalizeVT); \
555 } break;
556#include "llvm/IR/VPIntrinsics.def"
557 }
558
559 LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG));
560
561 SmallVector<SDValue, 8> ResultVals;
562 switch (Action) {
563 default: llvm_unreachable("This action is not supported yet!");
564 case TargetLowering::Promote:
565 assert((Op.getOpcode() != ISD::LOAD && Op.getOpcode() != ISD::STORE) &&
566 "This action is not supported yet!");
567 LLVM_DEBUG(dbgs() << "Promoting\n");
568 Promote(Node, ResultVals);
569 assert(!ResultVals.empty() && "No results for promotion?");
570 break;
571 case TargetLowering::Legal:
572 LLVM_DEBUG(dbgs() << "Legal node: nothing to do\n");
573 break;
574 case TargetLowering::Custom:
575 LLVM_DEBUG(dbgs() << "Trying custom legalization\n");
576 if (LowerOperationWrapper(Node, ResultVals))
577 break;
578 LLVM_DEBUG(dbgs() << "Could not custom legalize node\n");
579 [[fallthrough]];
580 case TargetLowering::Expand:
581 LLVM_DEBUG(dbgs() << "Expanding\n");
582 Expand(Node, ResultVals);
583 break;
584 }
585
586 if (ResultVals.empty())
587 return TranslateLegalizeResults(Op, Node);
588
589 Changed = true;
590 return RecursivelyLegalizeResults(Op, ResultVals);
591}
592
593// FIXME: This is very similar to TargetLowering::LowerOperationWrapper. Can we
594// merge them somehow?
595bool VectorLegalizer::LowerOperationWrapper(SDNode *Node,
596 SmallVectorImpl<SDValue> &Results) {
597 SDValue Res = TLI.LowerOperation(SDValue(Node, 0), DAG);
598
599 if (!Res.getNode())
600 return false;
601
602 if (Res == SDValue(Node, 0))
603 return true;
604
605 // If the original node has one result, take the return value from
606 // LowerOperation as is. It might not be result number 0.
607 if (Node->getNumValues() == 1) {
608 Results.push_back(Res);
609 return true;
610 }
611
612 // If the original node has multiple results, then the return node should
613 // have the same number of results.
614 assert((Node->getNumValues() == Res->getNumValues()) &&
615 "Lowering returned the wrong number of results!");
616
617 // Places new result values base on N result number.
618 for (unsigned I = 0, E = Node->getNumValues(); I != E; ++I)
619 Results.push_back(Res.getValue(I));
620
621 return true;
622}
623
624void VectorLegalizer::PromoteSETCC(SDNode *Node,
625 SmallVectorImpl<SDValue> &Results) {
626 MVT VecVT = Node->getOperand(0).getSimpleValueType();
627 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
628
629 unsigned ExtOp = VecVT.isFloatingPoint() ? ISD::FP_EXTEND : ISD::ANY_EXTEND;
630
631 SDLoc DL(Node);
632 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
633
634 Operands[0] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(0));
635 Operands[1] = DAG.getNode(ExtOp, DL, NewVecVT, Node->getOperand(1));
636 Operands[2] = Node->getOperand(2);
637
638 if (Node->getOpcode() == ISD::VP_SETCC) {
639 Operands[3] = Node->getOperand(3); // mask
640 Operands[4] = Node->getOperand(4); // evl
641 }
642
643 SDValue Res = DAG.getNode(Node->getOpcode(), DL, Node->getSimpleValueType(0),
644 Operands, Node->getFlags());
645
646 Results.push_back(Res);
647}
648
649void VectorLegalizer::PromoteSTRICT(SDNode *Node,
650 SmallVectorImpl<SDValue> &Results) {
651 MVT VecVT = Node->getOperand(1).getSimpleValueType();
652 MVT NewVecVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VecVT);
653
654 assert(VecVT.isFloatingPoint());
655
656 SDLoc DL(Node);
657 SmallVector<SDValue, 5> Operands(Node->getNumOperands());
659
660 for (unsigned j = 1; j != Node->getNumOperands(); ++j)
661 if (Node->getOperand(j).getValueType().isVector() &&
662 !(ISD::isVPOpcode(Node->getOpcode()) &&
663 ISD::getVPMaskIdx(Node->getOpcode()) == j)) // Skip mask operand.
664 {
665 // promote the vector operand.
666 SDValue Ext =
667 DAG.getNode(ISD::STRICT_FP_EXTEND, DL, {NewVecVT, MVT::Other},
668 {Node->getOperand(0), Node->getOperand(j)});
669 Operands[j] = Ext.getValue(0);
670 Chains.push_back(Ext.getValue(1));
671 } else
672 Operands[j] = Node->getOperand(j); // Skip no vector operand.
673
674 SDVTList VTs = DAG.getVTList(NewVecVT, Node->getValueType(1));
675
676 Operands[0] = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
677
678 SDValue Res =
679 DAG.getNode(Node->getOpcode(), DL, VTs, Operands, Node->getFlags());
680
681 SDValue Round =
682 DAG.getNode(ISD::STRICT_FP_ROUND, DL, {VecVT, MVT::Other},
683 {Res.getValue(1), Res.getValue(0),
684 DAG.getIntPtrConstant(0, DL, /*isTarget=*/true)});
685
686 Results.push_back(Round.getValue(0));
687 Results.push_back(Round.getValue(1));
688}
689
690void VectorLegalizer::PromoteFloatVECREDUCE(SDNode *Node,
691 SmallVectorImpl<SDValue> &Results,
692 bool NonArithmetic) {
693 MVT OpVT = Node->getOperand(0).getSimpleValueType();
694 assert(OpVT.isFloatingPoint() && "Expected floating point reduction!");
695 MVT NewOpVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OpVT);
696
697 SDLoc DL(Node);
698 SDValue NewOp = DAG.getNode(ISD::FP_EXTEND, DL, NewOpVT, Node->getOperand(0));
699 SDValue Rdx =
700 DAG.getNode(Node->getOpcode(), DL, NewOpVT.getVectorElementType(), NewOp,
701 Node->getFlags());
702 SDValue Res =
703 DAG.getNode(ISD::FP_ROUND, DL, Node->getValueType(0), Rdx,
704 DAG.getIntPtrConstant(NonArithmetic, DL, /*isTarget=*/true));
705 Results.push_back(Res);
706}
707
708void VectorLegalizer::Promote(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
709 // For a few operations there is a specific concept for promotion based on
710 // the operand's type.
711 switch (Node->getOpcode()) {
712 case ISD::SINT_TO_FP:
713 case ISD::UINT_TO_FP:
716 // "Promote" the operation by extending the operand.
717 PromoteINT_TO_FP(Node, Results);
718 return;
719 case ISD::FP_TO_UINT:
720 case ISD::FP_TO_SINT:
723 // Promote the operation by extending the operand.
724 PromoteFP_TO_INT(Node, Results);
725 return;
726 case ISD::VP_SETCC:
727 case ISD::SETCC:
728 // Promote the operation by extending the operand.
729 PromoteSETCC(Node, Results);
730 return;
731 case ISD::STRICT_FADD:
732 case ISD::STRICT_FSUB:
733 case ISD::STRICT_FMUL:
734 case ISD::STRICT_FDIV:
736 case ISD::STRICT_FMA:
737 PromoteSTRICT(Node, Results);
738 return;
740 PromoteFloatVECREDUCE(Node, Results, /*NonArithmetic=*/false);
741 return;
746 PromoteFloatVECREDUCE(Node, Results, /*NonArithmetic=*/true);
747 return;
748 case ISD::FP_ROUND:
749 case ISD::FP_EXTEND:
750 // These operations are used to do promotion so they can't be promoted
751 // themselves.
752 llvm_unreachable("Don't know how to promote this operation!");
753 case ISD::VP_FABS:
754 case ISD::VP_FCOPYSIGN:
755 case ISD::VP_FNEG:
756 // Promoting fabs, fneg, and fcopysign changes their semantics.
757 llvm_unreachable("These operations should not be promoted");
758 }
759
760 // There are currently two cases of vector promotion:
761 // 1) Bitcasting a vector of integers to a different type to a vector of the
762 // same overall length. For example, x86 promotes ISD::AND v2i32 to v1i64.
763 // 2) Extending a vector of floats to a vector of the same number of larger
764 // floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32.
765 assert(Node->getNumValues() == 1 &&
766 "Can't promote a vector with multiple results!");
767 MVT VT = Node->getSimpleValueType(0);
768 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
769 SDLoc dl(Node);
770 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
771
772 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
773 // Do not promote the mask operand of a VP OP.
774 bool SkipPromote = ISD::isVPOpcode(Node->getOpcode()) &&
775 ISD::getVPMaskIdx(Node->getOpcode()) == j;
776 if (Node->getOperand(j).getValueType().isVector() && !SkipPromote)
777 if (Node->getOperand(j)
778 .getValueType()
779 .getVectorElementType()
780 .isFloatingPoint() &&
782 if (ISD::isVPOpcode(Node->getOpcode())) {
783 unsigned EVLIdx =
785 unsigned MaskIdx = *ISD::getVPMaskIdx(Node->getOpcode());
786 Operands[j] =
787 DAG.getNode(ISD::VP_FP_EXTEND, dl, NVT, Node->getOperand(j),
788 Node->getOperand(MaskIdx), Node->getOperand(EVLIdx));
789 } else {
790 Operands[j] =
791 DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(j));
792 }
793 else
794 Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Node->getOperand(j));
795 else
796 Operands[j] = Node->getOperand(j);
797 }
798
799 SDValue Res =
800 DAG.getNode(Node->getOpcode(), dl, NVT, Operands, Node->getFlags());
801
802 if ((VT.isFloatingPoint() && NVT.isFloatingPoint()) ||
805 if (ISD::isVPOpcode(Node->getOpcode())) {
806 unsigned EVLIdx = *ISD::getVPExplicitVectorLengthIdx(Node->getOpcode());
807 unsigned MaskIdx = *ISD::getVPMaskIdx(Node->getOpcode());
808 Res = DAG.getNode(ISD::VP_FP_ROUND, dl, VT, Res,
809 Node->getOperand(MaskIdx), Node->getOperand(EVLIdx));
810 } else {
811 Res = DAG.getNode(ISD::FP_ROUND, dl, VT, Res,
812 DAG.getIntPtrConstant(0, dl, /*isTarget=*/true));
813 }
814 else
815 Res = DAG.getNode(ISD::BITCAST, dl, VT, Res);
816
817 Results.push_back(Res);
818}
819
820void VectorLegalizer::PromoteINT_TO_FP(SDNode *Node,
821 SmallVectorImpl<SDValue> &Results) {
822 // INT_TO_FP operations may require the input operand be promoted even
823 // when the type is otherwise legal.
824 bool IsStrict = Node->isStrictFPOpcode();
825 MVT VT = Node->getOperand(IsStrict ? 1 : 0).getSimpleValueType();
826 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
828 "Vectors have different number of elements!");
829
830 SDLoc dl(Node);
831 SmallVector<SDValue, 4> Operands(Node->getNumOperands());
832
833 unsigned Opc = (Node->getOpcode() == ISD::UINT_TO_FP ||
834 Node->getOpcode() == ISD::STRICT_UINT_TO_FP)
837 for (unsigned j = 0; j != Node->getNumOperands(); ++j) {
838 if (Node->getOperand(j).getValueType().isVector())
839 Operands[j] = DAG.getNode(Opc, dl, NVT, Node->getOperand(j));
840 else
841 Operands[j] = Node->getOperand(j);
842 }
843
844 if (IsStrict) {
845 SDValue Res = DAG.getNode(Node->getOpcode(), dl,
846 {Node->getValueType(0), MVT::Other}, Operands);
847 Results.push_back(Res);
848 Results.push_back(Res.getValue(1));
849 return;
850 }
851
852 SDValue Res =
853 DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Operands);
854 Results.push_back(Res);
855}
856
857// For FP_TO_INT we promote the result type to a vector type with wider
858// elements and then truncate the result. This is different from the default
859// PromoteVector which uses bitcast to promote thus assumning that the
860// promoted vector type has the same overall size.
861void VectorLegalizer::PromoteFP_TO_INT(SDNode *Node,
862 SmallVectorImpl<SDValue> &Results) {
863 MVT VT = Node->getSimpleValueType(0);
864 MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
865 bool IsStrict = Node->isStrictFPOpcode();
867 "Vectors have different number of elements!");
868
869 unsigned NewOpc = Node->getOpcode();
870 // Change FP_TO_UINT to FP_TO_SINT if possible.
871 // TODO: Should we only do this if FP_TO_UINT itself isn't legal?
872 if (NewOpc == ISD::FP_TO_UINT &&
874 NewOpc = ISD::FP_TO_SINT;
875
876 if (NewOpc == ISD::STRICT_FP_TO_UINT &&
878 NewOpc = ISD::STRICT_FP_TO_SINT;
879
880 SDLoc dl(Node);
881 SDValue Promoted, Chain;
882 if (IsStrict) {
883 Promoted = DAG.getNode(NewOpc, dl, {NVT, MVT::Other},
884 {Node->getOperand(0), Node->getOperand(1)});
885 Chain = Promoted.getValue(1);
886 } else
887 Promoted = DAG.getNode(NewOpc, dl, NVT, Node->getOperand(0));
888
889 // Assert that the converted value fits in the original type. If it doesn't
890 // (eg: because the value being converted is too big), then the result of the
891 // original operation was undefined anyway, so the assert is still correct.
892 if (Node->getOpcode() == ISD::FP_TO_UINT ||
893 Node->getOpcode() == ISD::STRICT_FP_TO_UINT)
894 NewOpc = ISD::AssertZext;
895 else
896 NewOpc = ISD::AssertSext;
897
898 Promoted = DAG.getNode(NewOpc, dl, NVT, Promoted,
899 DAG.getValueType(VT.getScalarType()));
900 Promoted = DAG.getNode(ISD::TRUNCATE, dl, VT, Promoted);
901 Results.push_back(Promoted);
902 if (IsStrict)
903 Results.push_back(Chain);
904}
905
906std::pair<SDValue, SDValue> VectorLegalizer::ExpandLoad(SDNode *N) {
907 LoadSDNode *LD = cast<LoadSDNode>(N);
908 return TLI.scalarizeVectorLoad(LD, DAG);
909}
910
911SDValue VectorLegalizer::ExpandStore(SDNode *N) {
912 StoreSDNode *ST = cast<StoreSDNode>(N);
913 SDValue TF = TLI.scalarizeVectorStore(ST, DAG);
914 return TF;
915}
916
917void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
918 switch (Node->getOpcode()) {
919 case ISD::LOAD: {
920 std::pair<SDValue, SDValue> Tmp = ExpandLoad(Node);
921 Results.push_back(Tmp.first);
922 Results.push_back(Tmp.second);
923 return;
924 }
925 case ISD::STORE:
926 Results.push_back(ExpandStore(Node));
927 return;
929 for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
930 Results.push_back(Node->getOperand(i));
931 return;
933 if (SDValue Expanded = ExpandSEXTINREG(Node)) {
934 Results.push_back(Expanded);
935 return;
936 }
937 break;
939 Results.push_back(ExpandANY_EXTEND_VECTOR_INREG(Node));
940 return;
942 Results.push_back(ExpandSIGN_EXTEND_VECTOR_INREG(Node));
943 return;
945 Results.push_back(ExpandZERO_EXTEND_VECTOR_INREG(Node));
946 return;
947 case ISD::BSWAP:
948 if (SDValue Expanded = ExpandBSWAP(Node)) {
949 Results.push_back(Expanded);
950 return;
951 }
952 break;
953 case ISD::VP_BSWAP:
954 Results.push_back(TLI.expandVPBSWAP(Node, DAG));
955 return;
956 case ISD::VSELECT:
957 if (SDValue Expanded = ExpandVSELECT(Node)) {
958 Results.push_back(Expanded);
959 return;
960 }
961 break;
962 case ISD::VP_SELECT:
963 if (SDValue Expanded = ExpandVP_SELECT(Node)) {
964 Results.push_back(Expanded);
965 return;
966 }
967 break;
968 case ISD::VP_SREM:
969 case ISD::VP_UREM:
970 if (SDValue Expanded = ExpandVP_REM(Node)) {
971 Results.push_back(Expanded);
972 return;
973 }
974 break;
975 case ISD::VP_FNEG:
976 if (SDValue Expanded = ExpandVP_FNEG(Node)) {
977 Results.push_back(Expanded);
978 return;
979 }
980 break;
981 case ISD::VP_FABS:
982 if (SDValue Expanded = ExpandVP_FABS(Node)) {
983 Results.push_back(Expanded);
984 return;
985 }
986 break;
987 case ISD::VP_FCOPYSIGN:
988 if (SDValue Expanded = ExpandVP_FCOPYSIGN(Node)) {
989 Results.push_back(Expanded);
990 return;
991 }
992 break;
993 case ISD::SELECT:
994 if (SDValue Expanded = ExpandSELECT(Node)) {
995 Results.push_back(Expanded);
996 return;
997 }
998 break;
999 case ISD::SELECT_CC: {
1000 if (Node->getValueType(0).isScalableVector()) {
1001 EVT CondVT = TLI.getSetCCResultType(
1002 DAG.getDataLayout(), *DAG.getContext(), Node->getValueType(0));
1003 SDValue SetCC =
1004 DAG.getNode(ISD::SETCC, SDLoc(Node), CondVT, Node->getOperand(0),
1005 Node->getOperand(1), Node->getOperand(4));
1006 Results.push_back(DAG.getSelect(SDLoc(Node), Node->getValueType(0), SetCC,
1007 Node->getOperand(2),
1008 Node->getOperand(3)));
1009 return;
1010 }
1011 break;
1012 }
1013 case ISD::FP_TO_UINT:
1014 ExpandFP_TO_UINT(Node, Results);
1015 return;
1016 case ISD::UINT_TO_FP:
1017 ExpandUINT_TO_FLOAT(Node, Results);
1018 return;
1019 case ISD::FNEG:
1020 if (SDValue Expanded = ExpandFNEG(Node)) {
1021 Results.push_back(Expanded);
1022 return;
1023 }
1024 break;
1025 case ISD::FABS:
1026 if (SDValue Expanded = ExpandFABS(Node)) {
1027 Results.push_back(Expanded);
1028 return;
1029 }
1030 break;
1031 case ISD::FCOPYSIGN:
1032 if (SDValue Expanded = ExpandFCOPYSIGN(Node)) {
1033 Results.push_back(Expanded);
1034 return;
1035 }
1036 break;
1037 case ISD::FSUB:
1038 ExpandFSUB(Node, Results);
1039 return;
1040 case ISD::SETCC:
1041 case ISD::VP_SETCC:
1042 ExpandSETCC(Node, Results);
1043 return;
1044 case ISD::ABS:
1045 if (SDValue Expanded = TLI.expandABS(Node, DAG)) {
1046 Results.push_back(Expanded);
1047 return;
1048 }
1049 break;
1050 case ISD::ABDS:
1051 case ISD::ABDU:
1052 if (SDValue Expanded = TLI.expandABD(Node, DAG)) {
1053 Results.push_back(Expanded);
1054 return;
1055 }
1056 break;
1057 case ISD::AVGCEILS:
1058 case ISD::AVGCEILU:
1059 case ISD::AVGFLOORS:
1060 case ISD::AVGFLOORU:
1061 if (SDValue Expanded = TLI.expandAVG(Node, DAG)) {
1062 Results.push_back(Expanded);
1063 return;
1064 }
1065 break;
1066 case ISD::BITREVERSE:
1067 if (SDValue Expanded = ExpandBITREVERSE(Node)) {
1068 Results.push_back(Expanded);
1069 return;
1070 }
1071 break;
1072 case ISD::VP_BITREVERSE:
1073 if (SDValue Expanded = TLI.expandVPBITREVERSE(Node, DAG)) {
1074 Results.push_back(Expanded);
1075 return;
1076 }
1077 break;
1078 case ISD::CTPOP:
1079 if (SDValue Expanded = TLI.expandCTPOP(Node, DAG)) {
1080 Results.push_back(Expanded);
1081 return;
1082 }
1083 break;
1084 case ISD::VP_CTPOP:
1085 if (SDValue Expanded = TLI.expandVPCTPOP(Node, DAG)) {
1086 Results.push_back(Expanded);
1087 return;
1088 }
1089 break;
1090 case ISD::CTLZ:
1092 if (SDValue Expanded = TLI.expandCTLZ(Node, DAG)) {
1093 Results.push_back(Expanded);
1094 return;
1095 }
1096 break;
1097 case ISD::VP_CTLZ:
1098 case ISD::VP_CTLZ_ZERO_UNDEF:
1099 if (SDValue Expanded = TLI.expandVPCTLZ(Node, DAG)) {
1100 Results.push_back(Expanded);
1101 return;
1102 }
1103 break;
1104 case ISD::CTTZ:
1106 if (SDValue Expanded = TLI.expandCTTZ(Node, DAG)) {
1107 Results.push_back(Expanded);
1108 return;
1109 }
1110 break;
1111 case ISD::VP_CTTZ:
1112 case ISD::VP_CTTZ_ZERO_UNDEF:
1113 if (SDValue Expanded = TLI.expandVPCTTZ(Node, DAG)) {
1114 Results.push_back(Expanded);
1115 return;
1116 }
1117 break;
1118 case ISD::FSHL:
1119 case ISD::VP_FSHL:
1120 case ISD::FSHR:
1121 case ISD::VP_FSHR:
1122 if (SDValue Expanded = TLI.expandFunnelShift(Node, DAG)) {
1123 Results.push_back(Expanded);
1124 return;
1125 }
1126 break;
1127 case ISD::ROTL:
1128 case ISD::ROTR:
1129 if (SDValue Expanded = TLI.expandROT(Node, false /*AllowVectorOps*/, DAG)) {
1130 Results.push_back(Expanded);
1131 return;
1132 }
1133 break;
1134 case ISD::FMINNUM:
1135 case ISD::FMAXNUM:
1136 if (SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Node, DAG)) {
1137 Results.push_back(Expanded);
1138 return;
1139 }
1140 break;
1141 case ISD::FMINIMUM:
1142 case ISD::FMAXIMUM:
1143 Results.push_back(TLI.expandFMINIMUM_FMAXIMUM(Node, DAG));
1144 return;
1145 case ISD::FMINIMUMNUM:
1146 case ISD::FMAXIMUMNUM:
1147 Results.push_back(TLI.expandFMINIMUMNUM_FMAXIMUMNUM(Node, DAG));
1148 return;
1149 case ISD::SMIN:
1150 case ISD::SMAX:
1151 case ISD::UMIN:
1152 case ISD::UMAX:
1153 if (SDValue Expanded = TLI.expandIntMINMAX(Node, DAG)) {
1154 Results.push_back(Expanded);
1155 return;
1156 }
1157 break;
1158 case ISD::UADDO:
1159 case ISD::USUBO:
1160 ExpandUADDSUBO(Node, Results);
1161 return;
1162 case ISD::SADDO:
1163 case ISD::SSUBO:
1164 ExpandSADDSUBO(Node, Results);
1165 return;
1166 case ISD::UMULO:
1167 case ISD::SMULO:
1168 ExpandMULO(Node, Results);
1169 return;
1170 case ISD::USUBSAT:
1171 case ISD::SSUBSAT:
1172 case ISD::UADDSAT:
1173 case ISD::SADDSAT:
1174 if (SDValue Expanded = TLI.expandAddSubSat(Node, DAG)) {
1175 Results.push_back(Expanded);
1176 return;
1177 }
1178 break;
1179 case ISD::USHLSAT:
1180 case ISD::SSHLSAT:
1181 if (SDValue Expanded = TLI.expandShlSat(Node, DAG)) {
1182 Results.push_back(Expanded);
1183 return;
1184 }
1185 break;
1188 // Expand the fpsosisat if it is scalable to prevent it from unrolling below.
1189 if (Node->getValueType(0).isScalableVector()) {
1190 if (SDValue Expanded = TLI.expandFP_TO_INT_SAT(Node, DAG)) {
1191 Results.push_back(Expanded);
1192 return;
1193 }
1194 }
1195 break;
1196 case ISD::SMULFIX:
1197 case ISD::UMULFIX:
1198 if (SDValue Expanded = TLI.expandFixedPointMul(Node, DAG)) {
1199 Results.push_back(Expanded);
1200 return;
1201 }
1202 break;
1203 case ISD::SMULFIXSAT:
1204 case ISD::UMULFIXSAT:
1205 // FIXME: We do not expand SMULFIXSAT/UMULFIXSAT here yet, not sure exactly
1206 // why. Maybe it results in worse codegen compared to the unroll for some
1207 // targets? This should probably be investigated. And if we still prefer to
1208 // unroll an explanation could be helpful.
1209 break;
1210 case ISD::SDIVFIX:
1211 case ISD::UDIVFIX:
1212 ExpandFixedPointDiv(Node, Results);
1213 return;
1214 case ISD::SDIVFIXSAT:
1215 case ISD::UDIVFIXSAT:
1216 break;
1217#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
1218 case ISD::STRICT_##DAGN:
1219#include "llvm/IR/ConstrainedOps.def"
1220 ExpandStrictFPOp(Node, Results);
1221 return;
1222 case ISD::VECREDUCE_ADD:
1223 case ISD::VECREDUCE_MUL:
1224 case ISD::VECREDUCE_AND:
1225 case ISD::VECREDUCE_OR:
1226 case ISD::VECREDUCE_XOR:
1237 Results.push_back(TLI.expandVecReduce(Node, DAG));
1238 return;
1243 Results.push_back(TLI.expandPartialReduceMLA(Node, DAG));
1244 return;
1247 Results.push_back(TLI.expandVecReduceSeq(Node, DAG));
1248 return;
1249 case ISD::SREM:
1250 case ISD::UREM:
1251 ExpandREM(Node, Results);
1252 return;
1253 case ISD::VP_MERGE:
1254 if (SDValue Expanded = ExpandVP_MERGE(Node)) {
1255 Results.push_back(Expanded);
1256 return;
1257 }
1258 break;
1259 case ISD::FREM: {
1260 RTLIB::Libcall LC = RTLIB::getREM(Node->getValueType(0));
1261 if (tryExpandVecMathCall(Node, LC, Results))
1262 return;
1263
1264 break;
1265 }
1266 case ISD::FSINCOS:
1267 case ISD::FSINCOSPI: {
1268 EVT VT = Node->getValueType(0);
1269 RTLIB::Libcall LC = Node->getOpcode() == ISD::FSINCOS
1270 ? RTLIB::getSINCOS(VT)
1271 : RTLIB::getSINCOSPI(VT);
1272 if (LC != RTLIB::UNKNOWN_LIBCALL &&
1273 TLI.expandMultipleResultFPLibCall(DAG, LC, Node, Results))
1274 return;
1275
1276 // TODO: Try to see if there's a narrower call available to use before
1277 // scalarizing.
1278 break;
1279 }
1280 case ISD::FMODF: {
1281 EVT VT = Node->getValueType(0);
1282 RTLIB::Libcall LC = RTLIB::getMODF(VT);
1283 if (LC != RTLIB::UNKNOWN_LIBCALL &&
1284 TLI.expandMultipleResultFPLibCall(DAG, LC, Node, Results,
1285 /*CallRetResNo=*/0))
1286 return;
1287 break;
1288 }
1290 Results.push_back(TLI.expandVECTOR_COMPRESS(Node, DAG));
1291 return;
1293 Results.push_back(TLI.expandVectorFindLastActive(Node, DAG));
1294 return;
1295 case ISD::SCMP:
1296 case ISD::UCMP:
1297 Results.push_back(TLI.expandCMP(Node, DAG));
1298 return;
1301 Results.push_back(ExpandLOOP_DEPENDENCE_MASK(Node));
1302 return;
1303
1304 case ISD::FADD:
1305 case ISD::FMUL:
1306 case ISD::FMA:
1307 case ISD::FDIV:
1308 case ISD::FCEIL:
1309 case ISD::FFLOOR:
1310 case ISD::FNEARBYINT:
1311 case ISD::FRINT:
1312 case ISD::FROUND:
1313 case ISD::FROUNDEVEN:
1314 case ISD::FTRUNC:
1315 case ISD::FSQRT:
1316 if (SDValue Expanded = TLI.expandVectorNaryOpBySplitting(Node, DAG)) {
1317 Results.push_back(Expanded);
1318 return;
1319 }
1320 break;
1321 }
1322
1323 SDValue Unrolled = DAG.UnrollVectorOp(Node);
1324 if (Node->getNumValues() == 1) {
1325 Results.push_back(Unrolled);
1326 } else {
1327 assert(Node->getNumValues() == Unrolled->getNumValues() &&
1328 "VectorLegalizer Expand returned wrong number of results!");
1329 for (unsigned I = 0, E = Unrolled->getNumValues(); I != E; ++I)
1330 Results.push_back(Unrolled.getValue(I));
1331 }
1332}
1333
1334SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
1335 // Lower a select instruction where the condition is a scalar and the
1336 // operands are vectors. Lower this select to VSELECT and implement it
1337 // using XOR AND OR. The selector bit is broadcasted.
1338 EVT VT = Node->getValueType(0);
1339 SDLoc DL(Node);
1340
1341 SDValue Mask = Node->getOperand(0);
1342 SDValue Op1 = Node->getOperand(1);
1343 SDValue Op2 = Node->getOperand(2);
1344
1345 assert(VT.isVector() && !Mask.getValueType().isVector()
1346 && Op1.getValueType() == Op2.getValueType() && "Invalid type");
1347
1348 // If we can't even use the basic vector operations of
1349 // AND,OR,XOR, we will have to scalarize the op.
1350 // Notice that the operation may be 'promoted' which means that it is
1351 // 'bitcasted' to another type which is handled.
1352 // Also, we need to be able to construct a splat vector using either
1353 // BUILD_VECTOR or SPLAT_VECTOR.
1354 // FIXME: Should we also permit fixed-length SPLAT_VECTOR as a fallback to
1355 // BUILD_VECTOR?
1356 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1357 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1358 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
1361 VT) == TargetLowering::Expand)
1362 return SDValue();
1363
1364 // Generate a mask operand.
1365 EVT MaskTy = VT.changeVectorElementTypeToInteger();
1366
1367 // What is the size of each element in the vector mask.
1368 EVT BitTy = MaskTy.getScalarType();
1369
1370 Mask = DAG.getSelect(DL, BitTy, Mask, DAG.getAllOnesConstant(DL, BitTy),
1371 DAG.getConstant(0, DL, BitTy));
1372
1373 // Broadcast the mask so that the entire vector is all one or all zero.
1374 Mask = DAG.getSplat(MaskTy, DL, Mask);
1375
1376 // Bitcast the operands to be the same type as the mask.
1377 // This is needed when we select between FP types because
1378 // the mask is a vector of integers.
1379 Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
1380 Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);
1381
1382 SDValue NotMask = DAG.getNOT(DL, Mask, MaskTy);
1383
1384 Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
1385 Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask);
1386 SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2);
1387 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1388}
1389
1390SDValue VectorLegalizer::ExpandSEXTINREG(SDNode *Node) {
1391 EVT VT = Node->getValueType(0);
1392
1393 // Make sure that the SRA and SHL instructions are available.
1394 if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
1395 TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
1396 return SDValue();
1397
1398 SDLoc DL(Node);
1399 EVT OrigTy = cast<VTSDNode>(Node->getOperand(1))->getVT();
1400
1401 unsigned BW = VT.getScalarSizeInBits();
1402 unsigned OrigBW = OrigTy.getScalarSizeInBits();
1403 SDValue ShiftSz = DAG.getConstant(BW - OrigBW, DL, VT);
1404
1405 SDValue Op = DAG.getNode(ISD::SHL, DL, VT, Node->getOperand(0), ShiftSz);
1406 return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz);
1407}
1408
1409// Generically expand a vector anyext in register to a shuffle of the relevant
1410// lanes into the appropriate locations, with other lanes left undef.
1411SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDNode *Node) {
1412 SDLoc DL(Node);
1413 EVT VT = Node->getValueType(0);
1414 int NumElements = VT.getVectorNumElements();
1415 SDValue Src = Node->getOperand(0);
1416 EVT SrcVT = Src.getValueType();
1417 int NumSrcElements = SrcVT.getVectorNumElements();
1418
1419 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1420 // into a larger vector type.
1421 if (SrcVT.bitsLE(VT)) {
1422 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1423 "ANY_EXTEND_VECTOR_INREG vector size mismatch");
1424 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1425 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1426 NumSrcElements);
1427 Src = DAG.getInsertSubvector(DL, DAG.getUNDEF(SrcVT), Src, 0);
1428 }
1429
1430 // Build a base mask of undef shuffles.
1431 SmallVector<int, 16> ShuffleMask;
1432 ShuffleMask.resize(NumSrcElements, -1);
1433
1434 // Place the extended lanes into the correct locations.
1435 int ExtLaneScale = NumSrcElements / NumElements;
1436 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1437 for (int i = 0; i < NumElements; ++i)
1438 ShuffleMask[i * ExtLaneScale + EndianOffset] = i;
1439
1440 return DAG.getNode(
1441 ISD::BITCAST, DL, VT,
1442 DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask));
1443}
1444
1445SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDNode *Node) {
1446 SDLoc DL(Node);
1447 EVT VT = Node->getValueType(0);
1448 SDValue Src = Node->getOperand(0);
1449 EVT SrcVT = Src.getValueType();
1450
1451 // First build an any-extend node which can be legalized above when we
1452 // recurse through it.
1454
1455 // Now we need sign extend. Do this by shifting the elements. Even if these
1456 // aren't legal operations, they have a better chance of being legalized
1457 // without full scalarization than the sign extension does.
1458 unsigned EltWidth = VT.getScalarSizeInBits();
1459 unsigned SrcEltWidth = SrcVT.getScalarSizeInBits();
1460 SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, DL, VT);
1461 return DAG.getNode(ISD::SRA, DL, VT,
1462 DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount),
1463 ShiftAmount);
1464}
1465
1466// Generically expand a vector zext in register to a shuffle of the relevant
1467// lanes into the appropriate locations, a blend of zero into the high bits,
1468// and a bitcast to the wider element type.
1469SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDNode *Node) {
1470 SDLoc DL(Node);
1471 EVT VT = Node->getValueType(0);
1472 int NumElements = VT.getVectorNumElements();
1473 SDValue Src = Node->getOperand(0);
1474 EVT SrcVT = Src.getValueType();
1475 int NumSrcElements = SrcVT.getVectorNumElements();
1476
1477 // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1478 // into a larger vector type.
1479 if (SrcVT.bitsLE(VT)) {
1480 assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1481 "ZERO_EXTEND_VECTOR_INREG vector size mismatch");
1482 NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1483 SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1484 NumSrcElements);
1485 Src = DAG.getInsertSubvector(DL, DAG.getUNDEF(SrcVT), Src, 0);
1486 }
1487
1488 // Build up a zero vector to blend into this one.
1489 SDValue Zero = DAG.getConstant(0, DL, SrcVT);
1490
1491 // Shuffle the incoming lanes into the correct position, and pull all other
1492 // lanes from the zero vector.
1493 auto ShuffleMask = llvm::to_vector<16>(llvm::seq<int>(0, NumSrcElements));
1494
1495 int ExtLaneScale = NumSrcElements / NumElements;
1496 int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1497 for (int i = 0; i < NumElements; ++i)
1498 ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i;
1499
1500 return DAG.getNode(ISD::BITCAST, DL, VT,
1501 DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask));
1502}
1503
1504static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
1505 int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
1506 for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
1507 for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
1508 ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
1509}
1510
1511SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) {
1512 EVT VT = Node->getValueType(0);
1513
1514 // Scalable vectors can't use shuffle expansion.
1515 if (VT.isScalableVector())
1516 return TLI.expandBSWAP(Node, DAG);
1517
1518 // Generate a byte wise shuffle mask for the BSWAP.
1519 SmallVector<int, 16> ShuffleMask;
1520 createBSWAPShuffleMask(VT, ShuffleMask);
1521 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
1522
1523 // Only emit a shuffle if the mask is legal.
1524 if (TLI.isShuffleMaskLegal(ShuffleMask, ByteVT)) {
1525 SDLoc DL(Node);
1526 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1527 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), ShuffleMask);
1528 return DAG.getNode(ISD::BITCAST, DL, VT, Op);
1529 }
1530
1531 // If we have the appropriate vector bit operations, it is better to use them
1532 // than unrolling and expanding each component.
1533 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1537 return TLI.expandBSWAP(Node, DAG);
1538
1539 // Otherwise let the caller unroll.
1540 return SDValue();
1541}
1542
1543SDValue VectorLegalizer::ExpandBITREVERSE(SDNode *Node) {
1544 EVT VT = Node->getValueType(0);
1545
1546 // We can't unroll or use shuffles for scalable vectors.
1547 if (VT.isScalableVector())
1548 return TLI.expandBITREVERSE(Node, DAG);
1549
1550 // If we have the scalar operation, it's probably cheaper to unroll it.
1552 return SDValue();
1553
1554 // If the vector element width is a whole number of bytes, test if its legal
1555 // to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte
1556 // vector. This greatly reduces the number of bit shifts necessary.
1557 unsigned ScalarSizeInBits = VT.getScalarSizeInBits();
1558 if (ScalarSizeInBits > 8 && (ScalarSizeInBits % 8) == 0) {
1559 SmallVector<int, 16> BSWAPMask;
1560 createBSWAPShuffleMask(VT, BSWAPMask);
1561
1562 EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, BSWAPMask.size());
1563 if (TLI.isShuffleMaskLegal(BSWAPMask, ByteVT) &&
1565 (TLI.isOperationLegalOrCustom(ISD::SHL, ByteVT) &&
1566 TLI.isOperationLegalOrCustom(ISD::SRL, ByteVT) &&
1569 SDLoc DL(Node);
1570 SDValue Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Node->getOperand(0));
1571 Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT),
1572 BSWAPMask);
1573 Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op);
1574 Op = DAG.getNode(ISD::BITCAST, DL, VT, Op);
1575 return Op;
1576 }
1577 }
1578
1579 // If we have the appropriate vector bit operations, it is better to use them
1580 // than unrolling and expanding each component.
1581 if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
1585 return TLI.expandBITREVERSE(Node, DAG);
1586
1587 // Otherwise unroll.
1588 return SDValue();
1589}
1590
1591SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
1592 // Implement VSELECT in terms of XOR, AND, OR
1593 // on platforms which do not support blend natively.
1594 SDLoc DL(Node);
1595
1596 SDValue Mask = Node->getOperand(0);
1597 SDValue Op1 = Node->getOperand(1);
1598 SDValue Op2 = Node->getOperand(2);
1599
1600 EVT VT = Mask.getValueType();
1601
1602 // If we can't even use the basic vector operations of
1603 // AND,OR,XOR, we will have to scalarize the op.
1604 // Notice that the operation may be 'promoted' which means that it is
1605 // 'bitcasted' to another type which is handled.
1606 if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1607 TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1608 TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand)
1609 return SDValue();
1610
1611 // This operation also isn't safe with AND, OR, XOR when the boolean type is
1612 // 0/1 and the select operands aren't also booleans, as we need an all-ones
1613 // vector constant to mask with.
1614 // FIXME: Sign extend 1 to all ones if that's legal on the target.
1615 auto BoolContents = TLI.getBooleanContents(Op1.getValueType());
1616 if (BoolContents != TargetLowering::ZeroOrNegativeOneBooleanContent &&
1617 !(BoolContents == TargetLowering::ZeroOrOneBooleanContent &&
1618 Op1.getValueType().getVectorElementType() == MVT::i1))
1619 return SDValue();
1620
1621 // If the mask and the type are different sizes, unroll the vector op. This
1622 // can occur when getSetCCResultType returns something that is different in
1623 // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
1624 if (VT.getSizeInBits() != Op1.getValueSizeInBits())
1625 return SDValue();
1626
1627 // Bitcast the operands to be the same type as the mask.
1628 // This is needed when we select between FP types because
1629 // the mask is a vector of integers.
1630 Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
1631 Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);
1632
1633 SDValue NotMask = DAG.getNOT(DL, Mask, VT);
1634
1635 Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
1636 Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask);
1637 SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2);
1638 return DAG.getNode(ISD::BITCAST, DL, Node->getValueType(0), Val);
1639}
1640
1641SDValue VectorLegalizer::ExpandVP_SELECT(SDNode *Node) {
1642 // Implement VP_SELECT in terms of VP_XOR, VP_AND and VP_OR on platforms which
1643 // do not support it natively.
1644 SDLoc DL(Node);
1645
1646 SDValue Mask = Node->getOperand(0);
1647 SDValue Op1 = Node->getOperand(1);
1648 SDValue Op2 = Node->getOperand(2);
1649 SDValue EVL = Node->getOperand(3);
1650
1651 EVT VT = Mask.getValueType();
1652
1653 // If we can't even use the basic vector operations of
1654 // VP_AND,VP_OR,VP_XOR, we will have to scalarize the op.
1655 if (TLI.getOperationAction(ISD::VP_AND, VT) == TargetLowering::Expand ||
1656 TLI.getOperationAction(ISD::VP_XOR, VT) == TargetLowering::Expand ||
1657 TLI.getOperationAction(ISD::VP_OR, VT) == TargetLowering::Expand)
1658 return SDValue();
1659
1660 // This operation also isn't safe when the operands aren't also booleans.
1661 if (Op1.getValueType().getVectorElementType() != MVT::i1)
1662 return SDValue();
1663
1664 SDValue Ones = DAG.getAllOnesConstant(DL, VT);
1665 SDValue NotMask = DAG.getNode(ISD::VP_XOR, DL, VT, Mask, Ones, Ones, EVL);
1666
1667 Op1 = DAG.getNode(ISD::VP_AND, DL, VT, Op1, Mask, Ones, EVL);
1668 Op2 = DAG.getNode(ISD::VP_AND, DL, VT, Op2, NotMask, Ones, EVL);
1669 return DAG.getNode(ISD::VP_OR, DL, VT, Op1, Op2, Ones, EVL);
1670}
1671
1672SDValue VectorLegalizer::ExpandVP_MERGE(SDNode *Node) {
1673 // Implement VP_MERGE in terms of VSELECT. Construct a mask where vector
1674 // indices less than the EVL/pivot are true. Combine that with the original
1675 // mask for a full-length mask. Use a full-length VSELECT to select between
1676 // the true and false values.
1677 SDLoc DL(Node);
1678
1679 SDValue Mask = Node->getOperand(0);
1680 SDValue Op1 = Node->getOperand(1);
1681 SDValue Op2 = Node->getOperand(2);
1682 SDValue EVL = Node->getOperand(3);
1683
1684 EVT MaskVT = Mask.getValueType();
1685 bool IsFixedLen = MaskVT.isFixedLengthVector();
1686
1687 EVT EVLVecVT = EVT::getVectorVT(*DAG.getContext(), EVL.getValueType(),
1688 MaskVT.getVectorElementCount());
1689
1690 // If we can't construct the EVL mask efficiently, it's better to unroll.
1691 if ((IsFixedLen &&
1693 (!IsFixedLen &&
1694 (!TLI.isOperationLegalOrCustom(ISD::STEP_VECTOR, EVLVecVT) ||
1696 return SDValue();
1697
1698 // If using a SETCC would result in a different type than the mask type,
1699 // unroll.
1700 if (TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
1701 EVLVecVT) != MaskVT)
1702 return SDValue();
1703
1704 SDValue StepVec = DAG.getStepVector(DL, EVLVecVT);
1705 SDValue SplatEVL = DAG.getSplat(EVLVecVT, DL, EVL);
1706 SDValue EVLMask =
1707 DAG.getSetCC(DL, MaskVT, StepVec, SplatEVL, ISD::CondCode::SETULT);
1708
1709 SDValue FullMask = DAG.getNode(ISD::AND, DL, MaskVT, Mask, EVLMask);
1710 return DAG.getSelect(DL, Node->getValueType(0), FullMask, Op1, Op2);
1711}
1712
1713SDValue VectorLegalizer::ExpandVP_REM(SDNode *Node) {
1714 // Implement VP_SREM/UREM in terms of VP_SDIV/VP_UDIV, VP_MUL, VP_SUB.
1715 EVT VT = Node->getValueType(0);
1716
1717 unsigned DivOpc = Node->getOpcode() == ISD::VP_SREM ? ISD::VP_SDIV : ISD::VP_UDIV;
1718
1719 if (!TLI.isOperationLegalOrCustom(DivOpc, VT) ||
1720 !TLI.isOperationLegalOrCustom(ISD::VP_MUL, VT) ||
1721 !TLI.isOperationLegalOrCustom(ISD::VP_SUB, VT))
1722 return SDValue();
1723
1724 SDLoc DL(Node);
1725
1726 SDValue Dividend = Node->getOperand(0);
1727 SDValue Divisor = Node->getOperand(1);
1728 SDValue Mask = Node->getOperand(2);
1729 SDValue EVL = Node->getOperand(3);
1730
1731 // X % Y -> X-X/Y*Y
1732 SDValue Div = DAG.getNode(DivOpc, DL, VT, Dividend, Divisor, Mask, EVL);
1733 SDValue Mul = DAG.getNode(ISD::VP_MUL, DL, VT, Divisor, Div, Mask, EVL);
1734 return DAG.getNode(ISD::VP_SUB, DL, VT, Dividend, Mul, Mask, EVL);
1735}
1736
1737SDValue VectorLegalizer::ExpandVP_FNEG(SDNode *Node) {
1738 EVT VT = Node->getValueType(0);
1739 EVT IntVT = VT.changeVectorElementTypeToInteger();
1740
1741 if (!TLI.isOperationLegalOrCustom(ISD::VP_XOR, IntVT))
1742 return SDValue();
1743
1744 SDValue Mask = Node->getOperand(1);
1745 SDValue EVL = Node->getOperand(2);
1746
1747 SDLoc DL(Node);
1748 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1749 SDValue SignMask = DAG.getConstant(
1750 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1751 SDValue Xor = DAG.getNode(ISD::VP_XOR, DL, IntVT, Cast, SignMask, Mask, EVL);
1752 return DAG.getNode(ISD::BITCAST, DL, VT, Xor);
1753}
1754
1755SDValue VectorLegalizer::ExpandVP_FABS(SDNode *Node) {
1756 EVT VT = Node->getValueType(0);
1757 EVT IntVT = VT.changeVectorElementTypeToInteger();
1758
1759 if (!TLI.isOperationLegalOrCustom(ISD::VP_AND, IntVT))
1760 return SDValue();
1761
1762 SDValue Mask = Node->getOperand(1);
1763 SDValue EVL = Node->getOperand(2);
1764
1765 SDLoc DL(Node);
1766 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1767 SDValue ClearSignMask = DAG.getConstant(
1769 SDValue ClearSign =
1770 DAG.getNode(ISD::VP_AND, DL, IntVT, Cast, ClearSignMask, Mask, EVL);
1771 return DAG.getNode(ISD::BITCAST, DL, VT, ClearSign);
1772}
1773
1774SDValue VectorLegalizer::ExpandVP_FCOPYSIGN(SDNode *Node) {
1775 EVT VT = Node->getValueType(0);
1776
1777 if (VT != Node->getOperand(1).getValueType())
1778 return SDValue();
1779
1780 EVT IntVT = VT.changeVectorElementTypeToInteger();
1781 if (!TLI.isOperationLegalOrCustom(ISD::VP_AND, IntVT) ||
1782 !TLI.isOperationLegalOrCustom(ISD::VP_XOR, IntVT))
1783 return SDValue();
1784
1785 SDValue Mask = Node->getOperand(2);
1786 SDValue EVL = Node->getOperand(3);
1787
1788 SDLoc DL(Node);
1789 SDValue Mag = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1790 SDValue Sign = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(1));
1791
1792 SDValue SignMask = DAG.getConstant(
1793 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1794 SDValue SignBit =
1795 DAG.getNode(ISD::VP_AND, DL, IntVT, Sign, SignMask, Mask, EVL);
1796
1797 SDValue ClearSignMask = DAG.getConstant(
1799 SDValue ClearedSign =
1800 DAG.getNode(ISD::VP_AND, DL, IntVT, Mag, ClearSignMask, Mask, EVL);
1801
1802 SDValue CopiedSign = DAG.getNode(ISD::VP_OR, DL, IntVT, ClearedSign, SignBit,
1803 Mask, EVL, SDNodeFlags::Disjoint);
1804
1805 return DAG.getNode(ISD::BITCAST, DL, VT, CopiedSign);
1806}
1807
1808SDValue VectorLegalizer::ExpandLOOP_DEPENDENCE_MASK(SDNode *N) {
1809 SDLoc DL(N);
1810 EVT VT = N->getValueType(0);
1811 SDValue SourceValue = N->getOperand(0);
1812 SDValue SinkValue = N->getOperand(1);
1813 SDValue EltSizeInBytes = N->getOperand(2);
1814
1815 // Note: The lane offset is scalable if the mask is scalable.
1816 ElementCount LaneOffsetEC =
1817 ElementCount::get(N->getConstantOperandVal(3), VT.isScalableVT());
1818
1819 EVT PtrVT = SourceValue->getValueType(0);
1820 bool IsReadAfterWrite = N->getOpcode() == ISD::LOOP_DEPENDENCE_RAW_MASK;
1821
1822 // Take the difference between the pointers and divided by the element size,
1823 // to see how many lanes separate them.
1824 SDValue Diff = DAG.getNode(ISD::SUB, DL, PtrVT, SinkValue, SourceValue);
1825 if (IsReadAfterWrite)
1826 Diff = DAG.getNode(ISD::ABS, DL, PtrVT, Diff);
1827 Diff = DAG.getNode(ISD::SDIV, DL, PtrVT, Diff, EltSizeInBytes);
1828
1829 // The pointers do not alias if:
1830 // * Diff <= 0 (WAR_MASK)
1831 // * Diff == 0 (RAW_MASK)
1832 EVT CmpVT =
1833 TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), PtrVT);
1834 SDValue Zero = DAG.getConstant(0, DL, PtrVT);
1835 SDValue Cmp = DAG.getSetCC(DL, CmpVT, Diff, Zero,
1836 IsReadAfterWrite ? ISD::SETEQ : ISD::SETLE);
1837
1838 // The pointers do not alias if:
1839 // Lane + LaneOffset < Diff (WAR/RAW_MASK)
1840 SDValue LaneOffset = DAG.getElementCount(DL, PtrVT, LaneOffsetEC);
1841 SDValue MaskN =
1842 DAG.getSelect(DL, PtrVT, Cmp, DAG.getConstant(-1, DL, PtrVT), Diff);
1843
1844 return DAG.getNode(ISD::GET_ACTIVE_LANE_MASK, DL, VT, LaneOffset, MaskN);
1845}
1846
1847void VectorLegalizer::ExpandFP_TO_UINT(SDNode *Node,
1848 SmallVectorImpl<SDValue> &Results) {
1849 // Attempt to expand using TargetLowering.
1850 SDValue Result, Chain;
1851 if (TLI.expandFP_TO_UINT(Node, Result, Chain, DAG)) {
1852 Results.push_back(Result);
1853 if (Node->isStrictFPOpcode())
1854 Results.push_back(Chain);
1855 return;
1856 }
1857
1858 // Otherwise go ahead and unroll.
1859 if (Node->isStrictFPOpcode()) {
1860 UnrollStrictFPOp(Node, Results);
1861 return;
1862 }
1863
1864 Results.push_back(DAG.UnrollVectorOp(Node));
1865}
1866
1867void VectorLegalizer::ExpandUINT_TO_FLOAT(SDNode *Node,
1868 SmallVectorImpl<SDValue> &Results) {
1869 bool IsStrict = Node->isStrictFPOpcode();
1870 unsigned OpNo = IsStrict ? 1 : 0;
1871 SDValue Src = Node->getOperand(OpNo);
1872 EVT SrcVT = Src.getValueType();
1873 EVT DstVT = Node->getValueType(0);
1874 SDLoc DL(Node);
1875
1876 // Attempt to expand using TargetLowering.
1878 SDValue Chain;
1879 if (TLI.expandUINT_TO_FP(Node, Result, Chain, DAG)) {
1880 Results.push_back(Result);
1881 if (IsStrict)
1882 Results.push_back(Chain);
1883 return;
1884 }
1885
1886 // Make sure that the SINT_TO_FP and SRL instructions are available.
1887 if (((!IsStrict && TLI.getOperationAction(ISD::SINT_TO_FP, SrcVT) ==
1888 TargetLowering::Expand) ||
1889 (IsStrict && TLI.getOperationAction(ISD::STRICT_SINT_TO_FP, SrcVT) ==
1890 TargetLowering::Expand)) ||
1891 TLI.getOperationAction(ISD::SRL, SrcVT) == TargetLowering::Expand) {
1892 if (IsStrict) {
1893 UnrollStrictFPOp(Node, Results);
1894 return;
1895 }
1896
1897 Results.push_back(DAG.UnrollVectorOp(Node));
1898 return;
1899 }
1900
1901 unsigned BW = SrcVT.getScalarSizeInBits();
1902 assert((BW == 64 || BW == 32) &&
1903 "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
1904
1905 // If STRICT_/FMUL is not supported by the target (in case of f16) replace the
1906 // UINT_TO_FP with a larger float and round to the smaller type
1907 if ((!IsStrict && !TLI.isOperationLegalOrCustom(ISD::FMUL, DstVT)) ||
1908 (IsStrict && !TLI.isOperationLegalOrCustom(ISD::STRICT_FMUL, DstVT))) {
1909 EVT FPVT = BW == 32 ? MVT::f32 : MVT::f64;
1910 SDValue UIToFP;
1912 SDValue TargetZero = DAG.getIntPtrConstant(0, DL, /*isTarget=*/true);
1913 EVT FloatVecVT = SrcVT.changeVectorElementType(FPVT);
1914 if (IsStrict) {
1915 UIToFP = DAG.getNode(ISD::STRICT_UINT_TO_FP, DL, {FloatVecVT, MVT::Other},
1916 {Node->getOperand(0), Src});
1917 Result = DAG.getNode(ISD::STRICT_FP_ROUND, DL, {DstVT, MVT::Other},
1918 {Node->getOperand(0), UIToFP, TargetZero});
1919 Results.push_back(Result);
1920 Results.push_back(Result.getValue(1));
1921 } else {
1922 UIToFP = DAG.getNode(ISD::UINT_TO_FP, DL, FloatVecVT, Src);
1923 Result = DAG.getNode(ISD::FP_ROUND, DL, DstVT, UIToFP, TargetZero);
1924 Results.push_back(Result);
1925 }
1926
1927 return;
1928 }
1929
1930 SDValue HalfWord = DAG.getConstant(BW / 2, DL, SrcVT);
1931
1932 // Constants to clear the upper part of the word.
1933 // Notice that we can also use SHL+SHR, but using a constant is slightly
1934 // faster on x86.
1935 uint64_t HWMask = (BW == 64) ? 0x00000000FFFFFFFF : 0x0000FFFF;
1936 SDValue HalfWordMask = DAG.getConstant(HWMask, DL, SrcVT);
1937
1938 // Two to the power of half-word-size.
1939 SDValue TWOHW = DAG.getConstantFP(1ULL << (BW / 2), DL, DstVT);
1940
1941 // Clear upper part of LO, lower HI
1942 SDValue HI = DAG.getNode(ISD::SRL, DL, SrcVT, Src, HalfWord);
1943 SDValue LO = DAG.getNode(ISD::AND, DL, SrcVT, Src, HalfWordMask);
1944
1945 if (IsStrict) {
1946 // Convert hi and lo to floats
1947 // Convert the hi part back to the upper values
1948 // TODO: Can any fast-math-flags be set on these nodes?
1949 SDValue fHI = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, {DstVT, MVT::Other},
1950 {Node->getOperand(0), HI});
1951 fHI = DAG.getNode(ISD::STRICT_FMUL, DL, {DstVT, MVT::Other},
1952 {fHI.getValue(1), fHI, TWOHW});
1953 SDValue fLO = DAG.getNode(ISD::STRICT_SINT_TO_FP, DL, {DstVT, MVT::Other},
1954 {Node->getOperand(0), LO});
1955
1956 SDValue TF = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, fHI.getValue(1),
1957 fLO.getValue(1));
1958
1959 // Add the two halves
1960 SDValue Result =
1961 DAG.getNode(ISD::STRICT_FADD, DL, {DstVT, MVT::Other}, {TF, fHI, fLO});
1962
1963 Results.push_back(Result);
1964 Results.push_back(Result.getValue(1));
1965 return;
1966 }
1967
1968 // Convert hi and lo to floats
1969 // Convert the hi part back to the upper values
1970 // TODO: Can any fast-math-flags be set on these nodes?
1971 SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, DstVT, HI);
1972 fHI = DAG.getNode(ISD::FMUL, DL, DstVT, fHI, TWOHW);
1973 SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, DstVT, LO);
1974
1975 // Add the two halves
1976 Results.push_back(DAG.getNode(ISD::FADD, DL, DstVT, fHI, fLO));
1977}
1978
1979SDValue VectorLegalizer::ExpandFNEG(SDNode *Node) {
1980 EVT VT = Node->getValueType(0);
1981 EVT IntVT = VT.changeVectorElementTypeToInteger();
1982
1983 if (!TLI.isOperationLegalOrCustom(ISD::XOR, IntVT))
1984 return SDValue();
1985
1986 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
1988 !VT.isScalableVector())
1989 return SDValue();
1990
1991 SDLoc DL(Node);
1992 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
1993 SDValue SignMask = DAG.getConstant(
1994 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
1995 SDValue Xor = DAG.getNode(ISD::XOR, DL, IntVT, Cast, SignMask);
1996 return DAG.getNode(ISD::BITCAST, DL, VT, Xor);
1997}
1998
1999SDValue VectorLegalizer::ExpandFABS(SDNode *Node) {
2000 EVT VT = Node->getValueType(0);
2001 EVT IntVT = VT.changeVectorElementTypeToInteger();
2002
2003 if (!TLI.isOperationLegalOrCustom(ISD::AND, IntVT))
2004 return SDValue();
2005
2006 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
2008 !VT.isScalableVector())
2009 return SDValue();
2010
2011 SDLoc DL(Node);
2012 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
2013 SDValue ClearSignMask = DAG.getConstant(
2015 SDValue ClearedSign = DAG.getNode(ISD::AND, DL, IntVT, Cast, ClearSignMask);
2016 return DAG.getNode(ISD::BITCAST, DL, VT, ClearedSign);
2017}
2018
2019SDValue VectorLegalizer::ExpandFCOPYSIGN(SDNode *Node) {
2020 EVT VT = Node->getValueType(0);
2021 EVT IntVT = VT.changeVectorElementTypeToInteger();
2022
2023 if (VT != Node->getOperand(1).getValueType() ||
2024 !TLI.isOperationLegalOrCustom(ISD::AND, IntVT) ||
2025 !TLI.isOperationLegalOrCustom(ISD::OR, IntVT))
2026 return SDValue();
2027
2028 // FIXME: The FSUB check is here to force unrolling v1f64 vectors on AArch64.
2030 !VT.isScalableVector())
2031 return SDValue();
2032
2033 SDLoc DL(Node);
2034 SDValue Mag = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(0));
2035 SDValue Sign = DAG.getNode(ISD::BITCAST, DL, IntVT, Node->getOperand(1));
2036
2037 SDValue SignMask = DAG.getConstant(
2038 APInt::getSignMask(IntVT.getScalarSizeInBits()), DL, IntVT);
2039 SDValue SignBit = DAG.getNode(ISD::AND, DL, IntVT, Sign, SignMask);
2040
2041 SDValue ClearSignMask = DAG.getConstant(
2043 SDValue ClearedSign = DAG.getNode(ISD::AND, DL, IntVT, Mag, ClearSignMask);
2044
2045 SDValue CopiedSign = DAG.getNode(ISD::OR, DL, IntVT, ClearedSign, SignBit,
2047
2048 return DAG.getNode(ISD::BITCAST, DL, VT, CopiedSign);
2049}
2050
2051void VectorLegalizer::ExpandFSUB(SDNode *Node,
2052 SmallVectorImpl<SDValue> &Results) {
2053 // For floating-point values, (a-b) is the same as a+(-b). If FNEG is legal,
2054 // we can defer this to operation legalization where it will be lowered as
2055 // a+(-b).
2056 EVT VT = Node->getValueType(0);
2057 if (TLI.isOperationLegalOrCustom(ISD::FNEG, VT) &&
2059 return; // Defer to LegalizeDAG
2060
2061 if (SDValue Expanded = TLI.expandVectorNaryOpBySplitting(Node, DAG)) {
2062 Results.push_back(Expanded);
2063 return;
2064 }
2065
2066 SDValue Tmp = DAG.UnrollVectorOp(Node);
2067 Results.push_back(Tmp);
2068}
2069
2070void VectorLegalizer::ExpandSETCC(SDNode *Node,
2071 SmallVectorImpl<SDValue> &Results) {
2072 bool NeedInvert = false;
2073 bool IsVP = Node->getOpcode() == ISD::VP_SETCC;
2074 bool IsStrict = Node->getOpcode() == ISD::STRICT_FSETCC ||
2075 Node->getOpcode() == ISD::STRICT_FSETCCS;
2076 bool IsSignaling = Node->getOpcode() == ISD::STRICT_FSETCCS;
2077 unsigned Offset = IsStrict ? 1 : 0;
2078
2079 SDValue Chain = IsStrict ? Node->getOperand(0) : SDValue();
2080 SDValue LHS = Node->getOperand(0 + Offset);
2081 SDValue RHS = Node->getOperand(1 + Offset);
2082 SDValue CC = Node->getOperand(2 + Offset);
2083
2084 MVT OpVT = LHS.getSimpleValueType();
2085 ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
2086
2087 if (TLI.getCondCodeAction(CCCode, OpVT) != TargetLowering::Expand) {
2088 if (IsStrict) {
2089 UnrollStrictFPOp(Node, Results);
2090 return;
2091 }
2092 Results.push_back(UnrollVSETCC(Node));
2093 return;
2094 }
2095
2096 SDValue Mask, EVL;
2097 if (IsVP) {
2098 Mask = Node->getOperand(3 + Offset);
2099 EVL = Node->getOperand(4 + Offset);
2100 }
2101
2102 SDLoc dl(Node);
2103 bool Legalized =
2104 TLI.LegalizeSetCCCondCode(DAG, Node->getValueType(0), LHS, RHS, CC, Mask,
2105 EVL, NeedInvert, dl, Chain, IsSignaling);
2106
2107 if (Legalized) {
2108 // If we expanded the SETCC by swapping LHS and RHS, or by inverting the
2109 // condition code, create a new SETCC node.
2110 if (CC.getNode()) {
2111 if (IsStrict) {
2112 LHS = DAG.getNode(Node->getOpcode(), dl, Node->getVTList(),
2113 {Chain, LHS, RHS, CC}, Node->getFlags());
2114 Chain = LHS.getValue(1);
2115 } else if (IsVP) {
2116 LHS = DAG.getNode(ISD::VP_SETCC, dl, Node->getValueType(0),
2117 {LHS, RHS, CC, Mask, EVL}, Node->getFlags());
2118 } else {
2119 LHS = DAG.getNode(ISD::SETCC, dl, Node->getValueType(0), LHS, RHS, CC,
2120 Node->getFlags());
2121 }
2122 }
2123
2124 // If we expanded the SETCC by inverting the condition code, then wrap
2125 // the existing SETCC in a NOT to restore the intended condition.
2126 if (NeedInvert) {
2127 if (!IsVP)
2128 LHS = DAG.getLogicalNOT(dl, LHS, LHS->getValueType(0));
2129 else
2130 LHS = DAG.getVPLogicalNOT(dl, LHS, Mask, EVL, LHS->getValueType(0));
2131 }
2132 } else {
2133 assert(!IsStrict && "Don't know how to expand for strict nodes.");
2134
2135 // Otherwise, SETCC for the given comparison type must be completely
2136 // illegal; expand it into a SELECT_CC.
2137 EVT VT = Node->getValueType(0);
2138 LHS = DAG.getNode(ISD::SELECT_CC, dl, VT, LHS, RHS,
2139 DAG.getBoolConstant(true, dl, VT, LHS.getValueType()),
2140 DAG.getBoolConstant(false, dl, VT, LHS.getValueType()),
2141 CC, Node->getFlags());
2142 }
2143
2144 Results.push_back(LHS);
2145 if (IsStrict)
2146 Results.push_back(Chain);
2147}
2148
2149void VectorLegalizer::ExpandUADDSUBO(SDNode *Node,
2150 SmallVectorImpl<SDValue> &Results) {
2151 SDValue Result, Overflow;
2152 TLI.expandUADDSUBO(Node, Result, Overflow, DAG);
2153 Results.push_back(Result);
2154 Results.push_back(Overflow);
2155}
2156
2157void VectorLegalizer::ExpandSADDSUBO(SDNode *Node,
2158 SmallVectorImpl<SDValue> &Results) {
2159 SDValue Result, Overflow;
2160 TLI.expandSADDSUBO(Node, Result, Overflow, DAG);
2161 Results.push_back(Result);
2162 Results.push_back(Overflow);
2163}
2164
2165void VectorLegalizer::ExpandMULO(SDNode *Node,
2166 SmallVectorImpl<SDValue> &Results) {
2167 SDValue Result, Overflow;
2168 if (!TLI.expandMULO(Node, Result, Overflow, DAG))
2169 std::tie(Result, Overflow) = DAG.UnrollVectorOverflowOp(Node);
2170
2171 Results.push_back(Result);
2172 Results.push_back(Overflow);
2173}
2174
2175void VectorLegalizer::ExpandFixedPointDiv(SDNode *Node,
2176 SmallVectorImpl<SDValue> &Results) {
2177 SDNode *N = Node;
2178 if (SDValue Expanded = TLI.expandFixedPointDiv(N->getOpcode(), SDLoc(N),
2179 N->getOperand(0), N->getOperand(1), N->getConstantOperandVal(2), DAG))
2180 Results.push_back(Expanded);
2181}
2182
2183void VectorLegalizer::ExpandStrictFPOp(SDNode *Node,
2184 SmallVectorImpl<SDValue> &Results) {
2185 if (Node->getOpcode() == ISD::STRICT_UINT_TO_FP) {
2186 ExpandUINT_TO_FLOAT(Node, Results);
2187 return;
2188 }
2189 if (Node->getOpcode() == ISD::STRICT_FP_TO_UINT) {
2190 ExpandFP_TO_UINT(Node, Results);
2191 return;
2192 }
2193
2194 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2195 Node->getOpcode() == ISD::STRICT_FSETCCS) {
2196 ExpandSETCC(Node, Results);
2197 return;
2198 }
2199
2200 UnrollStrictFPOp(Node, Results);
2201}
2202
2203void VectorLegalizer::ExpandREM(SDNode *Node,
2204 SmallVectorImpl<SDValue> &Results) {
2205 assert((Node->getOpcode() == ISD::SREM || Node->getOpcode() == ISD::UREM) &&
2206 "Expected REM node");
2207
2209 if (!TLI.expandREM(Node, Result, DAG))
2210 Result = DAG.UnrollVectorOp(Node);
2211 Results.push_back(Result);
2212}
2213
2214// Try to expand libm nodes into vector math routine calls. Callers provide the
2215// LibFunc equivalent of the passed in Node, which is used to lookup mappings
2216// within TargetLibraryInfo. The only mappings considered are those where the
2217// result and all operands are the same vector type. While predicated nodes are
2218// not supported, we will emit calls to masked routines by passing in an all
2219// true mask.
2220bool VectorLegalizer::tryExpandVecMathCall(SDNode *Node, RTLIB::Libcall LC,
2221 SmallVectorImpl<SDValue> &Results) {
2222 // Chain must be propagated but currently strict fp operations are down
2223 // converted to their none strict counterpart.
2224 assert(!Node->isStrictFPOpcode() && "Unexpected strict fp operation!");
2225
2226 RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC);
2227 if (LCImpl == RTLIB::Unsupported)
2228 return false;
2229
2230 EVT VT = Node->getValueType(0);
2231 const RTLIB::RuntimeLibcallsInfo &RTLCI = TLI.getRuntimeLibcallsInfo();
2232 LLVMContext &Ctx = *DAG.getContext();
2233
2234 auto [FuncTy, FuncAttrs] = RTLCI.getFunctionTy(
2235 Ctx, DAG.getSubtarget().getTargetTriple(), DAG.getDataLayout(), LCImpl);
2236
2237 SDLoc DL(Node);
2238 TargetLowering::ArgListTy Args;
2239
2240 bool HasMaskArg = RTLCI.hasVectorMaskArgument(LCImpl);
2241
2242 // Sanity check just in case function has unexpected parameters.
2243 assert(FuncTy->getNumParams() == Node->getNumOperands() + HasMaskArg &&
2244 EVT::getEVT(FuncTy->getReturnType(), true) == VT &&
2245 "mismatch in value type and call signature type");
2246
2247 for (unsigned I = 0, E = FuncTy->getNumParams(); I != E; ++I) {
2248 Type *ParamTy = FuncTy->getParamType(I);
2249
2250 if (HasMaskArg && I == E - 1) {
2251 assert(cast<VectorType>(ParamTy)->getElementType()->isIntegerTy(1) &&
2252 "unexpected vector mask type");
2253 EVT MaskVT = TLI.getSetCCResultType(DAG.getDataLayout(), Ctx, VT);
2254 Args.emplace_back(DAG.getBoolConstant(true, DL, MaskVT, VT),
2255 MaskVT.getTypeForEVT(Ctx));
2256
2257 } else {
2258 SDValue Op = Node->getOperand(I);
2259 assert(Op.getValueType() == EVT::getEVT(ParamTy, true) &&
2260 "mismatch in value type and call argument type");
2261 Args.emplace_back(Op, ParamTy);
2262 }
2263 }
2264
2265 // Emit a call to the vector function.
2266 SDValue Callee =
2267 DAG.getExternalSymbol(LCImpl, TLI.getPointerTy(DAG.getDataLayout()));
2268 CallingConv::ID CC = RTLCI.getLibcallImplCallingConv(LCImpl);
2269
2270 TargetLowering::CallLoweringInfo CLI(DAG);
2271 CLI.setDebugLoc(DL)
2272 .setChain(DAG.getEntryNode())
2273 .setLibCallee(CC, FuncTy->getReturnType(), Callee, std::move(Args));
2274
2275 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
2276 Results.push_back(CallResult.first);
2277 return true;
2278}
2279
2280void VectorLegalizer::UnrollStrictFPOp(SDNode *Node,
2281 SmallVectorImpl<SDValue> &Results) {
2282 EVT VT = Node->getValueType(0);
2283 EVT EltVT = VT.getVectorElementType();
2284 unsigned NumElems = VT.getVectorNumElements();
2285 unsigned NumOpers = Node->getNumOperands();
2286 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
2287
2288 EVT TmpEltVT = EltVT;
2289 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2290 Node->getOpcode() == ISD::STRICT_FSETCCS)
2291 TmpEltVT = TLI.getSetCCResultType(DAG.getDataLayout(),
2292 *DAG.getContext(), TmpEltVT);
2293
2294 EVT ValueVTs[] = {TmpEltVT, MVT::Other};
2295 SDValue Chain = Node->getOperand(0);
2296 SDLoc dl(Node);
2297
2298 SmallVector<SDValue, 32> OpValues;
2299 SmallVector<SDValue, 32> OpChains;
2300 for (unsigned i = 0; i < NumElems; ++i) {
2302 SDValue Idx = DAG.getVectorIdxConstant(i, dl);
2303
2304 // The Chain is the first operand.
2305 Opers.push_back(Chain);
2306
2307 // Now process the remaining operands.
2308 for (unsigned j = 1; j < NumOpers; ++j) {
2309 SDValue Oper = Node->getOperand(j);
2310 EVT OperVT = Oper.getValueType();
2311
2312 if (OperVT.isVector())
2313 Oper = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
2314 OperVT.getVectorElementType(), Oper, Idx);
2315
2316 Opers.push_back(Oper);
2317 }
2318
2319 SDValue ScalarOp = DAG.getNode(Node->getOpcode(), dl, ValueVTs, Opers);
2320 SDValue ScalarResult = ScalarOp.getValue(0);
2321 SDValue ScalarChain = ScalarOp.getValue(1);
2322
2323 if (Node->getOpcode() == ISD::STRICT_FSETCC ||
2324 Node->getOpcode() == ISD::STRICT_FSETCCS)
2325 ScalarResult = DAG.getSelect(dl, EltVT, ScalarResult,
2326 DAG.getAllOnesConstant(dl, EltVT),
2327 DAG.getConstant(0, dl, EltVT));
2328
2329 OpValues.push_back(ScalarResult);
2330 OpChains.push_back(ScalarChain);
2331 }
2332
2333 SDValue Result = DAG.getBuildVector(VT, dl, OpValues);
2334 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OpChains);
2335
2336 Results.push_back(Result);
2337 Results.push_back(NewChain);
2338}
2339
2340SDValue VectorLegalizer::UnrollVSETCC(SDNode *Node) {
2341 EVT VT = Node->getValueType(0);
2342 unsigned NumElems = VT.getVectorNumElements();
2343 EVT EltVT = VT.getVectorElementType();
2344 SDValue LHS = Node->getOperand(0);
2345 SDValue RHS = Node->getOperand(1);
2346 SDValue CC = Node->getOperand(2);
2347 EVT TmpEltVT = LHS.getValueType().getVectorElementType();
2348 SDLoc dl(Node);
2349 SmallVector<SDValue, 8> Ops(NumElems);
2350 for (unsigned i = 0; i < NumElems; ++i) {
2351 SDValue LHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS,
2352 DAG.getVectorIdxConstant(i, dl));
2353 SDValue RHSElem = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS,
2354 DAG.getVectorIdxConstant(i, dl));
2355 // FIXME: We should use i1 setcc + boolext here, but it causes regressions.
2356 Ops[i] = DAG.getNode(ISD::SETCC, dl,
2358 *DAG.getContext(), TmpEltVT),
2359 LHSElem, RHSElem, CC);
2360 Ops[i] = DAG.getSelect(dl, EltVT, Ops[i],
2361 DAG.getBoolConstant(true, dl, EltVT, VT),
2362 DAG.getConstant(0, dl, EltVT));
2363 }
2364 return DAG.getBuildVector(VT, dl, Ops);
2365}
2366
2368 return VectorLegalizer(*this).Run();
2369}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl< int > &ShuffleMask)
#define I(x, y, z)
Definition MD5.cpp:57
#define T
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
This file describes how to lower LLVM code to machine code.
Value * RHS
Value * LHS
BinaryOperator * Mul
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition APInt.h:230
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:210
bool isBigEndian() const
Definition DataLayout.h:215
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:241
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition TypeSize.h:315
size_t size() const
Definition Function.h:856
const Triple & getTargetTriple() const
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:298
Represents one node in the SelectionDAG.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
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...
LLVM_ABI SDValue getElementCount(const SDLoc &DL, EVT VT, ElementCount EC)
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
const TargetSubtargetInfo & getSubtarget() const
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getAllOnesConstant(const SDLoc &DL, EVT VT, bool IsTarget=false, bool IsOpaque=false)
LLVM_ABI bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI SDValue UnrollVectorOp(SDNode *N, unsigned ResNE=0)
Utility function used by legalize and lowering to "unroll" a vector operation by splitting out the sc...
LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
SDValue getInsertSubvector(const SDLoc &DL, SDValue Vec, SDValue SubVec, unsigned Idx)
Insert SubVec at the Idx element of Vec.
LLVM_ABI SDValue getStepVector(const SDLoc &DL, EVT ResVT, const APInt &StepVal)
Returns a vector of type ResVT whose elements contain the linear sequence <0, Step,...
LLVM_ABI SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
const TargetLowering & getTargetLoweringInfo() const
LLVM_ABI std::pair< SDValue, SDValue > UnrollVectorOverflowOp(SDNode *N, unsigned ResNE=0)
Like UnrollVectorOp(), but for the [US](ADD|SUB|MUL)O family of opcodes.
allnodes_const_iterator allnodes_begin() const
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
allnodes_const_iterator allnodes_end() const
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
LLVM_ABI SDValue getVPLogicalNOT(const SDLoc &DL, SDValue Val, SDValue Mask, SDValue EVL, EVT VT)
Create a vector-predicated logical NOT operation as (VP_XOR Val, BooleanOne, Mask,...
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVM_ABI unsigned AssignTopologicalOrder()
Topological-sort the AllNodes list and a assign a unique node id for each node in the DAG based on th...
LLVM_ABI SDValue getBoolConstant(bool V, const SDLoc &DL, EVT VT, EVT OpVT)
Create a true or false constant of type VT using the target's BooleanContent for type OpVT.
LLVM_ABI SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVMContext * getContext() const
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
LLVM_ABI SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
SDValue getSplat(EVT VT, const SDLoc &DL, SDValue Op)
Returns a node representing a splat of one value into all lanes of the provided vector type.
LLVM_ABI SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
LLVM_ABI SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a logical NOT operation as (XOR Val, BooleanOne).
ilist< SDNode >::iterator allnodes_iterator
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize(size_type N)
void push_back(const T &Elt)
virtual bool isShuffleMaskLegal(ArrayRef< int >, EVT) const
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
LegalizeAction getCondCodeAction(ISD::CondCode CC, MVT VT) const
Return how the condition code should be treated: either it is legal, needs to be expanded to some oth...
LegalizeAction getFixedPointOperationAction(unsigned Op, EVT VT, unsigned Scale) const
Some fixed point operations may be natively supported by the target but only for specific scales.
bool isStrictFPEnabled() const
Return true if the target support strict float operation.
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const
Return how this store with truncation should be treated: either it is legal, needs to be promoted to ...
LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT, EVT MemVT) const
Return how this load with extension should be treated: either it is legal, needs to be promoted to a ...
bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
LegalizeAction getPartialReduceMLAAction(unsigned Opc, EVT AccVT, EVT InputVT) const
Return how a PARTIAL_REDUCE_U/SMLA node with Acc type AccVT and Input type InputVT should be treated.
LegalizeAction getStrictFPOperationAction(unsigned Op, EVT VT) const
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Get the libcall impl routine name for the specified libcall.
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
MVT getTypeToPromoteTo(unsigned Op, MVT VT) const
If the action for this operation is to promote, this method returns the ValueType to promote to.
bool isOperationLegalOrCustomOrPromote(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
const RTLIB::RuntimeLibcallsInfo & getRuntimeLibcallsInfo() const
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT.
bool expandMultipleResultFPLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, SDNode *Node, SmallVectorImpl< SDValue > &Results, std::optional< unsigned > CallRetResNo={}) const
Expands a node with multiple results to an FP or vector libcall.
SDValue expandVPCTLZ(SDNode *N, SelectionDAG &DAG) const
Expand VP_CTLZ/VP_CTLZ_ZERO_UNDEF nodes.
bool expandMULO(SDNode *Node, SDValue &Result, SDValue &Overflow, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US]MULO.
SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const
SDValue expandVPBSWAP(SDNode *N, SelectionDAG &DAG) const
Expand VP_BSWAP nodes.
SDValue expandVecReduceSeq(SDNode *Node, SelectionDAG &DAG) const
Expand a VECREDUCE_SEQ_* into an explicit ordered calculation.
SDValue expandCTLZ(SDNode *N, SelectionDAG &DAG) const
Expand CTLZ/CTLZ_ZERO_UNDEF nodes.
SDValue expandBITREVERSE(SDNode *N, SelectionDAG &DAG) const
Expand BITREVERSE nodes.
SDValue expandCTTZ(SDNode *N, SelectionDAG &DAG) const
Expand CTTZ/CTTZ_ZERO_UNDEF nodes.
SDValue expandABD(SDNode *N, SelectionDAG &DAG) const
Expand ABDS/ABDU nodes.
SDValue expandShlSat(SDNode *Node, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US]SHLSAT.
SDValue expandFP_TO_INT_SAT(SDNode *N, SelectionDAG &DAG) const
Expand FP_TO_[US]INT_SAT into FP_TO_[US]INT and selects or min/max.
void expandSADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::S(ADD|SUB)O.
SDValue expandVPBITREVERSE(SDNode *N, SelectionDAG &DAG) const
Expand VP_BITREVERSE nodes.
SDValue expandABS(SDNode *N, SelectionDAG &DAG, bool IsNegative=false) const
Expand ABS nodes.
SDValue expandVecReduce(SDNode *Node, SelectionDAG &DAG) const
Expand a VECREDUCE_* into an explicit calculation.
bool expandFP_TO_UINT(SDNode *N, SDValue &Result, SDValue &Chain, SelectionDAG &DAG) const
Expand float to UINT conversion.
bool expandREM(SDNode *Node, SDValue &Result, SelectionDAG &DAG) const
Expand an SREM or UREM using SDIV/UDIV or SDIVREM/UDIVREM, if legal.
SDValue expandFMINIMUMNUM_FMAXIMUMNUM(SDNode *N, SelectionDAG &DAG) const
Expand fminimumnum/fmaximumnum into multiple comparison with selects.
SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const
Expand CTPOP nodes.
SDValue expandVectorNaryOpBySplitting(SDNode *Node, SelectionDAG &DAG) const
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
SDValue expandBSWAP(SDNode *N, SelectionDAG &DAG) const
Expand BSWAP nodes.
SDValue expandFMINIMUM_FMAXIMUM(SDNode *N, SelectionDAG &DAG) const
Expand fminimum/fmaximum into multiple comparison with selects.
std::pair< SDValue, SDValue > scalarizeVectorLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Turn load of vector type into a load of the individual elements.
SDValue expandFunnelShift(SDNode *N, SelectionDAG &DAG) const
Expand funnel shift.
bool LegalizeSetCCCondCode(SelectionDAG &DAG, EVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC, SDValue Mask, SDValue EVL, bool &NeedInvert, const SDLoc &dl, SDValue &Chain, bool IsSignaling=false) const
Legalize a SETCC or VP_SETCC with given LHS and RHS and condition code CC on the current target.
virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const
This callback is invoked for operations that are unsupported by the target, which are registered to u...
SDValue expandVPCTPOP(SDNode *N, SelectionDAG &DAG) const
Expand VP_CTPOP nodes.
SDValue expandFixedPointDiv(unsigned Opcode, const SDLoc &dl, SDValue LHS, SDValue RHS, unsigned Scale, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US]DIVFIX[SAT].
SDValue expandVPCTTZ(SDNode *N, SelectionDAG &DAG) const
Expand VP_CTTZ/VP_CTTZ_ZERO_UNDEF nodes.
SDValue expandVECTOR_COMPRESS(SDNode *Node, SelectionDAG &DAG) const
Expand a vector VECTOR_COMPRESS into a sequence of extract element, store temporarily,...
SDValue expandROT(SDNode *N, bool AllowVectorOps, SelectionDAG &DAG) const
Expand rotations.
SDValue expandFMINNUM_FMAXNUM(SDNode *N, SelectionDAG &DAG) const
Expand fminnum/fmaxnum into fminnum_ieee/fmaxnum_ieee with quieted inputs.
SDValue expandCMP(SDNode *Node, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US]CMP.
SDValue expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[U|S]MULFIX[SAT].
SDValue expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::[US][MIN|MAX].
SDValue expandVectorFindLastActive(SDNode *N, SelectionDAG &DAG) const
Expand VECTOR_FIND_LAST_ACTIVE nodes.
SDValue expandPartialReduceMLA(SDNode *Node, SelectionDAG &DAG) const
Expands PARTIAL_REDUCE_S/UMLA nodes to a series of simpler operations, consisting of zext/sext,...
void expandUADDSUBO(SDNode *Node, SDValue &Result, SDValue &Overflow, SelectionDAG &DAG) const
Method for building the DAG expansion of ISD::U(ADD|SUB)O.
bool expandUINT_TO_FP(SDNode *N, SDValue &Result, SDValue &Chain, SelectionDAG &DAG) const
Expand UINT(i64) to double(f64) conversion.
SDValue expandAVG(SDNode *N, SelectionDAG &DAG) const
Expand vector/scalar AVGCEILS/AVGCEILU/AVGFLOORS/AVGFLOORU nodes.
Changed
#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.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:807
@ MERGE_VALUES
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition ISDOpcodes.h:256
@ CTLZ_ZERO_UNDEF
Definition ISDOpcodes.h:780
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
Definition ISDOpcodes.h:504
@ PARTIAL_REDUCE_SMLA
@ LOOP_DEPENDENCE_RAW_MASK
@ VECREDUCE_SEQ_FADD
Generic reduction nodes.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:270
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:771
@ SMULFIX
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition ISDOpcodes.h:387
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:259
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ SMULFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition ISDOpcodes.h:393
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:841
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:511
@ VECTOR_FIND_LAST_ACTIVE
@ FMODF
FMODF - Decomposes the operand into integral and fractional parts, each having the same type and sign...
@ FATAN2
FATAN2 - atan2, inspired by libm.
@ FSINCOSPI
FSINCOSPI - Compute both the sine and cosine times pi more accurately than FSINCOS(pi*x),...
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:868
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:410
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition ISDOpcodes.h:744
@ SIGN_EXTEND_VECTOR_INREG
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition ISDOpcodes.h:898
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:275
@ FPTRUNC_ROUND
FPTRUNC_ROUND - This corresponds to the fptrunc_round intrinsic.
Definition ISDOpcodes.h:508
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition ISDOpcodes.h:981
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
@ SDIVFIX
RESULT = [US]DIVFIX(LHS, RHS, SCALE) - Perform fixed point division on 2 integers with the same width...
Definition ISDOpcodes.h:400
@ STRICT_FSQRT
Constrained versions of libm-equivalent floating point intrinsics.
Definition ISDOpcodes.h:431
@ PARTIAL_REDUCE_UMLA
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:832
@ AVGCEILS
AVGCEILS/AVGCEILU - Rounding averaging add - Add two integers using an integer of type i[N+2],...
Definition ISDOpcodes.h:712
@ STRICT_UINT_TO_FP
Definition ISDOpcodes.h:478
@ VECREDUCE_FADD
These reductions have relaxed evaluation order semantics, and have a single vector operand.
@ CTTZ_ZERO_UNDEF
Bit counting operators with an undefined result for zero inputs.
Definition ISDOpcodes.h:779
@ PARTIAL_REDUCE_FMLA
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ SSUBO
Same for subtraction.
Definition ISDOpcodes.h:347
@ STEP_VECTOR
STEP_VECTOR(IMM) - Returns a scalable vector whose lanes are comprised of a linear sequence of unsign...
Definition ISDOpcodes.h:688
@ FCANONICALIZE
Returns platform specific canonical encoding of a floating point number.
Definition ISDOpcodes.h:534
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition ISDOpcodes.h:369
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:784
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition ISDOpcodes.h:669
@ GET_ACTIVE_LANE_MASK
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition ISDOpcodes.h:343
@ VECREDUCE_ADD
Integer reductions may have a result type larger than the vector element type.
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:701
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:762
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:569
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:838
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:799
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum maximum on two values, following IEEE-754 definition...
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition ISDOpcodes.h:379
@ SMULO
Same for multiplication.
Definition ISDOpcodes.h:351
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition ISDOpcodes.h:887
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition ISDOpcodes.h:876
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:724
@ SDIVFIXSAT
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition ISDOpcodes.h:406
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition ISDOpcodes.h:966
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition ISDOpcodes.h:793
@ STRICT_SINT_TO_FP
STRICT_[US]INT_TO_FP - Convert a signed or unsigned integer to a floating point value.
Definition ISDOpcodes.h:477
@ MGATHER
Masked gather and scatter - load and store operations for a vector of random addresses with additiona...
@ STRICT_FP_TO_UINT
Definition ISDOpcodes.h:471
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
Definition ISDOpcodes.h:493
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:470
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:914
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition ISDOpcodes.h:498
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:736
@ SCMP
[US]CMP - 3-way comparison of signed or unsigned integers.
Definition ISDOpcodes.h:732
@ AVGFLOORS
AVGFLOORS/AVGFLOORU - Averaging add - Add two integers using an integer of type i[N+1],...
Definition ISDOpcodes.h:707
@ STRICT_FADD
Constrained versions of the binary floating point operators.
Definition ISDOpcodes.h:420
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:53
@ FFREXP
FFREXP - frexp, extract fractional and exponent component of a floating-point value.
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition ISDOpcodes.h:947
@ VECTOR_COMPRESS
VECTOR_COMPRESS(Vec, Mask, Passthru) consecutively place vector elements based on mask e....
Definition ISDOpcodes.h:696
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition ISDOpcodes.h:909
@ 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:933
@ VECREDUCE_FMINIMUM
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:844
@ VECREDUCE_SEQ_FMUL
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:62
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:527
@ PARTIAL_REDUCE_SUMLA
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition ISDOpcodes.h:360
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
@ ABDS
ABDS/ABDU - Absolute difference - Return the absolute difference between two numbers interpreted as s...
Definition ISDOpcodes.h:719
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:549
@ LOOP_DEPENDENCE_WAR_MASK
LLVM_ABI std::optional< unsigned > getVPMaskIdx(unsigned Opcode)
The operand position of the vector mask.
LLVM_ABI 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,...
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
LLVM_ABI bool isVPOpcode(unsigned Opcode)
Whether this is a vector-predicated Opcode.
LLVM_ABI Libcall getREM(EVT VT)
LLVM_ABI Libcall getSINCOSPI(EVT RetVT)
getSINCOSPI - Return the SINCOSPI_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getMODF(EVT VT)
getMODF - Return the MODF_* value for the given types, or UNKNOWN_LIBCALL if there is none.
LLVM_ABI Libcall getSINCOS(EVT RetVT)
getSINCOS - Return the SINCOS_* value for the given types, or UNKNOWN_LIBCALL if there is none.
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
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:1744
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Xor
Bitwise or logical XOR of integers.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:305
#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:350
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:373
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:385
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
bool isScalableVT() const
Return true if the type is a scalable type.
Definition ValueTypes.h:187
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:323
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
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:328
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:336
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition ValueTypes.h:308
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall.
std::pair< FunctionType *, AttributeList > getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const
static bool hasVectorMaskArgument(RTLIB::LibcallImpl Impl)
Returns true if the function has a vector mask argument, which is assumed to be the last argument.