LLVM  10.0.0svn
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/APInt.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/SmallVector.h"
38 #include "llvm/IR/DataLayout.h"
39 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/Compiler.h"
44 #include <cassert>
45 #include <cstdint>
46 #include <iterator>
47 #include <utility>
48 
49 using namespace llvm;
50 
51 #define DEBUG_TYPE "legalizevectorops"
52 
53 namespace {
54 
55 class 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, SDValue Result);
78 
79  /// Implements unrolling a VSETCC.
80  SDValue UnrollVSETCC(SDValue Op);
81 
82  /// Implement expand-based legalization of vector operations.
83  ///
84  /// This is just a high-level routine to dispatch to specific code paths for
85  /// operations to legalize them.
86  SDValue Expand(SDValue Op);
87 
88  /// Implements expansion for FP_TO_UINT; falls back to UnrollVectorOp if
89  /// FP_TO_SINT isn't legal.
90  SDValue ExpandFP_TO_UINT(SDValue Op);
91 
92  /// Implements expansion for UINT_TO_FLOAT; falls back to UnrollVectorOp if
93  /// SINT_TO_FLOAT and SHR on vectors isn't legal.
94  SDValue ExpandUINT_TO_FLOAT(SDValue Op);
95 
96  /// Implement expansion for SIGN_EXTEND_INREG using SRL and SRA.
97  SDValue ExpandSEXTINREG(SDValue Op);
98 
99  /// Implement expansion for ANY_EXTEND_VECTOR_INREG.
100  ///
101  /// Shuffles the low lanes of the operand into place and bitcasts to the proper
102  /// type. The contents of the bits in the extended part of each element are
103  /// undef.
104  SDValue ExpandANY_EXTEND_VECTOR_INREG(SDValue Op);
105 
106  /// Implement expansion for SIGN_EXTEND_VECTOR_INREG.
107  ///
108  /// Shuffles the low lanes of the operand into place, bitcasts to the proper
109  /// type, then shifts left and arithmetic shifts right to introduce a sign
110  /// extension.
111  SDValue ExpandSIGN_EXTEND_VECTOR_INREG(SDValue Op);
112 
113  /// Implement expansion for ZERO_EXTEND_VECTOR_INREG.
114  ///
115  /// Shuffles the low lanes of the operand into place and blends zeros into
116  /// the remaining lanes, finally bitcasting to the proper type.
117  SDValue ExpandZERO_EXTEND_VECTOR_INREG(SDValue Op);
118 
119  /// Implement expand-based legalization of ABS vector operations.
120  /// If following expanding is legal/custom then do it:
121  /// (ABS x) --> (XOR (ADD x, (SRA x, sizeof(x)-1)), (SRA x, sizeof(x)-1))
122  /// else unroll the operation.
123  SDValue ExpandABS(SDValue Op);
124 
125  /// Expand bswap of vectors into a shuffle if legal.
126  SDValue ExpandBSWAP(SDValue Op);
127 
128  /// Implement vselect in terms of XOR, AND, OR when blend is not
129  /// supported by the target.
130  SDValue ExpandVSELECT(SDValue Op);
131  SDValue ExpandSELECT(SDValue Op);
132  SDValue ExpandLoad(SDValue Op);
133  SDValue ExpandStore(SDValue Op);
134  SDValue ExpandFNEG(SDValue Op);
135  SDValue ExpandFSUB(SDValue Op);
136  SDValue ExpandBITREVERSE(SDValue Op);
137  SDValue ExpandCTPOP(SDValue Op);
138  SDValue ExpandCTLZ(SDValue Op);
139  SDValue ExpandCTTZ(SDValue Op);
140  SDValue ExpandFunnelShift(SDValue Op);
141  SDValue ExpandROT(SDValue Op);
142  SDValue ExpandFMINNUM_FMAXNUM(SDValue Op);
143  SDValue ExpandUADDSUBO(SDValue Op);
144  SDValue ExpandSADDSUBO(SDValue Op);
145  SDValue ExpandMULO(SDValue Op);
146  SDValue ExpandAddSubSat(SDValue Op);
147  SDValue ExpandFixedPointMul(SDValue Op);
148  SDValue ExpandStrictFPOp(SDValue Op);
149 
150  /// Implements vector promotion.
151  ///
152  /// This is essentially just bitcasting the operands to a different type and
153  /// bitcasting the result back to the original type.
154  SDValue Promote(SDValue Op);
155 
156  /// Implements [SU]INT_TO_FP vector promotion.
157  ///
158  /// This is a [zs]ext of the input operand to a larger integer type.
159  SDValue PromoteINT_TO_FP(SDValue Op);
160 
161  /// Implements FP_TO_[SU]INT vector promotion of the result type.
162  ///
163  /// It is promoted to a larger integer type. The result is then
164  /// truncated back to the original type.
165  SDValue PromoteFP_TO_INT(SDValue Op);
166 
167 public:
168  VectorLegalizer(SelectionDAG& dag) :
169  DAG(dag), TLI(dag.getTargetLoweringInfo()) {}
170 
171  /// Begin legalizer the vector operations in the DAG.
172  bool Run();
173 };
174 
175 } // end anonymous namespace
176 
177 bool VectorLegalizer::Run() {
178  // Before we start legalizing vector nodes, check if there are any vectors.
179  bool HasVectors = false;
180  for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
181  E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I) {
182  // Check if the values of the nodes contain vectors. We don't need to check
183  // the operands because we are going to check their values at some point.
184  for (SDNode::value_iterator J = I->value_begin(), E = I->value_end();
185  J != E; ++J)
186  HasVectors |= J->isVector();
187 
188  // If we found a vector node we can start the legalization.
189  if (HasVectors)
190  break;
191  }
192 
193  // If this basic block has no vectors then no need to legalize vectors.
194  if (!HasVectors)
195  return false;
196 
197  // The legalize process is inherently a bottom-up recursive process (users
198  // legalize their uses before themselves). Given infinite stack space, we
199  // could just start legalizing on the root and traverse the whole graph. In
200  // practice however, this causes us to run out of stack space on large basic
201  // blocks. To avoid this problem, compute an ordering of the nodes where each
202  // node is only legalized after all of its operands are legalized.
203  DAG.AssignTopologicalOrder();
204  for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
205  E = std::prev(DAG.allnodes_end()); I != std::next(E); ++I)
206  LegalizeOp(SDValue(&*I, 0));
207 
208  // Finally, it's possible the root changed. Get the new root.
209  SDValue OldRoot = DAG.getRoot();
210  assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
211  DAG.setRoot(LegalizedNodes[OldRoot]);
212 
213  LegalizedNodes.clear();
214 
215  // Remove dead nodes now.
216  DAG.RemoveDeadNodes();
217 
218  return Changed;
219 }
220 
221 SDValue VectorLegalizer::TranslateLegalizeResults(SDValue Op, SDValue Result) {
222  // Generic legalization: just pass the operand through.
223  for (unsigned i = 0, e = Op.getNode()->getNumValues(); i != e; ++i)
224  AddLegalizedOperand(Op.getValue(i), Result.getValue(i));
225  return Result.getValue(Op.getResNo());
226 }
227 
228 SDValue VectorLegalizer::LegalizeOp(SDValue Op) {
229  // Note that LegalizeOp may be reentered even from single-use nodes, which
230  // means that we always must cache transformed nodes.
231  DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
232  if (I != LegalizedNodes.end()) return I->second;
233 
234  SDNode* Node = Op.getNode();
235 
236  // Legalize the operands
238  for (const SDValue &Op : Node->op_values())
239  Ops.push_back(LegalizeOp(Op));
240 
241  SDValue Result = SDValue(DAG.UpdateNodeOperands(Op.getNode(), Ops),
242  Op.getResNo());
243 
244  if (Op.getOpcode() == ISD::LOAD) {
245  LoadSDNode *LD = cast<LoadSDNode>(Op.getNode());
247  if (LD->getMemoryVT().isVector() && ExtType != ISD::NON_EXTLOAD) {
248  LLVM_DEBUG(dbgs() << "\nLegalizing extending vector load: ";
249  Node->dump(&DAG));
250  switch (TLI.getLoadExtAction(LD->getExtensionType(), LD->getValueType(0),
251  LD->getMemoryVT())) {
252  default: llvm_unreachable("This action is not supported yet!");
254  return TranslateLegalizeResults(Op, Result);
256  if (SDValue Lowered = TLI.LowerOperation(Result, DAG)) {
257  assert(Lowered->getNumValues() == Op->getNumValues() &&
258  "Unexpected number of results");
259  if (Lowered != Result) {
260  // Make sure the new code is also legal.
261  Lowered = LegalizeOp(Lowered);
262  Changed = true;
263  }
264  return TranslateLegalizeResults(Op, Lowered);
265  }
268  Changed = true;
269  return ExpandLoad(Op);
270  }
271  }
272  } else if (Op.getOpcode() == ISD::STORE) {
273  StoreSDNode *ST = cast<StoreSDNode>(Op.getNode());
274  EVT StVT = ST->getMemoryVT();
275  MVT ValVT = ST->getValue().getSimpleValueType();
276  if (StVT.isVector() && ST->isTruncatingStore()) {
277  LLVM_DEBUG(dbgs() << "\nLegalizing truncating vector store: ";
278  Node->dump(&DAG));
279  switch (TLI.getTruncStoreAction(ValVT, StVT)) {
280  default: llvm_unreachable("This action is not supported yet!");
282  return TranslateLegalizeResults(Op, Result);
283  case TargetLowering::Custom: {
284  SDValue Lowered = TLI.LowerOperation(Result, DAG);
285  if (Lowered != Result) {
286  // Make sure the new code is also legal.
287  Lowered = LegalizeOp(Lowered);
288  Changed = true;
289  }
290  return TranslateLegalizeResults(Op, Lowered);
291  }
293  Changed = true;
294  return ExpandStore(Op);
295  }
296  }
297  }
298 
299  bool HasVectorValueOrOp = false;
300  for (auto J = Node->value_begin(), E = Node->value_end(); J != E; ++J)
301  HasVectorValueOrOp |= J->isVector();
302  for (const SDValue &Op : Node->op_values())
303  HasVectorValueOrOp |= Op.getValueType().isVector();
304 
305  if (!HasVectorValueOrOp)
306  return TranslateLegalizeResults(Op, Result);
307 
309  switch (Op.getOpcode()) {
310  default:
311  return TranslateLegalizeResults(Op, Result);
312  case ISD::STRICT_FADD:
313  case ISD::STRICT_FSUB:
314  case ISD::STRICT_FMUL:
315  case ISD::STRICT_FDIV:
316  case ISD::STRICT_FREM:
317  case ISD::STRICT_FSQRT:
318  case ISD::STRICT_FMA:
319  case ISD::STRICT_FPOW:
320  case ISD::STRICT_FPOWI:
321  case ISD::STRICT_FSIN:
322  case ISD::STRICT_FCOS:
323  case ISD::STRICT_FEXP:
324  case ISD::STRICT_FEXP2:
325  case ISD::STRICT_FLOG:
326  case ISD::STRICT_FLOG10:
327  case ISD::STRICT_FLOG2:
328  case ISD::STRICT_FRINT:
330  case ISD::STRICT_FMAXNUM:
331  case ISD::STRICT_FMINNUM:
332  case ISD::STRICT_FCEIL:
333  case ISD::STRICT_FFLOOR:
334  case ISD::STRICT_FROUND:
335  case ISD::STRICT_FTRUNC:
338  Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
339  // If we're asked to expand a strict vector floating-point operation,
340  // by default we're going to simply unroll it. That is usually the
341  // best approach, except in the case where the resulting strict (scalar)
342  // operations would themselves use the fallback mutation to non-strict.
343  // In that specific case, just do the fallback on the vector op.
344  if (Action == TargetLowering::Expand &&
345  TLI.getStrictFPOperationAction(Node->getOpcode(),
346  Node->getValueType(0))
348  EVT EltVT = Node->getValueType(0).getVectorElementType();
349  if (TLI.getOperationAction(Node->getOpcode(), EltVT)
351  TLI.getStrictFPOperationAction(Node->getOpcode(), EltVT)
353  Action = TargetLowering::Legal;
354  }
355  break;
356  case ISD::ADD:
357  case ISD::SUB:
358  case ISD::MUL:
359  case ISD::MULHS:
360  case ISD::MULHU:
361  case ISD::SDIV:
362  case ISD::UDIV:
363  case ISD::SREM:
364  case ISD::UREM:
365  case ISD::SDIVREM:
366  case ISD::UDIVREM:
367  case ISD::FADD:
368  case ISD::FSUB:
369  case ISD::FMUL:
370  case ISD::FDIV:
371  case ISD::FREM:
372  case ISD::AND:
373  case ISD::OR:
374  case ISD::XOR:
375  case ISD::SHL:
376  case ISD::SRA:
377  case ISD::SRL:
378  case ISD::FSHL:
379  case ISD::FSHR:
380  case ISD::ROTL:
381  case ISD::ROTR:
382  case ISD::ABS:
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::SETCC:
394  case ISD::ZERO_EXTEND:
395  case ISD::ANY_EXTEND:
396  case ISD::TRUNCATE:
397  case ISD::SIGN_EXTEND:
398  case ISD::FP_TO_SINT:
399  case ISD::FP_TO_UINT:
400  case ISD::FNEG:
401  case ISD::FABS:
402  case ISD::FMINNUM:
403  case ISD::FMAXNUM:
404  case ISD::FMINNUM_IEEE:
405  case ISD::FMAXNUM_IEEE:
406  case ISD::FMINIMUM:
407  case ISD::FMAXIMUM:
408  case ISD::FCOPYSIGN:
409  case ISD::FSQRT:
410  case ISD::FSIN:
411  case ISD::FCOS:
412  case ISD::FPOWI:
413  case ISD::FPOW:
414  case ISD::FLOG:
415  case ISD::FLOG2:
416  case ISD::FLOG10:
417  case ISD::FEXP:
418  case ISD::FEXP2:
419  case ISD::FCEIL:
420  case ISD::FTRUNC:
421  case ISD::FRINT:
422  case ISD::FNEARBYINT:
423  case ISD::FROUND:
424  case ISD::FFLOOR:
425  case ISD::FP_ROUND:
426  case ISD::FP_EXTEND:
427  case ISD::FMA:
432  case ISD::SMIN:
433  case ISD::SMAX:
434  case ISD::UMIN:
435  case ISD::UMAX:
436  case ISD::SMUL_LOHI:
437  case ISD::UMUL_LOHI:
438  case ISD::SADDO:
439  case ISD::UADDO:
440  case ISD::SSUBO:
441  case ISD::USUBO:
442  case ISD::SMULO:
443  case ISD::UMULO:
444  case ISD::FCANONICALIZE:
445  case ISD::SADDSAT:
446  case ISD::UADDSAT:
447  case ISD::SSUBSAT:
448  case ISD::USUBSAT:
449  Action = TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0));
450  break;
451  case ISD::SMULFIX:
452  case ISD::SMULFIXSAT:
453  case ISD::UMULFIX: {
454  unsigned Scale = Node->getConstantOperandVal(2);
455  Action = TLI.getFixedPointOperationAction(Node->getOpcode(),
456  Node->getValueType(0), Scale);
457  break;
458  }
459  case ISD::FP_ROUND_INREG:
460  Action = TLI.getOperationAction(Node->getOpcode(),
461  cast<VTSDNode>(Node->getOperand(1))->getVT());
462  break;
463  case ISD::SINT_TO_FP:
464  case ISD::UINT_TO_FP:
465  case ISD::VECREDUCE_ADD:
466  case ISD::VECREDUCE_MUL:
467  case ISD::VECREDUCE_AND:
468  case ISD::VECREDUCE_OR:
469  case ISD::VECREDUCE_XOR:
470  case ISD::VECREDUCE_SMAX:
471  case ISD::VECREDUCE_SMIN:
472  case ISD::VECREDUCE_UMAX:
473  case ISD::VECREDUCE_UMIN:
474  case ISD::VECREDUCE_FADD:
475  case ISD::VECREDUCE_FMUL:
476  case ISD::VECREDUCE_FMAX:
477  case ISD::VECREDUCE_FMIN:
478  Action = TLI.getOperationAction(Node->getOpcode(),
479  Node->getOperand(0).getValueType());
480  break;
481  }
482 
483  LLVM_DEBUG(dbgs() << "\nLegalizing vector op: "; Node->dump(&DAG));
484 
485  switch (Action) {
486  default: llvm_unreachable("This action is not supported yet!");
488  Result = Promote(Op);
489  Changed = true;
490  break;
492  LLVM_DEBUG(dbgs() << "Legal node: nothing to do\n");
493  break;
494  case TargetLowering::Custom: {
495  LLVM_DEBUG(dbgs() << "Trying custom legalization\n");
496  if (SDValue Tmp1 = TLI.LowerOperation(Op, DAG)) {
497  LLVM_DEBUG(dbgs() << "Successfully custom legalized node\n");
498  Result = Tmp1;
499  break;
500  }
501  LLVM_DEBUG(dbgs() << "Could not custom legalize node\n");
503  }
505  Result = Expand(Op);
506  }
507 
508  // Make sure that the generated code is itself legal.
509  if (Result != Op) {
510  Result = LegalizeOp(Result);
511  Changed = true;
512  }
513 
514  // Note that LegalizeOp may be reentered even from single-use nodes, which
515  // means that we always must cache transformed nodes.
516  AddLegalizedOperand(Op, Result);
517  return Result;
518 }
519 
520 SDValue VectorLegalizer::Promote(SDValue Op) {
521  // For a few operations there is a specific concept for promotion based on
522  // the operand's type.
523  switch (Op.getOpcode()) {
524  case ISD::SINT_TO_FP:
525  case ISD::UINT_TO_FP:
526  // "Promote" the operation by extending the operand.
527  return PromoteINT_TO_FP(Op);
528  case ISD::FP_TO_UINT:
529  case ISD::FP_TO_SINT:
530  // Promote the operation by extending the operand.
531  return PromoteFP_TO_INT(Op);
532  }
533 
534  // There are currently two cases of vector promotion:
535  // 1) Bitcasting a vector of integers to a different type to a vector of the
536  // same overall length. For example, x86 promotes ISD::AND v2i32 to v1i64.
537  // 2) Extending a vector of floats to a vector of the same number of larger
538  // floats. For example, AArch64 promotes ISD::FADD on v4f16 to v4f32.
539  MVT VT = Op.getSimpleValueType();
540  assert(Op.getNode()->getNumValues() == 1 &&
541  "Can't promote a vector with multiple results!");
542  MVT NVT = TLI.getTypeToPromoteTo(Op.getOpcode(), VT);
543  SDLoc dl(Op);
545 
546  for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
547  if (Op.getOperand(j).getValueType().isVector())
548  if (Op.getOperand(j)
549  .getValueType()
551  .isFloatingPoint() &&
552  NVT.isVector() && NVT.getVectorElementType().isFloatingPoint())
553  Operands[j] = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Op.getOperand(j));
554  else
555  Operands[j] = DAG.getNode(ISD::BITCAST, dl, NVT, Op.getOperand(j));
556  else
557  Operands[j] = Op.getOperand(j);
558  }
559 
560  Op = DAG.getNode(Op.getOpcode(), dl, NVT, Operands, Op.getNode()->getFlags());
561  if ((VT.isFloatingPoint() && NVT.isFloatingPoint()) ||
563  NVT.isVector() && NVT.getVectorElementType().isFloatingPoint()))
564  return DAG.getNode(ISD::FP_ROUND, dl, VT, Op, DAG.getIntPtrConstant(0, dl));
565  else
566  return DAG.getNode(ISD::BITCAST, dl, VT, Op);
567 }
568 
569 SDValue VectorLegalizer::PromoteINT_TO_FP(SDValue Op) {
570  // INT_TO_FP operations may require the input operand be promoted even
571  // when the type is otherwise legal.
572  MVT VT = Op.getOperand(0).getSimpleValueType();
573  MVT NVT = TLI.getTypeToPromoteTo(Op.getOpcode(), VT);
575  "Vectors have different number of elements!");
576 
577  SDLoc dl(Op);
579 
580  unsigned Opc = Op.getOpcode() == ISD::UINT_TO_FP ? ISD::ZERO_EXTEND :
582  for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
583  if (Op.getOperand(j).getValueType().isVector())
584  Operands[j] = DAG.getNode(Opc, dl, NVT, Op.getOperand(j));
585  else
586  Operands[j] = Op.getOperand(j);
587  }
588 
589  return DAG.getNode(Op.getOpcode(), dl, Op.getValueType(), Operands);
590 }
591 
592 // For FP_TO_INT we promote the result type to a vector type with wider
593 // elements and then truncate the result. This is different from the default
594 // PromoteVector which uses bitcast to promote thus assumning that the
595 // promoted vector type has the same overall size.
596 SDValue VectorLegalizer::PromoteFP_TO_INT(SDValue Op) {
597  MVT VT = Op.getSimpleValueType();
598  MVT NVT = TLI.getTypeToPromoteTo(Op.getOpcode(), VT);
600  "Vectors have different number of elements!");
601 
602  unsigned NewOpc = Op->getOpcode();
603  // Change FP_TO_UINT to FP_TO_SINT if possible.
604  // TODO: Should we only do this if FP_TO_UINT itself isn't legal?
605  if (NewOpc == ISD::FP_TO_UINT &&
606  TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT))
607  NewOpc = ISD::FP_TO_SINT;
608 
609  SDLoc dl(Op);
610  SDValue Promoted = DAG.getNode(NewOpc, dl, NVT, Op.getOperand(0));
611 
612  // Assert that the converted value fits in the original type. If it doesn't
613  // (eg: because the value being converted is too big), then the result of the
614  // original operation was undefined anyway, so the assert is still correct.
615  Promoted = DAG.getNode(Op->getOpcode() == ISD::FP_TO_UINT ? ISD::AssertZext
616  : ISD::AssertSext,
617  dl, NVT, Promoted,
618  DAG.getValueType(VT.getScalarType()));
619  return DAG.getNode(ISD::TRUNCATE, dl, VT, Promoted);
620 }
621 
622 SDValue VectorLegalizer::ExpandLoad(SDValue Op) {
623  LoadSDNode *LD = cast<LoadSDNode>(Op.getNode());
624 
625  EVT SrcVT = LD->getMemoryVT();
626  EVT SrcEltVT = SrcVT.getScalarType();
627  unsigned NumElem = SrcVT.getVectorNumElements();
628 
629  SDValue NewChain;
630  SDValue Value;
631  if (SrcVT.getVectorNumElements() > 1 && !SrcEltVT.isByteSized()) {
632  SDLoc dl(Op);
633 
635  SmallVector<SDValue, 8> LoadChains;
636 
637  EVT DstEltVT = LD->getValueType(0).getScalarType();
638  SDValue Chain = LD->getChain();
639  SDValue BasePTR = LD->getBasePtr();
641 
642  // When elements in a vector is not byte-addressable, we cannot directly
643  // load each element by advancing pointer, which could only address bytes.
644  // Instead, we load all significant words, mask bits off, and concatenate
645  // them to form each element. Finally, they are extended to destination
646  // scalar type to build the destination vector.
647  EVT WideVT = TLI.getPointerTy(DAG.getDataLayout());
648 
649  assert(WideVT.isRound() &&
650  "Could not handle the sophisticated case when the widest integer is"
651  " not power of 2.");
652  assert(WideVT.bitsGE(SrcEltVT) &&
653  "Type is not legalized?");
654 
655  unsigned WideBytes = WideVT.getStoreSize();
656  unsigned Offset = 0;
657  unsigned RemainingBytes = SrcVT.getStoreSize();
658  SmallVector<SDValue, 8> LoadVals;
659  while (RemainingBytes > 0) {
660  SDValue ScalarLoad;
661  unsigned LoadBytes = WideBytes;
662 
663  if (RemainingBytes >= LoadBytes) {
664  ScalarLoad =
665  DAG.getLoad(WideVT, dl, Chain, BasePTR,
666  LD->getPointerInfo().getWithOffset(Offset),
667  MinAlign(LD->getAlignment(), Offset),
668  LD->getMemOperand()->getFlags(), LD->getAAInfo());
669  } else {
670  EVT LoadVT = WideVT;
671  while (RemainingBytes < LoadBytes) {
672  LoadBytes >>= 1; // Reduce the load size by half.
673  LoadVT = EVT::getIntegerVT(*DAG.getContext(), LoadBytes << 3);
674  }
675  ScalarLoad =
676  DAG.getExtLoad(ISD::EXTLOAD, dl, WideVT, Chain, BasePTR,
677  LD->getPointerInfo().getWithOffset(Offset), LoadVT,
678  MinAlign(LD->getAlignment(), Offset),
679  LD->getMemOperand()->getFlags(), LD->getAAInfo());
680  }
681 
682  RemainingBytes -= LoadBytes;
683  Offset += LoadBytes;
684 
685  BasePTR = DAG.getObjectPtrOffset(dl, BasePTR, LoadBytes);
686 
687  LoadVals.push_back(ScalarLoad.getValue(0));
688  LoadChains.push_back(ScalarLoad.getValue(1));
689  }
690 
691  unsigned BitOffset = 0;
692  unsigned WideIdx = 0;
693  unsigned WideBits = WideVT.getSizeInBits();
694 
695  // Extract bits, pack and extend/trunc them into destination type.
696  unsigned SrcEltBits = SrcEltVT.getSizeInBits();
697  SDValue SrcEltBitMask = DAG.getConstant(
698  APInt::getLowBitsSet(WideBits, SrcEltBits), dl, WideVT);
699 
700  for (unsigned Idx = 0; Idx != NumElem; ++Idx) {
701  assert(BitOffset < WideBits && "Unexpected offset!");
702 
703  SDValue ShAmt = DAG.getConstant(
704  BitOffset, dl, TLI.getShiftAmountTy(WideVT, DAG.getDataLayout()));
705  SDValue Lo = DAG.getNode(ISD::SRL, dl, WideVT, LoadVals[WideIdx], ShAmt);
706 
707  BitOffset += SrcEltBits;
708  if (BitOffset >= WideBits) {
709  WideIdx++;
710  BitOffset -= WideBits;
711  if (BitOffset > 0) {
712  ShAmt = DAG.getConstant(
713  SrcEltBits - BitOffset, dl,
714  TLI.getShiftAmountTy(WideVT, DAG.getDataLayout()));
715  SDValue Hi =
716  DAG.getNode(ISD::SHL, dl, WideVT, LoadVals[WideIdx], ShAmt);
717  Lo = DAG.getNode(ISD::OR, dl, WideVT, Lo, Hi);
718  }
719  }
720 
721  Lo = DAG.getNode(ISD::AND, dl, WideVT, Lo, SrcEltBitMask);
722 
723  switch (ExtType) {
724  default: llvm_unreachable("Unknown extended-load op!");
725  case ISD::EXTLOAD:
726  Lo = DAG.getAnyExtOrTrunc(Lo, dl, DstEltVT);
727  break;
728  case ISD::ZEXTLOAD:
729  Lo = DAG.getZExtOrTrunc(Lo, dl, DstEltVT);
730  break;
731  case ISD::SEXTLOAD:
732  ShAmt =
733  DAG.getConstant(WideBits - SrcEltBits, dl,
734  TLI.getShiftAmountTy(WideVT, DAG.getDataLayout()));
735  Lo = DAG.getNode(ISD::SHL, dl, WideVT, Lo, ShAmt);
736  Lo = DAG.getNode(ISD::SRA, dl, WideVT, Lo, ShAmt);
737  Lo = DAG.getSExtOrTrunc(Lo, dl, DstEltVT);
738  break;
739  }
740  Vals.push_back(Lo);
741  }
742 
743  NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains);
744  Value = DAG.getBuildVector(Op.getNode()->getValueType(0), dl, Vals);
745  } else {
746  SDValue Scalarized = TLI.scalarizeVectorLoad(LD, DAG);
747  // Skip past MERGE_VALUE node if known.
748  if (Scalarized->getOpcode() == ISD::MERGE_VALUES) {
749  NewChain = Scalarized.getOperand(1);
750  Value = Scalarized.getOperand(0);
751  } else {
752  NewChain = Scalarized.getValue(1);
753  Value = Scalarized.getValue(0);
754  }
755  }
756 
757  AddLegalizedOperand(Op.getValue(0), Value);
758  AddLegalizedOperand(Op.getValue(1), NewChain);
759 
760  return (Op.getResNo() ? NewChain : Value);
761 }
762 
763 SDValue VectorLegalizer::ExpandStore(SDValue Op) {
764  StoreSDNode *ST = cast<StoreSDNode>(Op.getNode());
765  SDValue TF = TLI.scalarizeVectorStore(ST, DAG);
766  AddLegalizedOperand(Op, TF);
767  return TF;
768 }
769 
770 SDValue VectorLegalizer::Expand(SDValue Op) {
771  switch (Op->getOpcode()) {
773  return ExpandSEXTINREG(Op);
775  return ExpandANY_EXTEND_VECTOR_INREG(Op);
777  return ExpandSIGN_EXTEND_VECTOR_INREG(Op);
779  return ExpandZERO_EXTEND_VECTOR_INREG(Op);
780  case ISD::BSWAP:
781  return ExpandBSWAP(Op);
782  case ISD::VSELECT:
783  return ExpandVSELECT(Op);
784  case ISD::SELECT:
785  return ExpandSELECT(Op);
786  case ISD::FP_TO_UINT:
787  return ExpandFP_TO_UINT(Op);
788  case ISD::UINT_TO_FP:
789  return ExpandUINT_TO_FLOAT(Op);
790  case ISD::FNEG:
791  return ExpandFNEG(Op);
792  case ISD::FSUB:
793  return ExpandFSUB(Op);
794  case ISD::SETCC:
795  return UnrollVSETCC(Op);
796  case ISD::ABS:
797  return ExpandABS(Op);
798  case ISD::BITREVERSE:
799  return ExpandBITREVERSE(Op);
800  case ISD::CTPOP:
801  return ExpandCTPOP(Op);
802  case ISD::CTLZ:
804  return ExpandCTLZ(Op);
805  case ISD::CTTZ:
807  return ExpandCTTZ(Op);
808  case ISD::FSHL:
809  case ISD::FSHR:
810  return ExpandFunnelShift(Op);
811  case ISD::ROTL:
812  case ISD::ROTR:
813  return ExpandROT(Op);
814  case ISD::FMINNUM:
815  case ISD::FMAXNUM:
816  return ExpandFMINNUM_FMAXNUM(Op);
817  case ISD::UADDO:
818  case ISD::USUBO:
819  return ExpandUADDSUBO(Op);
820  case ISD::SADDO:
821  case ISD::SSUBO:
822  return ExpandSADDSUBO(Op);
823  case ISD::UMULO:
824  case ISD::SMULO:
825  return ExpandMULO(Op);
826  case ISD::USUBSAT:
827  case ISD::SSUBSAT:
828  case ISD::UADDSAT:
829  case ISD::SADDSAT:
830  return ExpandAddSubSat(Op);
831  case ISD::SMULFIX:
832  case ISD::UMULFIX:
833  return ExpandFixedPointMul(Op);
834  case ISD::SMULFIXSAT:
835  // FIXME: We do not expand SMULFIXSAT here yet, not sure why. Maybe it
836  // results in worse codegen compared to the default unroll? This should
837  // probably be investigated. And if we still prefer to unroll an explanation
838  // could be helpful, otherwise it just looks like something that hasn't been
839  // "implemented" yet.
840  return DAG.UnrollVectorOp(Op.getNode());
841  case ISD::STRICT_FADD:
842  case ISD::STRICT_FSUB:
843  case ISD::STRICT_FMUL:
844  case ISD::STRICT_FDIV:
845  case ISD::STRICT_FREM:
846  case ISD::STRICT_FSQRT:
847  case ISD::STRICT_FMA:
848  case ISD::STRICT_FPOW:
849  case ISD::STRICT_FPOWI:
850  case ISD::STRICT_FSIN:
851  case ISD::STRICT_FCOS:
852  case ISD::STRICT_FEXP:
853  case ISD::STRICT_FEXP2:
854  case ISD::STRICT_FLOG:
855  case ISD::STRICT_FLOG10:
856  case ISD::STRICT_FLOG2:
857  case ISD::STRICT_FRINT:
859  case ISD::STRICT_FMAXNUM:
860  case ISD::STRICT_FMINNUM:
861  case ISD::STRICT_FCEIL:
862  case ISD::STRICT_FFLOOR:
863  case ISD::STRICT_FROUND:
864  case ISD::STRICT_FTRUNC:
865  return ExpandStrictFPOp(Op);
866  case ISD::VECREDUCE_ADD:
867  case ISD::VECREDUCE_MUL:
868  case ISD::VECREDUCE_AND:
869  case ISD::VECREDUCE_OR:
870  case ISD::VECREDUCE_XOR:
871  case ISD::VECREDUCE_SMAX:
872  case ISD::VECREDUCE_SMIN:
873  case ISD::VECREDUCE_UMAX:
874  case ISD::VECREDUCE_UMIN:
875  case ISD::VECREDUCE_FADD:
876  case ISD::VECREDUCE_FMUL:
877  case ISD::VECREDUCE_FMAX:
878  case ISD::VECREDUCE_FMIN:
879  return TLI.expandVecReduce(Op.getNode(), DAG);
880  default:
881  return DAG.UnrollVectorOp(Op.getNode());
882  }
883 }
884 
885 SDValue VectorLegalizer::ExpandSELECT(SDValue Op) {
886  // Lower a select instruction where the condition is a scalar and the
887  // operands are vectors. Lower this select to VSELECT and implement it
888  // using XOR AND OR. The selector bit is broadcasted.
889  EVT VT = Op.getValueType();
890  SDLoc DL(Op);
891 
892  SDValue Mask = Op.getOperand(0);
893  SDValue Op1 = Op.getOperand(1);
894  SDValue Op2 = Op.getOperand(2);
895 
896  assert(VT.isVector() && !Mask.getValueType().isVector()
897  && Op1.getValueType() == Op2.getValueType() && "Invalid type");
898 
899  // If we can't even use the basic vector operations of
900  // AND,OR,XOR, we will have to scalarize the op.
901  // Notice that the operation may be 'promoted' which means that it is
902  // 'bitcasted' to another type which is handled.
903  // Also, we need to be able to construct a splat vector using BUILD_VECTOR.
904  if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
905  TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
906  TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
907  TLI.getOperationAction(ISD::BUILD_VECTOR, VT) == TargetLowering::Expand)
908  return DAG.UnrollVectorOp(Op.getNode());
909 
910  // Generate a mask operand.
912 
913  // What is the size of each element in the vector mask.
914  EVT BitTy = MaskTy.getScalarType();
915 
916  Mask = DAG.getSelect(DL, BitTy, Mask,
917  DAG.getConstant(APInt::getAllOnesValue(BitTy.getSizeInBits()), DL,
918  BitTy),
919  DAG.getConstant(0, DL, BitTy));
920 
921  // Broadcast the mask so that the entire vector is all-one or all zero.
922  Mask = DAG.getSplatBuildVector(MaskTy, DL, Mask);
923 
924  // Bitcast the operands to be the same type as the mask.
925  // This is needed when we select between FP types because
926  // the mask is a vector of integers.
927  Op1 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op1);
928  Op2 = DAG.getNode(ISD::BITCAST, DL, MaskTy, Op2);
929 
930  SDValue AllOnes = DAG.getConstant(
931  APInt::getAllOnesValue(BitTy.getSizeInBits()), DL, MaskTy);
932  SDValue NotMask = DAG.getNode(ISD::XOR, DL, MaskTy, Mask, AllOnes);
933 
934  Op1 = DAG.getNode(ISD::AND, DL, MaskTy, Op1, Mask);
935  Op2 = DAG.getNode(ISD::AND, DL, MaskTy, Op2, NotMask);
936  SDValue Val = DAG.getNode(ISD::OR, DL, MaskTy, Op1, Op2);
937  return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Val);
938 }
939 
940 SDValue VectorLegalizer::ExpandSEXTINREG(SDValue Op) {
941  EVT VT = Op.getValueType();
942 
943  // Make sure that the SRA and SHL instructions are available.
944  if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
945  TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
946  return DAG.UnrollVectorOp(Op.getNode());
947 
948  SDLoc DL(Op);
949  EVT OrigTy = cast<VTSDNode>(Op->getOperand(1))->getVT();
950 
951  unsigned BW = VT.getScalarSizeInBits();
952  unsigned OrigBW = OrigTy.getScalarSizeInBits();
953  SDValue ShiftSz = DAG.getConstant(BW - OrigBW, DL, VT);
954 
955  Op = Op.getOperand(0);
956  Op = DAG.getNode(ISD::SHL, DL, VT, Op, ShiftSz);
957  return DAG.getNode(ISD::SRA, DL, VT, Op, ShiftSz);
958 }
959 
960 // Generically expand a vector anyext in register to a shuffle of the relevant
961 // lanes into the appropriate locations, with other lanes left undef.
962 SDValue VectorLegalizer::ExpandANY_EXTEND_VECTOR_INREG(SDValue Op) {
963  SDLoc DL(Op);
964  EVT VT = Op.getValueType();
965  int NumElements = VT.getVectorNumElements();
966  SDValue Src = Op.getOperand(0);
967  EVT SrcVT = Src.getValueType();
968  int NumSrcElements = SrcVT.getVectorNumElements();
969 
970  // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
971  // into a larger vector type.
972  if (SrcVT.bitsLE(VT)) {
973  assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
974  "ANY_EXTEND_VECTOR_INREG vector size mismatch");
975  NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
976  SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
977  NumSrcElements);
978  Src = DAG.getNode(
979  ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT), Src,
980  DAG.getConstant(0, DL, TLI.getVectorIdxTy(DAG.getDataLayout())));
981  }
982 
983  // Build a base mask of undef shuffles.
984  SmallVector<int, 16> ShuffleMask;
985  ShuffleMask.resize(NumSrcElements, -1);
986 
987  // Place the extended lanes into the correct locations.
988  int ExtLaneScale = NumSrcElements / NumElements;
989  int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
990  for (int i = 0; i < NumElements; ++i)
991  ShuffleMask[i * ExtLaneScale + EndianOffset] = i;
992 
993  return DAG.getNode(
994  ISD::BITCAST, DL, VT,
995  DAG.getVectorShuffle(SrcVT, DL, Src, DAG.getUNDEF(SrcVT), ShuffleMask));
996 }
997 
998 SDValue VectorLegalizer::ExpandSIGN_EXTEND_VECTOR_INREG(SDValue Op) {
999  SDLoc DL(Op);
1000  EVT VT = Op.getValueType();
1001  SDValue Src = Op.getOperand(0);
1002  EVT SrcVT = Src.getValueType();
1003 
1004  // First build an any-extend node which can be legalized above when we
1005  // recurse through it.
1006  Op = DAG.getNode(ISD::ANY_EXTEND_VECTOR_INREG, DL, VT, Src);
1007 
1008  // Now we need sign extend. Do this by shifting the elements. Even if these
1009  // aren't legal operations, they have a better chance of being legalized
1010  // without full scalarization than the sign extension does.
1011  unsigned EltWidth = VT.getScalarSizeInBits();
1012  unsigned SrcEltWidth = SrcVT.getScalarSizeInBits();
1013  SDValue ShiftAmount = DAG.getConstant(EltWidth - SrcEltWidth, DL, VT);
1014  return DAG.getNode(ISD::SRA, DL, VT,
1015  DAG.getNode(ISD::SHL, DL, VT, Op, ShiftAmount),
1016  ShiftAmount);
1017 }
1018 
1019 // Generically expand a vector zext in register to a shuffle of the relevant
1020 // lanes into the appropriate locations, a blend of zero into the high bits,
1021 // and a bitcast to the wider element type.
1022 SDValue VectorLegalizer::ExpandZERO_EXTEND_VECTOR_INREG(SDValue Op) {
1023  SDLoc DL(Op);
1024  EVT VT = Op.getValueType();
1025  int NumElements = VT.getVectorNumElements();
1026  SDValue Src = Op.getOperand(0);
1027  EVT SrcVT = Src.getValueType();
1028  int NumSrcElements = SrcVT.getVectorNumElements();
1029 
1030  // *_EXTEND_VECTOR_INREG SrcVT can be smaller than VT - so insert the vector
1031  // into a larger vector type.
1032  if (SrcVT.bitsLE(VT)) {
1033  assert((VT.getSizeInBits() % SrcVT.getScalarSizeInBits()) == 0 &&
1034  "ZERO_EXTEND_VECTOR_INREG vector size mismatch");
1035  NumSrcElements = VT.getSizeInBits() / SrcVT.getScalarSizeInBits();
1036  SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getScalarType(),
1037  NumSrcElements);
1038  Src = DAG.getNode(
1039  ISD::INSERT_SUBVECTOR, DL, SrcVT, DAG.getUNDEF(SrcVT), Src,
1040  DAG.getConstant(0, DL, TLI.getVectorIdxTy(DAG.getDataLayout())));
1041  }
1042 
1043  // Build up a zero vector to blend into this one.
1044  SDValue Zero = DAG.getConstant(0, DL, SrcVT);
1045 
1046  // Shuffle the incoming lanes into the correct position, and pull all other
1047  // lanes from the zero vector.
1048  SmallVector<int, 16> ShuffleMask;
1049  ShuffleMask.reserve(NumSrcElements);
1050  for (int i = 0; i < NumSrcElements; ++i)
1051  ShuffleMask.push_back(i);
1052 
1053  int ExtLaneScale = NumSrcElements / NumElements;
1054  int EndianOffset = DAG.getDataLayout().isBigEndian() ? ExtLaneScale - 1 : 0;
1055  for (int i = 0; i < NumElements; ++i)
1056  ShuffleMask[i * ExtLaneScale + EndianOffset] = NumSrcElements + i;
1057 
1058  return DAG.getNode(ISD::BITCAST, DL, VT,
1059  DAG.getVectorShuffle(SrcVT, DL, Zero, Src, ShuffleMask));
1060 }
1061 
1062 static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl<int> &ShuffleMask) {
1063  int ScalarSizeInBytes = VT.getScalarSizeInBits() / 8;
1064  for (int I = 0, E = VT.getVectorNumElements(); I != E; ++I)
1065  for (int J = ScalarSizeInBytes - 1; J >= 0; --J)
1066  ShuffleMask.push_back((I * ScalarSizeInBytes) + J);
1067 }
1068 
1069 SDValue VectorLegalizer::ExpandBSWAP(SDValue Op) {
1070  EVT VT = Op.getValueType();
1071 
1072  // Generate a byte wise shuffle mask for the BSWAP.
1073  SmallVector<int, 16> ShuffleMask;
1074  createBSWAPShuffleMask(VT, ShuffleMask);
1075  EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, ShuffleMask.size());
1076 
1077  // Only emit a shuffle if the mask is legal.
1078  if (!TLI.isShuffleMaskLegal(ShuffleMask, ByteVT))
1079  return DAG.UnrollVectorOp(Op.getNode());
1080 
1081  SDLoc DL(Op);
1082  Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Op.getOperand(0));
1083  Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT), ShuffleMask);
1084  return DAG.getNode(ISD::BITCAST, DL, VT, Op);
1085 }
1086 
1087 SDValue VectorLegalizer::ExpandBITREVERSE(SDValue Op) {
1088  EVT VT = Op.getValueType();
1089 
1090  // If we have the scalar operation, it's probably cheaper to unroll it.
1091  if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType()))
1092  return DAG.UnrollVectorOp(Op.getNode());
1093 
1094  // If the vector element width is a whole number of bytes, test if its legal
1095  // to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte
1096  // vector. This greatly reduces the number of bit shifts necessary.
1097  unsigned ScalarSizeInBits = VT.getScalarSizeInBits();
1098  if (ScalarSizeInBits > 8 && (ScalarSizeInBits % 8) == 0) {
1099  SmallVector<int, 16> BSWAPMask;
1100  createBSWAPShuffleMask(VT, BSWAPMask);
1101 
1102  EVT ByteVT = EVT::getVectorVT(*DAG.getContext(), MVT::i8, BSWAPMask.size());
1103  if (TLI.isShuffleMaskLegal(BSWAPMask, ByteVT) &&
1104  (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, ByteVT) ||
1105  (TLI.isOperationLegalOrCustom(ISD::SHL, ByteVT) &&
1106  TLI.isOperationLegalOrCustom(ISD::SRL, ByteVT) &&
1107  TLI.isOperationLegalOrCustomOrPromote(ISD::AND, ByteVT) &&
1108  TLI.isOperationLegalOrCustomOrPromote(ISD::OR, ByteVT)))) {
1109  SDLoc DL(Op);
1110  Op = DAG.getNode(ISD::BITCAST, DL, ByteVT, Op.getOperand(0));
1111  Op = DAG.getVectorShuffle(ByteVT, DL, Op, DAG.getUNDEF(ByteVT),
1112  BSWAPMask);
1113  Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op);
1114  return DAG.getNode(ISD::BITCAST, DL, VT, Op);
1115  }
1116  }
1117 
1118  // If we have the appropriate vector bit operations, it is better to use them
1119  // than unrolling and expanding each component.
1120  if (!TLI.isOperationLegalOrCustom(ISD::SHL, VT) ||
1121  !TLI.isOperationLegalOrCustom(ISD::SRL, VT) ||
1122  !TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) ||
1123  !TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
1124  return DAG.UnrollVectorOp(Op.getNode());
1125 
1126  // Let LegalizeDAG handle this later.
1127  return Op;
1128 }
1129 
1130 SDValue VectorLegalizer::ExpandVSELECT(SDValue Op) {
1131  // Implement VSELECT in terms of XOR, AND, OR
1132  // on platforms which do not support blend natively.
1133  SDLoc DL(Op);
1134 
1135  SDValue Mask = Op.getOperand(0);
1136  SDValue Op1 = Op.getOperand(1);
1137  SDValue Op2 = Op.getOperand(2);
1138 
1139  EVT VT = Mask.getValueType();
1140 
1141  // If we can't even use the basic vector operations of
1142  // AND,OR,XOR, we will have to scalarize the op.
1143  // Notice that the operation may be 'promoted' which means that it is
1144  // 'bitcasted' to another type which is handled.
1145  // This operation also isn't safe with AND, OR, XOR when the boolean
1146  // type is 0/1 as we need an all ones vector constant to mask with.
1147  // FIXME: Sign extend 1 to all ones if thats legal on the target.
1148  if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
1149  TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
1150  TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand ||
1151  TLI.getBooleanContents(Op1.getValueType()) !=
1153  return DAG.UnrollVectorOp(Op.getNode());
1154 
1155  // If the mask and the type are different sizes, unroll the vector op. This
1156  // can occur when getSetCCResultType returns something that is different in
1157  // size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
1158  if (VT.getSizeInBits() != Op1.getValueSizeInBits())
1159  return DAG.UnrollVectorOp(Op.getNode());
1160 
1161  // Bitcast the operands to be the same type as the mask.
1162  // This is needed when we select between FP types because
1163  // the mask is a vector of integers.
1164  Op1 = DAG.getNode(ISD::BITCAST, DL, VT, Op1);
1165  Op2 = DAG.getNode(ISD::BITCAST, DL, VT, Op2);
1166 
1167  SDValue AllOnes = DAG.getConstant(
1169  SDValue NotMask = DAG.getNode(ISD::XOR, DL, VT, Mask, AllOnes);
1170 
1171  Op1 = DAG.getNode(ISD::AND, DL, VT, Op1, Mask);
1172  Op2 = DAG.getNode(ISD::AND, DL, VT, Op2, NotMask);
1173  SDValue Val = DAG.getNode(ISD::OR, DL, VT, Op1, Op2);
1174  return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Val);
1175 }
1176 
1177 SDValue VectorLegalizer::ExpandABS(SDValue Op) {
1178  // Attempt to expand using TargetLowering.
1179  SDValue Result;
1180  if (TLI.expandABS(Op.getNode(), Result, DAG))
1181  return Result;
1182 
1183  // Otherwise go ahead and unroll.
1184  return DAG.UnrollVectorOp(Op.getNode());
1185 }
1186 
1187 SDValue VectorLegalizer::ExpandFP_TO_UINT(SDValue Op) {
1188  // Attempt to expand using TargetLowering.
1189  SDValue Result;
1190  if (TLI.expandFP_TO_UINT(Op.getNode(), Result, DAG))
1191  return Result;
1192 
1193  // Otherwise go ahead and unroll.
1194  return DAG.UnrollVectorOp(Op.getNode());
1195 }
1196 
1197 SDValue VectorLegalizer::ExpandUINT_TO_FLOAT(SDValue Op) {
1198  EVT VT = Op.getOperand(0).getValueType();
1199  SDLoc DL(Op);
1200 
1201  // Attempt to expand using TargetLowering.
1202  SDValue Result;
1203  if (TLI.expandUINT_TO_FP(Op.getNode(), Result, DAG))
1204  return Result;
1205 
1206  // Make sure that the SINT_TO_FP and SRL instructions are available.
1207  if (TLI.getOperationAction(ISD::SINT_TO_FP, VT) == TargetLowering::Expand ||
1208  TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Expand)
1209  return DAG.UnrollVectorOp(Op.getNode());
1210 
1211  unsigned BW = VT.getScalarSizeInBits();
1212  assert((BW == 64 || BW == 32) &&
1213  "Elements in vector-UINT_TO_FP must be 32 or 64 bits wide");
1214 
1215  SDValue HalfWord = DAG.getConstant(BW / 2, DL, VT);
1216 
1217  // Constants to clear the upper part of the word.
1218  // Notice that we can also use SHL+SHR, but using a constant is slightly
1219  // faster on x86.
1220  uint64_t HWMask = (BW == 64) ? 0x00000000FFFFFFFF : 0x0000FFFF;
1221  SDValue HalfWordMask = DAG.getConstant(HWMask, DL, VT);
1222 
1223  // Two to the power of half-word-size.
1224  SDValue TWOHW = DAG.getConstantFP(1ULL << (BW / 2), DL, Op.getValueType());
1225 
1226  // Clear upper part of LO, lower HI
1227  SDValue HI = DAG.getNode(ISD::SRL, DL, VT, Op.getOperand(0), HalfWord);
1228  SDValue LO = DAG.getNode(ISD::AND, DL, VT, Op.getOperand(0), HalfWordMask);
1229 
1230  // Convert hi and lo to floats
1231  // Convert the hi part back to the upper values
1232  // TODO: Can any fast-math-flags be set on these nodes?
1233  SDValue fHI = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), HI);
1234  fHI = DAG.getNode(ISD::FMUL, DL, Op.getValueType(), fHI, TWOHW);
1235  SDValue fLO = DAG.getNode(ISD::SINT_TO_FP, DL, Op.getValueType(), LO);
1236 
1237  // Add the two halves
1238  return DAG.getNode(ISD::FADD, DL, Op.getValueType(), fHI, fLO);
1239 }
1240 
1241 SDValue VectorLegalizer::ExpandFNEG(SDValue Op) {
1242  if (TLI.isOperationLegalOrCustom(ISD::FSUB, Op.getValueType())) {
1243  SDLoc DL(Op);
1244  SDValue Zero = DAG.getConstantFP(-0.0, DL, Op.getValueType());
1245  // TODO: If FNEG had fast-math-flags, they'd get propagated to this FSUB.
1246  return DAG.getNode(ISD::FSUB, DL, Op.getValueType(),
1247  Zero, Op.getOperand(0));
1248  }
1249  return DAG.UnrollVectorOp(Op.getNode());
1250 }
1251 
1252 SDValue VectorLegalizer::ExpandFSUB(SDValue Op) {
1253  // For floating-point values, (a-b) is the same as a+(-b). If FNEG is legal,
1254  // we can defer this to operation legalization where it will be lowered as
1255  // a+(-b).
1256  EVT VT = Op.getValueType();
1257  if (TLI.isOperationLegalOrCustom(ISD::FNEG, VT) &&
1258  TLI.isOperationLegalOrCustom(ISD::FADD, VT))
1259  return Op; // Defer to LegalizeDAG
1260 
1261  return DAG.UnrollVectorOp(Op.getNode());
1262 }
1263 
1264 SDValue VectorLegalizer::ExpandCTPOP(SDValue Op) {
1265  SDValue Result;
1266  if (TLI.expandCTPOP(Op.getNode(), Result, DAG))
1267  return Result;
1268 
1269  return DAG.UnrollVectorOp(Op.getNode());
1270 }
1271 
1272 SDValue VectorLegalizer::ExpandCTLZ(SDValue Op) {
1273  SDValue Result;
1274  if (TLI.expandCTLZ(Op.getNode(), Result, DAG))
1275  return Result;
1276 
1277  return DAG.UnrollVectorOp(Op.getNode());
1278 }
1279 
1280 SDValue VectorLegalizer::ExpandCTTZ(SDValue Op) {
1281  SDValue Result;
1282  if (TLI.expandCTTZ(Op.getNode(), Result, DAG))
1283  return Result;
1284 
1285  return DAG.UnrollVectorOp(Op.getNode());
1286 }
1287 
1288 SDValue VectorLegalizer::ExpandFunnelShift(SDValue Op) {
1289  SDValue Result;
1290  if (TLI.expandFunnelShift(Op.getNode(), Result, DAG))
1291  return Result;
1292 
1293  return DAG.UnrollVectorOp(Op.getNode());
1294 }
1295 
1296 SDValue VectorLegalizer::ExpandROT(SDValue Op) {
1297  SDValue Result;
1298  if (TLI.expandROT(Op.getNode(), Result, DAG))
1299  return Result;
1300 
1301  return DAG.UnrollVectorOp(Op.getNode());
1302 }
1303 
1304 SDValue VectorLegalizer::ExpandFMINNUM_FMAXNUM(SDValue Op) {
1305  if (SDValue Expanded = TLI.expandFMINNUM_FMAXNUM(Op.getNode(), DAG))
1306  return Expanded;
1307  return DAG.UnrollVectorOp(Op.getNode());
1308 }
1309 
1310 SDValue VectorLegalizer::ExpandUADDSUBO(SDValue Op) {
1311  SDValue Result, Overflow;
1312  TLI.expandUADDSUBO(Op.getNode(), Result, Overflow, DAG);
1313 
1314  if (Op.getResNo() == 0) {
1315  AddLegalizedOperand(Op.getValue(1), LegalizeOp(Overflow));
1316  return Result;
1317  } else {
1318  AddLegalizedOperand(Op.getValue(0), LegalizeOp(Result));
1319  return Overflow;
1320  }
1321 }
1322 
1323 SDValue VectorLegalizer::ExpandSADDSUBO(SDValue Op) {
1324  SDValue Result, Overflow;
1325  TLI.expandSADDSUBO(Op.getNode(), Result, Overflow, DAG);
1326 
1327  if (Op.getResNo() == 0) {
1328  AddLegalizedOperand(Op.getValue(1), LegalizeOp(Overflow));
1329  return Result;
1330  } else {
1331  AddLegalizedOperand(Op.getValue(0), LegalizeOp(Result));
1332  return Overflow;
1333  }
1334 }
1335 
1336 SDValue VectorLegalizer::ExpandMULO(SDValue Op) {
1337  SDValue Result, Overflow;
1338  if (!TLI.expandMULO(Op.getNode(), Result, Overflow, DAG))
1339  std::tie(Result, Overflow) = DAG.UnrollVectorOverflowOp(Op.getNode());
1340 
1341  if (Op.getResNo() == 0) {
1342  AddLegalizedOperand(Op.getValue(1), LegalizeOp(Overflow));
1343  return Result;
1344  } else {
1345  AddLegalizedOperand(Op.getValue(0), LegalizeOp(Result));
1346  return Overflow;
1347  }
1348 }
1349 
1350 SDValue VectorLegalizer::ExpandAddSubSat(SDValue Op) {
1351  if (SDValue Expanded = TLI.expandAddSubSat(Op.getNode(), DAG))
1352  return Expanded;
1353  return DAG.UnrollVectorOp(Op.getNode());
1354 }
1355 
1356 SDValue VectorLegalizer::ExpandFixedPointMul(SDValue Op) {
1357  if (SDValue Expanded = TLI.expandFixedPointMul(Op.getNode(), DAG))
1358  return Expanded;
1359  return DAG.UnrollVectorOp(Op.getNode());
1360 }
1361 
1362 SDValue VectorLegalizer::ExpandStrictFPOp(SDValue Op) {
1363  EVT VT = Op.getValueType();
1364  EVT EltVT = VT.getVectorElementType();
1365  unsigned NumElems = VT.getVectorNumElements();
1366  unsigned NumOpers = Op.getNumOperands();
1367  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1368  EVT ValueVTs[] = {EltVT, MVT::Other};
1369  SDValue Chain = Op.getOperand(0);
1370  SDLoc dl(Op);
1371 
1372  SmallVector<SDValue, 32> OpValues;
1373  SmallVector<SDValue, 32> OpChains;
1374  for (unsigned i = 0; i < NumElems; ++i) {
1376  SDValue Idx = DAG.getConstant(i, dl,
1377  TLI.getVectorIdxTy(DAG.getDataLayout()));
1378 
1379  // The Chain is the first operand.
1380  Opers.push_back(Chain);
1381 
1382  // Now process the remaining operands.
1383  for (unsigned j = 1; j < NumOpers; ++j) {
1384  SDValue Oper = Op.getOperand(j);
1385  EVT OperVT = Oper.getValueType();
1386 
1387  if (OperVT.isVector())
1388  Oper = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
1389  OperVT.getVectorElementType(), Oper, Idx);
1390 
1391  Opers.push_back(Oper);
1392  }
1393 
1394  SDValue ScalarOp = DAG.getNode(Op->getOpcode(), dl, ValueVTs, Opers);
1395 
1396  OpValues.push_back(ScalarOp.getValue(0));
1397  OpChains.push_back(ScalarOp.getValue(1));
1398  }
1399 
1400  SDValue Result = DAG.getBuildVector(VT, dl, OpValues);
1401  SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, OpChains);
1402 
1403  AddLegalizedOperand(Op.getValue(0), Result);
1404  AddLegalizedOperand(Op.getValue(1), NewChain);
1405 
1406  return Op.getResNo() ? NewChain : Result;
1407 }
1408 
1409 SDValue VectorLegalizer::UnrollVSETCC(SDValue Op) {
1410  EVT VT = Op.getValueType();
1411  unsigned NumElems = VT.getVectorNumElements();
1412  EVT EltVT = VT.getVectorElementType();
1413  SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1), CC = Op.getOperand(2);
1414  EVT TmpEltVT = LHS.getValueType().getVectorElementType();
1415  SDLoc dl(Op);
1416  SmallVector<SDValue, 8> Ops(NumElems);
1417  for (unsigned i = 0; i < NumElems; ++i) {
1418  SDValue LHSElem = DAG.getNode(
1419  ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, LHS,
1420  DAG.getConstant(i, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
1421  SDValue RHSElem = DAG.getNode(
1422  ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT, RHS,
1423  DAG.getConstant(i, dl, TLI.getVectorIdxTy(DAG.getDataLayout())));
1424  Ops[i] = DAG.getNode(ISD::SETCC, dl,
1425  TLI.getSetCCResultType(DAG.getDataLayout(),
1426  *DAG.getContext(), TmpEltVT),
1427  LHSElem, RHSElem, CC);
1428  Ops[i] = DAG.getSelect(dl, EltVT, Ops[i],
1429  DAG.getConstant(APInt::getAllOnesValue
1430  (EltVT.getSizeInBits()), dl, EltVT),
1431  DAG.getConstant(0, dl, EltVT));
1432  }
1433  return DAG.getBuildVector(VT, dl, Ops);
1434 }
1435 
1437  return VectorLegalizer(*this).Run();
1438 }
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:595
X = FP_ROUND(Y, TRUNC) - Rounding &#39;Y&#39; from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:562
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:622
virtual MVT getVectorIdxTy(const DataLayout &DL) const
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
EVT getValueType() const
Return the ValueType of the referenced return value.
Constrained versions of libm-equivalent floating point intrinsics.
Definition: ISDOpcodes.h:300
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
Definition: APInt.h:561
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0...
Definition: ISDOpcodes.h:633
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:259
Same as the corresponding unsaturated fixed point instructions, but the result is clamped between the...
Definition: ISDOpcodes.h:284
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
Definition: ISDOpcodes.h:543
bool isVector() const
Return true if this is a vector value type.
const SDValue & getBasePtr() const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
const SDValue & getValue() const
bool LegalizeVectors()
This transforms the SelectionDAG into a SelectionDAG that only uses vector math operations supported ...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Definition: APInt.h:647
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:250
unsigned getVectorNumElements() const
const SDValue & getChain() const
unsigned getAlignment() const
Constrained versions of the binary floating point operators.
Definition: ISDOpcodes.h:293
SIGN_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register sign-extension of the low ...
Definition: ISDOpcodes.h:532
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
Definition: ISDOpcodes.h:408
const SDNodeFlags getFlags() const
SDNode * getNode() const
get the SDNode which holds the desired result
Same for subtraction.
Definition: ISDOpcodes.h:253
void reserve(size_type N)
Definition: SmallVector.h:369
bool isByteSized() const
Return true if the bit size is a multiple of 8.
Definition: ValueTypes.h:211
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
Definition: ISDOpcodes.h:377
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:459
bool isTruncatingStore() const
Return true if the op does a truncation before store.
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:209
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:135
Shift and rotation operations.
Definition: ISDOpcodes.h:434
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
Definition: ISDOpcodes.h:417
RESULT = [US]MULFIX(LHS, RHS, SCALE) - Perform fixed point multiplication on 2 integers with the same...
Definition: ISDOpcodes.h:279
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition: ValueTypes.h:303
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
unsigned getScalarSizeInBits() const
Definition: ValueTypes.h:297
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:291
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:502
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:453
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:323
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
Definition: ISDOpcodes.h:521
MVT getVectorElementType() const
This class is used to represent ISD::STORE nodes.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:548
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:351
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:614
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
Definition: ValueTypes.h:234
These reductions are non-strict, and have a single vector operand.
Definition: ISDOpcodes.h:901
Machine Value Type.
Simple binary floating point operators.
Definition: ISDOpcodes.h:287
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:272
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isRound() const
Return true if the size is a power-of-two number of bytes.
Definition: ValueTypes.h:216
const SDValue & getOperand(unsigned Num) const
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:987
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:246
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:56
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:440
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:580
Extended Value Type.
Definition: ValueTypes.h:33
size_t size() const
Definition: SmallVector.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition: ISDOpcodes.h:264
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:49
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:416
Iterator for intrusive lists based on ilist_node.
BlockVerifier::State From
Returns platform specific canonical encoding of a floating point number.
Definition: ISDOpcodes.h:343
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:363
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:264
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:221
X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and rounds it to a floating point val...
Definition: ISDOpcodes.h:577
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
Definition: ValueTypes.h:95
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimum or maximum on two values, following the IEEE-754 2008 definition.
Definition: ISDOpcodes.h:628
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:437
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
MachinePointerInfo getWithOffset(int64_t O) const
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:72
EVT getMemoryVT() const
Return the type of the in-memory value.
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:444
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:492
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:495
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:336
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:150
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:411
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:205
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:510
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:642
#define I(x, y, z)
Definition: MD5.cpp:58
Flags getFlags() const
Return the raw flags of the source value,.
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition: ISDOpcodes.h:272
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding &#39;Y&#39; from a larger floating point type down to the precision ...
Definition: ISDOpcodes.h:318
Same for multiplication.
Definition: ISDOpcodes.h:256
unsigned getOpcode() const
SDValue getValue(unsigned R) const
const MachinePointerInfo & getPointerInfo() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:326
Integer reductions may have a result type larger than the vector element type.
Definition: ISDOpcodes.h:907
unsigned getResNo() const
get the index which selects a specific result in the SDNode
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
Definition: ISDOpcodes.h:903
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:258
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E&#39;s largest value.
Definition: BitmaskEnum.h:80
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:467
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
Definition: ISDOpcodes.h:197
unsigned getNumOperands() const
Conversion operators.
Definition: ISDOpcodes.h:489
const SDValue & getOperand(unsigned i) const
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:498
#define LLVM_DEBUG(X)
Definition: Debug.h:122
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:610
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:63
static void createBSWAPShuffleMask(EVT VT, SmallVectorImpl< int > &ShuffleMask)
This file describes how to lower LLVM code to machine code.
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:404
void resize(size_type N)
Definition: SmallVector.h:344
This class is used to represent ISD::LOAD nodes.