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/KnownBits.h"
24 #include "llvm/Support/MathExtras.h"
25 #include "llvm/Support/raw_ostream.h"
29 #define DEBUG_TYPE "aarch64-isel"
31 //===--------------------------------------------------------------------===//
32 /// AArch64DAGToDAGISel - AArch64 specific code to select AArch64 machine
33 /// instructions for SelectionDAG operations.
37 class AArch64DAGToDAGISel : public SelectionDAGISel {
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), Subtarget(nullptr),
51 StringRef getPassName() const override {
52 return "AArch64 Instruction Selection";
55 bool runOnMachineFunction(MachineFunction &MF) override {
56 ForCodeSize = MF.getFunction().optForSize();
57 Subtarget = &MF.getSubtarget<AArch64Subtarget>();
58 return SelectionDAGISel::runOnMachineFunction(MF);
61 void Select(SDNode *Node) override;
63 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
64 /// inline asm expressions.
65 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
66 unsigned ConstraintID,
67 std::vector<SDValue> &OutOps) override;
69 bool tryMLAV64LaneV128(SDNode *N);
70 bool tryMULLV64LaneV128(unsigned IntNo, SDNode *N);
71 bool SelectArithExtendedRegister(SDValue N, SDValue &Reg, SDValue &Shift);
72 bool SelectArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
73 bool SelectNegArithImmed(SDValue N, SDValue &Val, SDValue &Shift);
74 bool SelectArithShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
75 return SelectShiftedRegister(N, false, Reg, Shift);
77 bool SelectLogicalShiftedRegister(SDValue N, SDValue &Reg, SDValue &Shift) {
78 return SelectShiftedRegister(N, true, Reg, Shift);
80 bool SelectAddrModeIndexed7S8(SDValue N, SDValue &Base, SDValue &OffImm) {
81 return SelectAddrModeIndexed7S(N, 1, Base, OffImm);
83 bool SelectAddrModeIndexed7S16(SDValue N, SDValue &Base, SDValue &OffImm) {
84 return SelectAddrModeIndexed7S(N, 2, Base, OffImm);
86 bool SelectAddrModeIndexed7S32(SDValue N, SDValue &Base, SDValue &OffImm) {
87 return SelectAddrModeIndexed7S(N, 4, Base, OffImm);
89 bool SelectAddrModeIndexed7S64(SDValue N, SDValue &Base, SDValue &OffImm) {
90 return SelectAddrModeIndexed7S(N, 8, Base, OffImm);
92 bool SelectAddrModeIndexed7S128(SDValue N, SDValue &Base, SDValue &OffImm) {
93 return SelectAddrModeIndexed7S(N, 16, Base, OffImm);
95 bool SelectAddrModeIndexed8(SDValue N, SDValue &Base, SDValue &OffImm) {
96 return SelectAddrModeIndexed(N, 1, Base, OffImm);
98 bool SelectAddrModeIndexed16(SDValue N, SDValue &Base, SDValue &OffImm) {
99 return SelectAddrModeIndexed(N, 2, Base, OffImm);
101 bool SelectAddrModeIndexed32(SDValue N, SDValue &Base, SDValue &OffImm) {
102 return SelectAddrModeIndexed(N, 4, Base, OffImm);
104 bool SelectAddrModeIndexed64(SDValue N, SDValue &Base, SDValue &OffImm) {
105 return SelectAddrModeIndexed(N, 8, Base, OffImm);
107 bool SelectAddrModeIndexed128(SDValue N, SDValue &Base, SDValue &OffImm) {
108 return SelectAddrModeIndexed(N, 16, Base, OffImm);
110 bool SelectAddrModeUnscaled8(SDValue N, SDValue &Base, SDValue &OffImm) {
111 return SelectAddrModeUnscaled(N, 1, Base, OffImm);
113 bool SelectAddrModeUnscaled16(SDValue N, SDValue &Base, SDValue &OffImm) {
114 return SelectAddrModeUnscaled(N, 2, Base, OffImm);
116 bool SelectAddrModeUnscaled32(SDValue N, SDValue &Base, SDValue &OffImm) {
117 return SelectAddrModeUnscaled(N, 4, Base, OffImm);
119 bool SelectAddrModeUnscaled64(SDValue N, SDValue &Base, SDValue &OffImm) {
120 return SelectAddrModeUnscaled(N, 8, Base, OffImm);
122 bool SelectAddrModeUnscaled128(SDValue N, SDValue &Base, SDValue &OffImm) {
123 return SelectAddrModeUnscaled(N, 16, Base, OffImm);
127 bool SelectAddrModeWRO(SDValue N, SDValue &Base, SDValue &Offset,
128 SDValue &SignExtend, SDValue &DoShift) {
129 return SelectAddrModeWRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
133 bool SelectAddrModeXRO(SDValue N, SDValue &Base, SDValue &Offset,
134 SDValue &SignExtend, SDValue &DoShift) {
135 return SelectAddrModeXRO(N, Width / 8, Base, Offset, SignExtend, DoShift);
139 /// Form sequences of consecutive 64/128-bit registers for use in NEON
140 /// instructions making use of a vector-list (e.g. ldN, tbl). Vecs must have
141 /// between 1 and 4 elements. If it contains a single element that is returned
142 /// unchanged; otherwise a REG_SEQUENCE value is returned.
143 SDValue createDTuple(ArrayRef<SDValue> Vecs);
144 SDValue createQTuple(ArrayRef<SDValue> Vecs);
146 /// Generic helper for the createDTuple/createQTuple
147 /// functions. Those should almost always be called instead.
148 SDValue createTuple(ArrayRef<SDValue> Vecs, const unsigned RegClassIDs[],
149 const unsigned SubRegs[]);
151 void SelectTable(SDNode *N, unsigned NumVecs, unsigned Opc, bool isExt);
153 bool tryIndexedLoad(SDNode *N);
155 void SelectLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
157 void SelectPostLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
159 void SelectLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
160 void SelectPostLoadLane(SDNode *N, unsigned NumVecs, unsigned Opc);
162 void SelectStore(SDNode *N, unsigned NumVecs, unsigned Opc);
163 void SelectPostStore(SDNode *N, unsigned NumVecs, unsigned Opc);
164 void SelectStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
165 void SelectPostStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
167 bool tryBitfieldExtractOp(SDNode *N);
168 bool tryBitfieldExtractOpFromSExt(SDNode *N);
169 bool tryBitfieldInsertOp(SDNode *N);
170 bool tryBitfieldInsertInZeroOp(SDNode *N);
171 bool tryShiftAmountMod(SDNode *N);
173 bool tryReadRegister(SDNode *N);
174 bool tryWriteRegister(SDNode *N);
176 // Include the pieces autogenerated from the target description.
177 #include "AArch64GenDAGISel.inc"
180 bool SelectShiftedRegister(SDValue N, bool AllowROR, SDValue &Reg,
182 bool SelectAddrModeIndexed7S(SDValue N, unsigned Size, SDValue &Base,
184 bool SelectAddrModeIndexed(SDValue N, unsigned Size, SDValue &Base,
186 bool SelectAddrModeUnscaled(SDValue N, unsigned Size, SDValue &Base,
188 bool SelectAddrModeWRO(SDValue N, unsigned Size, SDValue &Base,
189 SDValue &Offset, SDValue &SignExtend,
191 bool SelectAddrModeXRO(SDValue N, unsigned Size, SDValue &Base,
192 SDValue &Offset, SDValue &SignExtend,
194 bool isWorthFolding(SDValue V) const;
195 bool SelectExtendedSHL(SDValue N, unsigned Size, bool WantExtend,
196 SDValue &Offset, SDValue &SignExtend);
198 template<unsigned RegWidth>
199 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos) {
200 return SelectCVTFixedPosOperand(N, FixedPos, RegWidth);
203 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos, unsigned Width);
205 bool SelectCMP_SWAP(SDNode *N);
208 } // end anonymous namespace
210 /// isIntImmediate - This method tests to see if the node is a constant
211 /// operand. If so Imm will receive the 32-bit value.
212 static bool isIntImmediate(const SDNode *N, uint64_t &Imm) {
213 if (const ConstantSDNode *C = dyn_cast<const ConstantSDNode>(N)) {
214 Imm = C->getZExtValue();
220 // isIntImmediate - This method tests to see if a constant operand.
221 // If so Imm will receive the value.
222 static bool isIntImmediate(SDValue N, uint64_t &Imm) {
223 return isIntImmediate(N.getNode(), Imm);
226 // isOpcWithIntImmediate - This method tests to see if the node is a specific
227 // opcode and that it has a immediate integer right operand.
228 // If so Imm will receive the 32 bit value.
229 static bool isOpcWithIntImmediate(const SDNode *N, unsigned Opc,
231 return N->getOpcode() == Opc &&
232 isIntImmediate(N->getOperand(1).getNode(), Imm);
235 bool AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(
236 const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
237 switch(ConstraintID) {
239 llvm_unreachable("Unexpected asm memory constraint");
240 case InlineAsm::Constraint_i:
241 case InlineAsm::Constraint_m:
242 case InlineAsm::Constraint_Q:
243 // We need to make sure that this one operand does not end up in XZR, thus
244 // require the address to be in a PointerRegClass register.
245 const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
246 const TargetRegisterClass *TRC = TRI->getPointerRegClass(*MF);
248 SDValue RC = CurDAG->getTargetConstant(TRC->getID(), dl, MVT::i64);
250 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
251 dl, Op.getValueType(),
253 OutOps.push_back(NewOp);
259 /// SelectArithImmed - Select an immediate value that can be represented as
260 /// a 12-bit value shifted left by either 0 or 12. If so, return true with
261 /// Val set to the 12-bit value and Shift set to the shifter operand.
262 bool AArch64DAGToDAGISel::SelectArithImmed(SDValue N, SDValue &Val,
264 // This function is called from the addsub_shifted_imm ComplexPattern,
265 // which lists [imm] as the list of opcode it's interested in, however
266 // we still need to check whether the operand is actually an immediate
267 // here because the ComplexPattern opcode list is only used in
268 // root-level opcode matching.
269 if (!isa<ConstantSDNode>(N.getNode()))
272 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
275 if (Immed >> 12 == 0) {
277 } else if ((Immed & 0xfff) == 0 && Immed >> 24 == 0) {
283 unsigned ShVal = AArch64_AM::getShifterImm(AArch64_AM::LSL, ShiftAmt);
285 Val = CurDAG->getTargetConstant(Immed, dl, MVT::i32);
286 Shift = CurDAG->getTargetConstant(ShVal, dl, MVT::i32);
290 /// SelectNegArithImmed - As above, but negates the value before trying to
292 bool AArch64DAGToDAGISel::SelectNegArithImmed(SDValue N, SDValue &Val,
294 // This function is called from the addsub_shifted_imm ComplexPattern,
295 // which lists [imm] as the list of opcode it's interested in, however
296 // we still need to check whether the operand is actually an immediate
297 // here because the ComplexPattern opcode list is only used in
298 // root-level opcode matching.
299 if (!isa<ConstantSDNode>(N.getNode()))
302 // The immediate operand must be a 24-bit zero-extended immediate.
303 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
305 // This negation is almost always valid, but "cmp wN, #0" and "cmn wN, #0"
306 // have the opposite effect on the C flag, so this pattern mustn't match under
307 // those circumstances.
311 if (N.getValueType() == MVT::i32)
312 Immed = ~((uint32_t)Immed) + 1;
314 Immed = ~Immed + 1ULL;
315 if (Immed & 0xFFFFFFFFFF000000ULL)
318 Immed &= 0xFFFFFFULL;
319 return SelectArithImmed(CurDAG->getConstant(Immed, SDLoc(N), MVT::i32), Val,
323 /// getShiftTypeForNode - Translate a shift node to the corresponding
325 static AArch64_AM::ShiftExtendType getShiftTypeForNode(SDValue N) {
326 switch (N.getOpcode()) {
328 return AArch64_AM::InvalidShiftExtend;
330 return AArch64_AM::LSL;
332 return AArch64_AM::LSR;
334 return AArch64_AM::ASR;
336 return AArch64_AM::ROR;
340 /// Determine whether it is worth it to fold SHL into the addressing
342 static bool isWorthFoldingSHL(SDValue V) {
343 assert(V.getOpcode() == ISD::SHL && "invalid opcode");
344 // It is worth folding logical shift of up to three places.
345 auto *CSD = dyn_cast<ConstantSDNode>(V.getOperand(1));
348 unsigned ShiftVal = CSD->getZExtValue();
352 // Check if this particular node is reused in any non-memory related
353 // operation. If yes, do not try to fold this node into the address
354 // computation, since the computation will be kept.
355 const SDNode *Node = V.getNode();
356 for (SDNode *UI : Node->uses())
357 if (!isa<MemSDNode>(*UI))
358 for (SDNode *UII : UI->uses())
359 if (!isa<MemSDNode>(*UII))
364 /// Determine whether it is worth to fold V into an extended register.
365 bool AArch64DAGToDAGISel::isWorthFolding(SDValue V) const {
366 // Trivial if we are optimizing for code size or if there is only
367 // one use of the value.
368 if (ForCodeSize || V.hasOneUse())
370 // If a subtarget has a fastpath LSL we can fold a logical shift into
371 // the addressing mode and save a cycle.
372 if (Subtarget->hasLSLFast() && V.getOpcode() == ISD::SHL &&
373 isWorthFoldingSHL(V))
375 if (Subtarget->hasLSLFast() && V.getOpcode() == ISD::ADD) {
376 const SDValue LHS = V.getOperand(0);
377 const SDValue RHS = V.getOperand(1);
378 if (LHS.getOpcode() == ISD::SHL && isWorthFoldingSHL(LHS))
380 if (RHS.getOpcode() == ISD::SHL && isWorthFoldingSHL(RHS))
384 // It hurts otherwise, since the value will be reused.
388 /// SelectShiftedRegister - Select a "shifted register" operand. If the value
389 /// is not shifted, set the Shift operand to default of "LSL 0". The logical
390 /// instructions allow the shifted register to be rotated, but the arithmetic
391 /// instructions do not. The AllowROR parameter specifies whether ROR is
393 bool AArch64DAGToDAGISel::SelectShiftedRegister(SDValue N, bool AllowROR,
394 SDValue &Reg, SDValue &Shift) {
395 AArch64_AM::ShiftExtendType ShType = getShiftTypeForNode(N);
396 if (ShType == AArch64_AM::InvalidShiftExtend)
398 if (!AllowROR && ShType == AArch64_AM::ROR)
401 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
402 unsigned BitSize = N.getValueSizeInBits();
403 unsigned Val = RHS->getZExtValue() & (BitSize - 1);
404 unsigned ShVal = AArch64_AM::getShifterImm(ShType, Val);
406 Reg = N.getOperand(0);
407 Shift = CurDAG->getTargetConstant(ShVal, SDLoc(N), MVT::i32);
408 return isWorthFolding(N);
414 /// getExtendTypeForNode - Translate an extend node to the corresponding
415 /// ExtendType value.
416 static AArch64_AM::ShiftExtendType
417 getExtendTypeForNode(SDValue N, bool IsLoadStore = false) {
418 if (N.getOpcode() == ISD::SIGN_EXTEND ||
419 N.getOpcode() == ISD::SIGN_EXTEND_INREG) {
421 if (N.getOpcode() == ISD::SIGN_EXTEND_INREG)
422 SrcVT = cast<VTSDNode>(N.getOperand(1))->getVT();
424 SrcVT = N.getOperand(0).getValueType();
426 if (!IsLoadStore && SrcVT == MVT::i8)
427 return AArch64_AM::SXTB;
428 else if (!IsLoadStore && SrcVT == MVT::i16)
429 return AArch64_AM::SXTH;
430 else if (SrcVT == MVT::i32)
431 return AArch64_AM::SXTW;
432 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
434 return AArch64_AM::InvalidShiftExtend;
435 } else if (N.getOpcode() == ISD::ZERO_EXTEND ||
436 N.getOpcode() == ISD::ANY_EXTEND) {
437 EVT SrcVT = N.getOperand(0).getValueType();
438 if (!IsLoadStore && SrcVT == MVT::i8)
439 return AArch64_AM::UXTB;
440 else if (!IsLoadStore && SrcVT == MVT::i16)
441 return AArch64_AM::UXTH;
442 else if (SrcVT == MVT::i32)
443 return AArch64_AM::UXTW;
444 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
446 return AArch64_AM::InvalidShiftExtend;
447 } else if (N.getOpcode() == ISD::AND) {
448 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
450 return AArch64_AM::InvalidShiftExtend;
451 uint64_t AndMask = CSD->getZExtValue();
455 return AArch64_AM::InvalidShiftExtend;
457 return !IsLoadStore ? AArch64_AM::UXTB : AArch64_AM::InvalidShiftExtend;
459 return !IsLoadStore ? AArch64_AM::UXTH : AArch64_AM::InvalidShiftExtend;
461 return AArch64_AM::UXTW;
465 return AArch64_AM::InvalidShiftExtend;
468 // Helper for SelectMLAV64LaneV128 - Recognize high lane extracts.
469 static bool checkHighLaneIndex(SDNode *DL, SDValue &LaneOp, int &LaneIdx) {
470 if (DL->getOpcode() != AArch64ISD::DUPLANE16 &&
471 DL->getOpcode() != AArch64ISD::DUPLANE32)
474 SDValue SV = DL->getOperand(0);
475 if (SV.getOpcode() != ISD::INSERT_SUBVECTOR)
478 SDValue EV = SV.getOperand(1);
479 if (EV.getOpcode() != ISD::EXTRACT_SUBVECTOR)
482 ConstantSDNode *DLidx = cast<ConstantSDNode>(DL->getOperand(1).getNode());
483 ConstantSDNode *EVidx = cast<ConstantSDNode>(EV.getOperand(1).getNode());
484 LaneIdx = DLidx->getSExtValue() + EVidx->getSExtValue();
485 LaneOp = EV.getOperand(0);
490 // Helper for SelectOpcV64LaneV128 - Recognize operations where one operand is a
491 // high lane extract.
492 static bool checkV64LaneV128(SDValue Op0, SDValue Op1, SDValue &StdOp,
493 SDValue &LaneOp, int &LaneIdx) {
495 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx)) {
497 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx))
504 /// SelectMLAV64LaneV128 - AArch64 supports vector MLAs where one multiplicand
505 /// is a lane in the upper half of a 128-bit vector. Recognize and select this
506 /// so that we don't emit unnecessary lane extracts.
507 bool AArch64DAGToDAGISel::tryMLAV64LaneV128(SDNode *N) {
509 SDValue Op0 = N->getOperand(0);
510 SDValue Op1 = N->getOperand(1);
511 SDValue MLAOp1; // Will hold ordinary multiplicand for MLA.
512 SDValue MLAOp2; // Will hold lane-accessed multiplicand for MLA.
513 int LaneIdx = -1; // Will hold the lane index.
515 if (Op1.getOpcode() != ISD::MUL ||
516 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
519 if (Op1.getOpcode() != ISD::MUL ||
520 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
525 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
527 SDValue Ops[] = { Op0, MLAOp1, MLAOp2, LaneIdxVal };
529 unsigned MLAOpc = ~0U;
531 switch (N->getSimpleValueType(0).SimpleTy) {
533 llvm_unreachable("Unrecognized MLA.");
535 MLAOpc = AArch64::MLAv4i16_indexed;
538 MLAOpc = AArch64::MLAv8i16_indexed;
541 MLAOpc = AArch64::MLAv2i32_indexed;
544 MLAOpc = AArch64::MLAv4i32_indexed;
548 ReplaceNode(N, CurDAG->getMachineNode(MLAOpc, dl, N->getValueType(0), Ops));
552 bool AArch64DAGToDAGISel::tryMULLV64LaneV128(unsigned IntNo, SDNode *N) {
558 if (!checkV64LaneV128(N->getOperand(1), N->getOperand(2), SMULLOp0, SMULLOp1,
562 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
564 SDValue Ops[] = { SMULLOp0, SMULLOp1, LaneIdxVal };
566 unsigned SMULLOpc = ~0U;
568 if (IntNo == Intrinsic::aarch64_neon_smull) {
569 switch (N->getSimpleValueType(0).SimpleTy) {
571 llvm_unreachable("Unrecognized SMULL.");
573 SMULLOpc = AArch64::SMULLv4i16_indexed;
576 SMULLOpc = AArch64::SMULLv2i32_indexed;
579 } else if (IntNo == Intrinsic::aarch64_neon_umull) {
580 switch (N->getSimpleValueType(0).SimpleTy) {
582 llvm_unreachable("Unrecognized SMULL.");
584 SMULLOpc = AArch64::UMULLv4i16_indexed;
587 SMULLOpc = AArch64::UMULLv2i32_indexed;
591 llvm_unreachable("Unrecognized intrinsic.");
593 ReplaceNode(N, CurDAG->getMachineNode(SMULLOpc, dl, N->getValueType(0), Ops));
597 /// Instructions that accept extend modifiers like UXTW expect the register
598 /// being extended to be a GPR32, but the incoming DAG might be acting on a
599 /// GPR64 (either via SEXT_INREG or AND). Extract the appropriate low bits if
600 /// this is the case.
601 static SDValue narrowIfNeeded(SelectionDAG *CurDAG, SDValue N) {
602 if (N.getValueType() == MVT::i32)
606 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
607 MachineSDNode *Node = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
608 dl, MVT::i32, N, SubReg);
609 return SDValue(Node, 0);
613 /// SelectArithExtendedRegister - Select a "extended register" operand. This
614 /// operand folds in an extend followed by an optional left shift.
615 bool AArch64DAGToDAGISel::SelectArithExtendedRegister(SDValue N, SDValue &Reg,
617 unsigned ShiftVal = 0;
618 AArch64_AM::ShiftExtendType Ext;
620 if (N.getOpcode() == ISD::SHL) {
621 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
624 ShiftVal = CSD->getZExtValue();
628 Ext = getExtendTypeForNode(N.getOperand(0));
629 if (Ext == AArch64_AM::InvalidShiftExtend)
632 Reg = N.getOperand(0).getOperand(0);
634 Ext = getExtendTypeForNode(N);
635 if (Ext == AArch64_AM::InvalidShiftExtend)
638 Reg = N.getOperand(0);
640 // Don't match if free 32-bit -> 64-bit zext can be used instead.
641 if (Ext == AArch64_AM::UXTW &&
642 Reg->getValueType(0).getSizeInBits() == 32 && isDef32(*Reg.getNode()))
646 // AArch64 mandates that the RHS of the operation must use the smallest
647 // register class that could contain the size being extended from. Thus,
648 // if we're folding a (sext i8), we need the RHS to be a GPR32, even though
649 // there might not be an actual 32-bit value in the program. We can
650 // (harmlessly) synthesize one by injected an EXTRACT_SUBREG here.
651 assert(Ext != AArch64_AM::UXTX && Ext != AArch64_AM::SXTX);
652 Reg = narrowIfNeeded(CurDAG, Reg);
653 Shift = CurDAG->getTargetConstant(getArithExtendImm(Ext, ShiftVal), SDLoc(N),
655 return isWorthFolding(N);
658 /// If there's a use of this ADDlow that's not itself a load/store then we'll
659 /// need to create a real ADD instruction from it anyway and there's no point in
660 /// folding it into the mem op. Theoretically, it shouldn't matter, but there's
661 /// a single pseudo-instruction for an ADRP/ADD pair so over-aggressive folding
662 /// leads to duplicated ADRP instructions.
663 static bool isWorthFoldingADDlow(SDValue N) {
664 for (auto Use : N->uses()) {
665 if (Use->getOpcode() != ISD::LOAD && Use->getOpcode() != ISD::STORE &&
666 Use->getOpcode() != ISD::ATOMIC_LOAD &&
667 Use->getOpcode() != ISD::ATOMIC_STORE)
670 // ldar and stlr have much more restrictive addressing modes (just a
672 if (isStrongerThanMonotonic(cast<MemSDNode>(Use)->getOrdering()))
679 /// SelectAddrModeIndexed7S - Select a "register plus scaled signed 7-bit
680 /// immediate" address. The "Size" argument is the size in bytes of the memory
681 /// reference, which determines the scale.
682 bool AArch64DAGToDAGISel::SelectAddrModeIndexed7S(SDValue N, unsigned Size,
686 const DataLayout &DL = CurDAG->getDataLayout();
687 const TargetLowering *TLI = getTargetLowering();
688 if (N.getOpcode() == ISD::FrameIndex) {
689 int FI = cast<FrameIndexSDNode>(N)->getIndex();
690 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
691 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
695 // As opposed to the (12-bit) Indexed addressing mode below, the 7-bit signed
696 // selected here doesn't support labels/immediates, only base+offset.
698 if (CurDAG->isBaseWithConstantOffset(N)) {
699 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
700 int64_t RHSC = RHS->getSExtValue();
701 unsigned Scale = Log2_32(Size);
702 if ((RHSC & (Size - 1)) == 0 && RHSC >= -(0x40 << Scale) &&
703 RHSC < (0x40 << Scale)) {
704 Base = N.getOperand(0);
705 if (Base.getOpcode() == ISD::FrameIndex) {
706 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
707 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
709 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, dl, MVT::i64);
715 // Base only. The address will be materialized into a register before
716 // the memory is accessed.
717 // add x0, Xbase, #offset
720 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
724 /// SelectAddrModeIndexed - Select a "register plus scaled unsigned 12-bit
725 /// immediate" address. The "Size" argument is the size in bytes of the memory
726 /// reference, which determines the scale.
727 bool AArch64DAGToDAGISel::SelectAddrModeIndexed(SDValue N, unsigned Size,
728 SDValue &Base, SDValue &OffImm) {
730 const DataLayout &DL = CurDAG->getDataLayout();
731 const TargetLowering *TLI = getTargetLowering();
732 if (N.getOpcode() == ISD::FrameIndex) {
733 int FI = cast<FrameIndexSDNode>(N)->getIndex();
734 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
735 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
739 if (N.getOpcode() == AArch64ISD::ADDlow && isWorthFoldingADDlow(N)) {
740 GlobalAddressSDNode *GAN =
741 dyn_cast<GlobalAddressSDNode>(N.getOperand(1).getNode());
742 Base = N.getOperand(0);
743 OffImm = N.getOperand(1);
747 if (GAN->getOffset() % Size == 0) {
748 const GlobalValue *GV = GAN->getGlobal();
749 unsigned Alignment = GV->getAlignment();
750 Type *Ty = GV->getValueType();
751 if (Alignment == 0 && Ty->isSized())
752 Alignment = DL.getABITypeAlignment(Ty);
754 if (Alignment >= Size)
759 if (CurDAG->isBaseWithConstantOffset(N)) {
760 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
761 int64_t RHSC = (int64_t)RHS->getZExtValue();
762 unsigned Scale = Log2_32(Size);
763 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 << Scale)) {
764 Base = N.getOperand(0);
765 if (Base.getOpcode() == ISD::FrameIndex) {
766 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
767 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
769 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, dl, MVT::i64);
775 // Before falling back to our general case, check if the unscaled
776 // instructions can handle this. If so, that's preferable.
777 if (SelectAddrModeUnscaled(N, Size, Base, OffImm))
780 // Base only. The address will be materialized into a register before
781 // the memory is accessed.
782 // add x0, Xbase, #offset
785 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
789 /// SelectAddrModeUnscaled - Select a "register plus unscaled signed 9-bit
790 /// immediate" address. This should only match when there is an offset that
791 /// is not valid for a scaled immediate addressing mode. The "Size" argument
792 /// is the size in bytes of the memory reference, which is needed here to know
793 /// what is valid for a scaled immediate.
794 bool AArch64DAGToDAGISel::SelectAddrModeUnscaled(SDValue N, unsigned Size,
797 if (!CurDAG->isBaseWithConstantOffset(N))
799 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
800 int64_t RHSC = RHS->getSExtValue();
801 // If the offset is valid as a scaled immediate, don't match here.
802 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 &&
803 RHSC < (0x1000 << Log2_32(Size)))
805 if (RHSC >= -256 && RHSC < 256) {
806 Base = N.getOperand(0);
807 if (Base.getOpcode() == ISD::FrameIndex) {
808 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
809 const TargetLowering *TLI = getTargetLowering();
810 Base = CurDAG->getTargetFrameIndex(
811 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
813 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i64);
820 static SDValue Widen(SelectionDAG *CurDAG, SDValue N) {
822 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
823 SDValue ImpDef = SDValue(
824 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, MVT::i64), 0);
825 MachineSDNode *Node = CurDAG->getMachineNode(
826 TargetOpcode::INSERT_SUBREG, dl, MVT::i64, ImpDef, N, SubReg);
827 return SDValue(Node, 0);
830 /// Check if the given SHL node (\p N), can be used to form an
831 /// extended register for an addressing mode.
832 bool AArch64DAGToDAGISel::SelectExtendedSHL(SDValue N, unsigned Size,
833 bool WantExtend, SDValue &Offset,
834 SDValue &SignExtend) {
835 assert(N.getOpcode() == ISD::SHL && "Invalid opcode.");
836 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
837 if (!CSD || (CSD->getZExtValue() & 0x7) != CSD->getZExtValue())
842 AArch64_AM::ShiftExtendType Ext =
843 getExtendTypeForNode(N.getOperand(0), true);
844 if (Ext == AArch64_AM::InvalidShiftExtend)
847 Offset = narrowIfNeeded(CurDAG, N.getOperand(0).getOperand(0));
848 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
851 Offset = N.getOperand(0);
852 SignExtend = CurDAG->getTargetConstant(0, dl, MVT::i32);
855 unsigned LegalShiftVal = Log2_32(Size);
856 unsigned ShiftVal = CSD->getZExtValue();
858 if (ShiftVal != 0 && ShiftVal != LegalShiftVal)
861 return isWorthFolding(N);
864 bool AArch64DAGToDAGISel::SelectAddrModeWRO(SDValue N, unsigned Size,
865 SDValue &Base, SDValue &Offset,
868 if (N.getOpcode() != ISD::ADD)
870 SDValue LHS = N.getOperand(0);
871 SDValue RHS = N.getOperand(1);
874 // We don't want to match immediate adds here, because they are better lowered
875 // to the register-immediate addressing modes.
876 if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))
879 // Check if this particular node is reused in any non-memory related
880 // operation. If yes, do not try to fold this node into the address
881 // computation, since the computation will be kept.
882 const SDNode *Node = N.getNode();
883 for (SDNode *UI : Node->uses()) {
884 if (!isa<MemSDNode>(*UI))
888 // Remember if it is worth folding N when it produces extended register.
889 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
891 // Try to match a shifted extend on the RHS.
892 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
893 SelectExtendedSHL(RHS, Size, true, Offset, SignExtend)) {
895 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
899 // Try to match a shifted extend on the LHS.
900 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
901 SelectExtendedSHL(LHS, Size, true, Offset, SignExtend)) {
903 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
907 // There was no shift, whatever else we find.
908 DoShift = CurDAG->getTargetConstant(false, dl, MVT::i32);
910 AArch64_AM::ShiftExtendType Ext = AArch64_AM::InvalidShiftExtend;
911 // Try to match an unshifted extend on the LHS.
912 if (IsExtendedRegisterWorthFolding &&
913 (Ext = getExtendTypeForNode(LHS, true)) !=
914 AArch64_AM::InvalidShiftExtend) {
916 Offset = narrowIfNeeded(CurDAG, LHS.getOperand(0));
917 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
919 if (isWorthFolding(LHS))
923 // Try to match an unshifted extend on the RHS.
924 if (IsExtendedRegisterWorthFolding &&
925 (Ext = getExtendTypeForNode(RHS, true)) !=
926 AArch64_AM::InvalidShiftExtend) {
928 Offset = narrowIfNeeded(CurDAG, RHS.getOperand(0));
929 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
931 if (isWorthFolding(RHS))
938 // Check if the given immediate is preferred by ADD. If an immediate can be
939 // encoded in an ADD, or it can be encoded in an "ADD LSL #12" and can not be
940 // encoded by one MOVZ, return true.
941 static bool isPreferredADD(int64_t ImmOff) {
942 // Constant in [0x0, 0xfff] can be encoded in ADD.
943 if ((ImmOff & 0xfffffffffffff000LL) == 0x0LL)
945 // Check if it can be encoded in an "ADD LSL #12".
946 if ((ImmOff & 0xffffffffff000fffLL) == 0x0LL)
947 // As a single MOVZ is faster than a "ADD of LSL #12", ignore such constant.
948 return (ImmOff & 0xffffffffff00ffffLL) != 0x0LL &&
949 (ImmOff & 0xffffffffffff0fffLL) != 0x0LL;
953 bool AArch64DAGToDAGISel::SelectAddrModeXRO(SDValue N, unsigned Size,
954 SDValue &Base, SDValue &Offset,
957 if (N.getOpcode() != ISD::ADD)
959 SDValue LHS = N.getOperand(0);
960 SDValue RHS = N.getOperand(1);
963 // Check if this particular node is reused in any non-memory related
964 // operation. If yes, do not try to fold this node into the address
965 // computation, since the computation will be kept.
966 const SDNode *Node = N.getNode();
967 for (SDNode *UI : Node->uses()) {
968 if (!isa<MemSDNode>(*UI))
972 // Watch out if RHS is a wide immediate, it can not be selected into
973 // [BaseReg+Imm] addressing mode. Also it may not be able to be encoded into
974 // ADD/SUB. Instead it will use [BaseReg + 0] address mode and generate
975 // instructions like:
976 // MOV X0, WideImmediate
977 // ADD X1, BaseReg, X0
979 // For such situation, using [BaseReg, XReg] addressing mode can save one
981 // MOV X0, WideImmediate
982 // LDR X2, [BaseReg, X0]
983 if (isa<ConstantSDNode>(RHS)) {
984 int64_t ImmOff = (int64_t)cast<ConstantSDNode>(RHS)->getZExtValue();
985 unsigned Scale = Log2_32(Size);
986 // Skip the immediate can be selected by load/store addressing mode.
987 // Also skip the immediate can be encoded by a single ADD (SUB is also
988 // checked by using -ImmOff).
989 if ((ImmOff % Size == 0 && ImmOff >= 0 && ImmOff < (0x1000 << Scale)) ||
990 isPreferredADD(ImmOff) || isPreferredADD(-ImmOff))
993 SDValue Ops[] = { RHS };
995 CurDAG->getMachineNode(AArch64::MOVi64imm, DL, MVT::i64, Ops);
996 SDValue MOVIV = SDValue(MOVI, 0);
997 // This ADD of two X register will be selected into [Reg+Reg] mode.
998 N = CurDAG->getNode(ISD::ADD, DL, MVT::i64, LHS, MOVIV);
1001 // Remember if it is worth folding N when it produces extended register.
1002 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
1004 // Try to match a shifted extend on the RHS.
1005 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
1006 SelectExtendedSHL(RHS, Size, false, Offset, SignExtend)) {
1008 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
1012 // Try to match a shifted extend on the LHS.
1013 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
1014 SelectExtendedSHL(LHS, Size, false, Offset, SignExtend)) {
1016 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
1020 // Match any non-shifted, non-extend, non-immediate add expression.
1023 SignExtend = CurDAG->getTargetConstant(false, DL, MVT::i32);
1024 DoShift = CurDAG->getTargetConstant(false, DL, MVT::i32);
1025 // Reg1 + Reg2 is free: no check needed.
1029 SDValue AArch64DAGToDAGISel::createDTuple(ArrayRef<SDValue> Regs) {
1030 static const unsigned RegClassIDs[] = {
1031 AArch64::DDRegClassID, AArch64::DDDRegClassID, AArch64::DDDDRegClassID};
1032 static const unsigned SubRegs[] = {AArch64::dsub0, AArch64::dsub1,
1033 AArch64::dsub2, AArch64::dsub3};
1035 return createTuple(Regs, RegClassIDs, SubRegs);
1038 SDValue AArch64DAGToDAGISel::createQTuple(ArrayRef<SDValue> Regs) {
1039 static const unsigned RegClassIDs[] = {
1040 AArch64::QQRegClassID, AArch64::QQQRegClassID, AArch64::QQQQRegClassID};
1041 static const unsigned SubRegs[] = {AArch64::qsub0, AArch64::qsub1,
1042 AArch64::qsub2, AArch64::qsub3};
1044 return createTuple(Regs, RegClassIDs, SubRegs);
1047 SDValue AArch64DAGToDAGISel::createTuple(ArrayRef<SDValue> Regs,
1048 const unsigned RegClassIDs[],
1049 const unsigned SubRegs[]) {
1050 // There's no special register-class for a vector-list of 1 element: it's just
1052 if (Regs.size() == 1)
1055 assert(Regs.size() >= 2 && Regs.size() <= 4);
1059 SmallVector<SDValue, 4> Ops;
1061 // First operand of REG_SEQUENCE is the desired RegClass.
1063 CurDAG->getTargetConstant(RegClassIDs[Regs.size() - 2], DL, MVT::i32));
1065 // Then we get pairs of source & subregister-position for the components.
1066 for (unsigned i = 0; i < Regs.size(); ++i) {
1067 Ops.push_back(Regs[i]);
1068 Ops.push_back(CurDAG->getTargetConstant(SubRegs[i], DL, MVT::i32));
1072 CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops);
1073 return SDValue(N, 0);
1076 void AArch64DAGToDAGISel::SelectTable(SDNode *N, unsigned NumVecs, unsigned Opc,
1079 EVT VT = N->getValueType(0);
1081 unsigned ExtOff = isExt;
1083 // Form a REG_SEQUENCE to force register allocation.
1084 unsigned Vec0Off = ExtOff + 1;
1085 SmallVector<SDValue, 4> Regs(N->op_begin() + Vec0Off,
1086 N->op_begin() + Vec0Off + NumVecs);
1087 SDValue RegSeq = createQTuple(Regs);
1089 SmallVector<SDValue, 6> Ops;
1091 Ops.push_back(N->getOperand(1));
1092 Ops.push_back(RegSeq);
1093 Ops.push_back(N->getOperand(NumVecs + ExtOff + 1));
1094 ReplaceNode(N, CurDAG->getMachineNode(Opc, dl, VT, Ops));
1097 bool AArch64DAGToDAGISel::tryIndexedLoad(SDNode *N) {
1098 LoadSDNode *LD = cast<LoadSDNode>(N);
1099 if (LD->isUnindexed())
1101 EVT VT = LD->getMemoryVT();
1102 EVT DstVT = N->getValueType(0);
1103 ISD::MemIndexedMode AM = LD->getAddressingMode();
1104 bool IsPre = AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1106 // We're not doing validity checking here. That was done when checking
1107 // if we should mark the load as indexed or not. We're just selecting
1108 // the right instruction.
1109 unsigned Opcode = 0;
1111 ISD::LoadExtType ExtType = LD->getExtensionType();
1112 bool InsertTo64 = false;
1114 Opcode = IsPre ? AArch64::LDRXpre : AArch64::LDRXpost;
1115 else if (VT == MVT::i32) {
1116 if (ExtType == ISD::NON_EXTLOAD)
1117 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1118 else if (ExtType == ISD::SEXTLOAD)
1119 Opcode = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost;
1121 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1123 // The result of the load is only i32. It's the subreg_to_reg that makes
1127 } else if (VT == MVT::i16) {
1128 if (ExtType == ISD::SEXTLOAD) {
1129 if (DstVT == MVT::i64)
1130 Opcode = IsPre ? AArch64::LDRSHXpre : AArch64::LDRSHXpost;
1132 Opcode = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost;
1134 Opcode = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost;
1135 InsertTo64 = DstVT == MVT::i64;
1136 // The result of the load is only i32. It's the subreg_to_reg that makes
1140 } else if (VT == MVT::i8) {
1141 if (ExtType == ISD::SEXTLOAD) {
1142 if (DstVT == MVT::i64)
1143 Opcode = IsPre ? AArch64::LDRSBXpre : AArch64::LDRSBXpost;
1145 Opcode = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost;
1147 Opcode = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost;
1148 InsertTo64 = DstVT == MVT::i64;
1149 // The result of the load is only i32. It's the subreg_to_reg that makes
1153 } else if (VT == MVT::f16) {
1154 Opcode = IsPre ? AArch64::LDRHpre : AArch64::LDRHpost;
1155 } else if (VT == MVT::f32) {
1156 Opcode = IsPre ? AArch64::LDRSpre : AArch64::LDRSpost;
1157 } else if (VT == MVT::f64 || VT.is64BitVector()) {
1158 Opcode = IsPre ? AArch64::LDRDpre : AArch64::LDRDpost;
1159 } else if (VT.is128BitVector()) {
1160 Opcode = IsPre ? AArch64::LDRQpre : AArch64::LDRQpost;
1163 SDValue Chain = LD->getChain();
1164 SDValue Base = LD->getBasePtr();
1165 ConstantSDNode *OffsetOp = cast<ConstantSDNode>(LD->getOffset());
1166 int OffsetVal = (int)OffsetOp->getZExtValue();
1168 SDValue Offset = CurDAG->getTargetConstant(OffsetVal, dl, MVT::i64);
1169 SDValue Ops[] = { Base, Offset, Chain };
1170 SDNode *Res = CurDAG->getMachineNode(Opcode, dl, MVT::i64, DstVT,
1172 // Either way, we're replacing the node, so tell the caller that.
1173 SDValue LoadedVal = SDValue(Res, 1);
1175 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
1177 SDValue(CurDAG->getMachineNode(
1178 AArch64::SUBREG_TO_REG, dl, MVT::i64,
1179 CurDAG->getTargetConstant(0, dl, MVT::i64), LoadedVal,
1184 ReplaceUses(SDValue(N, 0), LoadedVal);
1185 ReplaceUses(SDValue(N, 1), SDValue(Res, 0));
1186 ReplaceUses(SDValue(N, 2), SDValue(Res, 2));
1187 CurDAG->RemoveDeadNode(N);
1191 void AArch64DAGToDAGISel::SelectLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
1192 unsigned SubRegIdx) {
1194 EVT VT = N->getValueType(0);
1195 SDValue Chain = N->getOperand(0);
1197 SDValue Ops[] = {N->getOperand(2), // Mem operand;
1200 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
1202 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1203 SDValue SuperReg = SDValue(Ld, 0);
1204 for (unsigned i = 0; i < NumVecs; ++i)
1205 ReplaceUses(SDValue(N, i),
1206 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1208 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1210 // Transfer memoperands.
1211 MachineMemOperand *MemOp = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1212 CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ld), {MemOp});
1214 CurDAG->RemoveDeadNode(N);
1217 void AArch64DAGToDAGISel::SelectPostLoad(SDNode *N, unsigned NumVecs,
1218 unsigned Opc, unsigned SubRegIdx) {
1220 EVT VT = N->getValueType(0);
1221 SDValue Chain = N->getOperand(0);
1223 SDValue Ops[] = {N->getOperand(1), // Mem operand
1224 N->getOperand(2), // Incremental
1227 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1228 MVT::Untyped, MVT::Other};
1230 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1232 // Update uses of write back register
1233 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1235 // Update uses of vector list
1236 SDValue SuperReg = SDValue(Ld, 1);
1238 ReplaceUses(SDValue(N, 0), SuperReg);
1240 for (unsigned i = 0; i < NumVecs; ++i)
1241 ReplaceUses(SDValue(N, i),
1242 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1245 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1246 CurDAG->RemoveDeadNode(N);
1249 void AArch64DAGToDAGISel::SelectStore(SDNode *N, unsigned NumVecs,
1252 EVT VT = N->getOperand(2)->getValueType(0);
1254 // Form a REG_SEQUENCE to force register allocation.
1255 bool Is128Bit = VT.getSizeInBits() == 128;
1256 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1257 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1259 SDValue Ops[] = {RegSeq, N->getOperand(NumVecs + 2), N->getOperand(0)};
1260 SDNode *St = CurDAG->getMachineNode(Opc, dl, N->getValueType(0), Ops);
1262 // Transfer memoperands.
1263 MachineMemOperand *MemOp = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1264 CurDAG->setNodeMemRefs(cast<MachineSDNode>(St), {MemOp});
1269 void AArch64DAGToDAGISel::SelectPostStore(SDNode *N, unsigned NumVecs,
1272 EVT VT = N->getOperand(2)->getValueType(0);
1273 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1274 MVT::Other}; // Type for the Chain
1276 // Form a REG_SEQUENCE to force register allocation.
1277 bool Is128Bit = VT.getSizeInBits() == 128;
1278 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1279 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1281 SDValue Ops[] = {RegSeq,
1282 N->getOperand(NumVecs + 1), // base register
1283 N->getOperand(NumVecs + 2), // Incremental
1284 N->getOperand(0)}; // Chain
1285 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1291 /// WidenVector - Given a value in the V64 register class, produce the
1292 /// equivalent value in the V128 register class.
1297 WidenVector(SelectionDAG &DAG) : DAG(DAG) {}
1299 SDValue operator()(SDValue V64Reg) {
1300 EVT VT = V64Reg.getValueType();
1301 unsigned NarrowSize = VT.getVectorNumElements();
1302 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1303 MVT WideTy = MVT::getVectorVT(EltTy, 2 * NarrowSize);
1307 SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, WideTy), 0);
1308 return DAG.getTargetInsertSubreg(AArch64::dsub, DL, WideTy, Undef, V64Reg);
1313 /// NarrowVector - Given a value in the V128 register class, produce the
1314 /// equivalent value in the V64 register class.
1315 static SDValue NarrowVector(SDValue V128Reg, SelectionDAG &DAG) {
1316 EVT VT = V128Reg.getValueType();
1317 unsigned WideSize = VT.getVectorNumElements();
1318 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1319 MVT NarrowTy = MVT::getVectorVT(EltTy, WideSize / 2);
1321 return DAG.getTargetExtractSubreg(AArch64::dsub, SDLoc(V128Reg), NarrowTy,
1325 void AArch64DAGToDAGISel::SelectLoadLane(SDNode *N, unsigned NumVecs,
1328 EVT VT = N->getValueType(0);
1329 bool Narrow = VT.getSizeInBits() == 64;
1331 // Form a REG_SEQUENCE to force register allocation.
1332 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1335 transform(Regs, Regs.begin(),
1336 WidenVector(*CurDAG));
1338 SDValue RegSeq = createQTuple(Regs);
1340 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
1343 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1345 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1346 N->getOperand(NumVecs + 3), N->getOperand(0)};
1347 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1348 SDValue SuperReg = SDValue(Ld, 0);
1350 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1351 static const unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1,
1352 AArch64::qsub2, AArch64::qsub3 };
1353 for (unsigned i = 0; i < NumVecs; ++i) {
1354 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT, SuperReg);
1356 NV = NarrowVector(NV, *CurDAG);
1357 ReplaceUses(SDValue(N, i), NV);
1360 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1361 CurDAG->RemoveDeadNode(N);
1364 void AArch64DAGToDAGISel::SelectPostLoadLane(SDNode *N, unsigned NumVecs,
1367 EVT VT = N->getValueType(0);
1368 bool Narrow = VT.getSizeInBits() == 64;
1370 // Form a REG_SEQUENCE to force register allocation.
1371 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1374 transform(Regs, Regs.begin(),
1375 WidenVector(*CurDAG));
1377 SDValue RegSeq = createQTuple(Regs);
1379 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1380 RegSeq->getValueType(0), MVT::Other};
1383 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1385 SDValue Ops[] = {RegSeq,
1386 CurDAG->getTargetConstant(LaneNo, dl,
1387 MVT::i64), // Lane Number
1388 N->getOperand(NumVecs + 2), // Base register
1389 N->getOperand(NumVecs + 3), // Incremental
1391 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1393 // Update uses of the write back register
1394 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1396 // Update uses of the vector list
1397 SDValue SuperReg = SDValue(Ld, 1);
1399 ReplaceUses(SDValue(N, 0),
1400 Narrow ? NarrowVector(SuperReg, *CurDAG) : SuperReg);
1402 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1403 static const unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1,
1404 AArch64::qsub2, AArch64::qsub3 };
1405 for (unsigned i = 0; i < NumVecs; ++i) {
1406 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT,
1409 NV = NarrowVector(NV, *CurDAG);
1410 ReplaceUses(SDValue(N, i), NV);
1415 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1416 CurDAG->RemoveDeadNode(N);
1419 void AArch64DAGToDAGISel::SelectStoreLane(SDNode *N, unsigned NumVecs,
1422 EVT VT = N->getOperand(2)->getValueType(0);
1423 bool Narrow = VT.getSizeInBits() == 64;
1425 // Form a REG_SEQUENCE to force register allocation.
1426 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1429 transform(Regs, Regs.begin(),
1430 WidenVector(*CurDAG));
1432 SDValue RegSeq = createQTuple(Regs);
1435 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1437 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1438 N->getOperand(NumVecs + 3), N->getOperand(0)};
1439 SDNode *St = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
1441 // Transfer memoperands.
1442 MachineMemOperand *MemOp = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1443 CurDAG->setNodeMemRefs(cast<MachineSDNode>(St), {MemOp});
1448 void AArch64DAGToDAGISel::SelectPostStoreLane(SDNode *N, unsigned NumVecs,
1451 EVT VT = N->getOperand(2)->getValueType(0);
1452 bool Narrow = VT.getSizeInBits() == 64;
1454 // Form a REG_SEQUENCE to force register allocation.
1455 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1458 transform(Regs, Regs.begin(),
1459 WidenVector(*CurDAG));
1461 SDValue RegSeq = createQTuple(Regs);
1463 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1467 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1469 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1470 N->getOperand(NumVecs + 2), // Base Register
1471 N->getOperand(NumVecs + 3), // Incremental
1473 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1475 // Transfer memoperands.
1476 MachineMemOperand *MemOp = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1477 CurDAG->setNodeMemRefs(cast<MachineSDNode>(St), {MemOp});
1482 static bool isBitfieldExtractOpFromAnd(SelectionDAG *CurDAG, SDNode *N,
1483 unsigned &Opc, SDValue &Opd0,
1484 unsigned &LSB, unsigned &MSB,
1485 unsigned NumberOfIgnoredLowBits,
1486 bool BiggerPattern) {
1487 assert(N->getOpcode() == ISD::AND &&
1488 "N must be a AND operation to call this function");
1490 EVT VT = N->getValueType(0);
1492 // Here we can test the type of VT and return false when the type does not
1493 // match, but since it is done prior to that call in the current context
1494 // we turned that into an assert to avoid redundant code.
1495 assert((VT == MVT::i32 || VT == MVT::i64) &&
1496 "Type checking must have been done before calling this function");
1498 // FIXME: simplify-demanded-bits in DAGCombine will probably have
1499 // changed the AND node to a 32-bit mask operation. We'll have to
1500 // undo that as part of the transform here if we want to catch all
1501 // the opportunities.
1502 // Currently the NumberOfIgnoredLowBits argument helps to recover
1503 // form these situations when matching bigger pattern (bitfield insert).
1505 // For unsigned extracts, check for a shift right and mask
1506 uint64_t AndImm = 0;
1507 if (!isOpcWithIntImmediate(N, ISD::AND, AndImm))
1510 const SDNode *Op0 = N->getOperand(0).getNode();
1512 // Because of simplify-demanded-bits in DAGCombine, the mask may have been
1513 // simplified. Try to undo that
1514 AndImm |= maskTrailingOnes<uint64_t>(NumberOfIgnoredLowBits);
1516 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1517 if (AndImm & (AndImm + 1))
1520 bool ClampMSB = false;
1521 uint64_t SrlImm = 0;
1522 // Handle the SRL + ANY_EXTEND case.
1523 if (VT == MVT::i64 && Op0->getOpcode() == ISD::ANY_EXTEND &&
1524 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL, SrlImm)) {
1525 // Extend the incoming operand of the SRL to 64-bit.
1526 Opd0 = Widen(CurDAG, Op0->getOperand(0).getOperand(0));
1527 // Make sure to clamp the MSB so that we preserve the semantics of the
1528 // original operations.
1530 } else if (VT == MVT::i32 && Op0->getOpcode() == ISD::TRUNCATE &&
1531 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL,
1533 // If the shift result was truncated, we can still combine them.
1534 Opd0 = Op0->getOperand(0).getOperand(0);
1536 // Use the type of SRL node.
1537 VT = Opd0->getValueType(0);
1538 } else if (isOpcWithIntImmediate(Op0, ISD::SRL, SrlImm)) {
1539 Opd0 = Op0->getOperand(0);
1540 } else if (BiggerPattern) {
1541 // Let's pretend a 0 shift right has been performed.
1542 // The resulting code will be at least as good as the original one
1543 // plus it may expose more opportunities for bitfield insert pattern.
1544 // FIXME: Currently we limit this to the bigger pattern, because
1545 // some optimizations expect AND and not UBFM.
1546 Opd0 = N->getOperand(0);
1550 // Bail out on large immediates. This happens when no proper
1551 // combining/constant folding was performed.
1552 if (!BiggerPattern && (SrlImm <= 0 || SrlImm >= VT.getSizeInBits())) {
1555 << ": Found large shift immediate, this should not happen\n"));
1560 MSB = SrlImm + (VT == MVT::i32 ? countTrailingOnes<uint32_t>(AndImm)
1561 : countTrailingOnes<uint64_t>(AndImm)) -
1564 // Since we're moving the extend before the right shift operation, we need
1565 // to clamp the MSB to make sure we don't shift in undefined bits instead of
1566 // the zeros which would get shifted in with the original right shift
1568 MSB = MSB > 31 ? 31 : MSB;
1570 Opc = VT == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1574 static bool isBitfieldExtractOpFromSExtInReg(SDNode *N, unsigned &Opc,
1575 SDValue &Opd0, unsigned &Immr,
1577 assert(N->getOpcode() == ISD::SIGN_EXTEND_INREG);
1579 EVT VT = N->getValueType(0);
1580 unsigned BitWidth = VT.getSizeInBits();
1581 assert((VT == MVT::i32 || VT == MVT::i64) &&
1582 "Type checking must have been done before calling this function");
1584 SDValue Op = N->getOperand(0);
1585 if (Op->getOpcode() == ISD::TRUNCATE) {
1586 Op = Op->getOperand(0);
1587 VT = Op->getValueType(0);
1588 BitWidth = VT.getSizeInBits();
1592 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRL, ShiftImm) &&
1593 !isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
1596 unsigned Width = cast<VTSDNode>(N->getOperand(1))->getVT().getSizeInBits();
1597 if (ShiftImm + Width > BitWidth)
1600 Opc = (VT == MVT::i32) ? AArch64::SBFMWri : AArch64::SBFMXri;
1601 Opd0 = Op.getOperand(0);
1603 Imms = ShiftImm + Width - 1;
1607 static bool isSeveralBitsExtractOpFromShr(SDNode *N, unsigned &Opc,
1608 SDValue &Opd0, unsigned &LSB,
1610 // We are looking for the following pattern which basically extracts several
1611 // continuous bits from the source value and places it from the LSB of the
1612 // destination value, all other bits of the destination value or set to zero:
1614 // Value2 = AND Value, MaskImm
1615 // SRL Value2, ShiftImm
1617 // with MaskImm >> ShiftImm to search for the bit width.
1619 // This gets selected into a single UBFM:
1621 // UBFM Value, ShiftImm, BitWide + SrlImm -1
1624 if (N->getOpcode() != ISD::SRL)
1627 uint64_t AndMask = 0;
1628 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, AndMask))
1631 Opd0 = N->getOperand(0).getOperand(0);
1633 uint64_t SrlImm = 0;
1634 if (!isIntImmediate(N->getOperand(1), SrlImm))
1637 // Check whether we really have several bits extract here.
1638 unsigned BitWide = 64 - countLeadingOnes(~(AndMask >> SrlImm));
1639 if (BitWide && isMask_64(AndMask >> SrlImm)) {
1640 if (N->getValueType(0) == MVT::i32)
1641 Opc = AArch64::UBFMWri;
1643 Opc = AArch64::UBFMXri;
1646 MSB = BitWide + SrlImm - 1;
1653 static bool isBitfieldExtractOpFromShr(SDNode *N, unsigned &Opc, SDValue &Opd0,
1654 unsigned &Immr, unsigned &Imms,
1655 bool BiggerPattern) {
1656 assert((N->getOpcode() == ISD::SRA || N->getOpcode() == ISD::SRL) &&
1657 "N must be a SHR/SRA operation to call this function");
1659 EVT VT = N->getValueType(0);
1661 // Here we can test the type of VT and return false when the type does not
1662 // match, but since it is done prior to that call in the current context
1663 // we turned that into an assert to avoid redundant code.
1664 assert((VT == MVT::i32 || VT == MVT::i64) &&
1665 "Type checking must have been done before calling this function");
1667 // Check for AND + SRL doing several bits extract.
1668 if (isSeveralBitsExtractOpFromShr(N, Opc, Opd0, Immr, Imms))
1671 // We're looking for a shift of a shift.
1672 uint64_t ShlImm = 0;
1673 uint64_t TruncBits = 0;
1674 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, ShlImm)) {
1675 Opd0 = N->getOperand(0).getOperand(0);
1676 } else if (VT == MVT::i32 && N->getOpcode() == ISD::SRL &&
1677 N->getOperand(0).getNode()->getOpcode() == ISD::TRUNCATE) {
1678 // We are looking for a shift of truncate. Truncate from i64 to i32 could
1679 // be considered as setting high 32 bits as zero. Our strategy here is to
1680 // always generate 64bit UBFM. This consistency will help the CSE pass
1681 // later find more redundancy.
1682 Opd0 = N->getOperand(0).getOperand(0);
1683 TruncBits = Opd0->getValueType(0).getSizeInBits() - VT.getSizeInBits();
1684 VT = Opd0.getValueType();
1685 assert(VT == MVT::i64 && "the promoted type should be i64");
1686 } else if (BiggerPattern) {
1687 // Let's pretend a 0 shift left has been performed.
1688 // FIXME: Currently we limit this to the bigger pattern case,
1689 // because some optimizations expect AND and not UBFM
1690 Opd0 = N->getOperand(0);
1694 // Missing combines/constant folding may have left us with strange
1696 if (ShlImm >= VT.getSizeInBits()) {
1699 << ": Found large shift immediate, this should not happen\n"));
1703 uint64_t SrlImm = 0;
1704 if (!isIntImmediate(N->getOperand(1), SrlImm))
1707 assert(SrlImm > 0 && SrlImm < VT.getSizeInBits() &&
1708 "bad amount in shift node!");
1709 int immr = SrlImm - ShlImm;
1710 Immr = immr < 0 ? immr + VT.getSizeInBits() : immr;
1711 Imms = VT.getSizeInBits() - ShlImm - TruncBits - 1;
1712 // SRA requires a signed extraction
1714 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMWri : AArch64::UBFMWri;
1716 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMXri : AArch64::UBFMXri;
1720 bool AArch64DAGToDAGISel::tryBitfieldExtractOpFromSExt(SDNode *N) {
1721 assert(N->getOpcode() == ISD::SIGN_EXTEND);
1723 EVT VT = N->getValueType(0);
1724 EVT NarrowVT = N->getOperand(0)->getValueType(0);
1725 if (VT != MVT::i64 || NarrowVT != MVT::i32)
1729 SDValue Op = N->getOperand(0);
1730 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
1734 // Extend the incoming operand of the shift to 64-bits.
1735 SDValue Opd0 = Widen(CurDAG, Op.getOperand(0));
1736 unsigned Immr = ShiftImm;
1737 unsigned Imms = NarrowVT.getSizeInBits() - 1;
1738 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
1739 CurDAG->getTargetConstant(Imms, dl, VT)};
1740 CurDAG->SelectNodeTo(N, AArch64::SBFMXri, VT, Ops);
1744 static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
1745 SDValue &Opd0, unsigned &Immr, unsigned &Imms,
1746 unsigned NumberOfIgnoredLowBits = 0,
1747 bool BiggerPattern = false) {
1748 if (N->getValueType(0) != MVT::i32 && N->getValueType(0) != MVT::i64)
1751 switch (N->getOpcode()) {
1753 if (!N->isMachineOpcode())
1757 return isBitfieldExtractOpFromAnd(CurDAG, N, Opc, Opd0, Immr, Imms,
1758 NumberOfIgnoredLowBits, BiggerPattern);
1761 return isBitfieldExtractOpFromShr(N, Opc, Opd0, Immr, Imms, BiggerPattern);
1763 case ISD::SIGN_EXTEND_INREG:
1764 return isBitfieldExtractOpFromSExtInReg(N, Opc, Opd0, Immr, Imms);
1767 unsigned NOpc = N->getMachineOpcode();
1771 case AArch64::SBFMWri:
1772 case AArch64::UBFMWri:
1773 case AArch64::SBFMXri:
1774 case AArch64::UBFMXri:
1776 Opd0 = N->getOperand(0);
1777 Immr = cast<ConstantSDNode>(N->getOperand(1).getNode())->getZExtValue();
1778 Imms = cast<ConstantSDNode>(N->getOperand(2).getNode())->getZExtValue();
1785 bool AArch64DAGToDAGISel::tryBitfieldExtractOp(SDNode *N) {
1786 unsigned Opc, Immr, Imms;
1788 if (!isBitfieldExtractOp(CurDAG, N, Opc, Opd0, Immr, Imms))
1791 EVT VT = N->getValueType(0);
1794 // If the bit extract operation is 64bit but the original type is 32bit, we
1795 // need to add one EXTRACT_SUBREG.
1796 if ((Opc == AArch64::SBFMXri || Opc == AArch64::UBFMXri) && VT == MVT::i32) {
1797 SDValue Ops64[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, MVT::i64),
1798 CurDAG->getTargetConstant(Imms, dl, MVT::i64)};
1800 SDNode *BFM = CurDAG->getMachineNode(Opc, dl, MVT::i64, Ops64);
1801 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
1802 ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl,
1803 MVT::i32, SDValue(BFM, 0), SubReg));
1807 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
1808 CurDAG->getTargetConstant(Imms, dl, VT)};
1809 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
1813 /// Does DstMask form a complementary pair with the mask provided by
1814 /// BitsToBeInserted, suitable for use in a BFI instruction. Roughly speaking,
1815 /// this asks whether DstMask zeroes precisely those bits that will be set by
1817 static bool isBitfieldDstMask(uint64_t DstMask, const APInt &BitsToBeInserted,
1818 unsigned NumberOfIgnoredHighBits, EVT VT) {
1819 assert((VT == MVT::i32 || VT == MVT::i64) &&
1820 "i32 or i64 mask type expected!");
1821 unsigned BitWidth = VT.getSizeInBits() - NumberOfIgnoredHighBits;
1823 APInt SignificantDstMask = APInt(BitWidth, DstMask);
1824 APInt SignificantBitsToBeInserted = BitsToBeInserted.zextOrTrunc(BitWidth);
1826 return (SignificantDstMask & SignificantBitsToBeInserted) == 0 &&
1827 (SignificantDstMask | SignificantBitsToBeInserted).isAllOnesValue();
1830 // Look for bits that will be useful for later uses.
1831 // A bit is consider useless as soon as it is dropped and never used
1832 // before it as been dropped.
1833 // E.g., looking for useful bit of x
1836 // After #1, x useful bits are 0x7, then the useful bits of x, live through
1838 // After #2, the useful bits of x are 0x4.
1839 // However, if x is used on an unpredicatable instruction, then all its bits
1845 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth = 0);
1847 static void getUsefulBitsFromAndWithImmediate(SDValue Op, APInt &UsefulBits,
1850 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1851 Imm = AArch64_AM::decodeLogicalImmediate(Imm, UsefulBits.getBitWidth());
1852 UsefulBits &= APInt(UsefulBits.getBitWidth(), Imm);
1853 getUsefulBits(Op, UsefulBits, Depth + 1);
1856 static void getUsefulBitsFromBitfieldMoveOpd(SDValue Op, APInt &UsefulBits,
1857 uint64_t Imm, uint64_t MSB,
1859 // inherit the bitwidth value
1860 APInt OpUsefulBits(UsefulBits);
1864 OpUsefulBits <<= MSB - Imm + 1;
1866 // The interesting part will be in the lower part of the result
1867 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1868 // The interesting part was starting at Imm in the argument
1869 OpUsefulBits <<= Imm;
1871 OpUsefulBits <<= MSB + 1;
1873 // The interesting part will be shifted in the result
1874 OpUsefulBits <<= OpUsefulBits.getBitWidth() - Imm;
1875 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1876 // The interesting part was at zero in the argument
1877 OpUsefulBits.lshrInPlace(OpUsefulBits.getBitWidth() - Imm);
1880 UsefulBits &= OpUsefulBits;
1883 static void getUsefulBitsFromUBFM(SDValue Op, APInt &UsefulBits,
1886 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1888 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1890 getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1893 static void getUsefulBitsFromOrWithShiftedReg(SDValue Op, APInt &UsefulBits,
1895 uint64_t ShiftTypeAndValue =
1896 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1897 APInt Mask(UsefulBits);
1898 Mask.clearAllBits();
1901 if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSL) {
1903 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1905 getUsefulBits(Op, Mask, Depth + 1);
1906 Mask.lshrInPlace(ShiftAmt);
1907 } else if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSR) {
1909 // We do not handle AArch64_AM::ASR, because the sign will change the
1910 // number of useful bits
1911 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1912 Mask.lshrInPlace(ShiftAmt);
1913 getUsefulBits(Op, Mask, Depth + 1);
1921 static void getUsefulBitsFromBFM(SDValue Op, SDValue Orig, APInt &UsefulBits,
1924 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1926 cast<const ConstantSDNode>(Op.getOperand(3).getNode())->getZExtValue();
1928 APInt OpUsefulBits(UsefulBits);
1931 APInt ResultUsefulBits(UsefulBits.getBitWidth(), 0);
1932 ResultUsefulBits.flipAllBits();
1933 APInt Mask(UsefulBits.getBitWidth(), 0);
1935 getUsefulBits(Op, ResultUsefulBits, Depth + 1);
1938 // The instruction is a BFXIL.
1939 uint64_t Width = MSB - Imm + 1;
1942 OpUsefulBits <<= Width;
1945 if (Op.getOperand(1) == Orig) {
1946 // Copy the low bits from the result to bits starting from LSB.
1947 Mask = ResultUsefulBits & OpUsefulBits;
1951 if (Op.getOperand(0) == Orig)
1952 // Bits starting from LSB in the input contribute to the result.
1953 Mask |= (ResultUsefulBits & ~OpUsefulBits);
1955 // The instruction is a BFI.
1956 uint64_t Width = MSB + 1;
1957 uint64_t LSB = UsefulBits.getBitWidth() - Imm;
1959 OpUsefulBits <<= Width;
1961 OpUsefulBits <<= LSB;
1963 if (Op.getOperand(1) == Orig) {
1964 // Copy the bits from the result to the zero bits.
1965 Mask = ResultUsefulBits & OpUsefulBits;
1966 Mask.lshrInPlace(LSB);
1969 if (Op.getOperand(0) == Orig)
1970 Mask |= (ResultUsefulBits & ~OpUsefulBits);
1976 static void getUsefulBitsForUse(SDNode *UserNode, APInt &UsefulBits,
1977 SDValue Orig, unsigned Depth) {
1979 // Users of this node should have already been instruction selected
1980 // FIXME: Can we turn that into an assert?
1981 if (!UserNode->isMachineOpcode())
1984 switch (UserNode->getMachineOpcode()) {
1987 case AArch64::ANDSWri:
1988 case AArch64::ANDSXri:
1989 case AArch64::ANDWri:
1990 case AArch64::ANDXri:
1991 // We increment Depth only when we call the getUsefulBits
1992 return getUsefulBitsFromAndWithImmediate(SDValue(UserNode, 0), UsefulBits,
1994 case AArch64::UBFMWri:
1995 case AArch64::UBFMXri:
1996 return getUsefulBitsFromUBFM(SDValue(UserNode, 0), UsefulBits, Depth);
1998 case AArch64::ORRWrs:
1999 case AArch64::ORRXrs:
2000 if (UserNode->getOperand(1) != Orig)
2002 return getUsefulBitsFromOrWithShiftedReg(SDValue(UserNode, 0), UsefulBits,
2004 case AArch64::BFMWri:
2005 case AArch64::BFMXri:
2006 return getUsefulBitsFromBFM(SDValue(UserNode, 0), Orig, UsefulBits, Depth);
2008 case AArch64::STRBBui:
2009 case AArch64::STURBBi:
2010 if (UserNode->getOperand(0) != Orig)
2012 UsefulBits &= APInt(UsefulBits.getBitWidth(), 0xff);
2015 case AArch64::STRHHui:
2016 case AArch64::STURHHi:
2017 if (UserNode->getOperand(0) != Orig)
2019 UsefulBits &= APInt(UsefulBits.getBitWidth(), 0xffff);
2024 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
2027 // Initialize UsefulBits
2029 unsigned Bitwidth = Op.getScalarValueSizeInBits();
2030 // At the beginning, assume every produced bits is useful
2031 UsefulBits = APInt(Bitwidth, 0);
2032 UsefulBits.flipAllBits();
2034 APInt UsersUsefulBits(UsefulBits.getBitWidth(), 0);
2036 for (SDNode *Node : Op.getNode()->uses()) {
2037 // A use cannot produce useful bits
2038 APInt UsefulBitsForUse = APInt(UsefulBits);
2039 getUsefulBitsForUse(Node, UsefulBitsForUse, Op, Depth);
2040 UsersUsefulBits |= UsefulBitsForUse;
2042 // UsefulBits contains the produced bits that are meaningful for the
2043 // current definition, thus a user cannot make a bit meaningful at
2045 UsefulBits &= UsersUsefulBits;
2048 /// Create a machine node performing a notional SHL of Op by ShlAmount. If
2049 /// ShlAmount is negative, do a (logical) right-shift instead. If ShlAmount is
2050 /// 0, return Op unchanged.
2051 static SDValue getLeftShift(SelectionDAG *CurDAG, SDValue Op, int ShlAmount) {
2055 EVT VT = Op.getValueType();
2057 unsigned BitWidth = VT.getSizeInBits();
2058 unsigned UBFMOpc = BitWidth == 32 ? AArch64::UBFMWri : AArch64::UBFMXri;
2061 if (ShlAmount > 0) {
2062 // LSL wD, wN, #Amt == UBFM wD, wN, #32-Amt, #31-Amt
2063 ShiftNode = CurDAG->getMachineNode(
2064 UBFMOpc, dl, VT, Op,
2065 CurDAG->getTargetConstant(BitWidth - ShlAmount, dl, VT),
2066 CurDAG->getTargetConstant(BitWidth - 1 - ShlAmount, dl, VT));
2068 // LSR wD, wN, #Amt == UBFM wD, wN, #Amt, #32-1
2069 assert(ShlAmount < 0 && "expected right shift");
2070 int ShrAmount = -ShlAmount;
2071 ShiftNode = CurDAG->getMachineNode(
2072 UBFMOpc, dl, VT, Op, CurDAG->getTargetConstant(ShrAmount, dl, VT),
2073 CurDAG->getTargetConstant(BitWidth - 1, dl, VT));
2076 return SDValue(ShiftNode, 0);
2079 /// Does this tree qualify as an attempt to move a bitfield into position,
2080 /// essentially "(and (shl VAL, N), Mask)".
2081 static bool isBitfieldPositioningOp(SelectionDAG *CurDAG, SDValue Op,
2083 SDValue &Src, int &ShiftAmount,
2085 EVT VT = Op.getValueType();
2086 unsigned BitWidth = VT.getSizeInBits();
2088 assert(BitWidth == 32 || BitWidth == 64);
2090 KnownBits Known = CurDAG->computeKnownBits(Op);
2092 // Non-zero in the sense that they're not provably zero, which is the key
2093 // point if we want to use this value
2094 uint64_t NonZeroBits = (~Known.Zero).getZExtValue();
2096 // Discard a constant AND mask if present. It's safe because the node will
2097 // already have been factored into the computeKnownBits calculation above.
2099 if (isOpcWithIntImmediate(Op.getNode(), ISD::AND, AndImm)) {
2100 assert((~APInt(BitWidth, AndImm) & ~Known.Zero) == 0);
2101 Op = Op.getOperand(0);
2104 // Don't match if the SHL has more than one use, since then we'll end up
2105 // generating SHL+UBFIZ instead of just keeping SHL+AND.
2106 if (!BiggerPattern && !Op.hasOneUse())
2110 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SHL, ShlImm))
2112 Op = Op.getOperand(0);
2114 if (!isShiftedMask_64(NonZeroBits))
2117 ShiftAmount = countTrailingZeros(NonZeroBits);
2118 MaskWidth = countTrailingOnes(NonZeroBits >> ShiftAmount);
2120 // BFI encompasses sufficiently many nodes that it's worth inserting an extra
2121 // LSL/LSR if the mask in NonZeroBits doesn't quite match up with the ISD::SHL
2122 // amount. BiggerPattern is true when this pattern is being matched for BFI,
2123 // BiggerPattern is false when this pattern is being matched for UBFIZ, in
2124 // which case it is not profitable to insert an extra shift.
2125 if (ShlImm - ShiftAmount != 0 && !BiggerPattern)
2127 Src = getLeftShift(CurDAG, Op, ShlImm - ShiftAmount);
2132 static bool isShiftedMask(uint64_t Mask, EVT VT) {
2133 assert(VT == MVT::i32 || VT == MVT::i64);
2135 return isShiftedMask_32(Mask);
2136 return isShiftedMask_64(Mask);
2139 // Generate a BFI/BFXIL from 'or (and X, MaskImm), OrImm' iff the value being
2140 // inserted only sets known zero bits.
2141 static bool tryBitfieldInsertOpFromOrAndImm(SDNode *N, SelectionDAG *CurDAG) {
2142 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
2144 EVT VT = N->getValueType(0);
2145 if (VT != MVT::i32 && VT != MVT::i64)
2148 unsigned BitWidth = VT.getSizeInBits();
2151 if (!isOpcWithIntImmediate(N, ISD::OR, OrImm))
2154 // Skip this transformation if the ORR immediate can be encoded in the ORR.
2155 // Otherwise, we'll trade an AND+ORR for ORR+BFI/BFXIL, which is most likely
2156 // performance neutral.
2157 if (AArch64_AM::isLogicalImmediate(OrImm, BitWidth))
2161 SDValue And = N->getOperand(0);
2162 // Must be a single use AND with an immediate operand.
2163 if (!And.hasOneUse() ||
2164 !isOpcWithIntImmediate(And.getNode(), ISD::AND, MaskImm))
2167 // Compute the Known Zero for the AND as this allows us to catch more general
2168 // cases than just looking for AND with imm.
2169 KnownBits Known = CurDAG->computeKnownBits(And);
2171 // Non-zero in the sense that they're not provably zero, which is the key
2172 // point if we want to use this value.
2173 uint64_t NotKnownZero = (~Known.Zero).getZExtValue();
2175 // The KnownZero mask must be a shifted mask (e.g., 1110..011, 11100..00).
2176 if (!isShiftedMask(Known.Zero.getZExtValue(), VT))
2179 // The bits being inserted must only set those bits that are known to be zero.
2180 if ((OrImm & NotKnownZero) != 0) {
2181 // FIXME: It's okay if the OrImm sets NotKnownZero bits to 1, but we don't
2182 // currently handle this case.
2186 // BFI/BFXIL dst, src, #lsb, #width.
2187 int LSB = countTrailingOnes(NotKnownZero);
2188 int Width = BitWidth - APInt(BitWidth, NotKnownZero).countPopulation();
2190 // BFI/BFXIL is an alias of BFM, so translate to BFM operands.
2191 unsigned ImmR = (BitWidth - LSB) % BitWidth;
2192 unsigned ImmS = Width - 1;
2194 // If we're creating a BFI instruction avoid cases where we need more
2195 // instructions to materialize the BFI constant as compared to the original
2196 // ORR. A BFXIL will use the same constant as the original ORR, so the code
2197 // should be no worse in this case.
2198 bool IsBFI = LSB != 0;
2199 uint64_t BFIImm = OrImm >> LSB;
2200 if (IsBFI && !AArch64_AM::isLogicalImmediate(BFIImm, BitWidth)) {
2201 // We have a BFI instruction and we know the constant can't be materialized
2202 // with a ORR-immediate with the zero register.
2203 unsigned OrChunks = 0, BFIChunks = 0;
2204 for (unsigned Shift = 0; Shift < BitWidth; Shift += 16) {
2205 if (((OrImm >> Shift) & 0xFFFF) != 0)
2207 if (((BFIImm >> Shift) & 0xFFFF) != 0)
2210 if (BFIChunks > OrChunks)
2214 // Materialize the constant to be inserted.
2216 unsigned MOVIOpc = VT == MVT::i32 ? AArch64::MOVi32imm : AArch64::MOVi64imm;
2217 SDNode *MOVI = CurDAG->getMachineNode(
2218 MOVIOpc, DL, VT, CurDAG->getTargetConstant(BFIImm, DL, VT));
2220 // Create the BFI/BFXIL instruction.
2221 SDValue Ops[] = {And.getOperand(0), SDValue(MOVI, 0),
2222 CurDAG->getTargetConstant(ImmR, DL, VT),
2223 CurDAG->getTargetConstant(ImmS, DL, VT)};
2224 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2225 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2229 static bool tryBitfieldInsertOpFromOr(SDNode *N, const APInt &UsefulBits,
2230 SelectionDAG *CurDAG) {
2231 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
2233 EVT VT = N->getValueType(0);
2234 if (VT != MVT::i32 && VT != MVT::i64)
2237 unsigned BitWidth = VT.getSizeInBits();
2239 // Because of simplify-demanded-bits in DAGCombine, involved masks may not
2240 // have the expected shape. Try to undo that.
2242 unsigned NumberOfIgnoredLowBits = UsefulBits.countTrailingZeros();
2243 unsigned NumberOfIgnoredHighBits = UsefulBits.countLeadingZeros();
2245 // Given a OR operation, check if we have the following pattern
2246 // ubfm c, b, imm, imm2 (or something that does the same jobs, see
2247 // isBitfieldExtractOp)
2248 // d = e & mask2 ; where mask is a binary sequence of 1..10..0 and
2249 // countTrailingZeros(mask2) == imm2 - imm + 1
2251 // if yes, replace the OR instruction with:
2252 // f = BFM Opd0, Opd1, LSB, MSB ; where LSB = imm, and MSB = imm2
2254 // OR is commutative, check all combinations of operand order and values of
2255 // BiggerPattern, i.e.
2256 // Opd0, Opd1, BiggerPattern=false
2257 // Opd1, Opd0, BiggerPattern=false
2258 // Opd0, Opd1, BiggerPattern=true
2259 // Opd1, Opd0, BiggerPattern=true
2260 // Several of these combinations may match, so check with BiggerPattern=false
2261 // first since that will produce better results by matching more instructions
2262 // and/or inserting fewer extra instructions.
2263 for (int I = 0; I < 4; ++I) {
2266 unsigned ImmR, ImmS;
2267 bool BiggerPattern = I / 2;
2268 SDValue OrOpd0Val = N->getOperand(I % 2);
2269 SDNode *OrOpd0 = OrOpd0Val.getNode();
2270 SDValue OrOpd1Val = N->getOperand((I + 1) % 2);
2271 SDNode *OrOpd1 = OrOpd1Val.getNode();
2275 if (isBitfieldExtractOp(CurDAG, OrOpd0, BFXOpc, Src, ImmR, ImmS,
2276 NumberOfIgnoredLowBits, BiggerPattern)) {
2277 // Check that the returned opcode is compatible with the pattern,
2278 // i.e., same type and zero extended (U and not S)
2279 if ((BFXOpc != AArch64::UBFMXri && VT == MVT::i64) ||
2280 (BFXOpc != AArch64::UBFMWri && VT == MVT::i32))
2283 // Compute the width of the bitfield insertion
2285 Width = ImmS - ImmR + 1;
2286 // FIXME: This constraint is to catch bitfield insertion we may
2287 // want to widen the pattern if we want to grab general bitfied
2292 // If the mask on the insertee is correct, we have a BFXIL operation. We
2293 // can share the ImmR and ImmS values from the already-computed UBFM.
2294 } else if (isBitfieldPositioningOp(CurDAG, OrOpd0Val,
2296 Src, DstLSB, Width)) {
2297 ImmR = (BitWidth - DstLSB) % BitWidth;
2302 // Check the second part of the pattern
2303 EVT VT = OrOpd1Val.getValueType();
2304 assert((VT == MVT::i32 || VT == MVT::i64) && "unexpected OR operand");
2306 // Compute the Known Zero for the candidate of the first operand.
2307 // This allows to catch more general case than just looking for
2308 // AND with imm. Indeed, simplify-demanded-bits may have removed
2309 // the AND instruction because it proves it was useless.
2310 KnownBits Known = CurDAG->computeKnownBits(OrOpd1Val);
2312 // Check if there is enough room for the second operand to appear
2314 APInt BitsToBeInserted =
2315 APInt::getBitsSet(Known.getBitWidth(), DstLSB, DstLSB + Width);
2317 if ((BitsToBeInserted & ~Known.Zero) != 0)
2320 // Set the first operand
2322 if (isOpcWithIntImmediate(OrOpd1, ISD::AND, Imm) &&
2323 isBitfieldDstMask(Imm, BitsToBeInserted, NumberOfIgnoredHighBits, VT))
2324 // In that case, we can eliminate the AND
2325 Dst = OrOpd1->getOperand(0);
2327 // Maybe the AND has been removed by simplify-demanded-bits
2328 // or is useful because it discards more bits
2333 SDValue Ops[] = {Dst, Src, CurDAG->getTargetConstant(ImmR, DL, VT),
2334 CurDAG->getTargetConstant(ImmS, DL, VT)};
2335 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2336 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2340 // Generate a BFXIL from 'or (and X, Mask0Imm), (and Y, Mask1Imm)' iff
2341 // Mask0Imm and ~Mask1Imm are equivalent and one of the MaskImms is a shifted
2342 // mask (e.g., 0x000ffff0).
2343 uint64_t Mask0Imm, Mask1Imm;
2344 SDValue And0 = N->getOperand(0);
2345 SDValue And1 = N->getOperand(1);
2346 if (And0.hasOneUse() && And1.hasOneUse() &&
2347 isOpcWithIntImmediate(And0.getNode(), ISD::AND, Mask0Imm) &&
2348 isOpcWithIntImmediate(And1.getNode(), ISD::AND, Mask1Imm) &&
2349 APInt(BitWidth, Mask0Imm) == ~APInt(BitWidth, Mask1Imm) &&
2350 (isShiftedMask(Mask0Imm, VT) || isShiftedMask(Mask1Imm, VT))) {
2352 // ORR is commutative, so canonicalize to the form 'or (and X, Mask0Imm),
2353 // (and Y, Mask1Imm)' where Mask1Imm is the shifted mask masking off the
2354 // bits to be inserted.
2355 if (isShiftedMask(Mask0Imm, VT)) {
2356 std::swap(And0, And1);
2357 std::swap(Mask0Imm, Mask1Imm);
2360 SDValue Src = And1->getOperand(0);
2361 SDValue Dst = And0->getOperand(0);
2362 unsigned LSB = countTrailingZeros(Mask1Imm);
2363 int Width = BitWidth - APInt(BitWidth, Mask0Imm).countPopulation();
2365 // The BFXIL inserts the low-order bits from a source register, so right
2366 // shift the needed bits into place.
2368 unsigned ShiftOpc = (VT == MVT::i32) ? AArch64::UBFMWri : AArch64::UBFMXri;
2369 SDNode *LSR = CurDAG->getMachineNode(
2370 ShiftOpc, DL, VT, Src, CurDAG->getTargetConstant(LSB, DL, VT),
2371 CurDAG->getTargetConstant(BitWidth - 1, DL, VT));
2373 // BFXIL is an alias of BFM, so translate to BFM operands.
2374 unsigned ImmR = (BitWidth - LSB) % BitWidth;
2375 unsigned ImmS = Width - 1;
2377 // Create the BFXIL instruction.
2378 SDValue Ops[] = {Dst, SDValue(LSR, 0),
2379 CurDAG->getTargetConstant(ImmR, DL, VT),
2380 CurDAG->getTargetConstant(ImmS, DL, VT)};
2381 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2382 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2389 bool AArch64DAGToDAGISel::tryBitfieldInsertOp(SDNode *N) {
2390 if (N->getOpcode() != ISD::OR)
2394 getUsefulBits(SDValue(N, 0), NUsefulBits);
2396 // If all bits are not useful, just return UNDEF.
2398 CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF, N->getValueType(0));
2402 if (tryBitfieldInsertOpFromOr(N, NUsefulBits, CurDAG))
2405 return tryBitfieldInsertOpFromOrAndImm(N, CurDAG);
2408 /// SelectBitfieldInsertInZeroOp - Match a UBFIZ instruction that is the
2409 /// equivalent of a left shift by a constant amount followed by an and masking
2410 /// out a contiguous set of bits.
2411 bool AArch64DAGToDAGISel::tryBitfieldInsertInZeroOp(SDNode *N) {
2412 if (N->getOpcode() != ISD::AND)
2415 EVT VT = N->getValueType(0);
2416 if (VT != MVT::i32 && VT != MVT::i64)
2421 if (!isBitfieldPositioningOp(CurDAG, SDValue(N, 0), /*BiggerPattern=*/false,
2422 Op0, DstLSB, Width))
2425 // ImmR is the rotate right amount.
2426 unsigned ImmR = (VT.getSizeInBits() - DstLSB) % VT.getSizeInBits();
2427 // ImmS is the most significant bit of the source to be moved.
2428 unsigned ImmS = Width - 1;
2431 SDValue Ops[] = {Op0, CurDAG->getTargetConstant(ImmR, DL, VT),
2432 CurDAG->getTargetConstant(ImmS, DL, VT)};
2433 unsigned Opc = (VT == MVT::i32) ? AArch64::UBFMWri : AArch64::UBFMXri;
2434 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2438 /// tryShiftAmountMod - Take advantage of built-in mod of shift amount in
2439 /// variable shift/rotate instructions.
2440 bool AArch64DAGToDAGISel::tryShiftAmountMod(SDNode *N) {
2441 EVT VT = N->getValueType(0);
2444 switch (N->getOpcode()) {
2446 Opc = (VT == MVT::i32) ? AArch64::RORVWr : AArch64::RORVXr;
2449 Opc = (VT == MVT::i32) ? AArch64::LSLVWr : AArch64::LSLVXr;
2452 Opc = (VT == MVT::i32) ? AArch64::LSRVWr : AArch64::LSRVXr;
2455 Opc = (VT == MVT::i32) ? AArch64::ASRVWr : AArch64::ASRVXr;
2463 if (VT == MVT::i32) {
2466 } else if (VT == MVT::i64) {
2472 SDValue ShiftAmt = N->getOperand(1);
2474 SDValue NewShiftAmt;
2476 // Skip over an extend of the shift amount.
2477 if (ShiftAmt->getOpcode() == ISD::ZERO_EXTEND ||
2478 ShiftAmt->getOpcode() == ISD::ANY_EXTEND)
2479 ShiftAmt = ShiftAmt->getOperand(0);
2481 if (ShiftAmt->getOpcode() == ISD::ADD || ShiftAmt->getOpcode() == ISD::SUB) {
2482 SDValue Add0 = ShiftAmt->getOperand(0);
2483 SDValue Add1 = ShiftAmt->getOperand(1);
2486 // If we are shifting by X+/-N where N == 0 mod Size, then just shift by X
2487 // to avoid the ADD/SUB.
2488 if (isIntImmediate(Add1, Add1Imm) && (Add1Imm % Size == 0))
2490 // If we are shifting by N-X where N == 0 mod Size, then just shift by -X to
2491 // generate a NEG instead of a SUB of a constant.
2492 else if (ShiftAmt->getOpcode() == ISD::SUB &&
2493 isIntImmediate(Add0, Add0Imm) && Add0Imm != 0 &&
2494 (Add0Imm % Size == 0)) {
2497 EVT SubVT = ShiftAmt->getValueType(0);
2498 if (SubVT == MVT::i32) {
2499 NegOpc = AArch64::SUBWrr;
2500 ZeroReg = AArch64::WZR;
2502 assert(SubVT == MVT::i64);
2503 NegOpc = AArch64::SUBXrr;
2504 ZeroReg = AArch64::XZR;
2507 CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL, ZeroReg, SubVT);
2508 MachineSDNode *Neg =
2509 CurDAG->getMachineNode(NegOpc, DL, SubVT, Zero, Add1);
2510 NewShiftAmt = SDValue(Neg, 0);
2514 // If the shift amount is masked with an AND, check that the mask covers the
2515 // bits that are implicitly ANDed off by the above opcodes and if so, skip
2518 if (!isOpcWithIntImmediate(ShiftAmt.getNode(), ISD::AND, MaskImm))
2521 if (countTrailingOnes(MaskImm) < Bits)
2524 NewShiftAmt = ShiftAmt->getOperand(0);
2527 // Narrow/widen the shift amount to match the size of the shift operation.
2529 NewShiftAmt = narrowIfNeeded(CurDAG, NewShiftAmt);
2530 else if (VT == MVT::i64 && NewShiftAmt->getValueType(0) == MVT::i32) {
2531 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, DL, MVT::i32);
2532 MachineSDNode *Ext = CurDAG->getMachineNode(
2533 AArch64::SUBREG_TO_REG, DL, VT,
2534 CurDAG->getTargetConstant(0, DL, MVT::i64), NewShiftAmt, SubReg);
2535 NewShiftAmt = SDValue(Ext, 0);
2538 SDValue Ops[] = {N->getOperand(0), NewShiftAmt};
2539 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2544 AArch64DAGToDAGISel::SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
2545 unsigned RegWidth) {
2547 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N))
2548 FVal = CN->getValueAPF();
2549 else if (LoadSDNode *LN = dyn_cast<LoadSDNode>(N)) {
2550 // Some otherwise illegal constants are allowed in this case.
2551 if (LN->getOperand(1).getOpcode() != AArch64ISD::ADDlow ||
2552 !isa<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1)))
2555 ConstantPoolSDNode *CN =
2556 dyn_cast<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1));
2557 FVal = cast<ConstantFP>(CN->getConstVal())->getValueAPF();
2561 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
2562 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
2565 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
2566 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
2570 // fbits is between 1 and 64 in the worst-case, which means the fmul
2571 // could have 2^64 as an actual operand. Need 65 bits of precision.
2572 APSInt IntVal(65, true);
2573 FVal.convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
2575 // N.b. isPowerOf2 also checks for > 0.
2576 if (!IsExact || !IntVal.isPowerOf2()) return false;
2577 unsigned FBits = IntVal.logBase2();
2579 // Checks above should have guaranteed that we haven't lost information in
2580 // finding FBits, but it must still be in range.
2581 if (FBits == 0 || FBits > RegWidth) return false;
2583 FixedPos = CurDAG->getTargetConstant(FBits, SDLoc(N), MVT::i32);
2587 // Inspects a register string of the form o0:op1:CRn:CRm:op2 gets the fields
2588 // of the string and obtains the integer values from them and combines these
2589 // into a single value to be used in the MRS/MSR instruction.
2590 static int getIntOperandFromRegisterString(StringRef RegString) {
2591 SmallVector<StringRef, 5> Fields;
2592 RegString.split(Fields, ':');
2594 if (Fields.size() == 1)
2597 assert(Fields.size() == 5
2598 && "Invalid number of fields in read register string");
2600 SmallVector<int, 5> Ops;
2601 bool AllIntFields = true;
2603 for (StringRef Field : Fields) {
2605 AllIntFields &= !Field.getAsInteger(10, IntField);
2606 Ops.push_back(IntField);
2609 assert(AllIntFields &&
2610 "Unexpected non-integer value in special register string.");
2612 // Need to combine the integer fields of the string into a single value
2613 // based on the bit encoding of MRS/MSR instruction.
2614 return (Ops[0] << 14) | (Ops[1] << 11) | (Ops[2] << 7) |
2615 (Ops[3] << 3) | (Ops[4]);
2618 // Lower the read_register intrinsic to an MRS instruction node if the special
2619 // register string argument is either of the form detailed in the ALCE (the
2620 // form described in getIntOperandsFromRegsterString) or is a named register
2621 // known by the MRS SysReg mapper.
2622 bool AArch64DAGToDAGISel::tryReadRegister(SDNode *N) {
2623 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2624 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2627 int Reg = getIntOperandFromRegisterString(RegString->getString());
2629 ReplaceNode(N, CurDAG->getMachineNode(
2630 AArch64::MRS, DL, N->getSimpleValueType(0), MVT::Other,
2631 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2636 // Use the sysreg mapper to map the remaining possible strings to the
2637 // value for the register to be used for the instruction operand.
2638 auto TheReg = AArch64SysReg::lookupSysRegByName(RegString->getString());
2639 if (TheReg && TheReg->Readable &&
2640 TheReg->haveFeatures(Subtarget->getFeatureBits()))
2641 Reg = TheReg->Encoding;
2643 Reg = AArch64SysReg::parseGenericRegister(RegString->getString());
2646 ReplaceNode(N, CurDAG->getMachineNode(
2647 AArch64::MRS, DL, N->getSimpleValueType(0), MVT::Other,
2648 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2656 // Lower the write_register intrinsic to an MSR instruction node if the special
2657 // register string argument is either of the form detailed in the ALCE (the
2658 // form described in getIntOperandsFromRegsterString) or is a named register
2659 // known by the MSR SysReg mapper.
2660 bool AArch64DAGToDAGISel::tryWriteRegister(SDNode *N) {
2661 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2662 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2665 int Reg = getIntOperandFromRegisterString(RegString->getString());
2668 N, CurDAG->getMachineNode(AArch64::MSR, DL, MVT::Other,
2669 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2670 N->getOperand(2), N->getOperand(0)));
2674 // Check if the register was one of those allowed as the pstatefield value in
2675 // the MSR (immediate) instruction. To accept the values allowed in the
2676 // pstatefield for the MSR (immediate) instruction, we also require that an
2677 // immediate value has been provided as an argument, we know that this is
2678 // the case as it has been ensured by semantic checking.
2679 auto PMapper = AArch64PState::lookupPStateByName(RegString->getString());
2681 assert (isa<ConstantSDNode>(N->getOperand(2))
2682 && "Expected a constant integer expression.");
2683 unsigned Reg = PMapper->Encoding;
2684 uint64_t Immed = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
2686 if (Reg == AArch64PState::PAN || Reg == AArch64PState::UAO || Reg == AArch64PState::SSBS) {
2687 assert(Immed < 2 && "Bad imm");
2688 State = AArch64::MSRpstateImm1;
2690 assert(Immed < 16 && "Bad imm");
2691 State = AArch64::MSRpstateImm4;
2693 ReplaceNode(N, CurDAG->getMachineNode(
2694 State, DL, MVT::Other,
2695 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2696 CurDAG->getTargetConstant(Immed, DL, MVT::i16),
2701 // Use the sysreg mapper to attempt to map the remaining possible strings
2702 // to the value for the register to be used for the MSR (register)
2703 // instruction operand.
2704 auto TheReg = AArch64SysReg::lookupSysRegByName(RegString->getString());
2705 if (TheReg && TheReg->Writeable &&
2706 TheReg->haveFeatures(Subtarget->getFeatureBits()))
2707 Reg = TheReg->Encoding;
2709 Reg = AArch64SysReg::parseGenericRegister(RegString->getString());
2711 ReplaceNode(N, CurDAG->getMachineNode(
2712 AArch64::MSR, DL, MVT::Other,
2713 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2714 N->getOperand(2), N->getOperand(0)));
2721 /// We've got special pseudo-instructions for these
2722 bool AArch64DAGToDAGISel::SelectCMP_SWAP(SDNode *N) {
2724 EVT MemTy = cast<MemSDNode>(N)->getMemoryVT();
2726 // Leave IR for LSE if subtarget supports it.
2727 if (Subtarget->hasLSE()) return false;
2729 if (MemTy == MVT::i8)
2730 Opcode = AArch64::CMP_SWAP_8;
2731 else if (MemTy == MVT::i16)
2732 Opcode = AArch64::CMP_SWAP_16;
2733 else if (MemTy == MVT::i32)
2734 Opcode = AArch64::CMP_SWAP_32;
2735 else if (MemTy == MVT::i64)
2736 Opcode = AArch64::CMP_SWAP_64;
2738 llvm_unreachable("Unknown AtomicCmpSwap type");
2740 MVT RegTy = MemTy == MVT::i64 ? MVT::i64 : MVT::i32;
2741 SDValue Ops[] = {N->getOperand(1), N->getOperand(2), N->getOperand(3),
2743 SDNode *CmpSwap = CurDAG->getMachineNode(
2745 CurDAG->getVTList(RegTy, MVT::i32, MVT::Other), Ops);
2747 MachineMemOperand *MemOp = cast<MemSDNode>(N)->getMemOperand();
2748 CurDAG->setNodeMemRefs(cast<MachineSDNode>(CmpSwap), {MemOp});
2750 ReplaceUses(SDValue(N, 0), SDValue(CmpSwap, 0));
2751 ReplaceUses(SDValue(N, 1), SDValue(CmpSwap, 2));
2752 CurDAG->RemoveDeadNode(N);
2757 void AArch64DAGToDAGISel::Select(SDNode *Node) {
2758 // If we have a custom node, we already have selected!
2759 if (Node->isMachineOpcode()) {
2760 LLVM_DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
2761 Node->setNodeId(-1);
2765 // Few custom selection stuff.
2766 EVT VT = Node->getValueType(0);
2768 switch (Node->getOpcode()) {
2772 case ISD::ATOMIC_CMP_SWAP:
2773 if (SelectCMP_SWAP(Node))
2777 case ISD::READ_REGISTER:
2778 if (tryReadRegister(Node))
2782 case ISD::WRITE_REGISTER:
2783 if (tryWriteRegister(Node))
2788 if (tryMLAV64LaneV128(Node))
2793 // Try to select as an indexed load. Fall through to normal processing
2795 if (tryIndexedLoad(Node))
2803 case ISD::SIGN_EXTEND_INREG:
2804 if (tryBitfieldExtractOp(Node))
2806 if (tryBitfieldInsertInZeroOp(Node))
2811 if (tryShiftAmountMod(Node))
2815 case ISD::SIGN_EXTEND:
2816 if (tryBitfieldExtractOpFromSExt(Node))
2821 if (tryBitfieldInsertOp(Node))
2825 case ISD::EXTRACT_VECTOR_ELT: {
2826 // Extracting lane zero is a special case where we can just use a plain
2827 // EXTRACT_SUBREG instruction, which will become FMOV. This is easier for
2828 // the rest of the compiler, especially the register allocator and copyi
2829 // propagation, to reason about, so is preferred when it's possible to
2831 ConstantSDNode *LaneNode = cast<ConstantSDNode>(Node->getOperand(1));
2832 // Bail and use the default Select() for non-zero lanes.
2833 if (LaneNode->getZExtValue() != 0)
2835 // If the element type is not the same as the result type, likewise
2836 // bail and use the default Select(), as there's more to do than just
2837 // a cross-class COPY. This catches extracts of i8 and i16 elements
2838 // since they will need an explicit zext.
2839 if (VT != Node->getOperand(0).getValueType().getVectorElementType())
2842 switch (Node->getOperand(0)
2844 .getVectorElementType()
2847 llvm_unreachable("Unexpected vector element type!");
2849 SubReg = AArch64::dsub;
2852 SubReg = AArch64::ssub;
2855 SubReg = AArch64::hsub;
2858 llvm_unreachable("unexpected zext-requiring extract element!");
2860 SDValue Extract = CurDAG->getTargetExtractSubreg(SubReg, SDLoc(Node), VT,
2861 Node->getOperand(0));
2862 LLVM_DEBUG(dbgs() << "ISEL: Custom selection!\n=> ");
2863 LLVM_DEBUG(Extract->dumpr(CurDAG));
2864 LLVM_DEBUG(dbgs() << "\n");
2865 ReplaceNode(Node, Extract.getNode());
2868 case ISD::Constant: {
2869 // Materialize zero constants as copies from WZR/XZR. This allows
2870 // the coalescer to propagate these into other instructions.
2871 ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
2872 if (ConstNode->isNullValue()) {
2873 if (VT == MVT::i32) {
2874 SDValue New = CurDAG->getCopyFromReg(
2875 CurDAG->getEntryNode(), SDLoc(Node), AArch64::WZR, MVT::i32);
2876 ReplaceNode(Node, New.getNode());
2878 } else if (VT == MVT::i64) {
2879 SDValue New = CurDAG->getCopyFromReg(
2880 CurDAG->getEntryNode(), SDLoc(Node), AArch64::XZR, MVT::i64);
2881 ReplaceNode(Node, New.getNode());
2888 case ISD::FrameIndex: {
2889 // Selects to ADDXri FI, 0 which in turn will become ADDXri SP, imm.
2890 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
2891 unsigned Shifter = AArch64_AM::getShifterImm(AArch64_AM::LSL, 0);
2892 const TargetLowering *TLI = getTargetLowering();
2893 SDValue TFI = CurDAG->getTargetFrameIndex(
2894 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
2896 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, DL, MVT::i32),
2897 CurDAG->getTargetConstant(Shifter, DL, MVT::i32) };
2898 CurDAG->SelectNodeTo(Node, AArch64::ADDXri, MVT::i64, Ops);
2901 case ISD::INTRINSIC_W_CHAIN: {
2902 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2906 case Intrinsic::aarch64_ldaxp:
2907 case Intrinsic::aarch64_ldxp: {
2909 IntNo == Intrinsic::aarch64_ldaxp ? AArch64::LDAXPX : AArch64::LDXPX;
2910 SDValue MemAddr = Node->getOperand(2);
2912 SDValue Chain = Node->getOperand(0);
2914 SDNode *Ld = CurDAG->getMachineNode(Op, DL, MVT::i64, MVT::i64,
2915 MVT::Other, MemAddr, Chain);
2917 // Transfer memoperands.
2918 MachineMemOperand *MemOp =
2919 cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2920 CurDAG->setNodeMemRefs(cast<MachineSDNode>(Ld), {MemOp});
2921 ReplaceNode(Node, Ld);
2924 case Intrinsic::aarch64_stlxp:
2925 case Intrinsic::aarch64_stxp: {
2927 IntNo == Intrinsic::aarch64_stlxp ? AArch64::STLXPX : AArch64::STXPX;
2929 SDValue Chain = Node->getOperand(0);
2930 SDValue ValLo = Node->getOperand(2);
2931 SDValue ValHi = Node->getOperand(3);
2932 SDValue MemAddr = Node->getOperand(4);
2934 // Place arguments in the right order.
2935 SDValue Ops[] = {ValLo, ValHi, MemAddr, Chain};
2937 SDNode *St = CurDAG->getMachineNode(Op, DL, MVT::i32, MVT::Other, Ops);
2938 // Transfer memoperands.
2939 MachineMemOperand *MemOp =
2940 cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2941 CurDAG->setNodeMemRefs(cast<MachineSDNode>(St), {MemOp});
2943 ReplaceNode(Node, St);
2946 case Intrinsic::aarch64_neon_ld1x2:
2947 if (VT == MVT::v8i8) {
2948 SelectLoad(Node, 2, AArch64::LD1Twov8b, AArch64::dsub0);
2950 } else if (VT == MVT::v16i8) {
2951 SelectLoad(Node, 2, AArch64::LD1Twov16b, AArch64::qsub0);
2953 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2954 SelectLoad(Node, 2, AArch64::LD1Twov4h, AArch64::dsub0);
2956 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2957 SelectLoad(Node, 2, AArch64::LD1Twov8h, AArch64::qsub0);
2959 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2960 SelectLoad(Node, 2, AArch64::LD1Twov2s, AArch64::dsub0);
2962 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2963 SelectLoad(Node, 2, AArch64::LD1Twov4s, AArch64::qsub0);
2965 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2966 SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2968 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2969 SelectLoad(Node, 2, AArch64::LD1Twov2d, AArch64::qsub0);
2973 case Intrinsic::aarch64_neon_ld1x3:
2974 if (VT == MVT::v8i8) {
2975 SelectLoad(Node, 3, AArch64::LD1Threev8b, AArch64::dsub0);
2977 } else if (VT == MVT::v16i8) {
2978 SelectLoad(Node, 3, AArch64::LD1Threev16b, AArch64::qsub0);
2980 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2981 SelectLoad(Node, 3, AArch64::LD1Threev4h, AArch64::dsub0);
2983 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2984 SelectLoad(Node, 3, AArch64::LD1Threev8h, AArch64::qsub0);
2986 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2987 SelectLoad(Node, 3, AArch64::LD1Threev2s, AArch64::dsub0);
2989 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2990 SelectLoad(Node, 3, AArch64::LD1Threev4s, AArch64::qsub0);
2992 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2993 SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2995 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2996 SelectLoad(Node, 3, AArch64::LD1Threev2d, AArch64::qsub0);
3000 case Intrinsic::aarch64_neon_ld1x4:
3001 if (VT == MVT::v8i8) {
3002 SelectLoad(Node, 4, AArch64::LD1Fourv8b, AArch64::dsub0);
3004 } else if (VT == MVT::v16i8) {
3005 SelectLoad(Node, 4, AArch64::LD1Fourv16b, AArch64::qsub0);
3007 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3008 SelectLoad(Node, 4, AArch64::LD1Fourv4h, AArch64::dsub0);
3010 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3011 SelectLoad(Node, 4, AArch64::LD1Fourv8h, AArch64::qsub0);
3013 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3014 SelectLoad(Node, 4, AArch64::LD1Fourv2s, AArch64::dsub0);
3016 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3017 SelectLoad(Node, 4, AArch64::LD1Fourv4s, AArch64::qsub0);
3019 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3020 SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
3022 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3023 SelectLoad(Node, 4, AArch64::LD1Fourv2d, AArch64::qsub0);
3027 case Intrinsic::aarch64_neon_ld2:
3028 if (VT == MVT::v8i8) {
3029 SelectLoad(Node, 2, AArch64::LD2Twov8b, AArch64::dsub0);
3031 } else if (VT == MVT::v16i8) {
3032 SelectLoad(Node, 2, AArch64::LD2Twov16b, AArch64::qsub0);
3034 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3035 SelectLoad(Node, 2, AArch64::LD2Twov4h, AArch64::dsub0);
3037 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3038 SelectLoad(Node, 2, AArch64::LD2Twov8h, AArch64::qsub0);
3040 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3041 SelectLoad(Node, 2, AArch64::LD2Twov2s, AArch64::dsub0);
3043 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3044 SelectLoad(Node, 2, AArch64::LD2Twov4s, AArch64::qsub0);
3046 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3047 SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
3049 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3050 SelectLoad(Node, 2, AArch64::LD2Twov2d, AArch64::qsub0);
3054 case Intrinsic::aarch64_neon_ld3:
3055 if (VT == MVT::v8i8) {
3056 SelectLoad(Node, 3, AArch64::LD3Threev8b, AArch64::dsub0);
3058 } else if (VT == MVT::v16i8) {
3059 SelectLoad(Node, 3, AArch64::LD3Threev16b, AArch64::qsub0);
3061 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3062 SelectLoad(Node, 3, AArch64::LD3Threev4h, AArch64::dsub0);
3064 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3065 SelectLoad(Node, 3, AArch64::LD3Threev8h, AArch64::qsub0);
3067 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3068 SelectLoad(Node, 3, AArch64::LD3Threev2s, AArch64::dsub0);
3070 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3071 SelectLoad(Node, 3, AArch64::LD3Threev4s, AArch64::qsub0);
3073 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3074 SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
3076 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3077 SelectLoad(Node, 3, AArch64::LD3Threev2d, AArch64::qsub0);
3081 case Intrinsic::aarch64_neon_ld4:
3082 if (VT == MVT::v8i8) {
3083 SelectLoad(Node, 4, AArch64::LD4Fourv8b, AArch64::dsub0);
3085 } else if (VT == MVT::v16i8) {
3086 SelectLoad(Node, 4, AArch64::LD4Fourv16b, AArch64::qsub0);
3088 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3089 SelectLoad(Node, 4, AArch64::LD4Fourv4h, AArch64::dsub0);
3091 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3092 SelectLoad(Node, 4, AArch64::LD4Fourv8h, AArch64::qsub0);
3094 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3095 SelectLoad(Node, 4, AArch64::LD4Fourv2s, AArch64::dsub0);
3097 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3098 SelectLoad(Node, 4, AArch64::LD4Fourv4s, AArch64::qsub0);
3100 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3101 SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
3103 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3104 SelectLoad(Node, 4, AArch64::LD4Fourv2d, AArch64::qsub0);
3108 case Intrinsic::aarch64_neon_ld2r:
3109 if (VT == MVT::v8i8) {
3110 SelectLoad(Node, 2, AArch64::LD2Rv8b, AArch64::dsub0);
3112 } else if (VT == MVT::v16i8) {
3113 SelectLoad(Node, 2, AArch64::LD2Rv16b, AArch64::qsub0);
3115 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3116 SelectLoad(Node, 2, AArch64::LD2Rv4h, AArch64::dsub0);
3118 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3119 SelectLoad(Node, 2, AArch64::LD2Rv8h, AArch64::qsub0);
3121 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3122 SelectLoad(Node, 2, AArch64::LD2Rv2s, AArch64::dsub0);
3124 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3125 SelectLoad(Node, 2, AArch64::LD2Rv4s, AArch64::qsub0);
3127 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3128 SelectLoad(Node, 2, AArch64::LD2Rv1d, AArch64::dsub0);
3130 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3131 SelectLoad(Node, 2, AArch64::LD2Rv2d, AArch64::qsub0);
3135 case Intrinsic::aarch64_neon_ld3r:
3136 if (VT == MVT::v8i8) {
3137 SelectLoad(Node, 3, AArch64::LD3Rv8b, AArch64::dsub0);
3139 } else if (VT == MVT::v16i8) {
3140 SelectLoad(Node, 3, AArch64::LD3Rv16b, AArch64::qsub0);
3142 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3143 SelectLoad(Node, 3, AArch64::LD3Rv4h, AArch64::dsub0);
3145 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3146 SelectLoad(Node, 3, AArch64::LD3Rv8h, AArch64::qsub0);
3148 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3149 SelectLoad(Node, 3, AArch64::LD3Rv2s, AArch64::dsub0);
3151 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3152 SelectLoad(Node, 3, AArch64::LD3Rv4s, AArch64::qsub0);
3154 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3155 SelectLoad(Node, 3, AArch64::LD3Rv1d, AArch64::dsub0);
3157 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3158 SelectLoad(Node, 3, AArch64::LD3Rv2d, AArch64::qsub0);
3162 case Intrinsic::aarch64_neon_ld4r:
3163 if (VT == MVT::v8i8) {
3164 SelectLoad(Node, 4, AArch64::LD4Rv8b, AArch64::dsub0);
3166 } else if (VT == MVT::v16i8) {
3167 SelectLoad(Node, 4, AArch64::LD4Rv16b, AArch64::qsub0);
3169 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3170 SelectLoad(Node, 4, AArch64::LD4Rv4h, AArch64::dsub0);
3172 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3173 SelectLoad(Node, 4, AArch64::LD4Rv8h, AArch64::qsub0);
3175 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3176 SelectLoad(Node, 4, AArch64::LD4Rv2s, AArch64::dsub0);
3178 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3179 SelectLoad(Node, 4, AArch64::LD4Rv4s, AArch64::qsub0);
3181 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3182 SelectLoad(Node, 4, AArch64::LD4Rv1d, AArch64::dsub0);
3184 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3185 SelectLoad(Node, 4, AArch64::LD4Rv2d, AArch64::qsub0);
3189 case Intrinsic::aarch64_neon_ld2lane:
3190 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3191 SelectLoadLane(Node, 2, AArch64::LD2i8);
3193 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3195 SelectLoadLane(Node, 2, AArch64::LD2i16);
3197 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3199 SelectLoadLane(Node, 2, AArch64::LD2i32);
3201 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3203 SelectLoadLane(Node, 2, AArch64::LD2i64);
3207 case Intrinsic::aarch64_neon_ld3lane:
3208 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3209 SelectLoadLane(Node, 3, AArch64::LD3i8);
3211 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3213 SelectLoadLane(Node, 3, AArch64::LD3i16);
3215 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3217 SelectLoadLane(Node, 3, AArch64::LD3i32);
3219 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3221 SelectLoadLane(Node, 3, AArch64::LD3i64);
3225 case Intrinsic::aarch64_neon_ld4lane:
3226 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3227 SelectLoadLane(Node, 4, AArch64::LD4i8);
3229 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3231 SelectLoadLane(Node, 4, AArch64::LD4i16);
3233 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3235 SelectLoadLane(Node, 4, AArch64::LD4i32);
3237 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3239 SelectLoadLane(Node, 4, AArch64::LD4i64);
3245 case ISD::INTRINSIC_WO_CHAIN: {
3246 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue();
3250 case Intrinsic::aarch64_neon_tbl2:
3251 SelectTable(Node, 2,
3252 VT == MVT::v8i8 ? AArch64::TBLv8i8Two : AArch64::TBLv16i8Two,
3255 case Intrinsic::aarch64_neon_tbl3:
3256 SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBLv8i8Three
3257 : AArch64::TBLv16i8Three,
3260 case Intrinsic::aarch64_neon_tbl4:
3261 SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBLv8i8Four
3262 : AArch64::TBLv16i8Four,
3265 case Intrinsic::aarch64_neon_tbx2:
3266 SelectTable(Node, 2,
3267 VT == MVT::v8i8 ? AArch64::TBXv8i8Two : AArch64::TBXv16i8Two,
3270 case Intrinsic::aarch64_neon_tbx3:
3271 SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBXv8i8Three
3272 : AArch64::TBXv16i8Three,
3275 case Intrinsic::aarch64_neon_tbx4:
3276 SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBXv8i8Four
3277 : AArch64::TBXv16i8Four,
3280 case Intrinsic::aarch64_neon_smull:
3281 case Intrinsic::aarch64_neon_umull:
3282 if (tryMULLV64LaneV128(IntNo, Node))
3288 case ISD::INTRINSIC_VOID: {
3289 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
3290 if (Node->getNumOperands() >= 3)
3291 VT = Node->getOperand(2)->getValueType(0);
3295 case Intrinsic::aarch64_neon_st1x2: {
3296 if (VT == MVT::v8i8) {
3297 SelectStore(Node, 2, AArch64::ST1Twov8b);
3299 } else if (VT == MVT::v16i8) {
3300 SelectStore(Node, 2, AArch64::ST1Twov16b);
3302 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3303 SelectStore(Node, 2, AArch64::ST1Twov4h);
3305 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3306 SelectStore(Node, 2, AArch64::ST1Twov8h);
3308 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3309 SelectStore(Node, 2, AArch64::ST1Twov2s);
3311 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3312 SelectStore(Node, 2, AArch64::ST1Twov4s);
3314 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3315 SelectStore(Node, 2, AArch64::ST1Twov2d);
3317 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3318 SelectStore(Node, 2, AArch64::ST1Twov1d);
3323 case Intrinsic::aarch64_neon_st1x3: {
3324 if (VT == MVT::v8i8) {
3325 SelectStore(Node, 3, AArch64::ST1Threev8b);
3327 } else if (VT == MVT::v16i8) {
3328 SelectStore(Node, 3, AArch64::ST1Threev16b);
3330 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3331 SelectStore(Node, 3, AArch64::ST1Threev4h);
3333 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3334 SelectStore(Node, 3, AArch64::ST1Threev8h);
3336 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3337 SelectStore(Node, 3, AArch64::ST1Threev2s);
3339 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3340 SelectStore(Node, 3, AArch64::ST1Threev4s);
3342 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3343 SelectStore(Node, 3, AArch64::ST1Threev2d);
3345 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3346 SelectStore(Node, 3, AArch64::ST1Threev1d);
3351 case Intrinsic::aarch64_neon_st1x4: {
3352 if (VT == MVT::v8i8) {
3353 SelectStore(Node, 4, AArch64::ST1Fourv8b);
3355 } else if (VT == MVT::v16i8) {
3356 SelectStore(Node, 4, AArch64::ST1Fourv16b);
3358 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3359 SelectStore(Node, 4, AArch64::ST1Fourv4h);
3361 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3362 SelectStore(Node, 4, AArch64::ST1Fourv8h);
3364 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3365 SelectStore(Node, 4, AArch64::ST1Fourv2s);
3367 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3368 SelectStore(Node, 4, AArch64::ST1Fourv4s);
3370 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3371 SelectStore(Node, 4, AArch64::ST1Fourv2d);
3373 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3374 SelectStore(Node, 4, AArch64::ST1Fourv1d);
3379 case Intrinsic::aarch64_neon_st2: {
3380 if (VT == MVT::v8i8) {
3381 SelectStore(Node, 2, AArch64::ST2Twov8b);
3383 } else if (VT == MVT::v16i8) {
3384 SelectStore(Node, 2, AArch64::ST2Twov16b);
3386 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3387 SelectStore(Node, 2, AArch64::ST2Twov4h);
3389 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3390 SelectStore(Node, 2, AArch64::ST2Twov8h);
3392 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3393 SelectStore(Node, 2, AArch64::ST2Twov2s);
3395 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3396 SelectStore(Node, 2, AArch64::ST2Twov4s);
3398 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3399 SelectStore(Node, 2, AArch64::ST2Twov2d);
3401 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3402 SelectStore(Node, 2, AArch64::ST1Twov1d);
3407 case Intrinsic::aarch64_neon_st3: {
3408 if (VT == MVT::v8i8) {
3409 SelectStore(Node, 3, AArch64::ST3Threev8b);
3411 } else if (VT == MVT::v16i8) {
3412 SelectStore(Node, 3, AArch64::ST3Threev16b);
3414 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3415 SelectStore(Node, 3, AArch64::ST3Threev4h);
3417 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3418 SelectStore(Node, 3, AArch64::ST3Threev8h);
3420 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3421 SelectStore(Node, 3, AArch64::ST3Threev2s);
3423 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3424 SelectStore(Node, 3, AArch64::ST3Threev4s);
3426 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3427 SelectStore(Node, 3, AArch64::ST3Threev2d);
3429 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3430 SelectStore(Node, 3, AArch64::ST1Threev1d);
3435 case Intrinsic::aarch64_neon_st4: {
3436 if (VT == MVT::v8i8) {
3437 SelectStore(Node, 4, AArch64::ST4Fourv8b);
3439 } else if (VT == MVT::v16i8) {
3440 SelectStore(Node, 4, AArch64::ST4Fourv16b);
3442 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3443 SelectStore(Node, 4, AArch64::ST4Fourv4h);
3445 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3446 SelectStore(Node, 4, AArch64::ST4Fourv8h);
3448 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3449 SelectStore(Node, 4, AArch64::ST4Fourv2s);
3451 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3452 SelectStore(Node, 4, AArch64::ST4Fourv4s);
3454 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3455 SelectStore(Node, 4, AArch64::ST4Fourv2d);
3457 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3458 SelectStore(Node, 4, AArch64::ST1Fourv1d);
3463 case Intrinsic::aarch64_neon_st2lane: {
3464 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3465 SelectStoreLane(Node, 2, AArch64::ST2i8);
3467 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3469 SelectStoreLane(Node, 2, AArch64::ST2i16);
3471 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3473 SelectStoreLane(Node, 2, AArch64::ST2i32);
3475 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3477 SelectStoreLane(Node, 2, AArch64::ST2i64);
3482 case Intrinsic::aarch64_neon_st3lane: {
3483 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3484 SelectStoreLane(Node, 3, AArch64::ST3i8);
3486 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3488 SelectStoreLane(Node, 3, AArch64::ST3i16);
3490 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3492 SelectStoreLane(Node, 3, AArch64::ST3i32);
3494 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3496 SelectStoreLane(Node, 3, AArch64::ST3i64);
3501 case Intrinsic::aarch64_neon_st4lane: {
3502 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3503 SelectStoreLane(Node, 4, AArch64::ST4i8);
3505 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3507 SelectStoreLane(Node, 4, AArch64::ST4i16);
3509 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3511 SelectStoreLane(Node, 4, AArch64::ST4i32);
3513 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3515 SelectStoreLane(Node, 4, AArch64::ST4i64);
3523 case AArch64ISD::LD2post: {
3524 if (VT == MVT::v8i8) {
3525 SelectPostLoad(Node, 2, AArch64::LD2Twov8b_POST, AArch64::dsub0);
3527 } else if (VT == MVT::v16i8) {
3528 SelectPostLoad(Node, 2, AArch64::LD2Twov16b_POST, AArch64::qsub0);
3530 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3531 SelectPostLoad(Node, 2, AArch64::LD2Twov4h_POST, AArch64::dsub0);
3533 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3534 SelectPostLoad(Node, 2, AArch64::LD2Twov8h_POST, AArch64::qsub0);
3536 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3537 SelectPostLoad(Node, 2, AArch64::LD2Twov2s_POST, AArch64::dsub0);
3539 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3540 SelectPostLoad(Node, 2, AArch64::LD2Twov4s_POST, AArch64::qsub0);
3542 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3543 SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
3545 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3546 SelectPostLoad(Node, 2, AArch64::LD2Twov2d_POST, AArch64::qsub0);
3551 case AArch64ISD::LD3post: {
3552 if (VT == MVT::v8i8) {
3553 SelectPostLoad(Node, 3, AArch64::LD3Threev8b_POST, AArch64::dsub0);
3555 } else if (VT == MVT::v16i8) {
3556 SelectPostLoad(Node, 3, AArch64::LD3Threev16b_POST, AArch64::qsub0);
3558 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3559 SelectPostLoad(Node, 3, AArch64::LD3Threev4h_POST, AArch64::dsub0);
3561 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3562 SelectPostLoad(Node, 3, AArch64::LD3Threev8h_POST, AArch64::qsub0);
3564 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3565 SelectPostLoad(Node, 3, AArch64::LD3Threev2s_POST, AArch64::dsub0);
3567 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3568 SelectPostLoad(Node, 3, AArch64::LD3Threev4s_POST, AArch64::qsub0);
3570 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3571 SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
3573 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3574 SelectPostLoad(Node, 3, AArch64::LD3Threev2d_POST, AArch64::qsub0);
3579 case AArch64ISD::LD4post: {
3580 if (VT == MVT::v8i8) {
3581 SelectPostLoad(Node, 4, AArch64::LD4Fourv8b_POST, AArch64::dsub0);
3583 } else if (VT == MVT::v16i8) {
3584 SelectPostLoad(Node, 4, AArch64::LD4Fourv16b_POST, AArch64::qsub0);
3586 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3587 SelectPostLoad(Node, 4, AArch64::LD4Fourv4h_POST, AArch64::dsub0);
3589 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3590 SelectPostLoad(Node, 4, AArch64::LD4Fourv8h_POST, AArch64::qsub0);
3592 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3593 SelectPostLoad(Node, 4, AArch64::LD4Fourv2s_POST, AArch64::dsub0);
3595 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3596 SelectPostLoad(Node, 4, AArch64::LD4Fourv4s_POST, AArch64::qsub0);
3598 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3599 SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
3601 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3602 SelectPostLoad(Node, 4, AArch64::LD4Fourv2d_POST, AArch64::qsub0);
3607 case AArch64ISD::LD1x2post: {
3608 if (VT == MVT::v8i8) {
3609 SelectPostLoad(Node, 2, AArch64::LD1Twov8b_POST, AArch64::dsub0);
3611 } else if (VT == MVT::v16i8) {
3612 SelectPostLoad(Node, 2, AArch64::LD1Twov16b_POST, AArch64::qsub0);
3614 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3615 SelectPostLoad(Node, 2, AArch64::LD1Twov4h_POST, AArch64::dsub0);
3617 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3618 SelectPostLoad(Node, 2, AArch64::LD1Twov8h_POST, AArch64::qsub0);
3620 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3621 SelectPostLoad(Node, 2, AArch64::LD1Twov2s_POST, AArch64::dsub0);
3623 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3624 SelectPostLoad(Node, 2, AArch64::LD1Twov4s_POST, AArch64::qsub0);
3626 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3627 SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
3629 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3630 SelectPostLoad(Node, 2, AArch64::LD1Twov2d_POST, AArch64::qsub0);
3635 case AArch64ISD::LD1x3post: {
3636 if (VT == MVT::v8i8) {
3637 SelectPostLoad(Node, 3, AArch64::LD1Threev8b_POST, AArch64::dsub0);
3639 } else if (VT == MVT::v16i8) {
3640 SelectPostLoad(Node, 3, AArch64::LD1Threev16b_POST, AArch64::qsub0);
3642 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3643 SelectPostLoad(Node, 3, AArch64::LD1Threev4h_POST, AArch64::dsub0);
3645 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3646 SelectPostLoad(Node, 3, AArch64::LD1Threev8h_POST, AArch64::qsub0);
3648 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3649 SelectPostLoad(Node, 3, AArch64::LD1Threev2s_POST, AArch64::dsub0);
3651 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3652 SelectPostLoad(Node, 3, AArch64::LD1Threev4s_POST, AArch64::qsub0);
3654 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3655 SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
3657 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3658 SelectPostLoad(Node, 3, AArch64::LD1Threev2d_POST, AArch64::qsub0);
3663 case AArch64ISD::LD1x4post: {
3664 if (VT == MVT::v8i8) {
3665 SelectPostLoad(Node, 4, AArch64::LD1Fourv8b_POST, AArch64::dsub0);
3667 } else if (VT == MVT::v16i8) {
3668 SelectPostLoad(Node, 4, AArch64::LD1Fourv16b_POST, AArch64::qsub0);
3670 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3671 SelectPostLoad(Node, 4, AArch64::LD1Fourv4h_POST, AArch64::dsub0);
3673 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3674 SelectPostLoad(Node, 4, AArch64::LD1Fourv8h_POST, AArch64::qsub0);
3676 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3677 SelectPostLoad(Node, 4, AArch64::LD1Fourv2s_POST, AArch64::dsub0);
3679 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3680 SelectPostLoad(Node, 4, AArch64::LD1Fourv4s_POST, AArch64::qsub0);
3682 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3683 SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
3685 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3686 SelectPostLoad(Node, 4, AArch64::LD1Fourv2d_POST, AArch64::qsub0);
3691 case AArch64ISD::LD1DUPpost: {
3692 if (VT == MVT::v8i8) {
3693 SelectPostLoad(Node, 1, AArch64::LD1Rv8b_POST, AArch64::dsub0);
3695 } else if (VT == MVT::v16i8) {
3696 SelectPostLoad(Node, 1, AArch64::LD1Rv16b_POST, AArch64::qsub0);
3698 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3699 SelectPostLoad(Node, 1, AArch64::LD1Rv4h_POST, AArch64::dsub0);
3701 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3702 SelectPostLoad(Node, 1, AArch64::LD1Rv8h_POST, AArch64::qsub0);
3704 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3705 SelectPostLoad(Node, 1, AArch64::LD1Rv2s_POST, AArch64::dsub0);
3707 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3708 SelectPostLoad(Node, 1, AArch64::LD1Rv4s_POST, AArch64::qsub0);
3710 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3711 SelectPostLoad(Node, 1, AArch64::LD1Rv1d_POST, AArch64::dsub0);
3713 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3714 SelectPostLoad(Node, 1, AArch64::LD1Rv2d_POST, AArch64::qsub0);
3719 case AArch64ISD::LD2DUPpost: {
3720 if (VT == MVT::v8i8) {
3721 SelectPostLoad(Node, 2, AArch64::LD2Rv8b_POST, AArch64::dsub0);
3723 } else if (VT == MVT::v16i8) {
3724 SelectPostLoad(Node, 2, AArch64::LD2Rv16b_POST, AArch64::qsub0);
3726 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3727 SelectPostLoad(Node, 2, AArch64::LD2Rv4h_POST, AArch64::dsub0);
3729 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3730 SelectPostLoad(Node, 2, AArch64::LD2Rv8h_POST, AArch64::qsub0);
3732 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3733 SelectPostLoad(Node, 2, AArch64::LD2Rv2s_POST, AArch64::dsub0);
3735 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3736 SelectPostLoad(Node, 2, AArch64::LD2Rv4s_POST, AArch64::qsub0);
3738 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3739 SelectPostLoad(Node, 2, AArch64::LD2Rv1d_POST, AArch64::dsub0);
3741 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3742 SelectPostLoad(Node, 2, AArch64::LD2Rv2d_POST, AArch64::qsub0);
3747 case AArch64ISD::LD3DUPpost: {
3748 if (VT == MVT::v8i8) {
3749 SelectPostLoad(Node, 3, AArch64::LD3Rv8b_POST, AArch64::dsub0);
3751 } else if (VT == MVT::v16i8) {
3752 SelectPostLoad(Node, 3, AArch64::LD3Rv16b_POST, AArch64::qsub0);
3754 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3755 SelectPostLoad(Node, 3, AArch64::LD3Rv4h_POST, AArch64::dsub0);
3757 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3758 SelectPostLoad(Node, 3, AArch64::LD3Rv8h_POST, AArch64::qsub0);
3760 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3761 SelectPostLoad(Node, 3, AArch64::LD3Rv2s_POST, AArch64::dsub0);
3763 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3764 SelectPostLoad(Node, 3, AArch64::LD3Rv4s_POST, AArch64::qsub0);
3766 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3767 SelectPostLoad(Node, 3, AArch64::LD3Rv1d_POST, AArch64::dsub0);
3769 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3770 SelectPostLoad(Node, 3, AArch64::LD3Rv2d_POST, AArch64::qsub0);
3775 case AArch64ISD::LD4DUPpost: {
3776 if (VT == MVT::v8i8) {
3777 SelectPostLoad(Node, 4, AArch64::LD4Rv8b_POST, AArch64::dsub0);
3779 } else if (VT == MVT::v16i8) {
3780 SelectPostLoad(Node, 4, AArch64::LD4Rv16b_POST, AArch64::qsub0);
3782 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3783 SelectPostLoad(Node, 4, AArch64::LD4Rv4h_POST, AArch64::dsub0);
3785 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3786 SelectPostLoad(Node, 4, AArch64::LD4Rv8h_POST, AArch64::qsub0);
3788 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3789 SelectPostLoad(Node, 4, AArch64::LD4Rv2s_POST, AArch64::dsub0);
3791 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3792 SelectPostLoad(Node, 4, AArch64::LD4Rv4s_POST, AArch64::qsub0);
3794 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3795 SelectPostLoad(Node, 4, AArch64::LD4Rv1d_POST, AArch64::dsub0);
3797 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3798 SelectPostLoad(Node, 4, AArch64::LD4Rv2d_POST, AArch64::qsub0);
3803 case AArch64ISD::LD1LANEpost: {
3804 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3805 SelectPostLoadLane(Node, 1, AArch64::LD1i8_POST);
3807 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3809 SelectPostLoadLane(Node, 1, AArch64::LD1i16_POST);
3811 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3813 SelectPostLoadLane(Node, 1, AArch64::LD1i32_POST);
3815 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3817 SelectPostLoadLane(Node, 1, AArch64::LD1i64_POST);
3822 case AArch64ISD::LD2LANEpost: {
3823 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3824 SelectPostLoadLane(Node, 2, AArch64::LD2i8_POST);
3826 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3828 SelectPostLoadLane(Node, 2, AArch64::LD2i16_POST);
3830 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3832 SelectPostLoadLane(Node, 2, AArch64::LD2i32_POST);
3834 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3836 SelectPostLoadLane(Node, 2, AArch64::LD2i64_POST);
3841 case AArch64ISD::LD3LANEpost: {
3842 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3843 SelectPostLoadLane(Node, 3, AArch64::LD3i8_POST);
3845 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3847 SelectPostLoadLane(Node, 3, AArch64::LD3i16_POST);
3849 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3851 SelectPostLoadLane(Node, 3, AArch64::LD3i32_POST);
3853 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3855 SelectPostLoadLane(Node, 3, AArch64::LD3i64_POST);
3860 case AArch64ISD::LD4LANEpost: {
3861 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3862 SelectPostLoadLane(Node, 4, AArch64::LD4i8_POST);
3864 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3866 SelectPostLoadLane(Node, 4, AArch64::LD4i16_POST);
3868 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3870 SelectPostLoadLane(Node, 4, AArch64::LD4i32_POST);
3872 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3874 SelectPostLoadLane(Node, 4, AArch64::LD4i64_POST);
3879 case AArch64ISD::ST2post: {
3880 VT = Node->getOperand(1).getValueType();
3881 if (VT == MVT::v8i8) {
3882 SelectPostStore(Node, 2, AArch64::ST2Twov8b_POST);
3884 } else if (VT == MVT::v16i8) {
3885 SelectPostStore(Node, 2, AArch64::ST2Twov16b_POST);
3887 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3888 SelectPostStore(Node, 2, AArch64::ST2Twov4h_POST);
3890 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3891 SelectPostStore(Node, 2, AArch64::ST2Twov8h_POST);
3893 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3894 SelectPostStore(Node, 2, AArch64::ST2Twov2s_POST);
3896 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3897 SelectPostStore(Node, 2, AArch64::ST2Twov4s_POST);
3899 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3900 SelectPostStore(Node, 2, AArch64::ST2Twov2d_POST);
3902 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3903 SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3908 case AArch64ISD::ST3post: {
3909 VT = Node->getOperand(1).getValueType();
3910 if (VT == MVT::v8i8) {
3911 SelectPostStore(Node, 3, AArch64::ST3Threev8b_POST);
3913 } else if (VT == MVT::v16i8) {
3914 SelectPostStore(Node, 3, AArch64::ST3Threev16b_POST);
3916 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3917 SelectPostStore(Node, 3, AArch64::ST3Threev4h_POST);
3919 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3920 SelectPostStore(Node, 3, AArch64::ST3Threev8h_POST);
3922 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3923 SelectPostStore(Node, 3, AArch64::ST3Threev2s_POST);
3925 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3926 SelectPostStore(Node, 3, AArch64::ST3Threev4s_POST);
3928 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3929 SelectPostStore(Node, 3, AArch64::ST3Threev2d_POST);
3931 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3932 SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3937 case AArch64ISD::ST4post: {
3938 VT = Node->getOperand(1).getValueType();
3939 if (VT == MVT::v8i8) {
3940 SelectPostStore(Node, 4, AArch64::ST4Fourv8b_POST);
3942 } else if (VT == MVT::v16i8) {
3943 SelectPostStore(Node, 4, AArch64::ST4Fourv16b_POST);
3945 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3946 SelectPostStore(Node, 4, AArch64::ST4Fourv4h_POST);
3948 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3949 SelectPostStore(Node, 4, AArch64::ST4Fourv8h_POST);
3951 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3952 SelectPostStore(Node, 4, AArch64::ST4Fourv2s_POST);
3954 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3955 SelectPostStore(Node, 4, AArch64::ST4Fourv4s_POST);
3957 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3958 SelectPostStore(Node, 4, AArch64::ST4Fourv2d_POST);
3960 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3961 SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3966 case AArch64ISD::ST1x2post: {
3967 VT = Node->getOperand(1).getValueType();
3968 if (VT == MVT::v8i8) {
3969 SelectPostStore(Node, 2, AArch64::ST1Twov8b_POST);
3971 } else if (VT == MVT::v16i8) {
3972 SelectPostStore(Node, 2, AArch64::ST1Twov16b_POST);
3974 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3975 SelectPostStore(Node, 2, AArch64::ST1Twov4h_POST);
3977 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3978 SelectPostStore(Node, 2, AArch64::ST1Twov8h_POST);
3980 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3981 SelectPostStore(Node, 2, AArch64::ST1Twov2s_POST);
3983 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3984 SelectPostStore(Node, 2, AArch64::ST1Twov4s_POST);
3986 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3987 SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3989 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3990 SelectPostStore(Node, 2, AArch64::ST1Twov2d_POST);
3995 case AArch64ISD::ST1x3post: {
3996 VT = Node->getOperand(1).getValueType();
3997 if (VT == MVT::v8i8) {
3998 SelectPostStore(Node, 3, AArch64::ST1Threev8b_POST);
4000 } else if (VT == MVT::v16i8) {
4001 SelectPostStore(Node, 3, AArch64::ST1Threev16b_POST);
4003 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
4004 SelectPostStore(Node, 3, AArch64::ST1Threev4h_POST);
4006 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
4007 SelectPostStore(Node, 3, AArch64::ST1Threev8h_POST);
4009 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
4010 SelectPostStore(Node, 3, AArch64::ST1Threev2s_POST);
4012 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
4013 SelectPostStore(Node, 3, AArch64::ST1Threev4s_POST);
4015 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
4016 SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
4018 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
4019 SelectPostStore(Node, 3, AArch64::ST1Threev2d_POST);
4024 case AArch64ISD::ST1x4post: {
4025 VT = Node->getOperand(1).getValueType();
4026 if (VT == MVT::v8i8) {
4027 SelectPostStore(Node, 4, AArch64::ST1Fourv8b_POST);
4029 } else if (VT == MVT::v16i8) {
4030 SelectPostStore(Node, 4, AArch64::ST1Fourv16b_POST);
4032 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
4033 SelectPostStore(Node, 4, AArch64::ST1Fourv4h_POST);
4035 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
4036 SelectPostStore(Node, 4, AArch64::ST1Fourv8h_POST);
4038 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
4039 SelectPostStore(Node, 4, AArch64::ST1Fourv2s_POST);
4041 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
4042 SelectPostStore(Node, 4, AArch64::ST1Fourv4s_POST);
4044 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
4045 SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
4047 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
4048 SelectPostStore(Node, 4, AArch64::ST1Fourv2d_POST);
4053 case AArch64ISD::ST2LANEpost: {
4054 VT = Node->getOperand(1).getValueType();
4055 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
4056 SelectPostStoreLane(Node, 2, AArch64::ST2i8_POST);
4058 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
4060 SelectPostStoreLane(Node, 2, AArch64::ST2i16_POST);
4062 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
4064 SelectPostStoreLane(Node, 2, AArch64::ST2i32_POST);
4066 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
4068 SelectPostStoreLane(Node, 2, AArch64::ST2i64_POST);
4073 case AArch64ISD::ST3LANEpost: {
4074 VT = Node->getOperand(1).getValueType();
4075 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
4076 SelectPostStoreLane(Node, 3, AArch64::ST3i8_POST);
4078 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
4080 SelectPostStoreLane(Node, 3, AArch64::ST3i16_POST);
4082 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
4084 SelectPostStoreLane(Node, 3, AArch64::ST3i32_POST);
4086 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
4088 SelectPostStoreLane(Node, 3, AArch64::ST3i64_POST);
4093 case AArch64ISD::ST4LANEpost: {
4094 VT = Node->getOperand(1).getValueType();
4095 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
4096 SelectPostStoreLane(Node, 4, AArch64::ST4i8_POST);
4098 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
4100 SelectPostStoreLane(Node, 4, AArch64::ST4i16_POST);
4102 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
4104 SelectPostStoreLane(Node, 4, AArch64::ST4i32_POST);
4106 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
4108 SelectPostStoreLane(Node, 4, AArch64::ST4i64_POST);
4115 // Select the default instruction
4119 /// createAArch64ISelDag - This pass converts a legalized DAG into a
4120 /// AArch64-specific DAG, ready for instruction scheduling.
4121 FunctionPass *llvm::createAArch64ISelDag(AArch64TargetMachine &TM,
4122 CodeGenOpt::Level OptLevel) {
4123 return new AArch64DAGToDAGISel(TM, OptLevel);