1 //===-- AArch64ISelDAGToDAG.cpp - A dag to dag inst selector for AArch64 --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an instruction selector for the AArch64 target.
12 //===----------------------------------------------------------------------===//
14 #include "AArch64TargetMachine.h"
15 #include "MCTargetDesc/AArch64AddressingModes.h"
16 #include "llvm/ADT/APSInt.h"
17 #include "llvm/CodeGen/SelectionDAGISel.h"
18 #include "llvm/IR/Function.h" // To access function attributes.
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/MathExtras.h"
24 #include "llvm/Support/raw_ostream.h"
28 #define DEBUG_TYPE "aarch64-isel"
30 //===--------------------------------------------------------------------===//
31 /// AArch64DAGToDAGISel - AArch64 specific code to select AArch64 machine
32 /// instructions for SelectionDAG operations.
36 class AArch64DAGToDAGISel : public SelectionDAGISel {
37 AArch64TargetMachine &TM;
39 /// Subtarget - Keep a pointer to the AArch64Subtarget around so that we can
40 /// make the right decision when generating code for different targets.
41 const AArch64Subtarget *Subtarget;
46 explicit AArch64DAGToDAGISel(AArch64TargetMachine &tm,
47 CodeGenOpt::Level OptLevel)
48 : SelectionDAGISel(tm, OptLevel), TM(tm), Subtarget(nullptr),
51 const char *getPassName() const override {
52 return "AArch64 Instruction Selection";
55 bool runOnMachineFunction(MachineFunction &MF) override {
56 AttributeSet FnAttrs = MF.getFunction()->getAttributes();
58 FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
59 Attribute::OptimizeForSize) ||
60 FnAttrs.hasAttribute(AttributeSet::FunctionIndex, Attribute::MinSize);
61 Subtarget = &MF.getSubtarget<AArch64Subtarget>();
62 return SelectionDAGISel::runOnMachineFunction(MF);
65 SDNode *Select(SDNode *Node) override;
67 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
68 /// inline asm expressions.
69 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
71 std::vector<SDValue> &OutOps) override;
73 SDNode *SelectMLAV64LaneV128(SDNode *N);
74 SDNode *SelectMULLV64LaneV128(unsigned IntNo, SDNode *N);
75 bool SelectArithExtendedRegister(SDValue N, SDValue &Reg, SDValue &Shift);
76 bool SelectArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
77 bool SelectNegArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
78 bool SelectArithShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
79 return SelectShiftedRegister(N, false, Reg, Shift);
81 bool SelectLogicalShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
82 return SelectShiftedRegister(N, true, Reg, Shift);
84 bool SelectAddrModeIndexed8(SDValue N, SDValue &Base, SDValue &OffImm) {
85 return SelectAddrModeIndexed(N, 1, Base, OffImm);
87 bool SelectAddrModeIndexed16(SDValue N, SDValue &Base, SDValue &OffImm) {
88 return SelectAddrModeIndexed(N, 2, Base, OffImm);
90 bool SelectAddrModeIndexed32(SDValue N, SDValue &Base, SDValue &OffImm) {
91 return SelectAddrModeIndexed(N, 4, Base, OffImm);
93 bool SelectAddrModeIndexed64(SDValue N, SDValue &Base, SDValue &OffImm) {
94 return SelectAddrModeIndexed(N, 8, Base, OffImm);
96 bool SelectAddrModeIndexed128(SDValue N, SDValue &Base, SDValue &OffImm) {
97 return SelectAddrModeIndexed(N, 16, Base, OffImm);
99 bool SelectAddrModeUnscaled8(SDValue N, SDValue &Base, SDValue &OffImm) {
100 return SelectAddrModeUnscaled(N, 1, Base, OffImm);
102 bool SelectAddrModeUnscaled16(SDValue N, SDValue &Base, SDValue &OffImm) {
103 return SelectAddrModeUnscaled(N, 2, Base, OffImm);
105 bool SelectAddrModeUnscaled32(SDValue N, SDValue &Base, SDValue &OffImm) {
106 return SelectAddrModeUnscaled(N, 4, Base, OffImm);
108 bool SelectAddrModeUnscaled64(SDValue N, SDValue &Base, SDValue &OffImm) {
109 return SelectAddrModeUnscaled(N, 8, Base, OffImm);
111 bool SelectAddrModeUnscaled128(SDValue N, SDValue &Base, SDValue &OffImm) {
112 return SelectAddrModeUnscaled(N, 16, Base, OffImm);
116 bool SelectAddrModeWRO(SDValue N, SDValue &Base, SDValue &Offset,
117 SDValue &SignExtend, SDValue &DoShift) {
118 return SelectAddrModeWRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
122 bool SelectAddrModeXRO(SDValue N, SDValue &Base, SDValue &Offset,
123 SDValue &SignExtend, SDValue &DoShift) {
124 return SelectAddrModeXRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
128 /// Form sequences of consecutive 64/128-bit registers for use in NEON
129 /// instructions making use of a vector-list (e.g. ldN, tbl). Vecs must have
130 /// between 1 and 4 elements. If it contains a single element that is returned
131 /// unchanged; otherwise a REG_SEQUENCE value is returned.
132 SDValue createDTuple(ArrayRef<SDValue> Vecs);
133 SDValue createQTuple(ArrayRef<SDValue> Vecs);
135 /// Generic helper for the createDTuple/createQTuple
136 /// functions. Those should almost always be called instead.
137 SDValue createTuple(ArrayRef<SDValue> Vecs, unsigned RegClassIDs[],
140 SDNode *SelectTable(SDNode *N, unsigned NumVecs, unsigned Opc, bool isExt);
142 SDNode *SelectIndexedLoad(SDNode *N, bool &Done);
144 SDNode *SelectLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
146 SDNode *SelectPostLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
148 SDNode *SelectLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
149 SDNode *SelectPostLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
151 SDNode *SelectStore(SDNode *N, unsigned NumVecs, unsigned Opc);
152 SDNode *SelectPostStore(SDNode *N, unsigned NumVecs, unsigned Opc);
153 SDNode *SelectStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
154 SDNode *SelectPostStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
156 SDNode *SelectBitfieldExtractOp(SDNode *N);
157 SDNode *SelectBitfieldInsertOp(SDNode *N);
159 SDNode *SelectLIBM(SDNode *N);
161 // Include the pieces autogenerated from the target description.
162 #include "AArch64GenDAGISel.inc"
165 bool SelectShiftedRegister(SDValue N, bool AllowROR, SDValue &Reg,
167 bool SelectAddrModeIndexed(SDValue N, unsigned Size, SDValue &Base,
169 bool SelectAddrModeUnscaled(SDValue N, unsigned Size, SDValue &Base,
171 bool SelectAddrModeWRO(SDValue N, unsigned Size, SDValue &Base,
172 SDValue &Offset, SDValue &SignExtend,
174 bool SelectAddrModeXRO(SDValue N, unsigned Size, SDValue &Base,
175 SDValue &Offset, SDValue &SignExtend,
177 bool isWorthFolding(SDValue V) const;
178 bool SelectExtendedSHL(SDValue N, unsigned Size, bool WantExtend,
179 SDValue &Offset, SDValue &SignExtend);
181 template<unsigned RegWidth>
182 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos) {
183 return SelectCVTFixedPosOperand(N, FixedPos, RegWidth);
186 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos, unsigned Width);
188 } // end anonymous namespace
190 /// isIntImmediate - This method tests to see if the node is a constant
191 /// operand. If so Imm will receive the 32-bit value.
192 static bool isIntImmediate(const SDNode *N, uint64_t &Imm) {
193 if (const ConstantSDNode *C = dyn_cast<const ConstantSDNode>(N)) {
194 Imm = C->getZExtValue();
200 // isIntImmediate - This method tests to see if a constant operand.
201 // If so Imm will receive the value.
202 static bool isIntImmediate(SDValue N, uint64_t &Imm) {
203 return isIntImmediate(N.getNode(), Imm);
206 // isOpcWithIntImmediate - This method tests to see if the node is a specific
207 // opcode and that it has a immediate integer right operand.
208 // If so Imm will receive the 32 bit value.
209 static bool isOpcWithIntImmediate(const SDNode *N, unsigned Opc,
211 return N->getOpcode() == Opc &&
212 isIntImmediate(N->getOperand(1).getNode(), Imm);
215 bool AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(
216 const SDValue &Op, char ConstraintCode, std::vector<SDValue> &OutOps) {
217 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
218 // Require the address to be in a register. That is safe for all AArch64
219 // variants and it is hard to do anything much smarter without knowing
220 // how the operand is used.
221 OutOps.push_back(Op);
225 /// SelectArithImmed - Select an immediate value that can be represented as
226 /// a 12-bit value shifted left by either 0 or 12. If so, return true with
227 /// Val set to the 12-bit value and Shift set to the shifter operand.
228 bool AArch64DAGToDAGISel::SelectArithImmed(SDValue N, SDValue &Val,
230 // This function is called from the addsub_shifted_imm ComplexPattern,
231 // which lists [imm] as the list of opcode it's interested in, however
232 // we still need to check whether the operand is actually an immediate
233 // here because the ComplexPattern opcode list is only used in
234 // root-level opcode matching.
235 if (!isa<ConstantSDNode>(N.getNode()))
238 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
241 if (Immed >> 12 == 0) {
243 } else if ((Immed & 0xfff) == 0 && Immed >> 24 == 0) {
249 unsigned ShVal = AArch64_AM::getShifterImm(AArch64_AM::LSL, ShiftAmt);
250 Val = CurDAG->getTargetConstant(Immed, MVT::i32);
251 Shift = CurDAG->getTargetConstant(ShVal, MVT::i32);
255 /// SelectNegArithImmed - As above, but negates the value before trying to
257 bool AArch64DAGToDAGISel::SelectNegArithImmed(SDValue N, SDValue &Val,
259 // This function is called from the addsub_shifted_imm ComplexPattern,
260 // which lists [imm] as the list of opcode it's interested in, however
261 // we still need to check whether the operand is actually an immediate
262 // here because the ComplexPattern opcode list is only used in
263 // root-level opcode matching.
264 if (!isa<ConstantSDNode>(N.getNode()))
267 // The immediate operand must be a 24-bit zero-extended immediate.
268 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
270 // This negation is almost always valid, but "cmp wN, #0" and "cmn wN, #0"
271 // have the opposite effect on the C flag, so this pattern mustn't match under
272 // those circumstances.
276 if (N.getValueType() == MVT::i32)
277 Immed = ~((uint32_t)Immed) + 1;
279 Immed = ~Immed + 1ULL;
280 if (Immed & 0xFFFFFFFFFF000000ULL)
283 Immed &= 0xFFFFFFULL;
284 return SelectArithImmed(CurDAG->getConstant(Immed, MVT::i32), Val, Shift);
287 /// getShiftTypeForNode - Translate a shift node to the corresponding
289 static AArch64_AM::ShiftExtendType getShiftTypeForNode(SDValue N) {
290 switch (N.getOpcode()) {
292 return AArch64_AM::InvalidShiftExtend;
294 return AArch64_AM::LSL;
296 return AArch64_AM::LSR;
298 return AArch64_AM::ASR;
300 return AArch64_AM::ROR;
304 /// \brief Determine wether it is worth to fold V into an extended register.
305 bool AArch64DAGToDAGISel::isWorthFolding(SDValue V) const {
306 // it hurts if the value is used at least twice, unless we are optimizing
308 if (ForCodeSize || V.hasOneUse())
313 /// SelectShiftedRegister - Select a "shifted register" operand. If the value
314 /// is not shifted, set the Shift operand to default of "LSL 0". The logical
315 /// instructions allow the shifted register to be rotated, but the arithmetic
316 /// instructions do not. The AllowROR parameter specifies whether ROR is
318 bool AArch64DAGToDAGISel::SelectShiftedRegister(SDValue N, bool AllowROR,
319 SDValue &Reg, SDValue &Shift) {
320 AArch64_AM::ShiftExtendType ShType = getShiftTypeForNode(N);
321 if (ShType == AArch64_AM::InvalidShiftExtend)
323 if (!AllowROR && ShType == AArch64_AM::ROR)
326 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
327 unsigned BitSize = N.getValueType().getSizeInBits();
328 unsigned Val = RHS->getZExtValue() & (BitSize - 1);
329 unsigned ShVal = AArch64_AM::getShifterImm(ShType, Val);
331 Reg = N.getOperand(0);
332 Shift = CurDAG->getTargetConstant(ShVal, MVT::i32);
333 return isWorthFolding(N);
339 /// getExtendTypeForNode - Translate an extend node to the corresponding
340 /// ExtendType value.
341 static AArch64_AM::ShiftExtendType
342 getExtendTypeForNode(SDValue N, bool IsLoadStore = false) {
343 if (N.getOpcode() == ISD::SIGN_EXTEND ||
344 N.getOpcode() == ISD::SIGN_EXTEND_INREG) {
346 if (N.getOpcode() == ISD::SIGN_EXTEND_INREG)
347 SrcVT = cast<VTSDNode>(N.getOperand(1))->getVT();
349 SrcVT = N.getOperand(0).getValueType();
351 if (!IsLoadStore && SrcVT == MVT::i8)
352 return AArch64_AM::SXTB;
353 else if (!IsLoadStore && SrcVT == MVT::i16)
354 return AArch64_AM::SXTH;
355 else if (SrcVT == MVT::i32)
356 return AArch64_AM::SXTW;
357 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
359 return AArch64_AM::InvalidShiftExtend;
360 } else if (N.getOpcode() == ISD::ZERO_EXTEND ||
361 N.getOpcode() == ISD::ANY_EXTEND) {
362 EVT SrcVT = N.getOperand(0).getValueType();
363 if (!IsLoadStore && SrcVT == MVT::i8)
364 return AArch64_AM::UXTB;
365 else if (!IsLoadStore && SrcVT == MVT::i16)
366 return AArch64_AM::UXTH;
367 else if (SrcVT == MVT::i32)
368 return AArch64_AM::UXTW;
369 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
371 return AArch64_AM::InvalidShiftExtend;
372 } else if (N.getOpcode() == ISD::AND) {
373 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
375 return AArch64_AM::InvalidShiftExtend;
376 uint64_t AndMask = CSD->getZExtValue();
380 return AArch64_AM::InvalidShiftExtend;
382 return !IsLoadStore ? AArch64_AM::UXTB : AArch64_AM::InvalidShiftExtend;
384 return !IsLoadStore ? AArch64_AM::UXTH : AArch64_AM::InvalidShiftExtend;
386 return AArch64_AM::UXTW;
390 return AArch64_AM::InvalidShiftExtend;
393 // Helper for SelectMLAV64LaneV128 - Recognize high lane extracts.
394 static bool checkHighLaneIndex(SDNode *DL, SDValue &LaneOp, int &LaneIdx) {
395 if (DL->getOpcode() != AArch64ISD::DUPLANE16 &&
396 DL->getOpcode() != AArch64ISD::DUPLANE32)
399 SDValue SV = DL->getOperand(0);
400 if (SV.getOpcode() != ISD::INSERT_SUBVECTOR)
403 SDValue EV = SV.getOperand(1);
404 if (EV.getOpcode() != ISD::EXTRACT_SUBVECTOR)
407 ConstantSDNode *DLidx = cast<ConstantSDNode>(DL->getOperand(1).getNode());
408 ConstantSDNode *EVidx = cast<ConstantSDNode>(EV.getOperand(1).getNode());
409 LaneIdx = DLidx->getSExtValue() + EVidx->getSExtValue();
410 LaneOp = EV.getOperand(0);
415 // Helper for SelectOpcV64LaneV128 - Recogzine operatinos where one operand is a
416 // high lane extract.
417 static bool checkV64LaneV128(SDValue Op0, SDValue Op1, SDValue &StdOp,
418 SDValue &LaneOp, int &LaneIdx) {
420 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx)) {
422 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx))
429 /// SelectMLAV64LaneV128 - AArch64 supports vector MLAs where one multiplicand
430 /// is a lane in the upper half of a 128-bit vector. Recognize and select this
431 /// so that we don't emit unnecessary lane extracts.
432 SDNode *AArch64DAGToDAGISel::SelectMLAV64LaneV128(SDNode *N) {
433 SDValue Op0 = N->getOperand(0);
434 SDValue Op1 = N->getOperand(1);
435 SDValue MLAOp1; // Will hold ordinary multiplicand for MLA.
436 SDValue MLAOp2; // Will hold lane-accessed multiplicand for MLA.
437 int LaneIdx = -1; // Will hold the lane index.
439 if (Op1.getOpcode() != ISD::MUL ||
440 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
443 if (Op1.getOpcode() != ISD::MUL ||
444 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
449 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, MVT::i64);
451 SDValue Ops[] = { Op0, MLAOp1, MLAOp2, LaneIdxVal };
453 unsigned MLAOpc = ~0U;
455 switch (N->getSimpleValueType(0).SimpleTy) {
457 llvm_unreachable("Unrecognized MLA.");
459 MLAOpc = AArch64::MLAv4i16_indexed;
462 MLAOpc = AArch64::MLAv8i16_indexed;
465 MLAOpc = AArch64::MLAv2i32_indexed;
468 MLAOpc = AArch64::MLAv4i32_indexed;
472 return CurDAG->getMachineNode(MLAOpc, SDLoc(N), N->getValueType(0), Ops);
475 SDNode *AArch64DAGToDAGISel::SelectMULLV64LaneV128(unsigned IntNo, SDNode *N) {
480 if (!checkV64LaneV128(N->getOperand(1), N->getOperand(2), SMULLOp0, SMULLOp1,
484 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, MVT::i64);
486 SDValue Ops[] = { SMULLOp0, SMULLOp1, LaneIdxVal };
488 unsigned SMULLOpc = ~0U;
490 if (IntNo == Intrinsic::aarch64_neon_smull) {
491 switch (N->getSimpleValueType(0).SimpleTy) {
493 llvm_unreachable("Unrecognized SMULL.");
495 SMULLOpc = AArch64::SMULLv4i16_indexed;
498 SMULLOpc = AArch64::SMULLv2i32_indexed;
501 } else if (IntNo == Intrinsic::aarch64_neon_umull) {
502 switch (N->getSimpleValueType(0).SimpleTy) {
504 llvm_unreachable("Unrecognized SMULL.");
506 SMULLOpc = AArch64::UMULLv4i16_indexed;
509 SMULLOpc = AArch64::UMULLv2i32_indexed;
513 llvm_unreachable("Unrecognized intrinsic.");
515 return CurDAG->getMachineNode(SMULLOpc, SDLoc(N), N->getValueType(0), Ops);
518 /// Instructions that accept extend modifiers like UXTW expect the register
519 /// being extended to be a GPR32, but the incoming DAG might be acting on a
520 /// GPR64 (either via SEXT_INREG or AND). Extract the appropriate low bits if
521 /// this is the case.
522 static SDValue narrowIfNeeded(SelectionDAG *CurDAG, SDValue N) {
523 if (N.getValueType() == MVT::i32)
526 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, MVT::i32);
527 MachineSDNode *Node = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
528 SDLoc(N), MVT::i32, N, SubReg);
529 return SDValue(Node, 0);
533 /// SelectArithExtendedRegister - Select a "extended register" operand. This
534 /// operand folds in an extend followed by an optional left shift.
535 bool AArch64DAGToDAGISel::SelectArithExtendedRegister(SDValue N, SDValue &Reg,
537 unsigned ShiftVal = 0;
538 AArch64_AM::ShiftExtendType Ext;
540 if (N.getOpcode() == ISD::SHL) {
541 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
544 ShiftVal = CSD->getZExtValue();
548 Ext = getExtendTypeForNode(N.getOperand(0));
549 if (Ext == AArch64_AM::InvalidShiftExtend)
552 Reg = N.getOperand(0).getOperand(0);
554 Ext = getExtendTypeForNode(N);
555 if (Ext == AArch64_AM::InvalidShiftExtend)
558 Reg = N.getOperand(0);
561 // AArch64 mandates that the RHS of the operation must use the smallest
562 // register classs that could contain the size being extended from. Thus,
563 // if we're folding a (sext i8), we need the RHS to be a GPR32, even though
564 // there might not be an actual 32-bit value in the program. We can
565 // (harmlessly) synthesize one by injected an EXTRACT_SUBREG here.
566 assert(Ext != AArch64_AM::UXTX && Ext != AArch64_AM::SXTX);
567 Reg = narrowIfNeeded(CurDAG, Reg);
568 Shift = CurDAG->getTargetConstant(getArithExtendImm(Ext, ShiftVal), MVT::i32);
569 return isWorthFolding(N);
572 /// If there's a use of this ADDlow that's not itself a load/store then we'll
573 /// need to create a real ADD instruction from it anyway and there's no point in
574 /// folding it into the mem op. Theoretically, it shouldn't matter, but there's
575 /// a single pseudo-instruction for an ADRP/ADD pair so over-aggressive folding
576 /// leads to duplaicated ADRP instructions.
577 static bool isWorthFoldingADDlow(SDValue N) {
578 for (auto Use : N->uses()) {
579 if (Use->getOpcode() != ISD::LOAD && Use->getOpcode() != ISD::STORE &&
580 Use->getOpcode() != ISD::ATOMIC_LOAD &&
581 Use->getOpcode() != ISD::ATOMIC_STORE)
584 // ldar and stlr have much more restrictive addressing modes (just a
586 if (cast<MemSDNode>(Use)->getOrdering() > Monotonic)
593 /// SelectAddrModeIndexed - Select a "register plus scaled unsigned 12-bit
594 /// immediate" address. The "Size" argument is the size in bytes of the memory
595 /// reference, which determines the scale.
596 bool AArch64DAGToDAGISel::SelectAddrModeIndexed(SDValue N, unsigned Size,
597 SDValue &Base, SDValue &OffImm) {
598 const TargetLowering *TLI = getTargetLowering();
599 if (N.getOpcode() == ISD::FrameIndex) {
600 int FI = cast<FrameIndexSDNode>(N)->getIndex();
601 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
602 OffImm = CurDAG->getTargetConstant(0, MVT::i64);
606 if (N.getOpcode() == AArch64ISD::ADDlow && isWorthFoldingADDlow(N)) {
607 GlobalAddressSDNode *GAN =
608 dyn_cast<GlobalAddressSDNode>(N.getOperand(1).getNode());
609 Base = N.getOperand(0);
610 OffImm = N.getOperand(1);
614 const GlobalValue *GV = GAN->getGlobal();
615 unsigned Alignment = GV->getAlignment();
616 const DataLayout *DL = TLI->getDataLayout();
617 Type *Ty = GV->getType()->getElementType();
618 if (Alignment == 0 && Ty->isSized())
619 Alignment = DL->getABITypeAlignment(Ty);
621 if (Alignment >= Size)
625 if (CurDAG->isBaseWithConstantOffset(N)) {
626 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
627 int64_t RHSC = (int64_t)RHS->getZExtValue();
628 unsigned Scale = Log2_32(Size);
629 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 << Scale)) {
630 Base = N.getOperand(0);
631 if (Base.getOpcode() == ISD::FrameIndex) {
632 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
633 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
635 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, MVT::i64);
641 // Before falling back to our general case, check if the unscaled
642 // instructions can handle this. If so, that's preferable.
643 if (SelectAddrModeUnscaled(N, Size, Base, OffImm))
646 // Base only. The address will be materialized into a register before
647 // the memory is accessed.
648 // add x0, Xbase, #offset
651 OffImm = CurDAG->getTargetConstant(0, MVT::i64);
655 /// SelectAddrModeUnscaled - Select a "register plus unscaled signed 9-bit
656 /// immediate" address. This should only match when there is an offset that
657 /// is not valid for a scaled immediate addressing mode. The "Size" argument
658 /// is the size in bytes of the memory reference, which is needed here to know
659 /// what is valid for a scaled immediate.
660 bool AArch64DAGToDAGISel::SelectAddrModeUnscaled(SDValue N, unsigned Size,
663 if (!CurDAG->isBaseWithConstantOffset(N))
665 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
666 int64_t RHSC = RHS->getSExtValue();
667 // If the offset is valid as a scaled immediate, don't match here.
668 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 &&
669 RHSC < (0x1000 << Log2_32(Size)))
671 if (RHSC >= -256 && RHSC < 256) {
672 Base = N.getOperand(0);
673 if (Base.getOpcode() == ISD::FrameIndex) {
674 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
675 const TargetLowering *TLI = getTargetLowering();
676 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
678 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i64);
685 static SDValue Widen(SelectionDAG *CurDAG, SDValue N) {
686 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, MVT::i32);
687 SDValue ImpDef = SDValue(
688 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, SDLoc(N), MVT::i64),
690 MachineSDNode *Node = CurDAG->getMachineNode(
691 TargetOpcode::INSERT_SUBREG, SDLoc(N), MVT::i64, ImpDef, N, SubReg);
692 return SDValue(Node, 0);
695 /// \brief Check if the given SHL node (\p N), can be used to form an
696 /// extended register for an addressing mode.
697 bool AArch64DAGToDAGISel::SelectExtendedSHL(SDValue N, unsigned Size,
698 bool WantExtend, SDValue &Offset,
699 SDValue &SignExtend) {
700 assert(N.getOpcode() == ISD::SHL && "Invalid opcode.");
701 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
702 if (!CSD || (CSD->getZExtValue() & 0x7) != CSD->getZExtValue())
706 AArch64_AM::ShiftExtendType Ext =
707 getExtendTypeForNode(N.getOperand(0), true);
708 if (Ext == AArch64_AM::InvalidShiftExtend)
711 Offset = narrowIfNeeded(CurDAG, N.getOperand(0).getOperand(0));
712 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, MVT::i32);
714 Offset = N.getOperand(0);
715 SignExtend = CurDAG->getTargetConstant(0, MVT::i32);
718 unsigned LegalShiftVal = Log2_32(Size);
719 unsigned ShiftVal = CSD->getZExtValue();
721 if (ShiftVal != 0 && ShiftVal != LegalShiftVal)
724 if (isWorthFolding(N))
730 bool AArch64DAGToDAGISel::SelectAddrModeWRO(SDValue N, unsigned Size,
731 SDValue &Base, SDValue &Offset,
734 if (N.getOpcode() != ISD::ADD)
736 SDValue LHS = N.getOperand(0);
737 SDValue RHS = N.getOperand(1);
739 // We don't want to match immediate adds here, because they are better lowered
740 // to the register-immediate addressing modes.
741 if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))
744 // Check if this particular node is reused in any non-memory related
745 // operation. If yes, do not try to fold this node into the address
746 // computation, since the computation will be kept.
747 const SDNode *Node = N.getNode();
748 for (SDNode *UI : Node->uses()) {
749 if (!isa<MemSDNode>(*UI))
753 // Remember if it is worth folding N when it produces extended register.
754 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
756 // Try to match a shifted extend on the RHS.
757 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
758 SelectExtendedSHL(RHS, Size, true, Offset, SignExtend)) {
760 DoShift = CurDAG->getTargetConstant(true, MVT::i32);
764 // Try to match a shifted extend on the LHS.
765 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
766 SelectExtendedSHL(LHS, Size, true, Offset, SignExtend)) {
768 DoShift = CurDAG->getTargetConstant(true, MVT::i32);
772 // There was no shift, whatever else we find.
773 DoShift = CurDAG->getTargetConstant(false, MVT::i32);
775 AArch64_AM::ShiftExtendType Ext = AArch64_AM::InvalidShiftExtend;
776 // Try to match an unshifted extend on the LHS.
777 if (IsExtendedRegisterWorthFolding &&
778 (Ext = getExtendTypeForNode(LHS, true)) !=
779 AArch64_AM::InvalidShiftExtend) {
781 Offset = narrowIfNeeded(CurDAG, LHS.getOperand(0));
782 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, MVT::i32);
783 if (isWorthFolding(LHS))
787 // Try to match an unshifted extend on the RHS.
788 if (IsExtendedRegisterWorthFolding &&
789 (Ext = getExtendTypeForNode(RHS, true)) !=
790 AArch64_AM::InvalidShiftExtend) {
792 Offset = narrowIfNeeded(CurDAG, RHS.getOperand(0));
793 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, MVT::i32);
794 if (isWorthFolding(RHS))
801 // Check if the given immediate is preferred by ADD. If an immediate can be
802 // encoded in an ADD, or it can be encoded in an "ADD LSL #12" and can not be
803 // encoded by one MOVZ, return true.
804 static bool isPreferredADD(int64_t ImmOff) {
805 // Constant in [0x0, 0xfff] can be encoded in ADD.
806 if ((ImmOff & 0xfffffffffffff000LL) == 0x0LL)
808 // Check if it can be encoded in an "ADD LSL #12".
809 if ((ImmOff & 0xffffffffff000fffLL) == 0x0LL)
810 // As a single MOVZ is faster than a "ADD of LSL #12", ignore such constant.
811 return (ImmOff & 0xffffffffff00ffffLL) != 0x0LL &&
812 (ImmOff & 0xffffffffffff0fffLL) != 0x0LL;
816 bool AArch64DAGToDAGISel::SelectAddrModeXRO(SDValue N, unsigned Size,
817 SDValue &Base, SDValue &Offset,
820 if (N.getOpcode() != ISD::ADD)
822 SDValue LHS = N.getOperand(0);
823 SDValue RHS = N.getOperand(1);
825 // Check if this particular node is reused in any non-memory related
826 // operation. If yes, do not try to fold this node into the address
827 // computation, since the computation will be kept.
828 const SDNode *Node = N.getNode();
829 for (SDNode *UI : Node->uses()) {
830 if (!isa<MemSDNode>(*UI))
834 // Watch out if RHS is a wide immediate, it can not be selected into
835 // [BaseReg+Imm] addressing mode. Also it may not be able to be encoded into
836 // ADD/SUB. Instead it will use [BaseReg + 0] address mode and generate
837 // instructions like:
838 // MOV X0, WideImmediate
839 // ADD X1, BaseReg, X0
841 // For such situation, using [BaseReg, XReg] addressing mode can save one
843 // MOV X0, WideImmediate
844 // LDR X2, [BaseReg, X0]
845 if (isa<ConstantSDNode>(RHS)) {
846 int64_t ImmOff = (int64_t)dyn_cast<ConstantSDNode>(RHS)->getZExtValue();
847 unsigned Scale = Log2_32(Size);
848 // Skip the immediate can be seleced by load/store addressing mode.
849 // Also skip the immediate can be encoded by a single ADD (SUB is also
850 // checked by using -ImmOff).
851 if ((ImmOff % Size == 0 && ImmOff >= 0 && ImmOff < (0x1000 << Scale)) ||
852 isPreferredADD(ImmOff) || isPreferredADD(-ImmOff))
855 SDLoc DL(N.getNode());
856 SDValue Ops[] = { RHS };
858 CurDAG->getMachineNode(AArch64::MOVi64imm, DL, MVT::i64, Ops);
859 SDValue MOVIV = SDValue(MOVI, 0);
860 // This ADD of two X register will be selected into [Reg+Reg] mode.
861 N = CurDAG->getNode(ISD::ADD, DL, MVT::i64, LHS, MOVIV);
864 // Remember if it is worth folding N when it produces extended register.
865 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
867 // Try to match a shifted extend on the RHS.
868 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
869 SelectExtendedSHL(RHS, Size, false, Offset, SignExtend)) {
871 DoShift = CurDAG->getTargetConstant(true, MVT::i32);
875 // Try to match a shifted extend on the LHS.
876 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
877 SelectExtendedSHL(LHS, Size, false, Offset, SignExtend)) {
879 DoShift = CurDAG->getTargetConstant(true, MVT::i32);
883 // Match any non-shifted, non-extend, non-immediate add expression.
886 SignExtend = CurDAG->getTargetConstant(false, MVT::i32);
887 DoShift = CurDAG->getTargetConstant(false, MVT::i32);
888 // Reg1 + Reg2 is free: no check needed.
892 SDValue AArch64DAGToDAGISel::createDTuple(ArrayRef<SDValue> Regs) {
893 static unsigned RegClassIDs[] = {
894 AArch64::DDRegClassID, AArch64::DDDRegClassID, AArch64::DDDDRegClassID};
895 static unsigned SubRegs[] = { AArch64::dsub0, AArch64::dsub1,
896 AArch64::dsub2, AArch64::dsub3 };
898 return createTuple(Regs, RegClassIDs, SubRegs);
901 SDValue AArch64DAGToDAGISel::createQTuple(ArrayRef<SDValue> Regs) {
902 static unsigned RegClassIDs[] = {
903 AArch64::QQRegClassID, AArch64::QQQRegClassID, AArch64::QQQQRegClassID};
904 static unsigned SubRegs[] = { AArch64::qsub0, AArch64::qsub1,
905 AArch64::qsub2, AArch64::qsub3 };
907 return createTuple(Regs, RegClassIDs, SubRegs);
910 SDValue AArch64DAGToDAGISel::createTuple(ArrayRef<SDValue> Regs,
911 unsigned RegClassIDs[],
912 unsigned SubRegs[]) {
913 // There's no special register-class for a vector-list of 1 element: it's just
915 if (Regs.size() == 1)
918 assert(Regs.size() >= 2 && Regs.size() <= 4);
920 SDLoc DL(Regs[0].getNode());
922 SmallVector<SDValue, 4> Ops;
924 // First operand of REG_SEQUENCE is the desired RegClass.
926 CurDAG->getTargetConstant(RegClassIDs[Regs.size() - 2], MVT::i32));
928 // Then we get pairs of source & subregister-position for the components.
929 for (unsigned i = 0; i < Regs.size(); ++i) {
930 Ops.push_back(Regs[i]);
931 Ops.push_back(CurDAG->getTargetConstant(SubRegs[i], MVT::i32));
935 CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops);
936 return SDValue(N, 0);
939 SDNode *AArch64DAGToDAGISel::SelectTable(SDNode *N, unsigned NumVecs,
940 unsigned Opc, bool isExt) {
942 EVT VT = N->getValueType(0);
944 unsigned ExtOff = isExt;
946 // Form a REG_SEQUENCE to force register allocation.
947 unsigned Vec0Off = ExtOff + 1;
948 SmallVector<SDValue, 4> Regs(N->op_begin() + Vec0Off,
949 N->op_begin() + Vec0Off + NumVecs);
950 SDValue RegSeq = createQTuple(Regs);
952 SmallVector<SDValue, 6> Ops;
954 Ops.push_back(N->getOperand(1));
955 Ops.push_back(RegSeq);
956 Ops.push_back(N->getOperand(NumVecs + ExtOff + 1));
957 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
960 SDNode *AArch64DAGToDAGISel::SelectIndexedLoad(SDNode *N, bool &Done) {
961 LoadSDNode *LD = cast<LoadSDNode>(N);
962 if (LD->isUnindexed())
964 EVT VT = LD->getMemoryVT();
965 EVT DstVT = N->getValueType(0);
966 ISD::MemIndexedMode AM = LD->getAddressingMode();
967 bool IsPre = AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
969 // We're not doing validity checking here. That was done when checking
970 // if we should mark the load as indexed or not. We're just selecting
971 // the right instruction.
974 ISD::LoadExtType ExtType = LD->getExtensionType();
975 bool InsertTo64 = false;
977 Opcode = IsPre ? AArch64::LDRXpre : AArch64::LDRXpost;
978 else if (VT == MVT::i32) {
979 if (ExtType == ISD::NON_EXTLOAD)
980 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
981 else if (ExtType == ISD::SEXTLOAD)
982 Opcode = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost;
984 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
986 // The result of the load is only i32. It's the subreg_to_reg that makes
990 } else if (VT == MVT::i16) {
991 if (ExtType == ISD::SEXTLOAD) {
992 if (DstVT == MVT::i64)
993 Opcode = IsPre ? AArch64::LDRSHXpre : AArch64::LDRSHXpost;
995 Opcode = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost;
997 Opcode = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost;
998 InsertTo64 = DstVT == MVT::i64;
999 // The result of the load is only i32. It's the subreg_to_reg that makes
1003 } else if (VT == MVT::i8) {
1004 if (ExtType == ISD::SEXTLOAD) {
1005 if (DstVT == MVT::i64)
1006 Opcode = IsPre ? AArch64::LDRSBXpre : AArch64::LDRSBXpost;
1008 Opcode = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost;
1010 Opcode = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost;
1011 InsertTo64 = DstVT == MVT::i64;
1012 // The result of the load is only i32. It's the subreg_to_reg that makes
1016 } else if (VT == MVT::f32) {
1017 Opcode = IsPre ? AArch64::LDRSpre : AArch64::LDRSpost;
1018 } else if (VT == MVT::f64 || VT.is64BitVector()) {
1019 Opcode = IsPre ? AArch64::LDRDpre : AArch64::LDRDpost;
1020 } else if (VT.is128BitVector()) {
1021 Opcode = IsPre ? AArch64::LDRQpre : AArch64::LDRQpost;
1024 SDValue Chain = LD->getChain();
1025 SDValue Base = LD->getBasePtr();
1026 ConstantSDNode *OffsetOp = cast<ConstantSDNode>(LD->getOffset());
1027 int OffsetVal = (int)OffsetOp->getZExtValue();
1028 SDValue Offset = CurDAG->getTargetConstant(OffsetVal, MVT::i64);
1029 SDValue Ops[] = { Base, Offset, Chain };
1030 SDNode *Res = CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i64, DstVT,
1032 // Either way, we're replacing the node, so tell the caller that.
1034 SDValue LoadedVal = SDValue(Res, 1);
1036 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, MVT::i32);
1038 SDValue(CurDAG->getMachineNode(
1039 AArch64::SUBREG_TO_REG, SDLoc(N), MVT::i64,
1040 CurDAG->getTargetConstant(0, MVT::i64), LoadedVal, SubReg),
1044 ReplaceUses(SDValue(N, 0), LoadedVal);
1045 ReplaceUses(SDValue(N, 1), SDValue(Res, 0));
1046 ReplaceUses(SDValue(N, 2), SDValue(Res, 2));
1051 SDNode *AArch64DAGToDAGISel::SelectLoad(SDNode *N, unsigned NumVecs,
1052 unsigned Opc, unsigned SubRegIdx) {
1054 EVT VT = N->getValueType(0);
1055 SDValue Chain = N->getOperand(0);
1057 SmallVector<SDValue, 6> Ops;
1058 Ops.push_back(N->getOperand(2)); // Mem operand;
1059 Ops.push_back(Chain);
1061 std::vector<EVT> ResTys;
1062 ResTys.push_back(MVT::Untyped);
1063 ResTys.push_back(MVT::Other);
1065 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1066 SDValue SuperReg = SDValue(Ld, 0);
1067 for (unsigned i = 0; i < NumVecs; ++i)
1068 ReplaceUses(SDValue(N, i),
1069 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1071 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1075 SDNode *AArch64DAGToDAGISel::SelectPostLoad(SDNode *N, unsigned NumVecs,
1076 unsigned Opc, unsigned SubRegIdx) {
1078 EVT VT = N->getValueType(0);
1079 SDValue Chain = N->getOperand(0);
1081 SmallVector<SDValue, 6> Ops;
1082 Ops.push_back(N->getOperand(1)); // Mem operand
1083 Ops.push_back(N->getOperand(2)); // Incremental
1084 Ops.push_back(Chain);
1086 std::vector<EVT> ResTys;
1087 ResTys.push_back(MVT::i64); // Type of the write back register
1088 ResTys.push_back(MVT::Untyped);
1089 ResTys.push_back(MVT::Other);
1091 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1093 // Update uses of write back register
1094 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1096 // Update uses of vector list
1097 SDValue SuperReg = SDValue(Ld, 1);
1099 ReplaceUses(SDValue(N, 0), SuperReg);
1101 for (unsigned i = 0; i < NumVecs; ++i)
1102 ReplaceUses(SDValue(N, i),
1103 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1106 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1110 SDNode *AArch64DAGToDAGISel::SelectStore(SDNode *N, unsigned NumVecs,
1113 EVT VT = N->getOperand(2)->getValueType(0);
1115 // Form a REG_SEQUENCE to force register allocation.
1116 bool Is128Bit = VT.getSizeInBits() == 128;
1117 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1118 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1120 SmallVector<SDValue, 6> Ops;
1121 Ops.push_back(RegSeq);
1122 Ops.push_back(N->getOperand(NumVecs + 2));
1123 Ops.push_back(N->getOperand(0));
1124 SDNode *St = CurDAG->getMachineNode(Opc, dl, N->getValueType(0), Ops);
1129 SDNode *AArch64DAGToDAGISel::SelectPostStore(SDNode *N, unsigned NumVecs,
1132 EVT VT = N->getOperand(2)->getValueType(0);
1133 SmallVector<EVT, 2> ResTys;
1134 ResTys.push_back(MVT::i64); // Type of the write back register
1135 ResTys.push_back(MVT::Other); // Type for the Chain
1137 // Form a REG_SEQUENCE to force register allocation.
1138 bool Is128Bit = VT.getSizeInBits() == 128;
1139 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1140 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1142 SmallVector<SDValue, 6> Ops;
1143 Ops.push_back(RegSeq);
1144 Ops.push_back(N->getOperand(NumVecs + 1)); // base register
1145 Ops.push_back(N->getOperand(NumVecs + 2)); // Incremental
1146 Ops.push_back(N->getOperand(0)); // Chain
1147 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1152 /// WidenVector - Given a value in the V64 register class, produce the
1153 /// equivalent value in the V128 register class.
1158 WidenVector(SelectionDAG &DAG) : DAG(DAG) {}
1160 SDValue operator()(SDValue V64Reg) {
1161 EVT VT = V64Reg.getValueType();
1162 unsigned NarrowSize = VT.getVectorNumElements();
1163 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1164 MVT WideTy = MVT::getVectorVT(EltTy, 2 * NarrowSize);
1168 SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, WideTy), 0);
1169 return DAG.getTargetInsertSubreg(AArch64::dsub, DL, WideTy, Undef, V64Reg);
1173 /// NarrowVector - Given a value in the V128 register class, produce the
1174 /// equivalent value in the V64 register class.
1175 static SDValue NarrowVector(SDValue V128Reg, SelectionDAG &DAG) {
1176 EVT VT = V128Reg.getValueType();
1177 unsigned WideSize = VT.getVectorNumElements();
1178 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1179 MVT NarrowTy = MVT::getVectorVT(EltTy, WideSize / 2);
1181 return DAG.getTargetExtractSubreg(AArch64::dsub, SDLoc(V128Reg), NarrowTy,
1185 SDNode *AArch64DAGToDAGISel::SelectLoadLane(SDNode *N, unsigned NumVecs,
1188 EVT VT = N->getValueType(0);
1189 bool Narrow = VT.getSizeInBits() == 64;
1191 // Form a REG_SEQUENCE to force register allocation.
1192 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1195 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1196 WidenVector(*CurDAG));
1198 SDValue RegSeq = createQTuple(Regs);
1200 std::vector<EVT> ResTys;
1201 ResTys.push_back(MVT::Untyped);
1202 ResTys.push_back(MVT::Other);
1205 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1207 SmallVector<SDValue, 6> Ops;
1208 Ops.push_back(RegSeq);
1209 Ops.push_back(CurDAG->getTargetConstant(LaneNo, MVT::i64));
1210 Ops.push_back(N->getOperand(NumVecs + 3));
1211 Ops.push_back(N->getOperand(0));
1212 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1213 SDValue SuperReg = SDValue(Ld, 0);
1215 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1216 static unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1, AArch64::qsub2,
1218 for (unsigned i = 0; i < NumVecs; ++i) {
1219 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT, SuperReg);
1221 NV = NarrowVector(NV, *CurDAG);
1222 ReplaceUses(SDValue(N, i), NV);
1225 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1230 SDNode *AArch64DAGToDAGISel::SelectPostLoadLane(SDNode *N, unsigned NumVecs,
1233 EVT VT = N->getValueType(0);
1234 bool Narrow = VT.getSizeInBits() == 64;
1236 // Form a REG_SEQUENCE to force register allocation.
1237 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1240 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1241 WidenVector(*CurDAG));
1243 SDValue RegSeq = createQTuple(Regs);
1245 std::vector<EVT> ResTys;
1246 ResTys.push_back(MVT::i64); // Type of the write back register
1247 ResTys.push_back(MVT::Untyped);
1248 ResTys.push_back(MVT::Other);
1251 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1253 SmallVector<SDValue, 6> Ops;
1254 Ops.push_back(RegSeq);
1255 Ops.push_back(CurDAG->getTargetConstant(LaneNo, MVT::i64)); // Lane Number
1256 Ops.push_back(N->getOperand(NumVecs + 2)); // Base register
1257 Ops.push_back(N->getOperand(NumVecs + 3)); // Incremental
1258 Ops.push_back(N->getOperand(0));
1259 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1261 // Update uses of the write back register
1262 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1264 // Update uses of the vector list
1265 SDValue SuperReg = SDValue(Ld, 1);
1267 ReplaceUses(SDValue(N, 0),
1268 Narrow ? NarrowVector(SuperReg, *CurDAG) : SuperReg);
1270 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1271 static unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1, AArch64::qsub2,
1273 for (unsigned i = 0; i < NumVecs; ++i) {
1274 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT,
1277 NV = NarrowVector(NV, *CurDAG);
1278 ReplaceUses(SDValue(N, i), NV);
1283 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1288 SDNode *AArch64DAGToDAGISel::SelectStoreLane(SDNode *N, unsigned NumVecs,
1291 EVT VT = N->getOperand(2)->getValueType(0);
1292 bool Narrow = VT.getSizeInBits() == 64;
1294 // Form a REG_SEQUENCE to force register allocation.
1295 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1298 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1299 WidenVector(*CurDAG));
1301 SDValue RegSeq = createQTuple(Regs);
1304 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1306 SmallVector<SDValue, 6> Ops;
1307 Ops.push_back(RegSeq);
1308 Ops.push_back(CurDAG->getTargetConstant(LaneNo, MVT::i64));
1309 Ops.push_back(N->getOperand(NumVecs + 3));
1310 Ops.push_back(N->getOperand(0));
1311 SDNode *St = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
1313 // Transfer memoperands.
1314 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1315 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1316 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1321 SDNode *AArch64DAGToDAGISel::SelectPostStoreLane(SDNode *N, unsigned NumVecs,
1324 EVT VT = N->getOperand(2)->getValueType(0);
1325 bool Narrow = VT.getSizeInBits() == 64;
1327 // Form a REG_SEQUENCE to force register allocation.
1328 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1331 std::transform(Regs.begin(), Regs.end(), Regs.begin(),
1332 WidenVector(*CurDAG));
1334 SDValue RegSeq = createQTuple(Regs);
1336 SmallVector<EVT, 2> ResTys;
1337 ResTys.push_back(MVT::i64); // Type of the write back register
1338 ResTys.push_back(MVT::Other);
1341 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1343 SmallVector<SDValue, 6> Ops;
1344 Ops.push_back(RegSeq);
1345 Ops.push_back(CurDAG->getTargetConstant(LaneNo, MVT::i64));
1346 Ops.push_back(N->getOperand(NumVecs + 2)); // Base Register
1347 Ops.push_back(N->getOperand(NumVecs + 3)); // Incremental
1348 Ops.push_back(N->getOperand(0));
1349 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1351 // Transfer memoperands.
1352 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1353 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1354 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1359 static bool isBitfieldExtractOpFromAnd(SelectionDAG *CurDAG, SDNode *N,
1360 unsigned &Opc, SDValue &Opd0,
1361 unsigned &LSB, unsigned &MSB,
1362 unsigned NumberOfIgnoredLowBits,
1363 bool BiggerPattern) {
1364 assert(N->getOpcode() == ISD::AND &&
1365 "N must be a AND operation to call this function");
1367 EVT VT = N->getValueType(0);
1369 // Here we can test the type of VT and return false when the type does not
1370 // match, but since it is done prior to that call in the current context
1371 // we turned that into an assert to avoid redundant code.
1372 assert((VT == MVT::i32 || VT == MVT::i64) &&
1373 "Type checking must have been done before calling this function");
1375 // FIXME: simplify-demanded-bits in DAGCombine will probably have
1376 // changed the AND node to a 32-bit mask operation. We'll have to
1377 // undo that as part of the transform here if we want to catch all
1378 // the opportunities.
1379 // Currently the NumberOfIgnoredLowBits argument helps to recover
1380 // form these situations when matching bigger pattern (bitfield insert).
1382 // For unsigned extracts, check for a shift right and mask
1383 uint64_t And_imm = 0;
1384 if (!isOpcWithIntImmediate(N, ISD::AND, And_imm))
1387 const SDNode *Op0 = N->getOperand(0).getNode();
1389 // Because of simplify-demanded-bits in DAGCombine, the mask may have been
1390 // simplified. Try to undo that
1391 And_imm |= (1 << NumberOfIgnoredLowBits) - 1;
1393 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1394 if (And_imm & (And_imm + 1))
1397 bool ClampMSB = false;
1398 uint64_t Srl_imm = 0;
1399 // Handle the SRL + ANY_EXTEND case.
1400 if (VT == MVT::i64 && Op0->getOpcode() == ISD::ANY_EXTEND &&
1401 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL, Srl_imm)) {
1402 // Extend the incoming operand of the SRL to 64-bit.
1403 Opd0 = Widen(CurDAG, Op0->getOperand(0).getOperand(0));
1404 // Make sure to clamp the MSB so that we preserve the semantics of the
1405 // original operations.
1407 } else if (VT == MVT::i32 && Op0->getOpcode() == ISD::TRUNCATE &&
1408 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL,
1410 // If the shift result was truncated, we can still combine them.
1411 Opd0 = Op0->getOperand(0).getOperand(0);
1413 // Use the type of SRL node.
1414 VT = Opd0->getValueType(0);
1415 } else if (isOpcWithIntImmediate(Op0, ISD::SRL, Srl_imm)) {
1416 Opd0 = Op0->getOperand(0);
1417 } else if (BiggerPattern) {
1418 // Let's pretend a 0 shift right has been performed.
1419 // The resulting code will be at least as good as the original one
1420 // plus it may expose more opportunities for bitfield insert pattern.
1421 // FIXME: Currently we limit this to the bigger pattern, because
1422 // some optimizations expect AND and not UBFM
1423 Opd0 = N->getOperand(0);
1427 assert((BiggerPattern || (Srl_imm > 0 && Srl_imm < VT.getSizeInBits())) &&
1428 "bad amount in shift node!");
1431 MSB = Srl_imm + (VT == MVT::i32 ? CountTrailingOnes_32(And_imm)
1432 : CountTrailingOnes_64(And_imm)) -
1435 // Since we're moving the extend before the right shift operation, we need
1436 // to clamp the MSB to make sure we don't shift in undefined bits instead of
1437 // the zeros which would get shifted in with the original right shift
1439 MSB = MSB > 31 ? 31 : MSB;
1441 Opc = VT == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1445 static bool isSeveralBitsExtractOpFromShr(SDNode *N, unsigned &Opc,
1446 SDValue &Opd0, unsigned &LSB,
1448 // We are looking for the following pattern which basically extracts several
1449 // continuous bits from the source value and places it from the LSB of the
1450 // destination value, all other bits of the destination value or set to zero:
1452 // Value2 = AND Value, MaskImm
1453 // SRL Value2, ShiftImm
1455 // with MaskImm >> ShiftImm to search for the bit width.
1457 // This gets selected into a single UBFM:
1459 // UBFM Value, ShiftImm, BitWide + Srl_imm -1
1462 if (N->getOpcode() != ISD::SRL)
1465 uint64_t And_mask = 0;
1466 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, And_mask))
1469 Opd0 = N->getOperand(0).getOperand(0);
1471 uint64_t Srl_imm = 0;
1472 if (!isIntImmediate(N->getOperand(1), Srl_imm))
1475 // Check whether we really have several bits extract here.
1476 unsigned BitWide = 64 - CountLeadingOnes_64(~(And_mask >> Srl_imm));
1477 if (BitWide && isMask_64(And_mask >> Srl_imm)) {
1478 if (N->getValueType(0) == MVT::i32)
1479 Opc = AArch64::UBFMWri;
1481 Opc = AArch64::UBFMXri;
1484 MSB = BitWide + Srl_imm - 1;
1491 static bool isBitfieldExtractOpFromShr(SDNode *N, unsigned &Opc, SDValue &Opd0,
1492 unsigned &LSB, unsigned &MSB,
1493 bool BiggerPattern) {
1494 assert((N->getOpcode() == ISD::SRA || N->getOpcode() == ISD::SRL) &&
1495 "N must be a SHR/SRA operation to call this function");
1497 EVT VT = N->getValueType(0);
1499 // Here we can test the type of VT and return false when the type does not
1500 // match, but since it is done prior to that call in the current context
1501 // we turned that into an assert to avoid redundant code.
1502 assert((VT == MVT::i32 || VT == MVT::i64) &&
1503 "Type checking must have been done before calling this function");
1505 // Check for AND + SRL doing several bits extract.
1506 if (isSeveralBitsExtractOpFromShr(N, Opc, Opd0, LSB, MSB))
1509 // we're looking for a shift of a shift
1510 uint64_t Shl_imm = 0;
1511 uint64_t Trunc_bits = 0;
1512 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
1513 Opd0 = N->getOperand(0).getOperand(0);
1514 } else if (VT == MVT::i32 && N->getOpcode() == ISD::SRL &&
1515 N->getOperand(0).getNode()->getOpcode() == ISD::TRUNCATE) {
1516 // We are looking for a shift of truncate. Truncate from i64 to i32 could
1517 // be considered as setting high 32 bits as zero. Our strategy here is to
1518 // always generate 64bit UBFM. This consistency will help the CSE pass
1519 // later find more redundancy.
1520 Opd0 = N->getOperand(0).getOperand(0);
1521 Trunc_bits = Opd0->getValueType(0).getSizeInBits() - VT.getSizeInBits();
1522 VT = Opd0->getValueType(0);
1523 assert(VT == MVT::i64 && "the promoted type should be i64");
1524 } else if (BiggerPattern) {
1525 // Let's pretend a 0 shift left has been performed.
1526 // FIXME: Currently we limit this to the bigger pattern case,
1527 // because some optimizations expect AND and not UBFM
1528 Opd0 = N->getOperand(0);
1532 assert(Shl_imm < VT.getSizeInBits() && "bad amount in shift node!");
1533 uint64_t Srl_imm = 0;
1534 if (!isIntImmediate(N->getOperand(1), Srl_imm))
1537 assert(Srl_imm > 0 && Srl_imm < VT.getSizeInBits() &&
1538 "bad amount in shift node!");
1539 // Note: The width operand is encoded as width-1.
1540 unsigned Width = VT.getSizeInBits() - Trunc_bits - Srl_imm - 1;
1541 int sLSB = Srl_imm - Shl_imm;
1546 // SRA requires a signed extraction
1548 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMWri : AArch64::UBFMWri;
1550 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMXri : AArch64::UBFMXri;
1554 static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
1555 SDValue &Opd0, unsigned &LSB, unsigned &MSB,
1556 unsigned NumberOfIgnoredLowBits = 0,
1557 bool BiggerPattern = false) {
1558 if (N->getValueType(0) != MVT::i32 && N->getValueType(0) != MVT::i64)
1561 switch (N->getOpcode()) {
1563 if (!N->isMachineOpcode())
1567 return isBitfieldExtractOpFromAnd(CurDAG, N, Opc, Opd0, LSB, MSB,
1568 NumberOfIgnoredLowBits, BiggerPattern);
1571 return isBitfieldExtractOpFromShr(N, Opc, Opd0, LSB, MSB, BiggerPattern);
1574 unsigned NOpc = N->getMachineOpcode();
1578 case AArch64::SBFMWri:
1579 case AArch64::UBFMWri:
1580 case AArch64::SBFMXri:
1581 case AArch64::UBFMXri:
1583 Opd0 = N->getOperand(0);
1584 LSB = cast<ConstantSDNode>(N->getOperand(1).getNode())->getZExtValue();
1585 MSB = cast<ConstantSDNode>(N->getOperand(2).getNode())->getZExtValue();
1592 SDNode *AArch64DAGToDAGISel::SelectBitfieldExtractOp(SDNode *N) {
1593 unsigned Opc, LSB, MSB;
1595 if (!isBitfieldExtractOp(CurDAG, N, Opc, Opd0, LSB, MSB))
1598 EVT VT = N->getValueType(0);
1600 // If the bit extract operation is 64bit but the original type is 32bit, we
1601 // need to add one EXTRACT_SUBREG.
1602 if ((Opc == AArch64::SBFMXri || Opc == AArch64::UBFMXri) && VT == MVT::i32) {
1603 SDValue Ops64[] = {Opd0, CurDAG->getTargetConstant(LSB, MVT::i64),
1604 CurDAG->getTargetConstant(MSB, MVT::i64)};
1606 SDNode *BFM = CurDAG->getMachineNode(Opc, SDLoc(N), MVT::i64, Ops64);
1607 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, MVT::i32);
1608 MachineSDNode *Node =
1609 CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, SDLoc(N), MVT::i32,
1610 SDValue(BFM, 0), SubReg);
1614 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(LSB, VT),
1615 CurDAG->getTargetConstant(MSB, VT)};
1616 return CurDAG->SelectNodeTo(N, Opc, VT, Ops);
1619 /// Does DstMask form a complementary pair with the mask provided by
1620 /// BitsToBeInserted, suitable for use in a BFI instruction. Roughly speaking,
1621 /// this asks whether DstMask zeroes precisely those bits that will be set by
1623 static bool isBitfieldDstMask(uint64_t DstMask, APInt BitsToBeInserted,
1624 unsigned NumberOfIgnoredHighBits, EVT VT) {
1625 assert((VT == MVT::i32 || VT == MVT::i64) &&
1626 "i32 or i64 mask type expected!");
1627 unsigned BitWidth = VT.getSizeInBits() - NumberOfIgnoredHighBits;
1629 APInt SignificantDstMask = APInt(BitWidth, DstMask);
1630 APInt SignificantBitsToBeInserted = BitsToBeInserted.zextOrTrunc(BitWidth);
1632 return (SignificantDstMask & SignificantBitsToBeInserted) == 0 &&
1633 (SignificantDstMask | SignificantBitsToBeInserted).isAllOnesValue();
1636 // Look for bits that will be useful for later uses.
1637 // A bit is consider useless as soon as it is dropped and never used
1638 // before it as been dropped.
1639 // E.g., looking for useful bit of x
1642 // After #1, x useful bits are 0x7, then the useful bits of x, live through
1644 // After #2, the useful bits of x are 0x4.
1645 // However, if x is used on an unpredicatable instruction, then all its bits
1651 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth = 0);
1653 static void getUsefulBitsFromAndWithImmediate(SDValue Op, APInt &UsefulBits,
1656 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1657 Imm = AArch64_AM::decodeLogicalImmediate(Imm, UsefulBits.getBitWidth());
1658 UsefulBits &= APInt(UsefulBits.getBitWidth(), Imm);
1659 getUsefulBits(Op, UsefulBits, Depth + 1);
1662 static void getUsefulBitsFromBitfieldMoveOpd(SDValue Op, APInt &UsefulBits,
1663 uint64_t Imm, uint64_t MSB,
1665 // inherit the bitwidth value
1666 APInt OpUsefulBits(UsefulBits);
1670 OpUsefulBits = OpUsefulBits.shl(MSB - Imm + 1);
1672 // The interesting part will be in the lower part of the result
1673 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1674 // The interesting part was starting at Imm in the argument
1675 OpUsefulBits = OpUsefulBits.shl(Imm);
1677 OpUsefulBits = OpUsefulBits.shl(MSB + 1);
1679 // The interesting part will be shifted in the result
1680 OpUsefulBits = OpUsefulBits.shl(OpUsefulBits.getBitWidth() - Imm);
1681 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1682 // The interesting part was at zero in the argument
1683 OpUsefulBits = OpUsefulBits.lshr(OpUsefulBits.getBitWidth() - Imm);
1686 UsefulBits &= OpUsefulBits;
1689 static void getUsefulBitsFromUBFM(SDValue Op, APInt &UsefulBits,
1692 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1694 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1696 getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1699 static void getUsefulBitsFromOrWithShiftedReg(SDValue Op, APInt &UsefulBits,
1701 uint64_t ShiftTypeAndValue =
1702 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1703 APInt Mask(UsefulBits);
1704 Mask.clearAllBits();
1707 if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSL) {
1709 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1710 Mask = Mask.shl(ShiftAmt);
1711 getUsefulBits(Op, Mask, Depth + 1);
1712 Mask = Mask.lshr(ShiftAmt);
1713 } else if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSR) {
1715 // We do not handle AArch64_AM::ASR, because the sign will change the
1716 // number of useful bits
1717 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1718 Mask = Mask.lshr(ShiftAmt);
1719 getUsefulBits(Op, Mask, Depth + 1);
1720 Mask = Mask.shl(ShiftAmt);
1727 static void getUsefulBitsFromBFM(SDValue Op, SDValue Orig, APInt &UsefulBits,
1730 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1732 cast<const ConstantSDNode>(Op.getOperand(3).getNode())->getZExtValue();
1734 if (Op.getOperand(1) == Orig)
1735 return getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1737 APInt OpUsefulBits(UsefulBits);
1741 OpUsefulBits = OpUsefulBits.shl(MSB - Imm + 1);
1743 UsefulBits &= ~OpUsefulBits;
1744 getUsefulBits(Op, UsefulBits, Depth + 1);
1746 OpUsefulBits = OpUsefulBits.shl(MSB + 1);
1748 UsefulBits = ~(OpUsefulBits.shl(OpUsefulBits.getBitWidth() - Imm));
1749 getUsefulBits(Op, UsefulBits, Depth + 1);
1753 static void getUsefulBitsForUse(SDNode *UserNode, APInt &UsefulBits,
1754 SDValue Orig, unsigned Depth) {
1756 // Users of this node should have already been instruction selected
1757 // FIXME: Can we turn that into an assert?
1758 if (!UserNode->isMachineOpcode())
1761 switch (UserNode->getMachineOpcode()) {
1764 case AArch64::ANDSWri:
1765 case AArch64::ANDSXri:
1766 case AArch64::ANDWri:
1767 case AArch64::ANDXri:
1768 // We increment Depth only when we call the getUsefulBits
1769 return getUsefulBitsFromAndWithImmediate(SDValue(UserNode, 0), UsefulBits,
1771 case AArch64::UBFMWri:
1772 case AArch64::UBFMXri:
1773 return getUsefulBitsFromUBFM(SDValue(UserNode, 0), UsefulBits, Depth);
1775 case AArch64::ORRWrs:
1776 case AArch64::ORRXrs:
1777 if (UserNode->getOperand(1) != Orig)
1779 return getUsefulBitsFromOrWithShiftedReg(SDValue(UserNode, 0), UsefulBits,
1781 case AArch64::BFMWri:
1782 case AArch64::BFMXri:
1783 return getUsefulBitsFromBFM(SDValue(UserNode, 0), Orig, UsefulBits, Depth);
1787 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
1790 // Initialize UsefulBits
1792 unsigned Bitwidth = Op.getValueType().getScalarType().getSizeInBits();
1793 // At the beginning, assume every produced bits is useful
1794 UsefulBits = APInt(Bitwidth, 0);
1795 UsefulBits.flipAllBits();
1797 APInt UsersUsefulBits(UsefulBits.getBitWidth(), 0);
1799 for (SDNode *Node : Op.getNode()->uses()) {
1800 // A use cannot produce useful bits
1801 APInt UsefulBitsForUse = APInt(UsefulBits);
1802 getUsefulBitsForUse(Node, UsefulBitsForUse, Op, Depth);
1803 UsersUsefulBits |= UsefulBitsForUse;
1805 // UsefulBits contains the produced bits that are meaningful for the
1806 // current definition, thus a user cannot make a bit meaningful at
1808 UsefulBits &= UsersUsefulBits;
1811 /// Create a machine node performing a notional SHL of Op by ShlAmount. If
1812 /// ShlAmount is negative, do a (logical) right-shift instead. If ShlAmount is
1813 /// 0, return Op unchanged.
1814 static SDValue getLeftShift(SelectionDAG *CurDAG, SDValue Op, int ShlAmount) {
1818 EVT VT = Op.getValueType();
1819 unsigned BitWidth = VT.getSizeInBits();
1820 unsigned UBFMOpc = BitWidth == 32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1823 if (ShlAmount > 0) {
1824 // LSL wD, wN, #Amt == UBFM wD, wN, #32-Amt, #31-Amt
1825 ShiftNode = CurDAG->getMachineNode(
1826 UBFMOpc, SDLoc(Op), VT, Op,
1827 CurDAG->getTargetConstant(BitWidth - ShlAmount, VT),
1828 CurDAG->getTargetConstant(BitWidth - 1 - ShlAmount, VT));
1830 // LSR wD, wN, #Amt == UBFM wD, wN, #Amt, #32-1
1831 assert(ShlAmount < 0 && "expected right shift");
1832 int ShrAmount = -ShlAmount;
1833 ShiftNode = CurDAG->getMachineNode(
1834 UBFMOpc, SDLoc(Op), VT, Op, CurDAG->getTargetConstant(ShrAmount, VT),
1835 CurDAG->getTargetConstant(BitWidth - 1, VT));
1838 return SDValue(ShiftNode, 0);
1841 /// Does this tree qualify as an attempt to move a bitfield into position,
1842 /// essentially "(and (shl VAL, N), Mask)".
1843 static bool isBitfieldPositioningOp(SelectionDAG *CurDAG, SDValue Op,
1844 SDValue &Src, int &ShiftAmount,
1846 EVT VT = Op.getValueType();
1847 unsigned BitWidth = VT.getSizeInBits();
1849 assert(BitWidth == 32 || BitWidth == 64);
1851 APInt KnownZero, KnownOne;
1852 CurDAG->computeKnownBits(Op, KnownZero, KnownOne);
1854 // Non-zero in the sense that they're not provably zero, which is the key
1855 // point if we want to use this value
1856 uint64_t NonZeroBits = (~KnownZero).getZExtValue();
1858 // Discard a constant AND mask if present. It's safe because the node will
1859 // already have been factored into the computeKnownBits calculation above.
1861 if (isOpcWithIntImmediate(Op.getNode(), ISD::AND, AndImm)) {
1862 assert((~APInt(BitWidth, AndImm) & ~KnownZero) == 0);
1863 Op = Op.getOperand(0);
1867 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SHL, ShlImm))
1869 Op = Op.getOperand(0);
1871 if (!isShiftedMask_64(NonZeroBits))
1874 ShiftAmount = countTrailingZeros(NonZeroBits);
1875 MaskWidth = CountTrailingOnes_64(NonZeroBits >> ShiftAmount);
1877 // BFI encompasses sufficiently many nodes that it's worth inserting an extra
1878 // LSL/LSR if the mask in NonZeroBits doesn't quite match up with the ISD::SHL
1880 Src = getLeftShift(CurDAG, Op, ShlImm - ShiftAmount);
1885 // Given a OR operation, check if we have the following pattern
1886 // ubfm c, b, imm, imm2 (or something that does the same jobs, see
1887 // isBitfieldExtractOp)
1888 // d = e & mask2 ; where mask is a binary sequence of 1..10..0 and
1889 // countTrailingZeros(mask2) == imm2 - imm + 1
1891 // if yes, given reference arguments will be update so that one can replace
1892 // the OR instruction with:
1893 // f = Opc Opd0, Opd1, LSB, MSB ; where Opc is a BFM, LSB = imm, and MSB = imm2
1894 static bool isBitfieldInsertOpFromOr(SDNode *N, unsigned &Opc, SDValue &Dst,
1895 SDValue &Src, unsigned &ImmR,
1896 unsigned &ImmS, SelectionDAG *CurDAG) {
1897 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
1900 EVT VT = N->getValueType(0);
1902 Opc = AArch64::BFMWri;
1903 else if (VT == MVT::i64)
1904 Opc = AArch64::BFMXri;
1908 // Because of simplify-demanded-bits in DAGCombine, involved masks may not
1909 // have the expected shape. Try to undo that.
1911 getUsefulBits(SDValue(N, 0), UsefulBits);
1913 unsigned NumberOfIgnoredLowBits = UsefulBits.countTrailingZeros();
1914 unsigned NumberOfIgnoredHighBits = UsefulBits.countLeadingZeros();
1916 // OR is commutative, check both possibilities (does llvm provide a
1917 // way to do that directely, e.g., via code matcher?)
1918 SDValue OrOpd1Val = N->getOperand(1);
1919 SDNode *OrOpd0 = N->getOperand(0).getNode();
1920 SDNode *OrOpd1 = N->getOperand(1).getNode();
1921 for (int i = 0; i < 2;
1922 ++i, std::swap(OrOpd0, OrOpd1), OrOpd1Val = N->getOperand(0)) {
1925 if (isBitfieldExtractOp(CurDAG, OrOpd0, BFXOpc, Src, ImmR, ImmS,
1926 NumberOfIgnoredLowBits, true)) {
1927 // Check that the returned opcode is compatible with the pattern,
1928 // i.e., same type and zero extended (U and not S)
1929 if ((BFXOpc != AArch64::UBFMXri && VT == MVT::i64) ||
1930 (BFXOpc != AArch64::UBFMWri && VT == MVT::i32))
1933 // Compute the width of the bitfield insertion
1935 Width = ImmS - ImmR + 1;
1936 // FIXME: This constraint is to catch bitfield insertion we may
1937 // want to widen the pattern if we want to grab general bitfied
1942 // If the mask on the insertee is correct, we have a BFXIL operation. We
1943 // can share the ImmR and ImmS values from the already-computed UBFM.
1944 } else if (isBitfieldPositioningOp(CurDAG, SDValue(OrOpd0, 0), Src,
1946 ImmR = (VT.getSizeInBits() - DstLSB) % VT.getSizeInBits();
1951 // Check the second part of the pattern
1952 EVT VT = OrOpd1->getValueType(0);
1953 assert((VT == MVT::i32 || VT == MVT::i64) && "unexpected OR operand");
1955 // Compute the Known Zero for the candidate of the first operand.
1956 // This allows to catch more general case than just looking for
1957 // AND with imm. Indeed, simplify-demanded-bits may have removed
1958 // the AND instruction because it proves it was useless.
1959 APInt KnownZero, KnownOne;
1960 CurDAG->computeKnownBits(OrOpd1Val, KnownZero, KnownOne);
1962 // Check if there is enough room for the second operand to appear
1964 APInt BitsToBeInserted =
1965 APInt::getBitsSet(KnownZero.getBitWidth(), DstLSB, DstLSB + Width);
1967 if ((BitsToBeInserted & ~KnownZero) != 0)
1970 // Set the first operand
1972 if (isOpcWithIntImmediate(OrOpd1, ISD::AND, Imm) &&
1973 isBitfieldDstMask(Imm, BitsToBeInserted, NumberOfIgnoredHighBits, VT))
1974 // In that case, we can eliminate the AND
1975 Dst = OrOpd1->getOperand(0);
1977 // Maybe the AND has been removed by simplify-demanded-bits
1978 // or is useful because it discards more bits
1988 SDNode *AArch64DAGToDAGISel::SelectBitfieldInsertOp(SDNode *N) {
1989 if (N->getOpcode() != ISD::OR)
1996 if (!isBitfieldInsertOpFromOr(N, Opc, Opd0, Opd1, LSB, MSB, CurDAG))
1999 EVT VT = N->getValueType(0);
2000 SDValue Ops[] = { Opd0,
2002 CurDAG->getTargetConstant(LSB, VT),
2003 CurDAG->getTargetConstant(MSB, VT) };
2004 return CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2007 SDNode *AArch64DAGToDAGISel::SelectLIBM(SDNode *N) {
2008 EVT VT = N->getValueType(0);
2011 unsigned FRINTXOpcs[] = { AArch64::FRINTXSr, AArch64::FRINTXDr };
2013 if (VT == MVT::f32) {
2015 } else if (VT == MVT::f64) {
2018 return nullptr; // Unrecognized argument type. Fall back on default codegen.
2020 // Pick the FRINTX variant needed to set the flags.
2021 unsigned FRINTXOpc = FRINTXOpcs[Variant];
2023 switch (N->getOpcode()) {
2025 return nullptr; // Unrecognized libm ISD node. Fall back on default codegen.
2027 unsigned FRINTPOpcs[] = { AArch64::FRINTPSr, AArch64::FRINTPDr };
2028 Opc = FRINTPOpcs[Variant];
2032 unsigned FRINTMOpcs[] = { AArch64::FRINTMSr, AArch64::FRINTMDr };
2033 Opc = FRINTMOpcs[Variant];
2037 unsigned FRINTZOpcs[] = { AArch64::FRINTZSr, AArch64::FRINTZDr };
2038 Opc = FRINTZOpcs[Variant];
2042 unsigned FRINTAOpcs[] = { AArch64::FRINTASr, AArch64::FRINTADr };
2043 Opc = FRINTAOpcs[Variant];
2049 SDValue In = N->getOperand(0);
2050 SmallVector<SDValue, 2> Ops;
2053 if (!TM.Options.UnsafeFPMath) {
2054 SDNode *FRINTX = CurDAG->getMachineNode(FRINTXOpc, dl, VT, MVT::Glue, In);
2055 Ops.push_back(SDValue(FRINTX, 1));
2058 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
2062 AArch64DAGToDAGISel::SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
2063 unsigned RegWidth) {
2065 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N))
2066 FVal = CN->getValueAPF();
2067 else if (LoadSDNode *LN = dyn_cast<LoadSDNode>(N)) {
2068 // Some otherwise illegal constants are allowed in this case.
2069 if (LN->getOperand(1).getOpcode() != AArch64ISD::ADDlow ||
2070 !isa<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1)))
2073 ConstantPoolSDNode *CN =
2074 dyn_cast<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1));
2075 FVal = cast<ConstantFP>(CN->getConstVal())->getValueAPF();
2079 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
2080 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
2083 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
2084 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
2088 // fbits is between 1 and 64 in the worst-case, which means the fmul
2089 // could have 2^64 as an actual operand. Need 65 bits of precision.
2090 APSInt IntVal(65, true);
2091 FVal.convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
2093 // N.b. isPowerOf2 also checks for > 0.
2094 if (!IsExact || !IntVal.isPowerOf2()) return false;
2095 unsigned FBits = IntVal.logBase2();
2097 // Checks above should have guaranteed that we haven't lost information in
2098 // finding FBits, but it must still be in range.
2099 if (FBits == 0 || FBits > RegWidth) return false;
2101 FixedPos = CurDAG->getTargetConstant(FBits, MVT::i32);
2105 SDNode *AArch64DAGToDAGISel::Select(SDNode *Node) {
2106 // Dump information about the Node being selected
2107 DEBUG(errs() << "Selecting: ");
2108 DEBUG(Node->dump(CurDAG));
2109 DEBUG(errs() << "\n");
2111 // If we have a custom node, we already have selected!
2112 if (Node->isMachineOpcode()) {
2113 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
2114 Node->setNodeId(-1);
2118 // Few custom selection stuff.
2119 SDNode *ResNode = nullptr;
2120 EVT VT = Node->getValueType(0);
2122 switch (Node->getOpcode()) {
2127 if (SDNode *I = SelectMLAV64LaneV128(Node))
2132 // Try to select as an indexed load. Fall through to normal processing
2135 SDNode *I = SelectIndexedLoad(Node, Done);
2144 if (SDNode *I = SelectBitfieldExtractOp(Node))
2149 if (SDNode *I = SelectBitfieldInsertOp(Node))
2153 case ISD::EXTRACT_VECTOR_ELT: {
2154 // Extracting lane zero is a special case where we can just use a plain
2155 // EXTRACT_SUBREG instruction, which will become FMOV. This is easier for
2156 // the rest of the compiler, especially the register allocator and copyi
2157 // propagation, to reason about, so is preferred when it's possible to
2159 ConstantSDNode *LaneNode = cast<ConstantSDNode>(Node->getOperand(1));
2160 // Bail and use the default Select() for non-zero lanes.
2161 if (LaneNode->getZExtValue() != 0)
2163 // If the element type is not the same as the result type, likewise
2164 // bail and use the default Select(), as there's more to do than just
2165 // a cross-class COPY. This catches extracts of i8 and i16 elements
2166 // since they will need an explicit zext.
2167 if (VT != Node->getOperand(0).getValueType().getVectorElementType())
2170 switch (Node->getOperand(0)
2172 .getVectorElementType()
2175 llvm_unreachable("Unexpected vector element type!");
2177 SubReg = AArch64::dsub;
2180 SubReg = AArch64::ssub;
2183 SubReg = AArch64::hsub;
2186 llvm_unreachable("unexpected zext-requiring extract element!");
2188 SDValue Extract = CurDAG->getTargetExtractSubreg(SubReg, SDLoc(Node), VT,
2189 Node->getOperand(0));
2190 DEBUG(dbgs() << "ISEL: Custom selection!\n=> ");
2191 DEBUG(Extract->dumpr(CurDAG));
2192 DEBUG(dbgs() << "\n");
2193 return Extract.getNode();
2195 case ISD::Constant: {
2196 // Materialize zero constants as copies from WZR/XZR. This allows
2197 // the coalescer to propagate these into other instructions.
2198 ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
2199 if (ConstNode->isNullValue()) {
2201 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDLoc(Node),
2202 AArch64::WZR, MVT::i32).getNode();
2203 else if (VT == MVT::i64)
2204 return CurDAG->getCopyFromReg(CurDAG->getEntryNode(), SDLoc(Node),
2205 AArch64::XZR, MVT::i64).getNode();
2210 case ISD::FrameIndex: {
2211 // Selects to ADDXri FI, 0 which in turn will become ADDXri SP, imm.
2212 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
2213 unsigned Shifter = AArch64_AM::getShifterImm(AArch64_AM::LSL, 0);
2214 const TargetLowering *TLI = getTargetLowering();
2215 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
2216 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2217 CurDAG->getTargetConstant(Shifter, MVT::i32) };
2218 return CurDAG->SelectNodeTo(Node, AArch64::ADDXri, MVT::i64, Ops);
2220 case ISD::INTRINSIC_W_CHAIN: {
2221 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2225 case Intrinsic::aarch64_ldaxp:
2226 case Intrinsic::aarch64_ldxp: {
2228 IntNo == Intrinsic::aarch64_ldaxp ? AArch64::LDAXPX : AArch64::LDXPX;
2229 SDValue MemAddr = Node->getOperand(2);
2231 SDValue Chain = Node->getOperand(0);
2233 SDNode *Ld = CurDAG->getMachineNode(Op, DL, MVT::i64, MVT::i64,
2234 MVT::Other, MemAddr, Chain);
2236 // Transfer memoperands.
2237 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2238 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2239 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2242 case Intrinsic::aarch64_stlxp:
2243 case Intrinsic::aarch64_stxp: {
2245 IntNo == Intrinsic::aarch64_stlxp ? AArch64::STLXPX : AArch64::STXPX;
2247 SDValue Chain = Node->getOperand(0);
2248 SDValue ValLo = Node->getOperand(2);
2249 SDValue ValHi = Node->getOperand(3);
2250 SDValue MemAddr = Node->getOperand(4);
2252 // Place arguments in the right order.
2253 SmallVector<SDValue, 7> Ops;
2254 Ops.push_back(ValLo);
2255 Ops.push_back(ValHi);
2256 Ops.push_back(MemAddr);
2257 Ops.push_back(Chain);
2259 SDNode *St = CurDAG->getMachineNode(Op, DL, MVT::i32, MVT::Other, Ops);
2260 // Transfer memoperands.
2261 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2262 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2263 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2267 case Intrinsic::aarch64_neon_ld1x2:
2268 if (VT == MVT::v8i8)
2269 return SelectLoad(Node, 2, AArch64::LD1Twov8b, AArch64::dsub0);
2270 else if (VT == MVT::v16i8)
2271 return SelectLoad(Node, 2, AArch64::LD1Twov16b, AArch64::qsub0);
2272 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2273 return SelectLoad(Node, 2, AArch64::LD1Twov4h, AArch64::dsub0);
2274 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2275 return SelectLoad(Node, 2, AArch64::LD1Twov8h, AArch64::qsub0);
2276 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2277 return SelectLoad(Node, 2, AArch64::LD1Twov2s, AArch64::dsub0);
2278 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2279 return SelectLoad(Node, 2, AArch64::LD1Twov4s, AArch64::qsub0);
2280 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2281 return SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2282 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2283 return SelectLoad(Node, 2, AArch64::LD1Twov2d, AArch64::qsub0);
2285 case Intrinsic::aarch64_neon_ld1x3:
2286 if (VT == MVT::v8i8)
2287 return SelectLoad(Node, 3, AArch64::LD1Threev8b, AArch64::dsub0);
2288 else if (VT == MVT::v16i8)
2289 return SelectLoad(Node, 3, AArch64::LD1Threev16b, AArch64::qsub0);
2290 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2291 return SelectLoad(Node, 3, AArch64::LD1Threev4h, AArch64::dsub0);
2292 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2293 return SelectLoad(Node, 3, AArch64::LD1Threev8h, AArch64::qsub0);
2294 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2295 return SelectLoad(Node, 3, AArch64::LD1Threev2s, AArch64::dsub0);
2296 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2297 return SelectLoad(Node, 3, AArch64::LD1Threev4s, AArch64::qsub0);
2298 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2299 return SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2300 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2301 return SelectLoad(Node, 3, AArch64::LD1Threev2d, AArch64::qsub0);
2303 case Intrinsic::aarch64_neon_ld1x4:
2304 if (VT == MVT::v8i8)
2305 return SelectLoad(Node, 4, AArch64::LD1Fourv8b, AArch64::dsub0);
2306 else if (VT == MVT::v16i8)
2307 return SelectLoad(Node, 4, AArch64::LD1Fourv16b, AArch64::qsub0);
2308 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2309 return SelectLoad(Node, 4, AArch64::LD1Fourv4h, AArch64::dsub0);
2310 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2311 return SelectLoad(Node, 4, AArch64::LD1Fourv8h, AArch64::qsub0);
2312 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2313 return SelectLoad(Node, 4, AArch64::LD1Fourv2s, AArch64::dsub0);
2314 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2315 return SelectLoad(Node, 4, AArch64::LD1Fourv4s, AArch64::qsub0);
2316 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2317 return SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2318 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2319 return SelectLoad(Node, 4, AArch64::LD1Fourv2d, AArch64::qsub0);
2321 case Intrinsic::aarch64_neon_ld2:
2322 if (VT == MVT::v8i8)
2323 return SelectLoad(Node, 2, AArch64::LD2Twov8b, AArch64::dsub0);
2324 else if (VT == MVT::v16i8)
2325 return SelectLoad(Node, 2, AArch64::LD2Twov16b, AArch64::qsub0);
2326 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2327 return SelectLoad(Node, 2, AArch64::LD2Twov4h, AArch64::dsub0);
2328 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2329 return SelectLoad(Node, 2, AArch64::LD2Twov8h, AArch64::qsub0);
2330 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2331 return SelectLoad(Node, 2, AArch64::LD2Twov2s, AArch64::dsub0);
2332 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2333 return SelectLoad(Node, 2, AArch64::LD2Twov4s, AArch64::qsub0);
2334 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2335 return SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2336 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2337 return SelectLoad(Node, 2, AArch64::LD2Twov2d, AArch64::qsub0);
2339 case Intrinsic::aarch64_neon_ld3:
2340 if (VT == MVT::v8i8)
2341 return SelectLoad(Node, 3, AArch64::LD3Threev8b, AArch64::dsub0);
2342 else if (VT == MVT::v16i8)
2343 return SelectLoad(Node, 3, AArch64::LD3Threev16b, AArch64::qsub0);
2344 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2345 return SelectLoad(Node, 3, AArch64::LD3Threev4h, AArch64::dsub0);
2346 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2347 return SelectLoad(Node, 3, AArch64::LD3Threev8h, AArch64::qsub0);
2348 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2349 return SelectLoad(Node, 3, AArch64::LD3Threev2s, AArch64::dsub0);
2350 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2351 return SelectLoad(Node, 3, AArch64::LD3Threev4s, AArch64::qsub0);
2352 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2353 return SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2354 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2355 return SelectLoad(Node, 3, AArch64::LD3Threev2d, AArch64::qsub0);
2357 case Intrinsic::aarch64_neon_ld4:
2358 if (VT == MVT::v8i8)
2359 return SelectLoad(Node, 4, AArch64::LD4Fourv8b, AArch64::dsub0);
2360 else if (VT == MVT::v16i8)
2361 return SelectLoad(Node, 4, AArch64::LD4Fourv16b, AArch64::qsub0);
2362 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2363 return SelectLoad(Node, 4, AArch64::LD4Fourv4h, AArch64::dsub0);
2364 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2365 return SelectLoad(Node, 4, AArch64::LD4Fourv8h, AArch64::qsub0);
2366 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2367 return SelectLoad(Node, 4, AArch64::LD4Fourv2s, AArch64::dsub0);
2368 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2369 return SelectLoad(Node, 4, AArch64::LD4Fourv4s, AArch64::qsub0);
2370 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2371 return SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2372 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2373 return SelectLoad(Node, 4, AArch64::LD4Fourv2d, AArch64::qsub0);
2375 case Intrinsic::aarch64_neon_ld2r:
2376 if (VT == MVT::v8i8)
2377 return SelectLoad(Node, 2, AArch64::LD2Rv8b, AArch64::dsub0);
2378 else if (VT == MVT::v16i8)
2379 return SelectLoad(Node, 2, AArch64::LD2Rv16b, AArch64::qsub0);
2380 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2381 return SelectLoad(Node, 2, AArch64::LD2Rv4h, AArch64::dsub0);
2382 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2383 return SelectLoad(Node, 2, AArch64::LD2Rv8h, AArch64::qsub0);
2384 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2385 return SelectLoad(Node, 2, AArch64::LD2Rv2s, AArch64::dsub0);
2386 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2387 return SelectLoad(Node, 2, AArch64::LD2Rv4s, AArch64::qsub0);
2388 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2389 return SelectLoad(Node, 2, AArch64::LD2Rv1d, AArch64::dsub0);
2390 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2391 return SelectLoad(Node, 2, AArch64::LD2Rv2d, AArch64::qsub0);
2393 case Intrinsic::aarch64_neon_ld3r:
2394 if (VT == MVT::v8i8)
2395 return SelectLoad(Node, 3, AArch64::LD3Rv8b, AArch64::dsub0);
2396 else if (VT == MVT::v16i8)
2397 return SelectLoad(Node, 3, AArch64::LD3Rv16b, AArch64::qsub0);
2398 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2399 return SelectLoad(Node, 3, AArch64::LD3Rv4h, AArch64::dsub0);
2400 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2401 return SelectLoad(Node, 3, AArch64::LD3Rv8h, AArch64::qsub0);
2402 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2403 return SelectLoad(Node, 3, AArch64::LD3Rv2s, AArch64::dsub0);
2404 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2405 return SelectLoad(Node, 3, AArch64::LD3Rv4s, AArch64::qsub0);
2406 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2407 return SelectLoad(Node, 3, AArch64::LD3Rv1d, AArch64::dsub0);
2408 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2409 return SelectLoad(Node, 3, AArch64::LD3Rv2d, AArch64::qsub0);
2411 case Intrinsic::aarch64_neon_ld4r:
2412 if (VT == MVT::v8i8)
2413 return SelectLoad(Node, 4, AArch64::LD4Rv8b, AArch64::dsub0);
2414 else if (VT == MVT::v16i8)
2415 return SelectLoad(Node, 4, AArch64::LD4Rv16b, AArch64::qsub0);
2416 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2417 return SelectLoad(Node, 4, AArch64::LD4Rv4h, AArch64::dsub0);
2418 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2419 return SelectLoad(Node, 4, AArch64::LD4Rv8h, AArch64::qsub0);
2420 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2421 return SelectLoad(Node, 4, AArch64::LD4Rv2s, AArch64::dsub0);
2422 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2423 return SelectLoad(Node, 4, AArch64::LD4Rv4s, AArch64::qsub0);
2424 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2425 return SelectLoad(Node, 4, AArch64::LD4Rv1d, AArch64::dsub0);
2426 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2427 return SelectLoad(Node, 4, AArch64::LD4Rv2d, AArch64::qsub0);
2429 case Intrinsic::aarch64_neon_ld2lane:
2430 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2431 return SelectLoadLane(Node, 2, AArch64::LD2i8);
2432 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2434 return SelectLoadLane(Node, 2, AArch64::LD2i16);
2435 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2437 return SelectLoadLane(Node, 2, AArch64::LD2i32);
2438 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2440 return SelectLoadLane(Node, 2, AArch64::LD2i64);
2442 case Intrinsic::aarch64_neon_ld3lane:
2443 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2444 return SelectLoadLane(Node, 3, AArch64::LD3i8);
2445 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2447 return SelectLoadLane(Node, 3, AArch64::LD3i16);
2448 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2450 return SelectLoadLane(Node, 3, AArch64::LD3i32);
2451 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2453 return SelectLoadLane(Node, 3, AArch64::LD3i64);
2455 case Intrinsic::aarch64_neon_ld4lane:
2456 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2457 return SelectLoadLane(Node, 4, AArch64::LD4i8);
2458 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2460 return SelectLoadLane(Node, 4, AArch64::LD4i16);
2461 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2463 return SelectLoadLane(Node, 4, AArch64::LD4i32);
2464 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2466 return SelectLoadLane(Node, 4, AArch64::LD4i64);
2470 case ISD::INTRINSIC_WO_CHAIN: {
2471 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue();
2475 case Intrinsic::aarch64_neon_tbl2:
2476 return SelectTable(Node, 2, VT == MVT::v8i8 ? AArch64::TBLv8i8Two
2477 : AArch64::TBLv16i8Two,
2479 case Intrinsic::aarch64_neon_tbl3:
2480 return SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBLv8i8Three
2481 : AArch64::TBLv16i8Three,
2483 case Intrinsic::aarch64_neon_tbl4:
2484 return SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBLv8i8Four
2485 : AArch64::TBLv16i8Four,
2487 case Intrinsic::aarch64_neon_tbx2:
2488 return SelectTable(Node, 2, VT == MVT::v8i8 ? AArch64::TBXv8i8Two
2489 : AArch64::TBXv16i8Two,
2491 case Intrinsic::aarch64_neon_tbx3:
2492 return SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBXv8i8Three
2493 : AArch64::TBXv16i8Three,
2495 case Intrinsic::aarch64_neon_tbx4:
2496 return SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBXv8i8Four
2497 : AArch64::TBXv16i8Four,
2499 case Intrinsic::aarch64_neon_smull:
2500 case Intrinsic::aarch64_neon_umull:
2501 if (SDNode *N = SelectMULLV64LaneV128(IntNo, Node))
2507 case ISD::INTRINSIC_VOID: {
2508 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2509 if (Node->getNumOperands() >= 3)
2510 VT = Node->getOperand(2)->getValueType(0);
2514 case Intrinsic::aarch64_neon_st1x2: {
2515 if (VT == MVT::v8i8)
2516 return SelectStore(Node, 2, AArch64::ST1Twov8b);
2517 else if (VT == MVT::v16i8)
2518 return SelectStore(Node, 2, AArch64::ST1Twov16b);
2519 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2520 return SelectStore(Node, 2, AArch64::ST1Twov4h);
2521 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2522 return SelectStore(Node, 2, AArch64::ST1Twov8h);
2523 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2524 return SelectStore(Node, 2, AArch64::ST1Twov2s);
2525 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2526 return SelectStore(Node, 2, AArch64::ST1Twov4s);
2527 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2528 return SelectStore(Node, 2, AArch64::ST1Twov2d);
2529 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2530 return SelectStore(Node, 2, AArch64::ST1Twov1d);
2533 case Intrinsic::aarch64_neon_st1x3: {
2534 if (VT == MVT::v8i8)
2535 return SelectStore(Node, 3, AArch64::ST1Threev8b);
2536 else if (VT == MVT::v16i8)
2537 return SelectStore(Node, 3, AArch64::ST1Threev16b);
2538 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2539 return SelectStore(Node, 3, AArch64::ST1Threev4h);
2540 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2541 return SelectStore(Node, 3, AArch64::ST1Threev8h);
2542 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2543 return SelectStore(Node, 3, AArch64::ST1Threev2s);
2544 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2545 return SelectStore(Node, 3, AArch64::ST1Threev4s);
2546 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2547 return SelectStore(Node, 3, AArch64::ST1Threev2d);
2548 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2549 return SelectStore(Node, 3, AArch64::ST1Threev1d);
2552 case Intrinsic::aarch64_neon_st1x4: {
2553 if (VT == MVT::v8i8)
2554 return SelectStore(Node, 4, AArch64::ST1Fourv8b);
2555 else if (VT == MVT::v16i8)
2556 return SelectStore(Node, 4, AArch64::ST1Fourv16b);
2557 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2558 return SelectStore(Node, 4, AArch64::ST1Fourv4h);
2559 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2560 return SelectStore(Node, 4, AArch64::ST1Fourv8h);
2561 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2562 return SelectStore(Node, 4, AArch64::ST1Fourv2s);
2563 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2564 return SelectStore(Node, 4, AArch64::ST1Fourv4s);
2565 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2566 return SelectStore(Node, 4, AArch64::ST1Fourv2d);
2567 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2568 return SelectStore(Node, 4, AArch64::ST1Fourv1d);
2571 case Intrinsic::aarch64_neon_st2: {
2572 if (VT == MVT::v8i8)
2573 return SelectStore(Node, 2, AArch64::ST2Twov8b);
2574 else if (VT == MVT::v16i8)
2575 return SelectStore(Node, 2, AArch64::ST2Twov16b);
2576 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2577 return SelectStore(Node, 2, AArch64::ST2Twov4h);
2578 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2579 return SelectStore(Node, 2, AArch64::ST2Twov8h);
2580 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2581 return SelectStore(Node, 2, AArch64::ST2Twov2s);
2582 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2583 return SelectStore(Node, 2, AArch64::ST2Twov4s);
2584 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2585 return SelectStore(Node, 2, AArch64::ST2Twov2d);
2586 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2587 return SelectStore(Node, 2, AArch64::ST1Twov1d);
2590 case Intrinsic::aarch64_neon_st3: {
2591 if (VT == MVT::v8i8)
2592 return SelectStore(Node, 3, AArch64::ST3Threev8b);
2593 else if (VT == MVT::v16i8)
2594 return SelectStore(Node, 3, AArch64::ST3Threev16b);
2595 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2596 return SelectStore(Node, 3, AArch64::ST3Threev4h);
2597 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2598 return SelectStore(Node, 3, AArch64::ST3Threev8h);
2599 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2600 return SelectStore(Node, 3, AArch64::ST3Threev2s);
2601 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2602 return SelectStore(Node, 3, AArch64::ST3Threev4s);
2603 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2604 return SelectStore(Node, 3, AArch64::ST3Threev2d);
2605 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2606 return SelectStore(Node, 3, AArch64::ST1Threev1d);
2609 case Intrinsic::aarch64_neon_st4: {
2610 if (VT == MVT::v8i8)
2611 return SelectStore(Node, 4, AArch64::ST4Fourv8b);
2612 else if (VT == MVT::v16i8)
2613 return SelectStore(Node, 4, AArch64::ST4Fourv16b);
2614 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2615 return SelectStore(Node, 4, AArch64::ST4Fourv4h);
2616 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2617 return SelectStore(Node, 4, AArch64::ST4Fourv8h);
2618 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2619 return SelectStore(Node, 4, AArch64::ST4Fourv2s);
2620 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2621 return SelectStore(Node, 4, AArch64::ST4Fourv4s);
2622 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2623 return SelectStore(Node, 4, AArch64::ST4Fourv2d);
2624 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2625 return SelectStore(Node, 4, AArch64::ST1Fourv1d);
2628 case Intrinsic::aarch64_neon_st2lane: {
2629 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2630 return SelectStoreLane(Node, 2, AArch64::ST2i8);
2631 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2633 return SelectStoreLane(Node, 2, AArch64::ST2i16);
2634 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2636 return SelectStoreLane(Node, 2, AArch64::ST2i32);
2637 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2639 return SelectStoreLane(Node, 2, AArch64::ST2i64);
2642 case Intrinsic::aarch64_neon_st3lane: {
2643 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2644 return SelectStoreLane(Node, 3, AArch64::ST3i8);
2645 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2647 return SelectStoreLane(Node, 3, AArch64::ST3i16);
2648 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2650 return SelectStoreLane(Node, 3, AArch64::ST3i32);
2651 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2653 return SelectStoreLane(Node, 3, AArch64::ST3i64);
2656 case Intrinsic::aarch64_neon_st4lane: {
2657 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2658 return SelectStoreLane(Node, 4, AArch64::ST4i8);
2659 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2661 return SelectStoreLane(Node, 4, AArch64::ST4i16);
2662 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2664 return SelectStoreLane(Node, 4, AArch64::ST4i32);
2665 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2667 return SelectStoreLane(Node, 4, AArch64::ST4i64);
2672 case AArch64ISD::LD2post: {
2673 if (VT == MVT::v8i8)
2674 return SelectPostLoad(Node, 2, AArch64::LD2Twov8b_POST, AArch64::dsub0);
2675 else if (VT == MVT::v16i8)
2676 return SelectPostLoad(Node, 2, AArch64::LD2Twov16b_POST, AArch64::qsub0);
2677 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2678 return SelectPostLoad(Node, 2, AArch64::LD2Twov4h_POST, AArch64::dsub0);
2679 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2680 return SelectPostLoad(Node, 2, AArch64::LD2Twov8h_POST, AArch64::qsub0);
2681 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2682 return SelectPostLoad(Node, 2, AArch64::LD2Twov2s_POST, AArch64::dsub0);
2683 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2684 return SelectPostLoad(Node, 2, AArch64::LD2Twov4s_POST, AArch64::qsub0);
2685 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2686 return SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
2687 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2688 return SelectPostLoad(Node, 2, AArch64::LD2Twov2d_POST, AArch64::qsub0);
2691 case AArch64ISD::LD3post: {
2692 if (VT == MVT::v8i8)
2693 return SelectPostLoad(Node, 3, AArch64::LD3Threev8b_POST, AArch64::dsub0);
2694 else if (VT == MVT::v16i8)
2695 return SelectPostLoad(Node, 3, AArch64::LD3Threev16b_POST, AArch64::qsub0);
2696 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2697 return SelectPostLoad(Node, 3, AArch64::LD3Threev4h_POST, AArch64::dsub0);
2698 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2699 return SelectPostLoad(Node, 3, AArch64::LD3Threev8h_POST, AArch64::qsub0);
2700 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2701 return SelectPostLoad(Node, 3, AArch64::LD3Threev2s_POST, AArch64::dsub0);
2702 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2703 return SelectPostLoad(Node, 3, AArch64::LD3Threev4s_POST, AArch64::qsub0);
2704 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2705 return SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
2706 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2707 return SelectPostLoad(Node, 3, AArch64::LD3Threev2d_POST, AArch64::qsub0);
2710 case AArch64ISD::LD4post: {
2711 if (VT == MVT::v8i8)
2712 return SelectPostLoad(Node, 4, AArch64::LD4Fourv8b_POST, AArch64::dsub0);
2713 else if (VT == MVT::v16i8)
2714 return SelectPostLoad(Node, 4, AArch64::LD4Fourv16b_POST, AArch64::qsub0);
2715 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2716 return SelectPostLoad(Node, 4, AArch64::LD4Fourv4h_POST, AArch64::dsub0);
2717 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2718 return SelectPostLoad(Node, 4, AArch64::LD4Fourv8h_POST, AArch64::qsub0);
2719 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2720 return SelectPostLoad(Node, 4, AArch64::LD4Fourv2s_POST, AArch64::dsub0);
2721 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2722 return SelectPostLoad(Node, 4, AArch64::LD4Fourv4s_POST, AArch64::qsub0);
2723 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2724 return SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
2725 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2726 return SelectPostLoad(Node, 4, AArch64::LD4Fourv2d_POST, AArch64::qsub0);
2729 case AArch64ISD::LD1x2post: {
2730 if (VT == MVT::v8i8)
2731 return SelectPostLoad(Node, 2, AArch64::LD1Twov8b_POST, AArch64::dsub0);
2732 else if (VT == MVT::v16i8)
2733 return SelectPostLoad(Node, 2, AArch64::LD1Twov16b_POST, AArch64::qsub0);
2734 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2735 return SelectPostLoad(Node, 2, AArch64::LD1Twov4h_POST, AArch64::dsub0);
2736 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2737 return SelectPostLoad(Node, 2, AArch64::LD1Twov8h_POST, AArch64::qsub0);
2738 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2739 return SelectPostLoad(Node, 2, AArch64::LD1Twov2s_POST, AArch64::dsub0);
2740 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2741 return SelectPostLoad(Node, 2, AArch64::LD1Twov4s_POST, AArch64::qsub0);
2742 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2743 return SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
2744 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2745 return SelectPostLoad(Node, 2, AArch64::LD1Twov2d_POST, AArch64::qsub0);
2748 case AArch64ISD::LD1x3post: {
2749 if (VT == MVT::v8i8)
2750 return SelectPostLoad(Node, 3, AArch64::LD1Threev8b_POST, AArch64::dsub0);
2751 else if (VT == MVT::v16i8)
2752 return SelectPostLoad(Node, 3, AArch64::LD1Threev16b_POST, AArch64::qsub0);
2753 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2754 return SelectPostLoad(Node, 3, AArch64::LD1Threev4h_POST, AArch64::dsub0);
2755 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2756 return SelectPostLoad(Node, 3, AArch64::LD1Threev8h_POST, AArch64::qsub0);
2757 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2758 return SelectPostLoad(Node, 3, AArch64::LD1Threev2s_POST, AArch64::dsub0);
2759 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2760 return SelectPostLoad(Node, 3, AArch64::LD1Threev4s_POST, AArch64::qsub0);
2761 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2762 return SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
2763 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2764 return SelectPostLoad(Node, 3, AArch64::LD1Threev2d_POST, AArch64::qsub0);
2767 case AArch64ISD::LD1x4post: {
2768 if (VT == MVT::v8i8)
2769 return SelectPostLoad(Node, 4, AArch64::LD1Fourv8b_POST, AArch64::dsub0);
2770 else if (VT == MVT::v16i8)
2771 return SelectPostLoad(Node, 4, AArch64::LD1Fourv16b_POST, AArch64::qsub0);
2772 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2773 return SelectPostLoad(Node, 4, AArch64::LD1Fourv4h_POST, AArch64::dsub0);
2774 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2775 return SelectPostLoad(Node, 4, AArch64::LD1Fourv8h_POST, AArch64::qsub0);
2776 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2777 return SelectPostLoad(Node, 4, AArch64::LD1Fourv2s_POST, AArch64::dsub0);
2778 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2779 return SelectPostLoad(Node, 4, AArch64::LD1Fourv4s_POST, AArch64::qsub0);
2780 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2781 return SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
2782 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2783 return SelectPostLoad(Node, 4, AArch64::LD1Fourv2d_POST, AArch64::qsub0);
2786 case AArch64ISD::LD1DUPpost: {
2787 if (VT == MVT::v8i8)
2788 return SelectPostLoad(Node, 1, AArch64::LD1Rv8b_POST, AArch64::dsub0);
2789 else if (VT == MVT::v16i8)
2790 return SelectPostLoad(Node, 1, AArch64::LD1Rv16b_POST, AArch64::qsub0);
2791 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2792 return SelectPostLoad(Node, 1, AArch64::LD1Rv4h_POST, AArch64::dsub0);
2793 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2794 return SelectPostLoad(Node, 1, AArch64::LD1Rv8h_POST, AArch64::qsub0);
2795 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2796 return SelectPostLoad(Node, 1, AArch64::LD1Rv2s_POST, AArch64::dsub0);
2797 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2798 return SelectPostLoad(Node, 1, AArch64::LD1Rv4s_POST, AArch64::qsub0);
2799 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2800 return SelectPostLoad(Node, 1, AArch64::LD1Rv1d_POST, AArch64::dsub0);
2801 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2802 return SelectPostLoad(Node, 1, AArch64::LD1Rv2d_POST, AArch64::qsub0);
2805 case AArch64ISD::LD2DUPpost: {
2806 if (VT == MVT::v8i8)
2807 return SelectPostLoad(Node, 2, AArch64::LD2Rv8b_POST, AArch64::dsub0);
2808 else if (VT == MVT::v16i8)
2809 return SelectPostLoad(Node, 2, AArch64::LD2Rv16b_POST, AArch64::qsub0);
2810 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2811 return SelectPostLoad(Node, 2, AArch64::LD2Rv4h_POST, AArch64::dsub0);
2812 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2813 return SelectPostLoad(Node, 2, AArch64::LD2Rv8h_POST, AArch64::qsub0);
2814 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2815 return SelectPostLoad(Node, 2, AArch64::LD2Rv2s_POST, AArch64::dsub0);
2816 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2817 return SelectPostLoad(Node, 2, AArch64::LD2Rv4s_POST, AArch64::qsub0);
2818 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2819 return SelectPostLoad(Node, 2, AArch64::LD2Rv1d_POST, AArch64::dsub0);
2820 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2821 return SelectPostLoad(Node, 2, AArch64::LD2Rv2d_POST, AArch64::qsub0);
2824 case AArch64ISD::LD3DUPpost: {
2825 if (VT == MVT::v8i8)
2826 return SelectPostLoad(Node, 3, AArch64::LD3Rv8b_POST, AArch64::dsub0);
2827 else if (VT == MVT::v16i8)
2828 return SelectPostLoad(Node, 3, AArch64::LD3Rv16b_POST, AArch64::qsub0);
2829 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2830 return SelectPostLoad(Node, 3, AArch64::LD3Rv4h_POST, AArch64::dsub0);
2831 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2832 return SelectPostLoad(Node, 3, AArch64::LD3Rv8h_POST, AArch64::qsub0);
2833 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2834 return SelectPostLoad(Node, 3, AArch64::LD3Rv2s_POST, AArch64::dsub0);
2835 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2836 return SelectPostLoad(Node, 3, AArch64::LD3Rv4s_POST, AArch64::qsub0);
2837 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2838 return SelectPostLoad(Node, 3, AArch64::LD3Rv1d_POST, AArch64::dsub0);
2839 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2840 return SelectPostLoad(Node, 3, AArch64::LD3Rv2d_POST, AArch64::qsub0);
2843 case AArch64ISD::LD4DUPpost: {
2844 if (VT == MVT::v8i8)
2845 return SelectPostLoad(Node, 4, AArch64::LD4Rv8b_POST, AArch64::dsub0);
2846 else if (VT == MVT::v16i8)
2847 return SelectPostLoad(Node, 4, AArch64::LD4Rv16b_POST, AArch64::qsub0);
2848 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2849 return SelectPostLoad(Node, 4, AArch64::LD4Rv4h_POST, AArch64::dsub0);
2850 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2851 return SelectPostLoad(Node, 4, AArch64::LD4Rv8h_POST, AArch64::qsub0);
2852 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2853 return SelectPostLoad(Node, 4, AArch64::LD4Rv2s_POST, AArch64::dsub0);
2854 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2855 return SelectPostLoad(Node, 4, AArch64::LD4Rv4s_POST, AArch64::qsub0);
2856 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2857 return SelectPostLoad(Node, 4, AArch64::LD4Rv1d_POST, AArch64::dsub0);
2858 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2859 return SelectPostLoad(Node, 4, AArch64::LD4Rv2d_POST, AArch64::qsub0);
2862 case AArch64ISD::LD1LANEpost: {
2863 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2864 return SelectPostLoadLane(Node, 1, AArch64::LD1i8_POST);
2865 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2867 return SelectPostLoadLane(Node, 1, AArch64::LD1i16_POST);
2868 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2870 return SelectPostLoadLane(Node, 1, AArch64::LD1i32_POST);
2871 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2873 return SelectPostLoadLane(Node, 1, AArch64::LD1i64_POST);
2876 case AArch64ISD::LD2LANEpost: {
2877 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2878 return SelectPostLoadLane(Node, 2, AArch64::LD2i8_POST);
2879 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2881 return SelectPostLoadLane(Node, 2, AArch64::LD2i16_POST);
2882 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2884 return SelectPostLoadLane(Node, 2, AArch64::LD2i32_POST);
2885 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2887 return SelectPostLoadLane(Node, 2, AArch64::LD2i64_POST);
2890 case AArch64ISD::LD3LANEpost: {
2891 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2892 return SelectPostLoadLane(Node, 3, AArch64::LD3i8_POST);
2893 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2895 return SelectPostLoadLane(Node, 3, AArch64::LD3i16_POST);
2896 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2898 return SelectPostLoadLane(Node, 3, AArch64::LD3i32_POST);
2899 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2901 return SelectPostLoadLane(Node, 3, AArch64::LD3i64_POST);
2904 case AArch64ISD::LD4LANEpost: {
2905 if (VT == MVT::v16i8 || VT == MVT::v8i8)
2906 return SelectPostLoadLane(Node, 4, AArch64::LD4i8_POST);
2907 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
2909 return SelectPostLoadLane(Node, 4, AArch64::LD4i16_POST);
2910 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
2912 return SelectPostLoadLane(Node, 4, AArch64::LD4i32_POST);
2913 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
2915 return SelectPostLoadLane(Node, 4, AArch64::LD4i64_POST);
2918 case AArch64ISD::ST2post: {
2919 VT = Node->getOperand(1).getValueType();
2920 if (VT == MVT::v8i8)
2921 return SelectPostStore(Node, 2, AArch64::ST2Twov8b_POST);
2922 else if (VT == MVT::v16i8)
2923 return SelectPostStore(Node, 2, AArch64::ST2Twov16b_POST);
2924 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2925 return SelectPostStore(Node, 2, AArch64::ST2Twov4h_POST);
2926 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2927 return SelectPostStore(Node, 2, AArch64::ST2Twov8h_POST);
2928 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2929 return SelectPostStore(Node, 2, AArch64::ST2Twov2s_POST);
2930 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2931 return SelectPostStore(Node, 2, AArch64::ST2Twov4s_POST);
2932 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2933 return SelectPostStore(Node, 2, AArch64::ST2Twov2d_POST);
2934 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2935 return SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
2938 case AArch64ISD::ST3post: {
2939 VT = Node->getOperand(1).getValueType();
2940 if (VT == MVT::v8i8)
2941 return SelectPostStore(Node, 3, AArch64::ST3Threev8b_POST);
2942 else if (VT == MVT::v16i8)
2943 return SelectPostStore(Node, 3, AArch64::ST3Threev16b_POST);
2944 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2945 return SelectPostStore(Node, 3, AArch64::ST3Threev4h_POST);
2946 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2947 return SelectPostStore(Node, 3, AArch64::ST3Threev8h_POST);
2948 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2949 return SelectPostStore(Node, 3, AArch64::ST3Threev2s_POST);
2950 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2951 return SelectPostStore(Node, 3, AArch64::ST3Threev4s_POST);
2952 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2953 return SelectPostStore(Node, 3, AArch64::ST3Threev2d_POST);
2954 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2955 return SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
2958 case AArch64ISD::ST4post: {
2959 VT = Node->getOperand(1).getValueType();
2960 if (VT == MVT::v8i8)
2961 return SelectPostStore(Node, 4, AArch64::ST4Fourv8b_POST);
2962 else if (VT == MVT::v16i8)
2963 return SelectPostStore(Node, 4, AArch64::ST4Fourv16b_POST);
2964 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2965 return SelectPostStore(Node, 4, AArch64::ST4Fourv4h_POST);
2966 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2967 return SelectPostStore(Node, 4, AArch64::ST4Fourv8h_POST);
2968 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2969 return SelectPostStore(Node, 4, AArch64::ST4Fourv2s_POST);
2970 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2971 return SelectPostStore(Node, 4, AArch64::ST4Fourv4s_POST);
2972 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2973 return SelectPostStore(Node, 4, AArch64::ST4Fourv2d_POST);
2974 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2975 return SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
2978 case AArch64ISD::ST1x2post: {
2979 VT = Node->getOperand(1).getValueType();
2980 if (VT == MVT::v8i8)
2981 return SelectPostStore(Node, 2, AArch64::ST1Twov8b_POST);
2982 else if (VT == MVT::v16i8)
2983 return SelectPostStore(Node, 2, AArch64::ST1Twov16b_POST);
2984 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
2985 return SelectPostStore(Node, 2, AArch64::ST1Twov4h_POST);
2986 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
2987 return SelectPostStore(Node, 2, AArch64::ST1Twov8h_POST);
2988 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
2989 return SelectPostStore(Node, 2, AArch64::ST1Twov2s_POST);
2990 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
2991 return SelectPostStore(Node, 2, AArch64::ST1Twov4s_POST);
2992 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
2993 return SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
2994 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
2995 return SelectPostStore(Node, 2, AArch64::ST1Twov2d_POST);
2998 case AArch64ISD::ST1x3post: {
2999 VT = Node->getOperand(1).getValueType();
3000 if (VT == MVT::v8i8)
3001 return SelectPostStore(Node, 3, AArch64::ST1Threev8b_POST);
3002 else if (VT == MVT::v16i8)
3003 return SelectPostStore(Node, 3, AArch64::ST1Threev16b_POST);
3004 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
3005 return SelectPostStore(Node, 3, AArch64::ST1Threev4h_POST);
3006 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
3007 return SelectPostStore(Node, 3, AArch64::ST1Threev8h_POST);
3008 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3009 return SelectPostStore(Node, 3, AArch64::ST1Threev2s_POST);
3010 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3011 return SelectPostStore(Node, 3, AArch64::ST1Threev4s_POST);
3012 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3013 return SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3014 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3015 return SelectPostStore(Node, 3, AArch64::ST1Threev2d_POST);
3018 case AArch64ISD::ST1x4post: {
3019 VT = Node->getOperand(1).getValueType();
3020 if (VT == MVT::v8i8)
3021 return SelectPostStore(Node, 4, AArch64::ST1Fourv8b_POST);
3022 else if (VT == MVT::v16i8)
3023 return SelectPostStore(Node, 4, AArch64::ST1Fourv16b_POST);
3024 else if (VT == MVT::v4i16 || VT == MVT::v4f16)
3025 return SelectPostStore(Node, 4, AArch64::ST1Fourv4h_POST);
3026 else if (VT == MVT::v8i16 || VT == MVT::v8f16)
3027 return SelectPostStore(Node, 4, AArch64::ST1Fourv8h_POST);
3028 else if (VT == MVT::v2i32 || VT == MVT::v2f32)
3029 return SelectPostStore(Node, 4, AArch64::ST1Fourv2s_POST);
3030 else if (VT == MVT::v4i32 || VT == MVT::v4f32)
3031 return SelectPostStore(Node, 4, AArch64::ST1Fourv4s_POST);
3032 else if (VT == MVT::v1i64 || VT == MVT::v1f64)
3033 return SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3034 else if (VT == MVT::v2i64 || VT == MVT::v2f64)
3035 return SelectPostStore(Node, 4, AArch64::ST1Fourv2d_POST);
3038 case AArch64ISD::ST2LANEpost: {
3039 VT = Node->getOperand(1).getValueType();
3040 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3041 return SelectPostStoreLane(Node, 2, AArch64::ST2i8_POST);
3042 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3044 return SelectPostStoreLane(Node, 2, AArch64::ST2i16_POST);
3045 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3047 return SelectPostStoreLane(Node, 2, AArch64::ST2i32_POST);
3048 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3050 return SelectPostStoreLane(Node, 2, AArch64::ST2i64_POST);
3053 case AArch64ISD::ST3LANEpost: {
3054 VT = Node->getOperand(1).getValueType();
3055 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3056 return SelectPostStoreLane(Node, 3, AArch64::ST3i8_POST);
3057 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3059 return SelectPostStoreLane(Node, 3, AArch64::ST3i16_POST);
3060 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3062 return SelectPostStoreLane(Node, 3, AArch64::ST3i32_POST);
3063 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3065 return SelectPostStoreLane(Node, 3, AArch64::ST3i64_POST);
3068 case AArch64ISD::ST4LANEpost: {
3069 VT = Node->getOperand(1).getValueType();
3070 if (VT == MVT::v16i8 || VT == MVT::v8i8)
3071 return SelectPostStoreLane(Node, 4, AArch64::ST4i8_POST);
3072 else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3074 return SelectPostStoreLane(Node, 4, AArch64::ST4i16_POST);
3075 else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3077 return SelectPostStoreLane(Node, 4, AArch64::ST4i32_POST);
3078 else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3080 return SelectPostStoreLane(Node, 4, AArch64::ST4i64_POST);
3088 if (SDNode *I = SelectLIBM(Node))
3093 // Select the default instruction
3094 ResNode = SelectCode(Node);
3096 DEBUG(errs() << "=> ");
3097 if (ResNode == nullptr || ResNode == Node)
3098 DEBUG(Node->dump(CurDAG));
3100 DEBUG(ResNode->dump(CurDAG));
3101 DEBUG(errs() << "\n");
3106 /// createAArch64ISelDag - This pass converts a legalized DAG into a
3107 /// AArch64-specific DAG, ready for instruction scheduling.
3108 FunctionPass *llvm::createAArch64ISelDag(AArch64TargetMachine &TM,
3109 CodeGenOpt::Level OptLevel) {
3110 return new AArch64DAGToDAGISel(TM, OptLevel);