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);
172 bool tryReadRegister(SDNode *N);
173 bool tryWriteRegister(SDNode *N);
175 // Include the pieces autogenerated from the target description.
176 #include "AArch64GenDAGISel.inc"
179 bool SelectShiftedRegister(SDValue N, bool AllowROR, SDValue &Reg,
181 bool SelectAddrModeIndexed7S(SDValue N, unsigned Size, SDValue &Base,
183 bool SelectAddrModeIndexed(SDValue N, unsigned Size, SDValue &Base,
185 bool SelectAddrModeUnscaled(SDValue N, unsigned Size, SDValue &Base,
187 bool SelectAddrModeWRO(SDValue N, unsigned Size, SDValue &Base,
188 SDValue &Offset, SDValue &SignExtend,
190 bool SelectAddrModeXRO(SDValue N, unsigned Size, SDValue &Base,
191 SDValue &Offset, SDValue &SignExtend,
193 bool isWorthFolding(SDValue V) const;
194 bool SelectExtendedSHL(SDValue N, unsigned Size, bool WantExtend,
195 SDValue &Offset, SDValue &SignExtend);
197 template<unsigned RegWidth>
198 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos) {
199 return SelectCVTFixedPosOperand(N, FixedPos, RegWidth);
202 bool SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos, unsigned Width);
204 void SelectCMP_SWAP(SDNode *N);
207 } // end anonymous namespace
209 /// isIntImmediate - This method tests to see if the node is a constant
210 /// operand. If so Imm will receive the 32-bit value.
211 static bool isIntImmediate(const SDNode *N, uint64_t &Imm) {
212 if (const ConstantSDNode *C = dyn_cast<const ConstantSDNode>(N)) {
213 Imm = C->getZExtValue();
219 // isIntImmediate - This method tests to see if a constant operand.
220 // If so Imm will receive the value.
221 static bool isIntImmediate(SDValue N, uint64_t &Imm) {
222 return isIntImmediate(N.getNode(), Imm);
225 // isOpcWithIntImmediate - This method tests to see if the node is a specific
226 // opcode and that it has a immediate integer right operand.
227 // If so Imm will receive the 32 bit value.
228 static bool isOpcWithIntImmediate(const SDNode *N, unsigned Opc,
230 return N->getOpcode() == Opc &&
231 isIntImmediate(N->getOperand(1).getNode(), Imm);
234 bool AArch64DAGToDAGISel::SelectInlineAsmMemoryOperand(
235 const SDValue &Op, unsigned ConstraintID, std::vector<SDValue> &OutOps) {
236 switch(ConstraintID) {
238 llvm_unreachable("Unexpected asm memory constraint");
239 case InlineAsm::Constraint_i:
240 case InlineAsm::Constraint_m:
241 case InlineAsm::Constraint_Q:
242 // Require the address to be in a register. That is safe for all AArch64
243 // variants and it is hard to do anything much smarter without knowing
244 // how the operand is used.
245 OutOps.push_back(Op);
251 /// SelectArithImmed - Select an immediate value that can be represented as
252 /// a 12-bit value shifted left by either 0 or 12. If so, return true with
253 /// Val set to the 12-bit value and Shift set to the shifter operand.
254 bool AArch64DAGToDAGISel::SelectArithImmed(SDValue N, SDValue &Val,
256 // This function is called from the addsub_shifted_imm ComplexPattern,
257 // which lists [imm] as the list of opcode it's interested in, however
258 // we still need to check whether the operand is actually an immediate
259 // here because the ComplexPattern opcode list is only used in
260 // root-level opcode matching.
261 if (!isa<ConstantSDNode>(N.getNode()))
264 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
267 if (Immed >> 12 == 0) {
269 } else if ((Immed & 0xfff) == 0 && Immed >> 24 == 0) {
275 unsigned ShVal = AArch64_AM::getShifterImm(AArch64_AM::LSL, ShiftAmt);
277 Val = CurDAG->getTargetConstant(Immed, dl, MVT::i32);
278 Shift = CurDAG->getTargetConstant(ShVal, dl, MVT::i32);
282 /// SelectNegArithImmed - As above, but negates the value before trying to
284 bool AArch64DAGToDAGISel::SelectNegArithImmed(SDValue N, SDValue &Val,
286 // This function is called from the addsub_shifted_imm ComplexPattern,
287 // which lists [imm] as the list of opcode it's interested in, however
288 // we still need to check whether the operand is actually an immediate
289 // here because the ComplexPattern opcode list is only used in
290 // root-level opcode matching.
291 if (!isa<ConstantSDNode>(N.getNode()))
294 // The immediate operand must be a 24-bit zero-extended immediate.
295 uint64_t Immed = cast<ConstantSDNode>(N.getNode())->getZExtValue();
297 // This negation is almost always valid, but "cmp wN, #0" and "cmn wN, #0"
298 // have the opposite effect on the C flag, so this pattern mustn't match under
299 // those circumstances.
303 if (N.getValueType() == MVT::i32)
304 Immed = ~((uint32_t)Immed) + 1;
306 Immed = ~Immed + 1ULL;
307 if (Immed & 0xFFFFFFFFFF000000ULL)
310 Immed &= 0xFFFFFFULL;
311 return SelectArithImmed(CurDAG->getConstant(Immed, SDLoc(N), MVT::i32), Val,
315 /// getShiftTypeForNode - Translate a shift node to the corresponding
317 static AArch64_AM::ShiftExtendType getShiftTypeForNode(SDValue N) {
318 switch (N.getOpcode()) {
320 return AArch64_AM::InvalidShiftExtend;
322 return AArch64_AM::LSL;
324 return AArch64_AM::LSR;
326 return AArch64_AM::ASR;
328 return AArch64_AM::ROR;
332 /// \brief Determine whether it is worth it to fold SHL into the addressing
334 static bool isWorthFoldingSHL(SDValue V) {
335 assert(V.getOpcode() == ISD::SHL && "invalid opcode");
336 // It is worth folding logical shift of up to three places.
337 auto *CSD = dyn_cast<ConstantSDNode>(V.getOperand(1));
340 unsigned ShiftVal = CSD->getZExtValue();
344 // Check if this particular node is reused in any non-memory related
345 // operation. If yes, do not try to fold this node into the address
346 // computation, since the computation will be kept.
347 const SDNode *Node = V.getNode();
348 for (SDNode *UI : Node->uses())
349 if (!isa<MemSDNode>(*UI))
350 for (SDNode *UII : UI->uses())
351 if (!isa<MemSDNode>(*UII))
356 /// \brief Determine whether it is worth to fold V into an extended register.
357 bool AArch64DAGToDAGISel::isWorthFolding(SDValue V) const {
358 // Trivial if we are optimizing for code size or if there is only
359 // one use of the value.
360 if (ForCodeSize || V.hasOneUse())
362 // If a subtarget has a fastpath LSL we can fold a logical shift into
363 // the addressing mode and save a cycle.
364 if (Subtarget->hasLSLFast() && V.getOpcode() == ISD::SHL &&
365 isWorthFoldingSHL(V))
367 if (Subtarget->hasLSLFast() && V.getOpcode() == ISD::ADD) {
368 const SDValue LHS = V.getOperand(0);
369 const SDValue RHS = V.getOperand(1);
370 if (LHS.getOpcode() == ISD::SHL && isWorthFoldingSHL(LHS))
372 if (RHS.getOpcode() == ISD::SHL && isWorthFoldingSHL(RHS))
376 // It hurts otherwise, since the value will be reused.
380 /// SelectShiftedRegister - Select a "shifted register" operand. If the value
381 /// is not shifted, set the Shift operand to default of "LSL 0". The logical
382 /// instructions allow the shifted register to be rotated, but the arithmetic
383 /// instructions do not. The AllowROR parameter specifies whether ROR is
385 bool AArch64DAGToDAGISel::SelectShiftedRegister(SDValue N, bool AllowROR,
386 SDValue &Reg, SDValue &Shift) {
387 AArch64_AM::ShiftExtendType ShType = getShiftTypeForNode(N);
388 if (ShType == AArch64_AM::InvalidShiftExtend)
390 if (!AllowROR && ShType == AArch64_AM::ROR)
393 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
394 unsigned BitSize = N.getValueSizeInBits();
395 unsigned Val = RHS->getZExtValue() & (BitSize - 1);
396 unsigned ShVal = AArch64_AM::getShifterImm(ShType, Val);
398 Reg = N.getOperand(0);
399 Shift = CurDAG->getTargetConstant(ShVal, SDLoc(N), MVT::i32);
400 return isWorthFolding(N);
406 /// getExtendTypeForNode - Translate an extend node to the corresponding
407 /// ExtendType value.
408 static AArch64_AM::ShiftExtendType
409 getExtendTypeForNode(SDValue N, bool IsLoadStore = false) {
410 if (N.getOpcode() == ISD::SIGN_EXTEND ||
411 N.getOpcode() == ISD::SIGN_EXTEND_INREG) {
413 if (N.getOpcode() == ISD::SIGN_EXTEND_INREG)
414 SrcVT = cast<VTSDNode>(N.getOperand(1))->getVT();
416 SrcVT = N.getOperand(0).getValueType();
418 if (!IsLoadStore && SrcVT == MVT::i8)
419 return AArch64_AM::SXTB;
420 else if (!IsLoadStore && SrcVT == MVT::i16)
421 return AArch64_AM::SXTH;
422 else if (SrcVT == MVT::i32)
423 return AArch64_AM::SXTW;
424 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
426 return AArch64_AM::InvalidShiftExtend;
427 } else if (N.getOpcode() == ISD::ZERO_EXTEND ||
428 N.getOpcode() == ISD::ANY_EXTEND) {
429 EVT SrcVT = N.getOperand(0).getValueType();
430 if (!IsLoadStore && SrcVT == MVT::i8)
431 return AArch64_AM::UXTB;
432 else if (!IsLoadStore && SrcVT == MVT::i16)
433 return AArch64_AM::UXTH;
434 else if (SrcVT == MVT::i32)
435 return AArch64_AM::UXTW;
436 assert(SrcVT != MVT::i64 && "extend from 64-bits?");
438 return AArch64_AM::InvalidShiftExtend;
439 } else if (N.getOpcode() == ISD::AND) {
440 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
442 return AArch64_AM::InvalidShiftExtend;
443 uint64_t AndMask = CSD->getZExtValue();
447 return AArch64_AM::InvalidShiftExtend;
449 return !IsLoadStore ? AArch64_AM::UXTB : AArch64_AM::InvalidShiftExtend;
451 return !IsLoadStore ? AArch64_AM::UXTH : AArch64_AM::InvalidShiftExtend;
453 return AArch64_AM::UXTW;
457 return AArch64_AM::InvalidShiftExtend;
460 // Helper for SelectMLAV64LaneV128 - Recognize high lane extracts.
461 static bool checkHighLaneIndex(SDNode *DL, SDValue &LaneOp, int &LaneIdx) {
462 if (DL->getOpcode() != AArch64ISD::DUPLANE16 &&
463 DL->getOpcode() != AArch64ISD::DUPLANE32)
466 SDValue SV = DL->getOperand(0);
467 if (SV.getOpcode() != ISD::INSERT_SUBVECTOR)
470 SDValue EV = SV.getOperand(1);
471 if (EV.getOpcode() != ISD::EXTRACT_SUBVECTOR)
474 ConstantSDNode *DLidx = cast<ConstantSDNode>(DL->getOperand(1).getNode());
475 ConstantSDNode *EVidx = cast<ConstantSDNode>(EV.getOperand(1).getNode());
476 LaneIdx = DLidx->getSExtValue() + EVidx->getSExtValue();
477 LaneOp = EV.getOperand(0);
482 // Helper for SelectOpcV64LaneV128 - Recognize operations where one operand is a
483 // high lane extract.
484 static bool checkV64LaneV128(SDValue Op0, SDValue Op1, SDValue &StdOp,
485 SDValue &LaneOp, int &LaneIdx) {
487 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx)) {
489 if (!checkHighLaneIndex(Op0.getNode(), LaneOp, LaneIdx))
496 /// SelectMLAV64LaneV128 - AArch64 supports vector MLAs where one multiplicand
497 /// is a lane in the upper half of a 128-bit vector. Recognize and select this
498 /// so that we don't emit unnecessary lane extracts.
499 bool AArch64DAGToDAGISel::tryMLAV64LaneV128(SDNode *N) {
501 SDValue Op0 = N->getOperand(0);
502 SDValue Op1 = N->getOperand(1);
503 SDValue MLAOp1; // Will hold ordinary multiplicand for MLA.
504 SDValue MLAOp2; // Will hold lane-accessed multiplicand for MLA.
505 int LaneIdx = -1; // Will hold the lane index.
507 if (Op1.getOpcode() != ISD::MUL ||
508 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
511 if (Op1.getOpcode() != ISD::MUL ||
512 !checkV64LaneV128(Op1.getOperand(0), Op1.getOperand(1), MLAOp1, MLAOp2,
517 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
519 SDValue Ops[] = { Op0, MLAOp1, MLAOp2, LaneIdxVal };
521 unsigned MLAOpc = ~0U;
523 switch (N->getSimpleValueType(0).SimpleTy) {
525 llvm_unreachable("Unrecognized MLA.");
527 MLAOpc = AArch64::MLAv4i16_indexed;
530 MLAOpc = AArch64::MLAv8i16_indexed;
533 MLAOpc = AArch64::MLAv2i32_indexed;
536 MLAOpc = AArch64::MLAv4i32_indexed;
540 ReplaceNode(N, CurDAG->getMachineNode(MLAOpc, dl, N->getValueType(0), Ops));
544 bool AArch64DAGToDAGISel::tryMULLV64LaneV128(unsigned IntNo, SDNode *N) {
550 if (!checkV64LaneV128(N->getOperand(1), N->getOperand(2), SMULLOp0, SMULLOp1,
554 SDValue LaneIdxVal = CurDAG->getTargetConstant(LaneIdx, dl, MVT::i64);
556 SDValue Ops[] = { SMULLOp0, SMULLOp1, LaneIdxVal };
558 unsigned SMULLOpc = ~0U;
560 if (IntNo == Intrinsic::aarch64_neon_smull) {
561 switch (N->getSimpleValueType(0).SimpleTy) {
563 llvm_unreachable("Unrecognized SMULL.");
565 SMULLOpc = AArch64::SMULLv4i16_indexed;
568 SMULLOpc = AArch64::SMULLv2i32_indexed;
571 } else if (IntNo == Intrinsic::aarch64_neon_umull) {
572 switch (N->getSimpleValueType(0).SimpleTy) {
574 llvm_unreachable("Unrecognized SMULL.");
576 SMULLOpc = AArch64::UMULLv4i16_indexed;
579 SMULLOpc = AArch64::UMULLv2i32_indexed;
583 llvm_unreachable("Unrecognized intrinsic.");
585 ReplaceNode(N, CurDAG->getMachineNode(SMULLOpc, dl, N->getValueType(0), Ops));
589 /// Instructions that accept extend modifiers like UXTW expect the register
590 /// being extended to be a GPR32, but the incoming DAG might be acting on a
591 /// GPR64 (either via SEXT_INREG or AND). Extract the appropriate low bits if
592 /// this is the case.
593 static SDValue narrowIfNeeded(SelectionDAG *CurDAG, SDValue N) {
594 if (N.getValueType() == MVT::i32)
598 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
599 MachineSDNode *Node = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
600 dl, MVT::i32, N, SubReg);
601 return SDValue(Node, 0);
605 /// SelectArithExtendedRegister - Select a "extended register" operand. This
606 /// operand folds in an extend followed by an optional left shift.
607 bool AArch64DAGToDAGISel::SelectArithExtendedRegister(SDValue N, SDValue &Reg,
609 unsigned ShiftVal = 0;
610 AArch64_AM::ShiftExtendType Ext;
612 if (N.getOpcode() == ISD::SHL) {
613 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
616 ShiftVal = CSD->getZExtValue();
620 Ext = getExtendTypeForNode(N.getOperand(0));
621 if (Ext == AArch64_AM::InvalidShiftExtend)
624 Reg = N.getOperand(0).getOperand(0);
626 Ext = getExtendTypeForNode(N);
627 if (Ext == AArch64_AM::InvalidShiftExtend)
630 Reg = N.getOperand(0);
632 // Don't match if free 32-bit -> 64-bit zext can be used instead.
633 if (Ext == AArch64_AM::UXTW &&
634 Reg->getValueType(0).getSizeInBits() == 32 && isDef32(*Reg.getNode()))
638 // AArch64 mandates that the RHS of the operation must use the smallest
639 // register class that could contain the size being extended from. Thus,
640 // if we're folding a (sext i8), we need the RHS to be a GPR32, even though
641 // there might not be an actual 32-bit value in the program. We can
642 // (harmlessly) synthesize one by injected an EXTRACT_SUBREG here.
643 assert(Ext != AArch64_AM::UXTX && Ext != AArch64_AM::SXTX);
644 Reg = narrowIfNeeded(CurDAG, Reg);
645 Shift = CurDAG->getTargetConstant(getArithExtendImm(Ext, ShiftVal), SDLoc(N),
647 return isWorthFolding(N);
650 /// If there's a use of this ADDlow that's not itself a load/store then we'll
651 /// need to create a real ADD instruction from it anyway and there's no point in
652 /// folding it into the mem op. Theoretically, it shouldn't matter, but there's
653 /// a single pseudo-instruction for an ADRP/ADD pair so over-aggressive folding
654 /// leads to duplicated ADRP instructions.
655 static bool isWorthFoldingADDlow(SDValue N) {
656 for (auto Use : N->uses()) {
657 if (Use->getOpcode() != ISD::LOAD && Use->getOpcode() != ISD::STORE &&
658 Use->getOpcode() != ISD::ATOMIC_LOAD &&
659 Use->getOpcode() != ISD::ATOMIC_STORE)
662 // ldar and stlr have much more restrictive addressing modes (just a
664 if (isStrongerThanMonotonic(cast<MemSDNode>(Use)->getOrdering()))
671 /// SelectAddrModeIndexed7S - Select a "register plus scaled signed 7-bit
672 /// immediate" address. The "Size" argument is the size in bytes of the memory
673 /// reference, which determines the scale.
674 bool AArch64DAGToDAGISel::SelectAddrModeIndexed7S(SDValue N, unsigned Size,
678 const DataLayout &DL = CurDAG->getDataLayout();
679 const TargetLowering *TLI = getTargetLowering();
680 if (N.getOpcode() == ISD::FrameIndex) {
681 int FI = cast<FrameIndexSDNode>(N)->getIndex();
682 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
683 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
687 // As opposed to the (12-bit) Indexed addressing mode below, the 7-bit signed
688 // selected here doesn't support labels/immediates, only base+offset.
690 if (CurDAG->isBaseWithConstantOffset(N)) {
691 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
692 int64_t RHSC = RHS->getSExtValue();
693 unsigned Scale = Log2_32(Size);
694 if ((RHSC & (Size - 1)) == 0 && RHSC >= -(0x40 << Scale) &&
695 RHSC < (0x40 << Scale)) {
696 Base = N.getOperand(0);
697 if (Base.getOpcode() == ISD::FrameIndex) {
698 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
699 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
701 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, dl, MVT::i64);
707 // Base only. The address will be materialized into a register before
708 // the memory is accessed.
709 // add x0, Xbase, #offset
712 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
716 /// SelectAddrModeIndexed - Select a "register plus scaled unsigned 12-bit
717 /// immediate" address. The "Size" argument is the size in bytes of the memory
718 /// reference, which determines the scale.
719 bool AArch64DAGToDAGISel::SelectAddrModeIndexed(SDValue N, unsigned Size,
720 SDValue &Base, SDValue &OffImm) {
722 const DataLayout &DL = CurDAG->getDataLayout();
723 const TargetLowering *TLI = getTargetLowering();
724 if (N.getOpcode() == ISD::FrameIndex) {
725 int FI = cast<FrameIndexSDNode>(N)->getIndex();
726 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
727 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
731 if (N.getOpcode() == AArch64ISD::ADDlow && isWorthFoldingADDlow(N)) {
732 GlobalAddressSDNode *GAN =
733 dyn_cast<GlobalAddressSDNode>(N.getOperand(1).getNode());
734 Base = N.getOperand(0);
735 OffImm = N.getOperand(1);
739 const GlobalValue *GV = GAN->getGlobal();
740 unsigned Alignment = GV->getAlignment();
741 Type *Ty = GV->getValueType();
742 if (Alignment == 0 && Ty->isSized())
743 Alignment = DL.getABITypeAlignment(Ty);
745 if (Alignment >= Size)
749 if (CurDAG->isBaseWithConstantOffset(N)) {
750 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
751 int64_t RHSC = (int64_t)RHS->getZExtValue();
752 unsigned Scale = Log2_32(Size);
753 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 && RHSC < (0x1000 << Scale)) {
754 Base = N.getOperand(0);
755 if (Base.getOpcode() == ISD::FrameIndex) {
756 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
757 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy(DL));
759 OffImm = CurDAG->getTargetConstant(RHSC >> Scale, dl, MVT::i64);
765 // Before falling back to our general case, check if the unscaled
766 // instructions can handle this. If so, that's preferable.
767 if (SelectAddrModeUnscaled(N, Size, Base, OffImm))
770 // Base only. The address will be materialized into a register before
771 // the memory is accessed.
772 // add x0, Xbase, #offset
775 OffImm = CurDAG->getTargetConstant(0, dl, MVT::i64);
779 /// SelectAddrModeUnscaled - Select a "register plus unscaled signed 9-bit
780 /// immediate" address. This should only match when there is an offset that
781 /// is not valid for a scaled immediate addressing mode. The "Size" argument
782 /// is the size in bytes of the memory reference, which is needed here to know
783 /// what is valid for a scaled immediate.
784 bool AArch64DAGToDAGISel::SelectAddrModeUnscaled(SDValue N, unsigned Size,
787 if (!CurDAG->isBaseWithConstantOffset(N))
789 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
790 int64_t RHSC = RHS->getSExtValue();
791 // If the offset is valid as a scaled immediate, don't match here.
792 if ((RHSC & (Size - 1)) == 0 && RHSC >= 0 &&
793 RHSC < (0x1000 << Log2_32(Size)))
795 if (RHSC >= -256 && RHSC < 256) {
796 Base = N.getOperand(0);
797 if (Base.getOpcode() == ISD::FrameIndex) {
798 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
799 const TargetLowering *TLI = getTargetLowering();
800 Base = CurDAG->getTargetFrameIndex(
801 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
803 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i64);
810 static SDValue Widen(SelectionDAG *CurDAG, SDValue N) {
812 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
813 SDValue ImpDef = SDValue(
814 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, MVT::i64), 0);
815 MachineSDNode *Node = CurDAG->getMachineNode(
816 TargetOpcode::INSERT_SUBREG, dl, MVT::i64, ImpDef, N, SubReg);
817 return SDValue(Node, 0);
820 /// \brief Check if the given SHL node (\p N), can be used to form an
821 /// extended register for an addressing mode.
822 bool AArch64DAGToDAGISel::SelectExtendedSHL(SDValue N, unsigned Size,
823 bool WantExtend, SDValue &Offset,
824 SDValue &SignExtend) {
825 assert(N.getOpcode() == ISD::SHL && "Invalid opcode.");
826 ConstantSDNode *CSD = dyn_cast<ConstantSDNode>(N.getOperand(1));
827 if (!CSD || (CSD->getZExtValue() & 0x7) != CSD->getZExtValue())
832 AArch64_AM::ShiftExtendType Ext =
833 getExtendTypeForNode(N.getOperand(0), true);
834 if (Ext == AArch64_AM::InvalidShiftExtend)
837 Offset = narrowIfNeeded(CurDAG, N.getOperand(0).getOperand(0));
838 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
841 Offset = N.getOperand(0);
842 SignExtend = CurDAG->getTargetConstant(0, dl, MVT::i32);
845 unsigned LegalShiftVal = Log2_32(Size);
846 unsigned ShiftVal = CSD->getZExtValue();
848 if (ShiftVal != 0 && ShiftVal != LegalShiftVal)
851 return isWorthFolding(N);
854 bool AArch64DAGToDAGISel::SelectAddrModeWRO(SDValue N, unsigned Size,
855 SDValue &Base, SDValue &Offset,
858 if (N.getOpcode() != ISD::ADD)
860 SDValue LHS = N.getOperand(0);
861 SDValue RHS = N.getOperand(1);
864 // We don't want to match immediate adds here, because they are better lowered
865 // to the register-immediate addressing modes.
866 if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))
869 // Check if this particular node is reused in any non-memory related
870 // operation. If yes, do not try to fold this node into the address
871 // computation, since the computation will be kept.
872 const SDNode *Node = N.getNode();
873 for (SDNode *UI : Node->uses()) {
874 if (!isa<MemSDNode>(*UI))
878 // Remember if it is worth folding N when it produces extended register.
879 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
881 // Try to match a shifted extend on the RHS.
882 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
883 SelectExtendedSHL(RHS, Size, true, Offset, SignExtend)) {
885 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
889 // Try to match a shifted extend on the LHS.
890 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
891 SelectExtendedSHL(LHS, Size, true, Offset, SignExtend)) {
893 DoShift = CurDAG->getTargetConstant(true, dl, MVT::i32);
897 // There was no shift, whatever else we find.
898 DoShift = CurDAG->getTargetConstant(false, dl, MVT::i32);
900 AArch64_AM::ShiftExtendType Ext = AArch64_AM::InvalidShiftExtend;
901 // Try to match an unshifted extend on the LHS.
902 if (IsExtendedRegisterWorthFolding &&
903 (Ext = getExtendTypeForNode(LHS, true)) !=
904 AArch64_AM::InvalidShiftExtend) {
906 Offset = narrowIfNeeded(CurDAG, LHS.getOperand(0));
907 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
909 if (isWorthFolding(LHS))
913 // Try to match an unshifted extend on the RHS.
914 if (IsExtendedRegisterWorthFolding &&
915 (Ext = getExtendTypeForNode(RHS, true)) !=
916 AArch64_AM::InvalidShiftExtend) {
918 Offset = narrowIfNeeded(CurDAG, RHS.getOperand(0));
919 SignExtend = CurDAG->getTargetConstant(Ext == AArch64_AM::SXTW, dl,
921 if (isWorthFolding(RHS))
928 // Check if the given immediate is preferred by ADD. If an immediate can be
929 // encoded in an ADD, or it can be encoded in an "ADD LSL #12" and can not be
930 // encoded by one MOVZ, return true.
931 static bool isPreferredADD(int64_t ImmOff) {
932 // Constant in [0x0, 0xfff] can be encoded in ADD.
933 if ((ImmOff & 0xfffffffffffff000LL) == 0x0LL)
935 // Check if it can be encoded in an "ADD LSL #12".
936 if ((ImmOff & 0xffffffffff000fffLL) == 0x0LL)
937 // As a single MOVZ is faster than a "ADD of LSL #12", ignore such constant.
938 return (ImmOff & 0xffffffffff00ffffLL) != 0x0LL &&
939 (ImmOff & 0xffffffffffff0fffLL) != 0x0LL;
943 bool AArch64DAGToDAGISel::SelectAddrModeXRO(SDValue N, unsigned Size,
944 SDValue &Base, SDValue &Offset,
947 if (N.getOpcode() != ISD::ADD)
949 SDValue LHS = N.getOperand(0);
950 SDValue RHS = N.getOperand(1);
953 // Check if this particular node is reused in any non-memory related
954 // operation. If yes, do not try to fold this node into the address
955 // computation, since the computation will be kept.
956 const SDNode *Node = N.getNode();
957 for (SDNode *UI : Node->uses()) {
958 if (!isa<MemSDNode>(*UI))
962 // Watch out if RHS is a wide immediate, it can not be selected into
963 // [BaseReg+Imm] addressing mode. Also it may not be able to be encoded into
964 // ADD/SUB. Instead it will use [BaseReg + 0] address mode and generate
965 // instructions like:
966 // MOV X0, WideImmediate
967 // ADD X1, BaseReg, X0
969 // For such situation, using [BaseReg, XReg] addressing mode can save one
971 // MOV X0, WideImmediate
972 // LDR X2, [BaseReg, X0]
973 if (isa<ConstantSDNode>(RHS)) {
974 int64_t ImmOff = (int64_t)cast<ConstantSDNode>(RHS)->getZExtValue();
975 unsigned Scale = Log2_32(Size);
976 // Skip the immediate can be selected by load/store addressing mode.
977 // Also skip the immediate can be encoded by a single ADD (SUB is also
978 // checked by using -ImmOff).
979 if ((ImmOff % Size == 0 && ImmOff >= 0 && ImmOff < (0x1000 << Scale)) ||
980 isPreferredADD(ImmOff) || isPreferredADD(-ImmOff))
983 SDValue Ops[] = { RHS };
985 CurDAG->getMachineNode(AArch64::MOVi64imm, DL, MVT::i64, Ops);
986 SDValue MOVIV = SDValue(MOVI, 0);
987 // This ADD of two X register will be selected into [Reg+Reg] mode.
988 N = CurDAG->getNode(ISD::ADD, DL, MVT::i64, LHS, MOVIV);
991 // Remember if it is worth folding N when it produces extended register.
992 bool IsExtendedRegisterWorthFolding = isWorthFolding(N);
994 // Try to match a shifted extend on the RHS.
995 if (IsExtendedRegisterWorthFolding && RHS.getOpcode() == ISD::SHL &&
996 SelectExtendedSHL(RHS, Size, false, Offset, SignExtend)) {
998 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
1002 // Try to match a shifted extend on the LHS.
1003 if (IsExtendedRegisterWorthFolding && LHS.getOpcode() == ISD::SHL &&
1004 SelectExtendedSHL(LHS, Size, false, Offset, SignExtend)) {
1006 DoShift = CurDAG->getTargetConstant(true, DL, MVT::i32);
1010 // Match any non-shifted, non-extend, non-immediate add expression.
1013 SignExtend = CurDAG->getTargetConstant(false, DL, MVT::i32);
1014 DoShift = CurDAG->getTargetConstant(false, DL, MVT::i32);
1015 // Reg1 + Reg2 is free: no check needed.
1019 SDValue AArch64DAGToDAGISel::createDTuple(ArrayRef<SDValue> Regs) {
1020 static const unsigned RegClassIDs[] = {
1021 AArch64::DDRegClassID, AArch64::DDDRegClassID, AArch64::DDDDRegClassID};
1022 static const unsigned SubRegs[] = {AArch64::dsub0, AArch64::dsub1,
1023 AArch64::dsub2, AArch64::dsub3};
1025 return createTuple(Regs, RegClassIDs, SubRegs);
1028 SDValue AArch64DAGToDAGISel::createQTuple(ArrayRef<SDValue> Regs) {
1029 static const unsigned RegClassIDs[] = {
1030 AArch64::QQRegClassID, AArch64::QQQRegClassID, AArch64::QQQQRegClassID};
1031 static const unsigned SubRegs[] = {AArch64::qsub0, AArch64::qsub1,
1032 AArch64::qsub2, AArch64::qsub3};
1034 return createTuple(Regs, RegClassIDs, SubRegs);
1037 SDValue AArch64DAGToDAGISel::createTuple(ArrayRef<SDValue> Regs,
1038 const unsigned RegClassIDs[],
1039 const unsigned SubRegs[]) {
1040 // There's no special register-class for a vector-list of 1 element: it's just
1042 if (Regs.size() == 1)
1045 assert(Regs.size() >= 2 && Regs.size() <= 4);
1049 SmallVector<SDValue, 4> Ops;
1051 // First operand of REG_SEQUENCE is the desired RegClass.
1053 CurDAG->getTargetConstant(RegClassIDs[Regs.size() - 2], DL, MVT::i32));
1055 // Then we get pairs of source & subregister-position for the components.
1056 for (unsigned i = 0; i < Regs.size(); ++i) {
1057 Ops.push_back(Regs[i]);
1058 Ops.push_back(CurDAG->getTargetConstant(SubRegs[i], DL, MVT::i32));
1062 CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL, MVT::Untyped, Ops);
1063 return SDValue(N, 0);
1066 void AArch64DAGToDAGISel::SelectTable(SDNode *N, unsigned NumVecs, unsigned Opc,
1069 EVT VT = N->getValueType(0);
1071 unsigned ExtOff = isExt;
1073 // Form a REG_SEQUENCE to force register allocation.
1074 unsigned Vec0Off = ExtOff + 1;
1075 SmallVector<SDValue, 4> Regs(N->op_begin() + Vec0Off,
1076 N->op_begin() + Vec0Off + NumVecs);
1077 SDValue RegSeq = createQTuple(Regs);
1079 SmallVector<SDValue, 6> Ops;
1081 Ops.push_back(N->getOperand(1));
1082 Ops.push_back(RegSeq);
1083 Ops.push_back(N->getOperand(NumVecs + ExtOff + 1));
1084 ReplaceNode(N, CurDAG->getMachineNode(Opc, dl, VT, Ops));
1087 bool AArch64DAGToDAGISel::tryIndexedLoad(SDNode *N) {
1088 LoadSDNode *LD = cast<LoadSDNode>(N);
1089 if (LD->isUnindexed())
1091 EVT VT = LD->getMemoryVT();
1092 EVT DstVT = N->getValueType(0);
1093 ISD::MemIndexedMode AM = LD->getAddressingMode();
1094 bool IsPre = AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1096 // We're not doing validity checking here. That was done when checking
1097 // if we should mark the load as indexed or not. We're just selecting
1098 // the right instruction.
1099 unsigned Opcode = 0;
1101 ISD::LoadExtType ExtType = LD->getExtensionType();
1102 bool InsertTo64 = false;
1104 Opcode = IsPre ? AArch64::LDRXpre : AArch64::LDRXpost;
1105 else if (VT == MVT::i32) {
1106 if (ExtType == ISD::NON_EXTLOAD)
1107 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1108 else if (ExtType == ISD::SEXTLOAD)
1109 Opcode = IsPre ? AArch64::LDRSWpre : AArch64::LDRSWpost;
1111 Opcode = IsPre ? AArch64::LDRWpre : AArch64::LDRWpost;
1113 // The result of the load is only i32. It's the subreg_to_reg that makes
1117 } else if (VT == MVT::i16) {
1118 if (ExtType == ISD::SEXTLOAD) {
1119 if (DstVT == MVT::i64)
1120 Opcode = IsPre ? AArch64::LDRSHXpre : AArch64::LDRSHXpost;
1122 Opcode = IsPre ? AArch64::LDRSHWpre : AArch64::LDRSHWpost;
1124 Opcode = IsPre ? AArch64::LDRHHpre : AArch64::LDRHHpost;
1125 InsertTo64 = DstVT == MVT::i64;
1126 // The result of the load is only i32. It's the subreg_to_reg that makes
1130 } else if (VT == MVT::i8) {
1131 if (ExtType == ISD::SEXTLOAD) {
1132 if (DstVT == MVT::i64)
1133 Opcode = IsPre ? AArch64::LDRSBXpre : AArch64::LDRSBXpost;
1135 Opcode = IsPre ? AArch64::LDRSBWpre : AArch64::LDRSBWpost;
1137 Opcode = IsPre ? AArch64::LDRBBpre : AArch64::LDRBBpost;
1138 InsertTo64 = DstVT == MVT::i64;
1139 // The result of the load is only i32. It's the subreg_to_reg that makes
1143 } else if (VT == MVT::f16) {
1144 Opcode = IsPre ? AArch64::LDRHpre : AArch64::LDRHpost;
1145 } else if (VT == MVT::f32) {
1146 Opcode = IsPre ? AArch64::LDRSpre : AArch64::LDRSpost;
1147 } else if (VT == MVT::f64 || VT.is64BitVector()) {
1148 Opcode = IsPre ? AArch64::LDRDpre : AArch64::LDRDpost;
1149 } else if (VT.is128BitVector()) {
1150 Opcode = IsPre ? AArch64::LDRQpre : AArch64::LDRQpost;
1153 SDValue Chain = LD->getChain();
1154 SDValue Base = LD->getBasePtr();
1155 ConstantSDNode *OffsetOp = cast<ConstantSDNode>(LD->getOffset());
1156 int OffsetVal = (int)OffsetOp->getZExtValue();
1158 SDValue Offset = CurDAG->getTargetConstant(OffsetVal, dl, MVT::i64);
1159 SDValue Ops[] = { Base, Offset, Chain };
1160 SDNode *Res = CurDAG->getMachineNode(Opcode, dl, MVT::i64, DstVT,
1162 // Either way, we're replacing the node, so tell the caller that.
1163 SDValue LoadedVal = SDValue(Res, 1);
1165 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
1167 SDValue(CurDAG->getMachineNode(
1168 AArch64::SUBREG_TO_REG, dl, MVT::i64,
1169 CurDAG->getTargetConstant(0, dl, MVT::i64), LoadedVal,
1174 ReplaceUses(SDValue(N, 0), LoadedVal);
1175 ReplaceUses(SDValue(N, 1), SDValue(Res, 0));
1176 ReplaceUses(SDValue(N, 2), SDValue(Res, 2));
1177 CurDAG->RemoveDeadNode(N);
1181 void AArch64DAGToDAGISel::SelectLoad(SDNode *N, unsigned NumVecs, unsigned Opc,
1182 unsigned SubRegIdx) {
1184 EVT VT = N->getValueType(0);
1185 SDValue Chain = N->getOperand(0);
1187 SDValue Ops[] = {N->getOperand(2), // Mem operand;
1190 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
1192 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1193 SDValue SuperReg = SDValue(Ld, 0);
1194 for (unsigned i = 0; i < NumVecs; ++i)
1195 ReplaceUses(SDValue(N, i),
1196 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1198 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1200 // Transfer memoperands.
1201 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1202 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1203 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
1205 CurDAG->RemoveDeadNode(N);
1208 void AArch64DAGToDAGISel::SelectPostLoad(SDNode *N, unsigned NumVecs,
1209 unsigned Opc, unsigned SubRegIdx) {
1211 EVT VT = N->getValueType(0);
1212 SDValue Chain = N->getOperand(0);
1214 SDValue Ops[] = {N->getOperand(1), // Mem operand
1215 N->getOperand(2), // Incremental
1218 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1219 MVT::Untyped, MVT::Other};
1221 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1223 // Update uses of write back register
1224 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1226 // Update uses of vector list
1227 SDValue SuperReg = SDValue(Ld, 1);
1229 ReplaceUses(SDValue(N, 0), SuperReg);
1231 for (unsigned i = 0; i < NumVecs; ++i)
1232 ReplaceUses(SDValue(N, i),
1233 CurDAG->getTargetExtractSubreg(SubRegIdx + i, dl, VT, SuperReg));
1236 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1237 CurDAG->RemoveDeadNode(N);
1240 void AArch64DAGToDAGISel::SelectStore(SDNode *N, unsigned NumVecs,
1243 EVT VT = N->getOperand(2)->getValueType(0);
1245 // Form a REG_SEQUENCE to force register allocation.
1246 bool Is128Bit = VT.getSizeInBits() == 128;
1247 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1248 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1250 SDValue Ops[] = {RegSeq, N->getOperand(NumVecs + 2), N->getOperand(0)};
1251 SDNode *St = CurDAG->getMachineNode(Opc, dl, N->getValueType(0), Ops);
1253 // Transfer memoperands.
1254 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1255 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1256 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1261 void AArch64DAGToDAGISel::SelectPostStore(SDNode *N, unsigned NumVecs,
1264 EVT VT = N->getOperand(2)->getValueType(0);
1265 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1266 MVT::Other}; // Type for the Chain
1268 // Form a REG_SEQUENCE to force register allocation.
1269 bool Is128Bit = VT.getSizeInBits() == 128;
1270 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1271 SDValue RegSeq = Is128Bit ? createQTuple(Regs) : createDTuple(Regs);
1273 SDValue Ops[] = {RegSeq,
1274 N->getOperand(NumVecs + 1), // base register
1275 N->getOperand(NumVecs + 2), // Incremental
1276 N->getOperand(0)}; // Chain
1277 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1283 /// WidenVector - Given a value in the V64 register class, produce the
1284 /// equivalent value in the V128 register class.
1289 WidenVector(SelectionDAG &DAG) : DAG(DAG) {}
1291 SDValue operator()(SDValue V64Reg) {
1292 EVT VT = V64Reg.getValueType();
1293 unsigned NarrowSize = VT.getVectorNumElements();
1294 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1295 MVT WideTy = MVT::getVectorVT(EltTy, 2 * NarrowSize);
1299 SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, WideTy), 0);
1300 return DAG.getTargetInsertSubreg(AArch64::dsub, DL, WideTy, Undef, V64Reg);
1305 /// NarrowVector - Given a value in the V128 register class, produce the
1306 /// equivalent value in the V64 register class.
1307 static SDValue NarrowVector(SDValue V128Reg, SelectionDAG &DAG) {
1308 EVT VT = V128Reg.getValueType();
1309 unsigned WideSize = VT.getVectorNumElements();
1310 MVT EltTy = VT.getVectorElementType().getSimpleVT();
1311 MVT NarrowTy = MVT::getVectorVT(EltTy, WideSize / 2);
1313 return DAG.getTargetExtractSubreg(AArch64::dsub, SDLoc(V128Reg), NarrowTy,
1317 void AArch64DAGToDAGISel::SelectLoadLane(SDNode *N, unsigned NumVecs,
1320 EVT VT = N->getValueType(0);
1321 bool Narrow = VT.getSizeInBits() == 64;
1323 // Form a REG_SEQUENCE to force register allocation.
1324 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1327 transform(Regs, Regs.begin(),
1328 WidenVector(*CurDAG));
1330 SDValue RegSeq = createQTuple(Regs);
1332 const EVT ResTys[] = {MVT::Untyped, MVT::Other};
1335 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1337 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1338 N->getOperand(NumVecs + 3), N->getOperand(0)};
1339 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1340 SDValue SuperReg = SDValue(Ld, 0);
1342 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1343 static const unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1,
1344 AArch64::qsub2, AArch64::qsub3 };
1345 for (unsigned i = 0; i < NumVecs; ++i) {
1346 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT, SuperReg);
1348 NV = NarrowVector(NV, *CurDAG);
1349 ReplaceUses(SDValue(N, i), NV);
1352 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 1));
1353 CurDAG->RemoveDeadNode(N);
1356 void AArch64DAGToDAGISel::SelectPostLoadLane(SDNode *N, unsigned NumVecs,
1359 EVT VT = N->getValueType(0);
1360 bool Narrow = VT.getSizeInBits() == 64;
1362 // Form a REG_SEQUENCE to force register allocation.
1363 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1366 transform(Regs, Regs.begin(),
1367 WidenVector(*CurDAG));
1369 SDValue RegSeq = createQTuple(Regs);
1371 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1372 RegSeq->getValueType(0), MVT::Other};
1375 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1377 SDValue Ops[] = {RegSeq,
1378 CurDAG->getTargetConstant(LaneNo, dl,
1379 MVT::i64), // Lane Number
1380 N->getOperand(NumVecs + 2), // Base register
1381 N->getOperand(NumVecs + 3), // Incremental
1383 SDNode *Ld = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1385 // Update uses of the write back register
1386 ReplaceUses(SDValue(N, NumVecs), SDValue(Ld, 0));
1388 // Update uses of the vector list
1389 SDValue SuperReg = SDValue(Ld, 1);
1391 ReplaceUses(SDValue(N, 0),
1392 Narrow ? NarrowVector(SuperReg, *CurDAG) : SuperReg);
1394 EVT WideVT = RegSeq.getOperand(1)->getValueType(0);
1395 static const unsigned QSubs[] = { AArch64::qsub0, AArch64::qsub1,
1396 AArch64::qsub2, AArch64::qsub3 };
1397 for (unsigned i = 0; i < NumVecs; ++i) {
1398 SDValue NV = CurDAG->getTargetExtractSubreg(QSubs[i], dl, WideVT,
1401 NV = NarrowVector(NV, *CurDAG);
1402 ReplaceUses(SDValue(N, i), NV);
1407 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(Ld, 2));
1408 CurDAG->RemoveDeadNode(N);
1411 void AArch64DAGToDAGISel::SelectStoreLane(SDNode *N, unsigned NumVecs,
1414 EVT VT = N->getOperand(2)->getValueType(0);
1415 bool Narrow = VT.getSizeInBits() == 64;
1417 // Form a REG_SEQUENCE to force register allocation.
1418 SmallVector<SDValue, 4> Regs(N->op_begin() + 2, N->op_begin() + 2 + NumVecs);
1421 transform(Regs, Regs.begin(),
1422 WidenVector(*CurDAG));
1424 SDValue RegSeq = createQTuple(Regs);
1427 cast<ConstantSDNode>(N->getOperand(NumVecs + 2))->getZExtValue();
1429 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1430 N->getOperand(NumVecs + 3), N->getOperand(0)};
1431 SDNode *St = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
1433 // Transfer memoperands.
1434 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1435 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1436 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1441 void AArch64DAGToDAGISel::SelectPostStoreLane(SDNode *N, unsigned NumVecs,
1444 EVT VT = N->getOperand(2)->getValueType(0);
1445 bool Narrow = VT.getSizeInBits() == 64;
1447 // Form a REG_SEQUENCE to force register allocation.
1448 SmallVector<SDValue, 4> Regs(N->op_begin() + 1, N->op_begin() + 1 + NumVecs);
1451 transform(Regs, Regs.begin(),
1452 WidenVector(*CurDAG));
1454 SDValue RegSeq = createQTuple(Regs);
1456 const EVT ResTys[] = {MVT::i64, // Type of the write back register
1460 cast<ConstantSDNode>(N->getOperand(NumVecs + 1))->getZExtValue();
1462 SDValue Ops[] = {RegSeq, CurDAG->getTargetConstant(LaneNo, dl, MVT::i64),
1463 N->getOperand(NumVecs + 2), // Base Register
1464 N->getOperand(NumVecs + 3), // Incremental
1466 SDNode *St = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1468 // Transfer memoperands.
1469 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1470 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1471 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
1476 static bool isBitfieldExtractOpFromAnd(SelectionDAG *CurDAG, SDNode *N,
1477 unsigned &Opc, SDValue &Opd0,
1478 unsigned &LSB, unsigned &MSB,
1479 unsigned NumberOfIgnoredLowBits,
1480 bool BiggerPattern) {
1481 assert(N->getOpcode() == ISD::AND &&
1482 "N must be a AND operation to call this function");
1484 EVT VT = N->getValueType(0);
1486 // Here we can test the type of VT and return false when the type does not
1487 // match, but since it is done prior to that call in the current context
1488 // we turned that into an assert to avoid redundant code.
1489 assert((VT == MVT::i32 || VT == MVT::i64) &&
1490 "Type checking must have been done before calling this function");
1492 // FIXME: simplify-demanded-bits in DAGCombine will probably have
1493 // changed the AND node to a 32-bit mask operation. We'll have to
1494 // undo that as part of the transform here if we want to catch all
1495 // the opportunities.
1496 // Currently the NumberOfIgnoredLowBits argument helps to recover
1497 // form these situations when matching bigger pattern (bitfield insert).
1499 // For unsigned extracts, check for a shift right and mask
1500 uint64_t AndImm = 0;
1501 if (!isOpcWithIntImmediate(N, ISD::AND, AndImm))
1504 const SDNode *Op0 = N->getOperand(0).getNode();
1506 // Because of simplify-demanded-bits in DAGCombine, the mask may have been
1507 // simplified. Try to undo that
1508 AndImm |= (1 << NumberOfIgnoredLowBits) - 1;
1510 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1511 if (AndImm & (AndImm + 1))
1514 bool ClampMSB = false;
1515 uint64_t SrlImm = 0;
1516 // Handle the SRL + ANY_EXTEND case.
1517 if (VT == MVT::i64 && Op0->getOpcode() == ISD::ANY_EXTEND &&
1518 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL, SrlImm)) {
1519 // Extend the incoming operand of the SRL to 64-bit.
1520 Opd0 = Widen(CurDAG, Op0->getOperand(0).getOperand(0));
1521 // Make sure to clamp the MSB so that we preserve the semantics of the
1522 // original operations.
1524 } else if (VT == MVT::i32 && Op0->getOpcode() == ISD::TRUNCATE &&
1525 isOpcWithIntImmediate(Op0->getOperand(0).getNode(), ISD::SRL,
1527 // If the shift result was truncated, we can still combine them.
1528 Opd0 = Op0->getOperand(0).getOperand(0);
1530 // Use the type of SRL node.
1531 VT = Opd0->getValueType(0);
1532 } else if (isOpcWithIntImmediate(Op0, ISD::SRL, SrlImm)) {
1533 Opd0 = Op0->getOperand(0);
1534 } else if (BiggerPattern) {
1535 // Let's pretend a 0 shift right has been performed.
1536 // The resulting code will be at least as good as the original one
1537 // plus it may expose more opportunities for bitfield insert pattern.
1538 // FIXME: Currently we limit this to the bigger pattern, because
1539 // some optimizations expect AND and not UBFM.
1540 Opd0 = N->getOperand(0);
1544 // Bail out on large immediates. This happens when no proper
1545 // combining/constant folding was performed.
1546 if (!BiggerPattern && (SrlImm <= 0 || SrlImm >= VT.getSizeInBits())) {
1548 << ": Found large shift immediate, this should not happen\n"));
1553 MSB = SrlImm + (VT == MVT::i32 ? countTrailingOnes<uint32_t>(AndImm)
1554 : countTrailingOnes<uint64_t>(AndImm)) -
1557 // Since we're moving the extend before the right shift operation, we need
1558 // to clamp the MSB to make sure we don't shift in undefined bits instead of
1559 // the zeros which would get shifted in with the original right shift
1561 MSB = MSB > 31 ? 31 : MSB;
1563 Opc = VT == MVT::i32 ? AArch64::UBFMWri : AArch64::UBFMXri;
1567 static bool isBitfieldExtractOpFromSExtInReg(SDNode *N, unsigned &Opc,
1568 SDValue &Opd0, unsigned &Immr,
1570 assert(N->getOpcode() == ISD::SIGN_EXTEND_INREG);
1572 EVT VT = N->getValueType(0);
1573 unsigned BitWidth = VT.getSizeInBits();
1574 assert((VT == MVT::i32 || VT == MVT::i64) &&
1575 "Type checking must have been done before calling this function");
1577 SDValue Op = N->getOperand(0);
1578 if (Op->getOpcode() == ISD::TRUNCATE) {
1579 Op = Op->getOperand(0);
1580 VT = Op->getValueType(0);
1581 BitWidth = VT.getSizeInBits();
1585 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRL, ShiftImm) &&
1586 !isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
1589 unsigned Width = cast<VTSDNode>(N->getOperand(1))->getVT().getSizeInBits();
1590 if (ShiftImm + Width > BitWidth)
1593 Opc = (VT == MVT::i32) ? AArch64::SBFMWri : AArch64::SBFMXri;
1594 Opd0 = Op.getOperand(0);
1596 Imms = ShiftImm + Width - 1;
1600 static bool isSeveralBitsExtractOpFromShr(SDNode *N, unsigned &Opc,
1601 SDValue &Opd0, unsigned &LSB,
1603 // We are looking for the following pattern which basically extracts several
1604 // continuous bits from the source value and places it from the LSB of the
1605 // destination value, all other bits of the destination value or set to zero:
1607 // Value2 = AND Value, MaskImm
1608 // SRL Value2, ShiftImm
1610 // with MaskImm >> ShiftImm to search for the bit width.
1612 // This gets selected into a single UBFM:
1614 // UBFM Value, ShiftImm, BitWide + SrlImm -1
1617 if (N->getOpcode() != ISD::SRL)
1620 uint64_t AndMask = 0;
1621 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::AND, AndMask))
1624 Opd0 = N->getOperand(0).getOperand(0);
1626 uint64_t SrlImm = 0;
1627 if (!isIntImmediate(N->getOperand(1), SrlImm))
1630 // Check whether we really have several bits extract here.
1631 unsigned BitWide = 64 - countLeadingOnes(~(AndMask >> SrlImm));
1632 if (BitWide && isMask_64(AndMask >> SrlImm)) {
1633 if (N->getValueType(0) == MVT::i32)
1634 Opc = AArch64::UBFMWri;
1636 Opc = AArch64::UBFMXri;
1639 MSB = BitWide + SrlImm - 1;
1646 static bool isBitfieldExtractOpFromShr(SDNode *N, unsigned &Opc, SDValue &Opd0,
1647 unsigned &Immr, unsigned &Imms,
1648 bool BiggerPattern) {
1649 assert((N->getOpcode() == ISD::SRA || N->getOpcode() == ISD::SRL) &&
1650 "N must be a SHR/SRA operation to call this function");
1652 EVT VT = N->getValueType(0);
1654 // Here we can test the type of VT and return false when the type does not
1655 // match, but since it is done prior to that call in the current context
1656 // we turned that into an assert to avoid redundant code.
1657 assert((VT == MVT::i32 || VT == MVT::i64) &&
1658 "Type checking must have been done before calling this function");
1660 // Check for AND + SRL doing several bits extract.
1661 if (isSeveralBitsExtractOpFromShr(N, Opc, Opd0, Immr, Imms))
1664 // We're looking for a shift of a shift.
1665 uint64_t ShlImm = 0;
1666 uint64_t TruncBits = 0;
1667 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, ShlImm)) {
1668 Opd0 = N->getOperand(0).getOperand(0);
1669 } else if (VT == MVT::i32 && N->getOpcode() == ISD::SRL &&
1670 N->getOperand(0).getNode()->getOpcode() == ISD::TRUNCATE) {
1671 // We are looking for a shift of truncate. Truncate from i64 to i32 could
1672 // be considered as setting high 32 bits as zero. Our strategy here is to
1673 // always generate 64bit UBFM. This consistency will help the CSE pass
1674 // later find more redundancy.
1675 Opd0 = N->getOperand(0).getOperand(0);
1676 TruncBits = Opd0->getValueType(0).getSizeInBits() - VT.getSizeInBits();
1677 VT = Opd0->getValueType(0);
1678 assert(VT == MVT::i64 && "the promoted type should be i64");
1679 } else if (BiggerPattern) {
1680 // Let's pretend a 0 shift left has been performed.
1681 // FIXME: Currently we limit this to the bigger pattern case,
1682 // because some optimizations expect AND and not UBFM
1683 Opd0 = N->getOperand(0);
1687 // Missing combines/constant folding may have left us with strange
1689 if (ShlImm >= VT.getSizeInBits()) {
1691 << ": Found large shift immediate, this should not happen\n"));
1695 uint64_t SrlImm = 0;
1696 if (!isIntImmediate(N->getOperand(1), SrlImm))
1699 assert(SrlImm > 0 && SrlImm < VT.getSizeInBits() &&
1700 "bad amount in shift node!");
1701 int immr = SrlImm - ShlImm;
1702 Immr = immr < 0 ? immr + VT.getSizeInBits() : immr;
1703 Imms = VT.getSizeInBits() - ShlImm - TruncBits - 1;
1704 // SRA requires a signed extraction
1706 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMWri : AArch64::UBFMWri;
1708 Opc = N->getOpcode() == ISD::SRA ? AArch64::SBFMXri : AArch64::UBFMXri;
1712 bool AArch64DAGToDAGISel::tryBitfieldExtractOpFromSExt(SDNode *N) {
1713 assert(N->getOpcode() == ISD::SIGN_EXTEND);
1715 EVT VT = N->getValueType(0);
1716 EVT NarrowVT = N->getOperand(0)->getValueType(0);
1717 if (VT != MVT::i64 || NarrowVT != MVT::i32)
1721 SDValue Op = N->getOperand(0);
1722 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
1726 // Extend the incoming operand of the shift to 64-bits.
1727 SDValue Opd0 = Widen(CurDAG, Op.getOperand(0));
1728 unsigned Immr = ShiftImm;
1729 unsigned Imms = NarrowVT.getSizeInBits() - 1;
1730 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
1731 CurDAG->getTargetConstant(Imms, dl, VT)};
1732 CurDAG->SelectNodeTo(N, AArch64::SBFMXri, VT, Ops);
1736 static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
1737 SDValue &Opd0, unsigned &Immr, unsigned &Imms,
1738 unsigned NumberOfIgnoredLowBits = 0,
1739 bool BiggerPattern = false) {
1740 if (N->getValueType(0) != MVT::i32 && N->getValueType(0) != MVT::i64)
1743 switch (N->getOpcode()) {
1745 if (!N->isMachineOpcode())
1749 return isBitfieldExtractOpFromAnd(CurDAG, N, Opc, Opd0, Immr, Imms,
1750 NumberOfIgnoredLowBits, BiggerPattern);
1753 return isBitfieldExtractOpFromShr(N, Opc, Opd0, Immr, Imms, BiggerPattern);
1755 case ISD::SIGN_EXTEND_INREG:
1756 return isBitfieldExtractOpFromSExtInReg(N, Opc, Opd0, Immr, Imms);
1759 unsigned NOpc = N->getMachineOpcode();
1763 case AArch64::SBFMWri:
1764 case AArch64::UBFMWri:
1765 case AArch64::SBFMXri:
1766 case AArch64::UBFMXri:
1768 Opd0 = N->getOperand(0);
1769 Immr = cast<ConstantSDNode>(N->getOperand(1).getNode())->getZExtValue();
1770 Imms = cast<ConstantSDNode>(N->getOperand(2).getNode())->getZExtValue();
1777 bool AArch64DAGToDAGISel::tryBitfieldExtractOp(SDNode *N) {
1778 unsigned Opc, Immr, Imms;
1780 if (!isBitfieldExtractOp(CurDAG, N, Opc, Opd0, Immr, Imms))
1783 EVT VT = N->getValueType(0);
1786 // If the bit extract operation is 64bit but the original type is 32bit, we
1787 // need to add one EXTRACT_SUBREG.
1788 if ((Opc == AArch64::SBFMXri || Opc == AArch64::UBFMXri) && VT == MVT::i32) {
1789 SDValue Ops64[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, MVT::i64),
1790 CurDAG->getTargetConstant(Imms, dl, MVT::i64)};
1792 SDNode *BFM = CurDAG->getMachineNode(Opc, dl, MVT::i64, Ops64);
1793 SDValue SubReg = CurDAG->getTargetConstant(AArch64::sub_32, dl, MVT::i32);
1794 ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl,
1795 MVT::i32, SDValue(BFM, 0), SubReg));
1799 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
1800 CurDAG->getTargetConstant(Imms, dl, VT)};
1801 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
1805 /// Does DstMask form a complementary pair with the mask provided by
1806 /// BitsToBeInserted, suitable for use in a BFI instruction. Roughly speaking,
1807 /// this asks whether DstMask zeroes precisely those bits that will be set by
1809 static bool isBitfieldDstMask(uint64_t DstMask, const APInt &BitsToBeInserted,
1810 unsigned NumberOfIgnoredHighBits, EVT VT) {
1811 assert((VT == MVT::i32 || VT == MVT::i64) &&
1812 "i32 or i64 mask type expected!");
1813 unsigned BitWidth = VT.getSizeInBits() - NumberOfIgnoredHighBits;
1815 APInt SignificantDstMask = APInt(BitWidth, DstMask);
1816 APInt SignificantBitsToBeInserted = BitsToBeInserted.zextOrTrunc(BitWidth);
1818 return (SignificantDstMask & SignificantBitsToBeInserted) == 0 &&
1819 (SignificantDstMask | SignificantBitsToBeInserted).isAllOnesValue();
1822 // Look for bits that will be useful for later uses.
1823 // A bit is consider useless as soon as it is dropped and never used
1824 // before it as been dropped.
1825 // E.g., looking for useful bit of x
1828 // After #1, x useful bits are 0x7, then the useful bits of x, live through
1830 // After #2, the useful bits of x are 0x4.
1831 // However, if x is used on an unpredicatable instruction, then all its bits
1837 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth = 0);
1839 static void getUsefulBitsFromAndWithImmediate(SDValue Op, APInt &UsefulBits,
1842 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1843 Imm = AArch64_AM::decodeLogicalImmediate(Imm, UsefulBits.getBitWidth());
1844 UsefulBits &= APInt(UsefulBits.getBitWidth(), Imm);
1845 getUsefulBits(Op, UsefulBits, Depth + 1);
1848 static void getUsefulBitsFromBitfieldMoveOpd(SDValue Op, APInt &UsefulBits,
1849 uint64_t Imm, uint64_t MSB,
1851 // inherit the bitwidth value
1852 APInt OpUsefulBits(UsefulBits);
1856 OpUsefulBits <<= MSB - Imm + 1;
1858 // The interesting part will be in the lower part of the result
1859 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1860 // The interesting part was starting at Imm in the argument
1861 OpUsefulBits <<= Imm;
1863 OpUsefulBits <<= MSB + 1;
1865 // The interesting part will be shifted in the result
1866 OpUsefulBits <<= OpUsefulBits.getBitWidth() - Imm;
1867 getUsefulBits(Op, OpUsefulBits, Depth + 1);
1868 // The interesting part was at zero in the argument
1869 OpUsefulBits.lshrInPlace(OpUsefulBits.getBitWidth() - Imm);
1872 UsefulBits &= OpUsefulBits;
1875 static void getUsefulBitsFromUBFM(SDValue Op, APInt &UsefulBits,
1878 cast<const ConstantSDNode>(Op.getOperand(1).getNode())->getZExtValue();
1880 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1882 getUsefulBitsFromBitfieldMoveOpd(Op, UsefulBits, Imm, MSB, Depth);
1885 static void getUsefulBitsFromOrWithShiftedReg(SDValue Op, APInt &UsefulBits,
1887 uint64_t ShiftTypeAndValue =
1888 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1889 APInt Mask(UsefulBits);
1890 Mask.clearAllBits();
1893 if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSL) {
1895 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1897 getUsefulBits(Op, Mask, Depth + 1);
1898 Mask.lshrInPlace(ShiftAmt);
1899 } else if (AArch64_AM::getShiftType(ShiftTypeAndValue) == AArch64_AM::LSR) {
1901 // We do not handle AArch64_AM::ASR, because the sign will change the
1902 // number of useful bits
1903 uint64_t ShiftAmt = AArch64_AM::getShiftValue(ShiftTypeAndValue);
1904 Mask.lshrInPlace(ShiftAmt);
1905 getUsefulBits(Op, Mask, Depth + 1);
1913 static void getUsefulBitsFromBFM(SDValue Op, SDValue Orig, APInt &UsefulBits,
1916 cast<const ConstantSDNode>(Op.getOperand(2).getNode())->getZExtValue();
1918 cast<const ConstantSDNode>(Op.getOperand(3).getNode())->getZExtValue();
1920 APInt OpUsefulBits(UsefulBits);
1923 APInt ResultUsefulBits(UsefulBits.getBitWidth(), 0);
1924 ResultUsefulBits.flipAllBits();
1925 APInt Mask(UsefulBits.getBitWidth(), 0);
1927 getUsefulBits(Op, ResultUsefulBits, Depth + 1);
1930 // The instruction is a BFXIL.
1931 uint64_t Width = MSB - Imm + 1;
1934 OpUsefulBits <<= Width;
1937 if (Op.getOperand(1) == Orig) {
1938 // Copy the low bits from the result to bits starting from LSB.
1939 Mask = ResultUsefulBits & OpUsefulBits;
1943 if (Op.getOperand(0) == Orig)
1944 // Bits starting from LSB in the input contribute to the result.
1945 Mask |= (ResultUsefulBits & ~OpUsefulBits);
1947 // The instruction is a BFI.
1948 uint64_t Width = MSB + 1;
1949 uint64_t LSB = UsefulBits.getBitWidth() - Imm;
1951 OpUsefulBits <<= Width;
1953 OpUsefulBits <<= LSB;
1955 if (Op.getOperand(1) == Orig) {
1956 // Copy the bits from the result to the zero bits.
1957 Mask = ResultUsefulBits & OpUsefulBits;
1958 Mask.lshrInPlace(LSB);
1961 if (Op.getOperand(0) == Orig)
1962 Mask |= (ResultUsefulBits & ~OpUsefulBits);
1968 static void getUsefulBitsForUse(SDNode *UserNode, APInt &UsefulBits,
1969 SDValue Orig, unsigned Depth) {
1971 // Users of this node should have already been instruction selected
1972 // FIXME: Can we turn that into an assert?
1973 if (!UserNode->isMachineOpcode())
1976 switch (UserNode->getMachineOpcode()) {
1979 case AArch64::ANDSWri:
1980 case AArch64::ANDSXri:
1981 case AArch64::ANDWri:
1982 case AArch64::ANDXri:
1983 // We increment Depth only when we call the getUsefulBits
1984 return getUsefulBitsFromAndWithImmediate(SDValue(UserNode, 0), UsefulBits,
1986 case AArch64::UBFMWri:
1987 case AArch64::UBFMXri:
1988 return getUsefulBitsFromUBFM(SDValue(UserNode, 0), UsefulBits, Depth);
1990 case AArch64::ORRWrs:
1991 case AArch64::ORRXrs:
1992 if (UserNode->getOperand(1) != Orig)
1994 return getUsefulBitsFromOrWithShiftedReg(SDValue(UserNode, 0), UsefulBits,
1996 case AArch64::BFMWri:
1997 case AArch64::BFMXri:
1998 return getUsefulBitsFromBFM(SDValue(UserNode, 0), Orig, UsefulBits, Depth);
2000 case AArch64::STRBBui:
2001 case AArch64::STURBBi:
2002 if (UserNode->getOperand(0) != Orig)
2004 UsefulBits &= APInt(UsefulBits.getBitWidth(), 0xff);
2007 case AArch64::STRHHui:
2008 case AArch64::STURHHi:
2009 if (UserNode->getOperand(0) != Orig)
2011 UsefulBits &= APInt(UsefulBits.getBitWidth(), 0xffff);
2016 static void getUsefulBits(SDValue Op, APInt &UsefulBits, unsigned Depth) {
2019 // Initialize UsefulBits
2021 unsigned Bitwidth = Op.getScalarValueSizeInBits();
2022 // At the beginning, assume every produced bits is useful
2023 UsefulBits = APInt(Bitwidth, 0);
2024 UsefulBits.flipAllBits();
2026 APInt UsersUsefulBits(UsefulBits.getBitWidth(), 0);
2028 for (SDNode *Node : Op.getNode()->uses()) {
2029 // A use cannot produce useful bits
2030 APInt UsefulBitsForUse = APInt(UsefulBits);
2031 getUsefulBitsForUse(Node, UsefulBitsForUse, Op, Depth);
2032 UsersUsefulBits |= UsefulBitsForUse;
2034 // UsefulBits contains the produced bits that are meaningful for the
2035 // current definition, thus a user cannot make a bit meaningful at
2037 UsefulBits &= UsersUsefulBits;
2040 /// Create a machine node performing a notional SHL of Op by ShlAmount. If
2041 /// ShlAmount is negative, do a (logical) right-shift instead. If ShlAmount is
2042 /// 0, return Op unchanged.
2043 static SDValue getLeftShift(SelectionDAG *CurDAG, SDValue Op, int ShlAmount) {
2047 EVT VT = Op.getValueType();
2049 unsigned BitWidth = VT.getSizeInBits();
2050 unsigned UBFMOpc = BitWidth == 32 ? AArch64::UBFMWri : AArch64::UBFMXri;
2053 if (ShlAmount > 0) {
2054 // LSL wD, wN, #Amt == UBFM wD, wN, #32-Amt, #31-Amt
2055 ShiftNode = CurDAG->getMachineNode(
2056 UBFMOpc, dl, VT, Op,
2057 CurDAG->getTargetConstant(BitWidth - ShlAmount, dl, VT),
2058 CurDAG->getTargetConstant(BitWidth - 1 - ShlAmount, dl, VT));
2060 // LSR wD, wN, #Amt == UBFM wD, wN, #Amt, #32-1
2061 assert(ShlAmount < 0 && "expected right shift");
2062 int ShrAmount = -ShlAmount;
2063 ShiftNode = CurDAG->getMachineNode(
2064 UBFMOpc, dl, VT, Op, CurDAG->getTargetConstant(ShrAmount, dl, VT),
2065 CurDAG->getTargetConstant(BitWidth - 1, dl, VT));
2068 return SDValue(ShiftNode, 0);
2071 /// Does this tree qualify as an attempt to move a bitfield into position,
2072 /// essentially "(and (shl VAL, N), Mask)".
2073 static bool isBitfieldPositioningOp(SelectionDAG *CurDAG, SDValue Op,
2075 SDValue &Src, int &ShiftAmount,
2077 EVT VT = Op.getValueType();
2078 unsigned BitWidth = VT.getSizeInBits();
2080 assert(BitWidth == 32 || BitWidth == 64);
2083 CurDAG->computeKnownBits(Op, Known);
2085 // Non-zero in the sense that they're not provably zero, which is the key
2086 // point if we want to use this value
2087 uint64_t NonZeroBits = (~Known.Zero).getZExtValue();
2089 // Discard a constant AND mask if present. It's safe because the node will
2090 // already have been factored into the computeKnownBits calculation above.
2092 if (isOpcWithIntImmediate(Op.getNode(), ISD::AND, AndImm)) {
2093 assert((~APInt(BitWidth, AndImm) & ~Known.Zero) == 0);
2094 Op = Op.getOperand(0);
2097 // Don't match if the SHL has more than one use, since then we'll end up
2098 // generating SHL+UBFIZ instead of just keeping SHL+AND.
2099 if (!BiggerPattern && !Op.hasOneUse())
2103 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SHL, ShlImm))
2105 Op = Op.getOperand(0);
2107 if (!isShiftedMask_64(NonZeroBits))
2110 ShiftAmount = countTrailingZeros(NonZeroBits);
2111 MaskWidth = countTrailingOnes(NonZeroBits >> ShiftAmount);
2113 // BFI encompasses sufficiently many nodes that it's worth inserting an extra
2114 // LSL/LSR if the mask in NonZeroBits doesn't quite match up with the ISD::SHL
2115 // amount. BiggerPattern is true when this pattern is being matched for BFI,
2116 // BiggerPattern is false when this pattern is being matched for UBFIZ, in
2117 // which case it is not profitable to insert an extra shift.
2118 if (ShlImm - ShiftAmount != 0 && !BiggerPattern)
2120 Src = getLeftShift(CurDAG, Op, ShlImm - ShiftAmount);
2125 static bool isShiftedMask(uint64_t Mask, EVT VT) {
2126 assert(VT == MVT::i32 || VT == MVT::i64);
2128 return isShiftedMask_32(Mask);
2129 return isShiftedMask_64(Mask);
2132 // Generate a BFI/BFXIL from 'or (and X, MaskImm), OrImm' iff the value being
2133 // inserted only sets known zero bits.
2134 static bool tryBitfieldInsertOpFromOrAndImm(SDNode *N, SelectionDAG *CurDAG) {
2135 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
2137 EVT VT = N->getValueType(0);
2138 if (VT != MVT::i32 && VT != MVT::i64)
2141 unsigned BitWidth = VT.getSizeInBits();
2144 if (!isOpcWithIntImmediate(N, ISD::OR, OrImm))
2147 // Skip this transformation if the ORR immediate can be encoded in the ORR.
2148 // Otherwise, we'll trade an AND+ORR for ORR+BFI/BFXIL, which is most likely
2149 // performance neutral.
2150 if (AArch64_AM::isLogicalImmediate(OrImm, BitWidth))
2154 SDValue And = N->getOperand(0);
2155 // Must be a single use AND with an immediate operand.
2156 if (!And.hasOneUse() ||
2157 !isOpcWithIntImmediate(And.getNode(), ISD::AND, MaskImm))
2160 // Compute the Known Zero for the AND as this allows us to catch more general
2161 // cases than just looking for AND with imm.
2163 CurDAG->computeKnownBits(And, Known);
2165 // Non-zero in the sense that they're not provably zero, which is the key
2166 // point if we want to use this value.
2167 uint64_t NotKnownZero = (~Known.Zero).getZExtValue();
2169 // The KnownZero mask must be a shifted mask (e.g., 1110..011, 11100..00).
2170 if (!isShiftedMask(Known.Zero.getZExtValue(), VT))
2173 // The bits being inserted must only set those bits that are known to be zero.
2174 if ((OrImm & NotKnownZero) != 0) {
2175 // FIXME: It's okay if the OrImm sets NotKnownZero bits to 1, but we don't
2176 // currently handle this case.
2180 // BFI/BFXIL dst, src, #lsb, #width.
2181 int LSB = countTrailingOnes(NotKnownZero);
2182 int Width = BitWidth - APInt(BitWidth, NotKnownZero).countPopulation();
2184 // BFI/BFXIL is an alias of BFM, so translate to BFM operands.
2185 unsigned ImmR = (BitWidth - LSB) % BitWidth;
2186 unsigned ImmS = Width - 1;
2188 // If we're creating a BFI instruction avoid cases where we need more
2189 // instructions to materialize the BFI constant as compared to the original
2190 // ORR. A BFXIL will use the same constant as the original ORR, so the code
2191 // should be no worse in this case.
2192 bool IsBFI = LSB != 0;
2193 uint64_t BFIImm = OrImm >> LSB;
2194 if (IsBFI && !AArch64_AM::isLogicalImmediate(BFIImm, BitWidth)) {
2195 // We have a BFI instruction and we know the constant can't be materialized
2196 // with a ORR-immediate with the zero register.
2197 unsigned OrChunks = 0, BFIChunks = 0;
2198 for (unsigned Shift = 0; Shift < BitWidth; Shift += 16) {
2199 if (((OrImm >> Shift) & 0xFFFF) != 0)
2201 if (((BFIImm >> Shift) & 0xFFFF) != 0)
2204 if (BFIChunks > OrChunks)
2208 // Materialize the constant to be inserted.
2210 unsigned MOVIOpc = VT == MVT::i32 ? AArch64::MOVi32imm : AArch64::MOVi64imm;
2211 SDNode *MOVI = CurDAG->getMachineNode(
2212 MOVIOpc, DL, VT, CurDAG->getTargetConstant(BFIImm, DL, VT));
2214 // Create the BFI/BFXIL instruction.
2215 SDValue Ops[] = {And.getOperand(0), SDValue(MOVI, 0),
2216 CurDAG->getTargetConstant(ImmR, DL, VT),
2217 CurDAG->getTargetConstant(ImmS, DL, VT)};
2218 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2219 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2223 static bool tryBitfieldInsertOpFromOr(SDNode *N, const APInt &UsefulBits,
2224 SelectionDAG *CurDAG) {
2225 assert(N->getOpcode() == ISD::OR && "Expect a OR operation");
2227 EVT VT = N->getValueType(0);
2228 if (VT != MVT::i32 && VT != MVT::i64)
2231 unsigned BitWidth = VT.getSizeInBits();
2233 // Because of simplify-demanded-bits in DAGCombine, involved masks may not
2234 // have the expected shape. Try to undo that.
2236 unsigned NumberOfIgnoredLowBits = UsefulBits.countTrailingZeros();
2237 unsigned NumberOfIgnoredHighBits = UsefulBits.countLeadingZeros();
2239 // Given a OR operation, check if we have the following pattern
2240 // ubfm c, b, imm, imm2 (or something that does the same jobs, see
2241 // isBitfieldExtractOp)
2242 // d = e & mask2 ; where mask is a binary sequence of 1..10..0 and
2243 // countTrailingZeros(mask2) == imm2 - imm + 1
2245 // if yes, replace the OR instruction with:
2246 // f = BFM Opd0, Opd1, LSB, MSB ; where LSB = imm, and MSB = imm2
2248 // OR is commutative, check all combinations of operand order and values of
2249 // BiggerPattern, i.e.
2250 // Opd0, Opd1, BiggerPattern=false
2251 // Opd1, Opd0, BiggerPattern=false
2252 // Opd0, Opd1, BiggerPattern=true
2253 // Opd1, Opd0, BiggerPattern=true
2254 // Several of these combinations may match, so check with BiggerPattern=false
2255 // first since that will produce better results by matching more instructions
2256 // and/or inserting fewer extra instructions.
2257 for (int I = 0; I < 4; ++I) {
2260 unsigned ImmR, ImmS;
2261 bool BiggerPattern = I / 2;
2262 SDValue OrOpd0Val = N->getOperand(I % 2);
2263 SDNode *OrOpd0 = OrOpd0Val.getNode();
2264 SDValue OrOpd1Val = N->getOperand((I + 1) % 2);
2265 SDNode *OrOpd1 = OrOpd1Val.getNode();
2269 if (isBitfieldExtractOp(CurDAG, OrOpd0, BFXOpc, Src, ImmR, ImmS,
2270 NumberOfIgnoredLowBits, BiggerPattern)) {
2271 // Check that the returned opcode is compatible with the pattern,
2272 // i.e., same type and zero extended (U and not S)
2273 if ((BFXOpc != AArch64::UBFMXri && VT == MVT::i64) ||
2274 (BFXOpc != AArch64::UBFMWri && VT == MVT::i32))
2277 // Compute the width of the bitfield insertion
2279 Width = ImmS - ImmR + 1;
2280 // FIXME: This constraint is to catch bitfield insertion we may
2281 // want to widen the pattern if we want to grab general bitfied
2286 // If the mask on the insertee is correct, we have a BFXIL operation. We
2287 // can share the ImmR and ImmS values from the already-computed UBFM.
2288 } else if (isBitfieldPositioningOp(CurDAG, OrOpd0Val,
2290 Src, DstLSB, Width)) {
2291 ImmR = (BitWidth - DstLSB) % BitWidth;
2296 // Check the second part of the pattern
2297 EVT VT = OrOpd1->getValueType(0);
2298 assert((VT == MVT::i32 || VT == MVT::i64) && "unexpected OR operand");
2300 // Compute the Known Zero for the candidate of the first operand.
2301 // This allows to catch more general case than just looking for
2302 // AND with imm. Indeed, simplify-demanded-bits may have removed
2303 // the AND instruction because it proves it was useless.
2305 CurDAG->computeKnownBits(OrOpd1Val, Known);
2307 // Check if there is enough room for the second operand to appear
2309 APInt BitsToBeInserted =
2310 APInt::getBitsSet(Known.getBitWidth(), DstLSB, DstLSB + Width);
2312 if ((BitsToBeInserted & ~Known.Zero) != 0)
2315 // Set the first operand
2317 if (isOpcWithIntImmediate(OrOpd1, ISD::AND, Imm) &&
2318 isBitfieldDstMask(Imm, BitsToBeInserted, NumberOfIgnoredHighBits, VT))
2319 // In that case, we can eliminate the AND
2320 Dst = OrOpd1->getOperand(0);
2322 // Maybe the AND has been removed by simplify-demanded-bits
2323 // or is useful because it discards more bits
2328 SDValue Ops[] = {Dst, Src, CurDAG->getTargetConstant(ImmR, DL, VT),
2329 CurDAG->getTargetConstant(ImmS, DL, VT)};
2330 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2331 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2335 // Generate a BFXIL from 'or (and X, Mask0Imm), (and Y, Mask1Imm)' iff
2336 // Mask0Imm and ~Mask1Imm are equivalent and one of the MaskImms is a shifted
2337 // mask (e.g., 0x000ffff0).
2338 uint64_t Mask0Imm, Mask1Imm;
2339 SDValue And0 = N->getOperand(0);
2340 SDValue And1 = N->getOperand(1);
2341 if (And0.hasOneUse() && And1.hasOneUse() &&
2342 isOpcWithIntImmediate(And0.getNode(), ISD::AND, Mask0Imm) &&
2343 isOpcWithIntImmediate(And1.getNode(), ISD::AND, Mask1Imm) &&
2344 APInt(BitWidth, Mask0Imm) == ~APInt(BitWidth, Mask1Imm) &&
2345 (isShiftedMask(Mask0Imm, VT) || isShiftedMask(Mask1Imm, VT))) {
2347 // ORR is commutative, so canonicalize to the form 'or (and X, Mask0Imm),
2348 // (and Y, Mask1Imm)' where Mask1Imm is the shifted mask masking off the
2349 // bits to be inserted.
2350 if (isShiftedMask(Mask0Imm, VT)) {
2351 std::swap(And0, And1);
2352 std::swap(Mask0Imm, Mask1Imm);
2355 SDValue Src = And1->getOperand(0);
2356 SDValue Dst = And0->getOperand(0);
2357 unsigned LSB = countTrailingZeros(Mask1Imm);
2358 int Width = BitWidth - APInt(BitWidth, Mask0Imm).countPopulation();
2360 // The BFXIL inserts the low-order bits from a source register, so right
2361 // shift the needed bits into place.
2363 unsigned ShiftOpc = (VT == MVT::i32) ? AArch64::UBFMWri : AArch64::UBFMXri;
2364 SDNode *LSR = CurDAG->getMachineNode(
2365 ShiftOpc, DL, VT, Src, CurDAG->getTargetConstant(LSB, DL, VT),
2366 CurDAG->getTargetConstant(BitWidth - 1, DL, VT));
2368 // BFXIL is an alias of BFM, so translate to BFM operands.
2369 unsigned ImmR = (BitWidth - LSB) % BitWidth;
2370 unsigned ImmS = Width - 1;
2372 // Create the BFXIL instruction.
2373 SDValue Ops[] = {Dst, SDValue(LSR, 0),
2374 CurDAG->getTargetConstant(ImmR, DL, VT),
2375 CurDAG->getTargetConstant(ImmS, DL, VT)};
2376 unsigned Opc = (VT == MVT::i32) ? AArch64::BFMWri : AArch64::BFMXri;
2377 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2384 bool AArch64DAGToDAGISel::tryBitfieldInsertOp(SDNode *N) {
2385 if (N->getOpcode() != ISD::OR)
2389 getUsefulBits(SDValue(N, 0), NUsefulBits);
2391 // If all bits are not useful, just return UNDEF.
2393 CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF, N->getValueType(0));
2397 if (tryBitfieldInsertOpFromOr(N, NUsefulBits, CurDAG))
2400 return tryBitfieldInsertOpFromOrAndImm(N, CurDAG);
2403 /// SelectBitfieldInsertInZeroOp - Match a UBFIZ instruction that is the
2404 /// equivalent of a left shift by a constant amount followed by an and masking
2405 /// out a contiguous set of bits.
2406 bool AArch64DAGToDAGISel::tryBitfieldInsertInZeroOp(SDNode *N) {
2407 if (N->getOpcode() != ISD::AND)
2410 EVT VT = N->getValueType(0);
2411 if (VT != MVT::i32 && VT != MVT::i64)
2416 if (!isBitfieldPositioningOp(CurDAG, SDValue(N, 0), /*BiggerPattern=*/false,
2417 Op0, DstLSB, Width))
2420 // ImmR is the rotate right amount.
2421 unsigned ImmR = (VT.getSizeInBits() - DstLSB) % VT.getSizeInBits();
2422 // ImmS is the most significant bit of the source to be moved.
2423 unsigned ImmS = Width - 1;
2426 SDValue Ops[] = {Op0, CurDAG->getTargetConstant(ImmR, DL, VT),
2427 CurDAG->getTargetConstant(ImmS, DL, VT)};
2428 unsigned Opc = (VT == MVT::i32) ? AArch64::UBFMWri : AArch64::UBFMXri;
2429 CurDAG->SelectNodeTo(N, Opc, VT, Ops);
2434 AArch64DAGToDAGISel::SelectCVTFixedPosOperand(SDValue N, SDValue &FixedPos,
2435 unsigned RegWidth) {
2437 if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N))
2438 FVal = CN->getValueAPF();
2439 else if (LoadSDNode *LN = dyn_cast<LoadSDNode>(N)) {
2440 // Some otherwise illegal constants are allowed in this case.
2441 if (LN->getOperand(1).getOpcode() != AArch64ISD::ADDlow ||
2442 !isa<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1)))
2445 ConstantPoolSDNode *CN =
2446 dyn_cast<ConstantPoolSDNode>(LN->getOperand(1)->getOperand(1));
2447 FVal = cast<ConstantFP>(CN->getConstVal())->getValueAPF();
2451 // An FCVT[SU] instruction performs: convertToInt(Val * 2^fbits) where fbits
2452 // is between 1 and 32 for a destination w-register, or 1 and 64 for an
2455 // By this stage, we've detected (fp_to_[su]int (fmul Val, THIS_NODE)) so we
2456 // want THIS_NODE to be 2^fbits. This is much easier to deal with using
2460 // fbits is between 1 and 64 in the worst-case, which means the fmul
2461 // could have 2^64 as an actual operand. Need 65 bits of precision.
2462 APSInt IntVal(65, true);
2463 FVal.convertToInteger(IntVal, APFloat::rmTowardZero, &IsExact);
2465 // N.b. isPowerOf2 also checks for > 0.
2466 if (!IsExact || !IntVal.isPowerOf2()) return false;
2467 unsigned FBits = IntVal.logBase2();
2469 // Checks above should have guaranteed that we haven't lost information in
2470 // finding FBits, but it must still be in range.
2471 if (FBits == 0 || FBits > RegWidth) return false;
2473 FixedPos = CurDAG->getTargetConstant(FBits, SDLoc(N), MVT::i32);
2477 // Inspects a register string of the form o0:op1:CRn:CRm:op2 gets the fields
2478 // of the string and obtains the integer values from them and combines these
2479 // into a single value to be used in the MRS/MSR instruction.
2480 static int getIntOperandFromRegisterString(StringRef RegString) {
2481 SmallVector<StringRef, 5> Fields;
2482 RegString.split(Fields, ':');
2484 if (Fields.size() == 1)
2487 assert(Fields.size() == 5
2488 && "Invalid number of fields in read register string");
2490 SmallVector<int, 5> Ops;
2491 bool AllIntFields = true;
2493 for (StringRef Field : Fields) {
2495 AllIntFields &= !Field.getAsInteger(10, IntField);
2496 Ops.push_back(IntField);
2499 assert(AllIntFields &&
2500 "Unexpected non-integer value in special register string.");
2502 // Need to combine the integer fields of the string into a single value
2503 // based on the bit encoding of MRS/MSR instruction.
2504 return (Ops[0] << 14) | (Ops[1] << 11) | (Ops[2] << 7) |
2505 (Ops[3] << 3) | (Ops[4]);
2508 // Lower the read_register intrinsic to an MRS instruction node if the special
2509 // register string argument is either of the form detailed in the ALCE (the
2510 // form described in getIntOperandsFromRegsterString) or is a named register
2511 // known by the MRS SysReg mapper.
2512 bool AArch64DAGToDAGISel::tryReadRegister(SDNode *N) {
2513 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2514 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2517 int Reg = getIntOperandFromRegisterString(RegString->getString());
2519 ReplaceNode(N, CurDAG->getMachineNode(
2520 AArch64::MRS, DL, N->getSimpleValueType(0), MVT::Other,
2521 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2526 // Use the sysreg mapper to map the remaining possible strings to the
2527 // value for the register to be used for the instruction operand.
2528 auto TheReg = AArch64SysReg::lookupSysRegByName(RegString->getString());
2529 if (TheReg && TheReg->Readable &&
2530 TheReg->haveFeatures(Subtarget->getFeatureBits()))
2531 Reg = TheReg->Encoding;
2533 Reg = AArch64SysReg::parseGenericRegister(RegString->getString());
2536 ReplaceNode(N, CurDAG->getMachineNode(
2537 AArch64::MRS, DL, N->getSimpleValueType(0), MVT::Other,
2538 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2546 // Lower the write_register intrinsic to an MSR instruction node if the special
2547 // register string argument is either of the form detailed in the ALCE (the
2548 // form described in getIntOperandsFromRegsterString) or is a named register
2549 // known by the MSR SysReg mapper.
2550 bool AArch64DAGToDAGISel::tryWriteRegister(SDNode *N) {
2551 const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(N->getOperand(1));
2552 const MDString *RegString = dyn_cast<MDString>(MD->getMD()->getOperand(0));
2555 int Reg = getIntOperandFromRegisterString(RegString->getString());
2558 N, CurDAG->getMachineNode(AArch64::MSR, DL, MVT::Other,
2559 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2560 N->getOperand(2), N->getOperand(0)));
2564 // Check if the register was one of those allowed as the pstatefield value in
2565 // the MSR (immediate) instruction. To accept the values allowed in the
2566 // pstatefield for the MSR (immediate) instruction, we also require that an
2567 // immediate value has been provided as an argument, we know that this is
2568 // the case as it has been ensured by semantic checking.
2569 auto PMapper = AArch64PState::lookupPStateByName(RegString->getString());;
2571 assert (isa<ConstantSDNode>(N->getOperand(2))
2572 && "Expected a constant integer expression.");
2573 unsigned Reg = PMapper->Encoding;
2574 uint64_t Immed = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
2576 if (Reg == AArch64PState::PAN || Reg == AArch64PState::UAO) {
2577 assert(Immed < 2 && "Bad imm");
2578 State = AArch64::MSRpstateImm1;
2580 assert(Immed < 16 && "Bad imm");
2581 State = AArch64::MSRpstateImm4;
2583 ReplaceNode(N, CurDAG->getMachineNode(
2584 State, DL, MVT::Other,
2585 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2586 CurDAG->getTargetConstant(Immed, DL, MVT::i16),
2591 // Use the sysreg mapper to attempt to map the remaining possible strings
2592 // to the value for the register to be used for the MSR (register)
2593 // instruction operand.
2594 auto TheReg = AArch64SysReg::lookupSysRegByName(RegString->getString());
2595 if (TheReg && TheReg->Writeable &&
2596 TheReg->haveFeatures(Subtarget->getFeatureBits()))
2597 Reg = TheReg->Encoding;
2599 Reg = AArch64SysReg::parseGenericRegister(RegString->getString());
2601 ReplaceNode(N, CurDAG->getMachineNode(
2602 AArch64::MSR, DL, MVT::Other,
2603 CurDAG->getTargetConstant(Reg, DL, MVT::i32),
2604 N->getOperand(2), N->getOperand(0)));
2611 /// We've got special pseudo-instructions for these
2612 void AArch64DAGToDAGISel::SelectCMP_SWAP(SDNode *N) {
2614 EVT MemTy = cast<MemSDNode>(N)->getMemoryVT();
2615 if (MemTy == MVT::i8)
2616 Opcode = AArch64::CMP_SWAP_8;
2617 else if (MemTy == MVT::i16)
2618 Opcode = AArch64::CMP_SWAP_16;
2619 else if (MemTy == MVT::i32)
2620 Opcode = AArch64::CMP_SWAP_32;
2621 else if (MemTy == MVT::i64)
2622 Opcode = AArch64::CMP_SWAP_64;
2624 llvm_unreachable("Unknown AtomicCmpSwap type");
2626 MVT RegTy = MemTy == MVT::i64 ? MVT::i64 : MVT::i32;
2627 SDValue Ops[] = {N->getOperand(1), N->getOperand(2), N->getOperand(3),
2629 SDNode *CmpSwap = CurDAG->getMachineNode(
2631 CurDAG->getVTList(RegTy, MVT::i32, MVT::Other), Ops);
2633 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2634 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2635 cast<MachineSDNode>(CmpSwap)->setMemRefs(MemOp, MemOp + 1);
2637 ReplaceUses(SDValue(N, 0), SDValue(CmpSwap, 0));
2638 ReplaceUses(SDValue(N, 1), SDValue(CmpSwap, 2));
2639 CurDAG->RemoveDeadNode(N);
2642 void AArch64DAGToDAGISel::Select(SDNode *Node) {
2643 // Dump information about the Node being selected
2644 DEBUG(errs() << "Selecting: ");
2645 DEBUG(Node->dump(CurDAG));
2646 DEBUG(errs() << "\n");
2648 // If we have a custom node, we already have selected!
2649 if (Node->isMachineOpcode()) {
2650 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
2651 Node->setNodeId(-1);
2655 // Few custom selection stuff.
2656 EVT VT = Node->getValueType(0);
2658 switch (Node->getOpcode()) {
2662 case ISD::ATOMIC_CMP_SWAP:
2663 SelectCMP_SWAP(Node);
2666 case ISD::READ_REGISTER:
2667 if (tryReadRegister(Node))
2671 case ISD::WRITE_REGISTER:
2672 if (tryWriteRegister(Node))
2677 if (tryMLAV64LaneV128(Node))
2682 // Try to select as an indexed load. Fall through to normal processing
2684 if (tryIndexedLoad(Node))
2692 case ISD::SIGN_EXTEND_INREG:
2693 if (tryBitfieldExtractOp(Node))
2695 if (tryBitfieldInsertInZeroOp(Node))
2699 case ISD::SIGN_EXTEND:
2700 if (tryBitfieldExtractOpFromSExt(Node))
2705 if (tryBitfieldInsertOp(Node))
2709 case ISD::EXTRACT_VECTOR_ELT: {
2710 // Extracting lane zero is a special case where we can just use a plain
2711 // EXTRACT_SUBREG instruction, which will become FMOV. This is easier for
2712 // the rest of the compiler, especially the register allocator and copyi
2713 // propagation, to reason about, so is preferred when it's possible to
2715 ConstantSDNode *LaneNode = cast<ConstantSDNode>(Node->getOperand(1));
2716 // Bail and use the default Select() for non-zero lanes.
2717 if (LaneNode->getZExtValue() != 0)
2719 // If the element type is not the same as the result type, likewise
2720 // bail and use the default Select(), as there's more to do than just
2721 // a cross-class COPY. This catches extracts of i8 and i16 elements
2722 // since they will need an explicit zext.
2723 if (VT != Node->getOperand(0).getValueType().getVectorElementType())
2726 switch (Node->getOperand(0)
2728 .getVectorElementType()
2731 llvm_unreachable("Unexpected vector element type!");
2733 SubReg = AArch64::dsub;
2736 SubReg = AArch64::ssub;
2739 SubReg = AArch64::hsub;
2742 llvm_unreachable("unexpected zext-requiring extract element!");
2744 SDValue Extract = CurDAG->getTargetExtractSubreg(SubReg, SDLoc(Node), VT,
2745 Node->getOperand(0));
2746 DEBUG(dbgs() << "ISEL: Custom selection!\n=> ");
2747 DEBUG(Extract->dumpr(CurDAG));
2748 DEBUG(dbgs() << "\n");
2749 ReplaceNode(Node, Extract.getNode());
2752 case ISD::Constant: {
2753 // Materialize zero constants as copies from WZR/XZR. This allows
2754 // the coalescer to propagate these into other instructions.
2755 ConstantSDNode *ConstNode = cast<ConstantSDNode>(Node);
2756 if (ConstNode->isNullValue()) {
2757 if (VT == MVT::i32) {
2758 SDValue New = CurDAG->getCopyFromReg(
2759 CurDAG->getEntryNode(), SDLoc(Node), AArch64::WZR, MVT::i32);
2760 ReplaceNode(Node, New.getNode());
2762 } else if (VT == MVT::i64) {
2763 SDValue New = CurDAG->getCopyFromReg(
2764 CurDAG->getEntryNode(), SDLoc(Node), AArch64::XZR, MVT::i64);
2765 ReplaceNode(Node, New.getNode());
2772 case ISD::FrameIndex: {
2773 // Selects to ADDXri FI, 0 which in turn will become ADDXri SP, imm.
2774 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
2775 unsigned Shifter = AArch64_AM::getShifterImm(AArch64_AM::LSL, 0);
2776 const TargetLowering *TLI = getTargetLowering();
2777 SDValue TFI = CurDAG->getTargetFrameIndex(
2778 FI, TLI->getPointerTy(CurDAG->getDataLayout()));
2780 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, DL, MVT::i32),
2781 CurDAG->getTargetConstant(Shifter, DL, MVT::i32) };
2782 CurDAG->SelectNodeTo(Node, AArch64::ADDXri, MVT::i64, Ops);
2785 case ISD::INTRINSIC_W_CHAIN: {
2786 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
2790 case Intrinsic::aarch64_ldaxp:
2791 case Intrinsic::aarch64_ldxp: {
2793 IntNo == Intrinsic::aarch64_ldaxp ? AArch64::LDAXPX : AArch64::LDXPX;
2794 SDValue MemAddr = Node->getOperand(2);
2796 SDValue Chain = Node->getOperand(0);
2798 SDNode *Ld = CurDAG->getMachineNode(Op, DL, MVT::i64, MVT::i64,
2799 MVT::Other, MemAddr, Chain);
2801 // Transfer memoperands.
2802 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2803 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2804 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2805 ReplaceNode(Node, Ld);
2808 case Intrinsic::aarch64_stlxp:
2809 case Intrinsic::aarch64_stxp: {
2811 IntNo == Intrinsic::aarch64_stlxp ? AArch64::STLXPX : AArch64::STXPX;
2813 SDValue Chain = Node->getOperand(0);
2814 SDValue ValLo = Node->getOperand(2);
2815 SDValue ValHi = Node->getOperand(3);
2816 SDValue MemAddr = Node->getOperand(4);
2818 // Place arguments in the right order.
2819 SDValue Ops[] = {ValLo, ValHi, MemAddr, Chain};
2821 SDNode *St = CurDAG->getMachineNode(Op, DL, MVT::i32, MVT::Other, Ops);
2822 // Transfer memoperands.
2823 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2824 MemOp[0] = cast<MemIntrinsicSDNode>(Node)->getMemOperand();
2825 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2827 ReplaceNode(Node, St);
2830 case Intrinsic::aarch64_neon_ld1x2:
2831 if (VT == MVT::v8i8) {
2832 SelectLoad(Node, 2, AArch64::LD1Twov8b, AArch64::dsub0);
2834 } else if (VT == MVT::v16i8) {
2835 SelectLoad(Node, 2, AArch64::LD1Twov16b, AArch64::qsub0);
2837 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2838 SelectLoad(Node, 2, AArch64::LD1Twov4h, AArch64::dsub0);
2840 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2841 SelectLoad(Node, 2, AArch64::LD1Twov8h, AArch64::qsub0);
2843 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2844 SelectLoad(Node, 2, AArch64::LD1Twov2s, AArch64::dsub0);
2846 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2847 SelectLoad(Node, 2, AArch64::LD1Twov4s, AArch64::qsub0);
2849 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2850 SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2852 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2853 SelectLoad(Node, 2, AArch64::LD1Twov2d, AArch64::qsub0);
2857 case Intrinsic::aarch64_neon_ld1x3:
2858 if (VT == MVT::v8i8) {
2859 SelectLoad(Node, 3, AArch64::LD1Threev8b, AArch64::dsub0);
2861 } else if (VT == MVT::v16i8) {
2862 SelectLoad(Node, 3, AArch64::LD1Threev16b, AArch64::qsub0);
2864 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2865 SelectLoad(Node, 3, AArch64::LD1Threev4h, AArch64::dsub0);
2867 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2868 SelectLoad(Node, 3, AArch64::LD1Threev8h, AArch64::qsub0);
2870 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2871 SelectLoad(Node, 3, AArch64::LD1Threev2s, AArch64::dsub0);
2873 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2874 SelectLoad(Node, 3, AArch64::LD1Threev4s, AArch64::qsub0);
2876 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2877 SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2879 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2880 SelectLoad(Node, 3, AArch64::LD1Threev2d, AArch64::qsub0);
2884 case Intrinsic::aarch64_neon_ld1x4:
2885 if (VT == MVT::v8i8) {
2886 SelectLoad(Node, 4, AArch64::LD1Fourv8b, AArch64::dsub0);
2888 } else if (VT == MVT::v16i8) {
2889 SelectLoad(Node, 4, AArch64::LD1Fourv16b, AArch64::qsub0);
2891 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2892 SelectLoad(Node, 4, AArch64::LD1Fourv4h, AArch64::dsub0);
2894 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2895 SelectLoad(Node, 4, AArch64::LD1Fourv8h, AArch64::qsub0);
2897 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2898 SelectLoad(Node, 4, AArch64::LD1Fourv2s, AArch64::dsub0);
2900 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2901 SelectLoad(Node, 4, AArch64::LD1Fourv4s, AArch64::qsub0);
2903 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2904 SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2906 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2907 SelectLoad(Node, 4, AArch64::LD1Fourv2d, AArch64::qsub0);
2911 case Intrinsic::aarch64_neon_ld2:
2912 if (VT == MVT::v8i8) {
2913 SelectLoad(Node, 2, AArch64::LD2Twov8b, AArch64::dsub0);
2915 } else if (VT == MVT::v16i8) {
2916 SelectLoad(Node, 2, AArch64::LD2Twov16b, AArch64::qsub0);
2918 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2919 SelectLoad(Node, 2, AArch64::LD2Twov4h, AArch64::dsub0);
2921 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2922 SelectLoad(Node, 2, AArch64::LD2Twov8h, AArch64::qsub0);
2924 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2925 SelectLoad(Node, 2, AArch64::LD2Twov2s, AArch64::dsub0);
2927 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2928 SelectLoad(Node, 2, AArch64::LD2Twov4s, AArch64::qsub0);
2930 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2931 SelectLoad(Node, 2, AArch64::LD1Twov1d, AArch64::dsub0);
2933 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2934 SelectLoad(Node, 2, AArch64::LD2Twov2d, AArch64::qsub0);
2938 case Intrinsic::aarch64_neon_ld3:
2939 if (VT == MVT::v8i8) {
2940 SelectLoad(Node, 3, AArch64::LD3Threev8b, AArch64::dsub0);
2942 } else if (VT == MVT::v16i8) {
2943 SelectLoad(Node, 3, AArch64::LD3Threev16b, AArch64::qsub0);
2945 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2946 SelectLoad(Node, 3, AArch64::LD3Threev4h, AArch64::dsub0);
2948 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2949 SelectLoad(Node, 3, AArch64::LD3Threev8h, AArch64::qsub0);
2951 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2952 SelectLoad(Node, 3, AArch64::LD3Threev2s, AArch64::dsub0);
2954 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2955 SelectLoad(Node, 3, AArch64::LD3Threev4s, AArch64::qsub0);
2957 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2958 SelectLoad(Node, 3, AArch64::LD1Threev1d, AArch64::dsub0);
2960 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2961 SelectLoad(Node, 3, AArch64::LD3Threev2d, AArch64::qsub0);
2965 case Intrinsic::aarch64_neon_ld4:
2966 if (VT == MVT::v8i8) {
2967 SelectLoad(Node, 4, AArch64::LD4Fourv8b, AArch64::dsub0);
2969 } else if (VT == MVT::v16i8) {
2970 SelectLoad(Node, 4, AArch64::LD4Fourv16b, AArch64::qsub0);
2972 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
2973 SelectLoad(Node, 4, AArch64::LD4Fourv4h, AArch64::dsub0);
2975 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
2976 SelectLoad(Node, 4, AArch64::LD4Fourv8h, AArch64::qsub0);
2978 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
2979 SelectLoad(Node, 4, AArch64::LD4Fourv2s, AArch64::dsub0);
2981 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
2982 SelectLoad(Node, 4, AArch64::LD4Fourv4s, AArch64::qsub0);
2984 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
2985 SelectLoad(Node, 4, AArch64::LD1Fourv1d, AArch64::dsub0);
2987 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
2988 SelectLoad(Node, 4, AArch64::LD4Fourv2d, AArch64::qsub0);
2992 case Intrinsic::aarch64_neon_ld2r:
2993 if (VT == MVT::v8i8) {
2994 SelectLoad(Node, 2, AArch64::LD2Rv8b, AArch64::dsub0);
2996 } else if (VT == MVT::v16i8) {
2997 SelectLoad(Node, 2, AArch64::LD2Rv16b, AArch64::qsub0);
2999 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3000 SelectLoad(Node, 2, AArch64::LD2Rv4h, AArch64::dsub0);
3002 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3003 SelectLoad(Node, 2, AArch64::LD2Rv8h, AArch64::qsub0);
3005 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3006 SelectLoad(Node, 2, AArch64::LD2Rv2s, AArch64::dsub0);
3008 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3009 SelectLoad(Node, 2, AArch64::LD2Rv4s, AArch64::qsub0);
3011 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3012 SelectLoad(Node, 2, AArch64::LD2Rv1d, AArch64::dsub0);
3014 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3015 SelectLoad(Node, 2, AArch64::LD2Rv2d, AArch64::qsub0);
3019 case Intrinsic::aarch64_neon_ld3r:
3020 if (VT == MVT::v8i8) {
3021 SelectLoad(Node, 3, AArch64::LD3Rv8b, AArch64::dsub0);
3023 } else if (VT == MVT::v16i8) {
3024 SelectLoad(Node, 3, AArch64::LD3Rv16b, AArch64::qsub0);
3026 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3027 SelectLoad(Node, 3, AArch64::LD3Rv4h, AArch64::dsub0);
3029 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3030 SelectLoad(Node, 3, AArch64::LD3Rv8h, AArch64::qsub0);
3032 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3033 SelectLoad(Node, 3, AArch64::LD3Rv2s, AArch64::dsub0);
3035 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3036 SelectLoad(Node, 3, AArch64::LD3Rv4s, AArch64::qsub0);
3038 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3039 SelectLoad(Node, 3, AArch64::LD3Rv1d, AArch64::dsub0);
3041 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3042 SelectLoad(Node, 3, AArch64::LD3Rv2d, AArch64::qsub0);
3046 case Intrinsic::aarch64_neon_ld4r:
3047 if (VT == MVT::v8i8) {
3048 SelectLoad(Node, 4, AArch64::LD4Rv8b, AArch64::dsub0);
3050 } else if (VT == MVT::v16i8) {
3051 SelectLoad(Node, 4, AArch64::LD4Rv16b, AArch64::qsub0);
3053 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3054 SelectLoad(Node, 4, AArch64::LD4Rv4h, AArch64::dsub0);
3056 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3057 SelectLoad(Node, 4, AArch64::LD4Rv8h, AArch64::qsub0);
3059 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3060 SelectLoad(Node, 4, AArch64::LD4Rv2s, AArch64::dsub0);
3062 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3063 SelectLoad(Node, 4, AArch64::LD4Rv4s, AArch64::qsub0);
3065 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3066 SelectLoad(Node, 4, AArch64::LD4Rv1d, AArch64::dsub0);
3068 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3069 SelectLoad(Node, 4, AArch64::LD4Rv2d, AArch64::qsub0);
3073 case Intrinsic::aarch64_neon_ld2lane:
3074 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3075 SelectLoadLane(Node, 2, AArch64::LD2i8);
3077 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3079 SelectLoadLane(Node, 2, AArch64::LD2i16);
3081 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3083 SelectLoadLane(Node, 2, AArch64::LD2i32);
3085 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3087 SelectLoadLane(Node, 2, AArch64::LD2i64);
3091 case Intrinsic::aarch64_neon_ld3lane:
3092 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3093 SelectLoadLane(Node, 3, AArch64::LD3i8);
3095 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3097 SelectLoadLane(Node, 3, AArch64::LD3i16);
3099 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3101 SelectLoadLane(Node, 3, AArch64::LD3i32);
3103 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3105 SelectLoadLane(Node, 3, AArch64::LD3i64);
3109 case Intrinsic::aarch64_neon_ld4lane:
3110 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3111 SelectLoadLane(Node, 4, AArch64::LD4i8);
3113 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3115 SelectLoadLane(Node, 4, AArch64::LD4i16);
3117 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3119 SelectLoadLane(Node, 4, AArch64::LD4i32);
3121 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3123 SelectLoadLane(Node, 4, AArch64::LD4i64);
3129 case ISD::INTRINSIC_WO_CHAIN: {
3130 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(0))->getZExtValue();
3134 case Intrinsic::aarch64_neon_tbl2:
3135 SelectTable(Node, 2,
3136 VT == MVT::v8i8 ? AArch64::TBLv8i8Two : AArch64::TBLv16i8Two,
3139 case Intrinsic::aarch64_neon_tbl3:
3140 SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBLv8i8Three
3141 : AArch64::TBLv16i8Three,
3144 case Intrinsic::aarch64_neon_tbl4:
3145 SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBLv8i8Four
3146 : AArch64::TBLv16i8Four,
3149 case Intrinsic::aarch64_neon_tbx2:
3150 SelectTable(Node, 2,
3151 VT == MVT::v8i8 ? AArch64::TBXv8i8Two : AArch64::TBXv16i8Two,
3154 case Intrinsic::aarch64_neon_tbx3:
3155 SelectTable(Node, 3, VT == MVT::v8i8 ? AArch64::TBXv8i8Three
3156 : AArch64::TBXv16i8Three,
3159 case Intrinsic::aarch64_neon_tbx4:
3160 SelectTable(Node, 4, VT == MVT::v8i8 ? AArch64::TBXv8i8Four
3161 : AArch64::TBXv16i8Four,
3164 case Intrinsic::aarch64_neon_smull:
3165 case Intrinsic::aarch64_neon_umull:
3166 if (tryMULLV64LaneV128(IntNo, Node))
3172 case ISD::INTRINSIC_VOID: {
3173 unsigned IntNo = cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();
3174 if (Node->getNumOperands() >= 3)
3175 VT = Node->getOperand(2)->getValueType(0);
3179 case Intrinsic::aarch64_neon_st1x2: {
3180 if (VT == MVT::v8i8) {
3181 SelectStore(Node, 2, AArch64::ST1Twov8b);
3183 } else if (VT == MVT::v16i8) {
3184 SelectStore(Node, 2, AArch64::ST1Twov16b);
3186 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3187 SelectStore(Node, 2, AArch64::ST1Twov4h);
3189 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3190 SelectStore(Node, 2, AArch64::ST1Twov8h);
3192 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3193 SelectStore(Node, 2, AArch64::ST1Twov2s);
3195 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3196 SelectStore(Node, 2, AArch64::ST1Twov4s);
3198 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3199 SelectStore(Node, 2, AArch64::ST1Twov2d);
3201 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3202 SelectStore(Node, 2, AArch64::ST1Twov1d);
3207 case Intrinsic::aarch64_neon_st1x3: {
3208 if (VT == MVT::v8i8) {
3209 SelectStore(Node, 3, AArch64::ST1Threev8b);
3211 } else if (VT == MVT::v16i8) {
3212 SelectStore(Node, 3, AArch64::ST1Threev16b);
3214 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3215 SelectStore(Node, 3, AArch64::ST1Threev4h);
3217 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3218 SelectStore(Node, 3, AArch64::ST1Threev8h);
3220 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3221 SelectStore(Node, 3, AArch64::ST1Threev2s);
3223 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3224 SelectStore(Node, 3, AArch64::ST1Threev4s);
3226 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3227 SelectStore(Node, 3, AArch64::ST1Threev2d);
3229 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3230 SelectStore(Node, 3, AArch64::ST1Threev1d);
3235 case Intrinsic::aarch64_neon_st1x4: {
3236 if (VT == MVT::v8i8) {
3237 SelectStore(Node, 4, AArch64::ST1Fourv8b);
3239 } else if (VT == MVT::v16i8) {
3240 SelectStore(Node, 4, AArch64::ST1Fourv16b);
3242 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3243 SelectStore(Node, 4, AArch64::ST1Fourv4h);
3245 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3246 SelectStore(Node, 4, AArch64::ST1Fourv8h);
3248 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3249 SelectStore(Node, 4, AArch64::ST1Fourv2s);
3251 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3252 SelectStore(Node, 4, AArch64::ST1Fourv4s);
3254 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3255 SelectStore(Node, 4, AArch64::ST1Fourv2d);
3257 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3258 SelectStore(Node, 4, AArch64::ST1Fourv1d);
3263 case Intrinsic::aarch64_neon_st2: {
3264 if (VT == MVT::v8i8) {
3265 SelectStore(Node, 2, AArch64::ST2Twov8b);
3267 } else if (VT == MVT::v16i8) {
3268 SelectStore(Node, 2, AArch64::ST2Twov16b);
3270 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3271 SelectStore(Node, 2, AArch64::ST2Twov4h);
3273 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3274 SelectStore(Node, 2, AArch64::ST2Twov8h);
3276 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3277 SelectStore(Node, 2, AArch64::ST2Twov2s);
3279 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3280 SelectStore(Node, 2, AArch64::ST2Twov4s);
3282 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3283 SelectStore(Node, 2, AArch64::ST2Twov2d);
3285 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3286 SelectStore(Node, 2, AArch64::ST1Twov1d);
3291 case Intrinsic::aarch64_neon_st3: {
3292 if (VT == MVT::v8i8) {
3293 SelectStore(Node, 3, AArch64::ST3Threev8b);
3295 } else if (VT == MVT::v16i8) {
3296 SelectStore(Node, 3, AArch64::ST3Threev16b);
3298 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3299 SelectStore(Node, 3, AArch64::ST3Threev4h);
3301 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3302 SelectStore(Node, 3, AArch64::ST3Threev8h);
3304 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3305 SelectStore(Node, 3, AArch64::ST3Threev2s);
3307 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3308 SelectStore(Node, 3, AArch64::ST3Threev4s);
3310 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3311 SelectStore(Node, 3, AArch64::ST3Threev2d);
3313 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3314 SelectStore(Node, 3, AArch64::ST1Threev1d);
3319 case Intrinsic::aarch64_neon_st4: {
3320 if (VT == MVT::v8i8) {
3321 SelectStore(Node, 4, AArch64::ST4Fourv8b);
3323 } else if (VT == MVT::v16i8) {
3324 SelectStore(Node, 4, AArch64::ST4Fourv16b);
3326 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3327 SelectStore(Node, 4, AArch64::ST4Fourv4h);
3329 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3330 SelectStore(Node, 4, AArch64::ST4Fourv8h);
3332 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3333 SelectStore(Node, 4, AArch64::ST4Fourv2s);
3335 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3336 SelectStore(Node, 4, AArch64::ST4Fourv4s);
3338 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3339 SelectStore(Node, 4, AArch64::ST4Fourv2d);
3341 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3342 SelectStore(Node, 4, AArch64::ST1Fourv1d);
3347 case Intrinsic::aarch64_neon_st2lane: {
3348 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3349 SelectStoreLane(Node, 2, AArch64::ST2i8);
3351 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3353 SelectStoreLane(Node, 2, AArch64::ST2i16);
3355 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3357 SelectStoreLane(Node, 2, AArch64::ST2i32);
3359 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3361 SelectStoreLane(Node, 2, AArch64::ST2i64);
3366 case Intrinsic::aarch64_neon_st3lane: {
3367 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3368 SelectStoreLane(Node, 3, AArch64::ST3i8);
3370 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3372 SelectStoreLane(Node, 3, AArch64::ST3i16);
3374 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3376 SelectStoreLane(Node, 3, AArch64::ST3i32);
3378 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3380 SelectStoreLane(Node, 3, AArch64::ST3i64);
3385 case Intrinsic::aarch64_neon_st4lane: {
3386 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3387 SelectStoreLane(Node, 4, AArch64::ST4i8);
3389 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3391 SelectStoreLane(Node, 4, AArch64::ST4i16);
3393 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3395 SelectStoreLane(Node, 4, AArch64::ST4i32);
3397 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3399 SelectStoreLane(Node, 4, AArch64::ST4i64);
3407 case AArch64ISD::LD2post: {
3408 if (VT == MVT::v8i8) {
3409 SelectPostLoad(Node, 2, AArch64::LD2Twov8b_POST, AArch64::dsub0);
3411 } else if (VT == MVT::v16i8) {
3412 SelectPostLoad(Node, 2, AArch64::LD2Twov16b_POST, AArch64::qsub0);
3414 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3415 SelectPostLoad(Node, 2, AArch64::LD2Twov4h_POST, AArch64::dsub0);
3417 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3418 SelectPostLoad(Node, 2, AArch64::LD2Twov8h_POST, AArch64::qsub0);
3420 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3421 SelectPostLoad(Node, 2, AArch64::LD2Twov2s_POST, AArch64::dsub0);
3423 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3424 SelectPostLoad(Node, 2, AArch64::LD2Twov4s_POST, AArch64::qsub0);
3426 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3427 SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
3429 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3430 SelectPostLoad(Node, 2, AArch64::LD2Twov2d_POST, AArch64::qsub0);
3435 case AArch64ISD::LD3post: {
3436 if (VT == MVT::v8i8) {
3437 SelectPostLoad(Node, 3, AArch64::LD3Threev8b_POST, AArch64::dsub0);
3439 } else if (VT == MVT::v16i8) {
3440 SelectPostLoad(Node, 3, AArch64::LD3Threev16b_POST, AArch64::qsub0);
3442 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3443 SelectPostLoad(Node, 3, AArch64::LD3Threev4h_POST, AArch64::dsub0);
3445 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3446 SelectPostLoad(Node, 3, AArch64::LD3Threev8h_POST, AArch64::qsub0);
3448 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3449 SelectPostLoad(Node, 3, AArch64::LD3Threev2s_POST, AArch64::dsub0);
3451 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3452 SelectPostLoad(Node, 3, AArch64::LD3Threev4s_POST, AArch64::qsub0);
3454 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3455 SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
3457 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3458 SelectPostLoad(Node, 3, AArch64::LD3Threev2d_POST, AArch64::qsub0);
3463 case AArch64ISD::LD4post: {
3464 if (VT == MVT::v8i8) {
3465 SelectPostLoad(Node, 4, AArch64::LD4Fourv8b_POST, AArch64::dsub0);
3467 } else if (VT == MVT::v16i8) {
3468 SelectPostLoad(Node, 4, AArch64::LD4Fourv16b_POST, AArch64::qsub0);
3470 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3471 SelectPostLoad(Node, 4, AArch64::LD4Fourv4h_POST, AArch64::dsub0);
3473 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3474 SelectPostLoad(Node, 4, AArch64::LD4Fourv8h_POST, AArch64::qsub0);
3476 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3477 SelectPostLoad(Node, 4, AArch64::LD4Fourv2s_POST, AArch64::dsub0);
3479 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3480 SelectPostLoad(Node, 4, AArch64::LD4Fourv4s_POST, AArch64::qsub0);
3482 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3483 SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
3485 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3486 SelectPostLoad(Node, 4, AArch64::LD4Fourv2d_POST, AArch64::qsub0);
3491 case AArch64ISD::LD1x2post: {
3492 if (VT == MVT::v8i8) {
3493 SelectPostLoad(Node, 2, AArch64::LD1Twov8b_POST, AArch64::dsub0);
3495 } else if (VT == MVT::v16i8) {
3496 SelectPostLoad(Node, 2, AArch64::LD1Twov16b_POST, AArch64::qsub0);
3498 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3499 SelectPostLoad(Node, 2, AArch64::LD1Twov4h_POST, AArch64::dsub0);
3501 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3502 SelectPostLoad(Node, 2, AArch64::LD1Twov8h_POST, AArch64::qsub0);
3504 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3505 SelectPostLoad(Node, 2, AArch64::LD1Twov2s_POST, AArch64::dsub0);
3507 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3508 SelectPostLoad(Node, 2, AArch64::LD1Twov4s_POST, AArch64::qsub0);
3510 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3511 SelectPostLoad(Node, 2, AArch64::LD1Twov1d_POST, AArch64::dsub0);
3513 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3514 SelectPostLoad(Node, 2, AArch64::LD1Twov2d_POST, AArch64::qsub0);
3519 case AArch64ISD::LD1x3post: {
3520 if (VT == MVT::v8i8) {
3521 SelectPostLoad(Node, 3, AArch64::LD1Threev8b_POST, AArch64::dsub0);
3523 } else if (VT == MVT::v16i8) {
3524 SelectPostLoad(Node, 3, AArch64::LD1Threev16b_POST, AArch64::qsub0);
3526 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3527 SelectPostLoad(Node, 3, AArch64::LD1Threev4h_POST, AArch64::dsub0);
3529 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3530 SelectPostLoad(Node, 3, AArch64::LD1Threev8h_POST, AArch64::qsub0);
3532 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3533 SelectPostLoad(Node, 3, AArch64::LD1Threev2s_POST, AArch64::dsub0);
3535 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3536 SelectPostLoad(Node, 3, AArch64::LD1Threev4s_POST, AArch64::qsub0);
3538 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3539 SelectPostLoad(Node, 3, AArch64::LD1Threev1d_POST, AArch64::dsub0);
3541 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3542 SelectPostLoad(Node, 3, AArch64::LD1Threev2d_POST, AArch64::qsub0);
3547 case AArch64ISD::LD1x4post: {
3548 if (VT == MVT::v8i8) {
3549 SelectPostLoad(Node, 4, AArch64::LD1Fourv8b_POST, AArch64::dsub0);
3551 } else if (VT == MVT::v16i8) {
3552 SelectPostLoad(Node, 4, AArch64::LD1Fourv16b_POST, AArch64::qsub0);
3554 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3555 SelectPostLoad(Node, 4, AArch64::LD1Fourv4h_POST, AArch64::dsub0);
3557 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3558 SelectPostLoad(Node, 4, AArch64::LD1Fourv8h_POST, AArch64::qsub0);
3560 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3561 SelectPostLoad(Node, 4, AArch64::LD1Fourv2s_POST, AArch64::dsub0);
3563 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3564 SelectPostLoad(Node, 4, AArch64::LD1Fourv4s_POST, AArch64::qsub0);
3566 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3567 SelectPostLoad(Node, 4, AArch64::LD1Fourv1d_POST, AArch64::dsub0);
3569 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3570 SelectPostLoad(Node, 4, AArch64::LD1Fourv2d_POST, AArch64::qsub0);
3575 case AArch64ISD::LD1DUPpost: {
3576 if (VT == MVT::v8i8) {
3577 SelectPostLoad(Node, 1, AArch64::LD1Rv8b_POST, AArch64::dsub0);
3579 } else if (VT == MVT::v16i8) {
3580 SelectPostLoad(Node, 1, AArch64::LD1Rv16b_POST, AArch64::qsub0);
3582 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3583 SelectPostLoad(Node, 1, AArch64::LD1Rv4h_POST, AArch64::dsub0);
3585 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3586 SelectPostLoad(Node, 1, AArch64::LD1Rv8h_POST, AArch64::qsub0);
3588 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3589 SelectPostLoad(Node, 1, AArch64::LD1Rv2s_POST, AArch64::dsub0);
3591 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3592 SelectPostLoad(Node, 1, AArch64::LD1Rv4s_POST, AArch64::qsub0);
3594 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3595 SelectPostLoad(Node, 1, AArch64::LD1Rv1d_POST, AArch64::dsub0);
3597 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3598 SelectPostLoad(Node, 1, AArch64::LD1Rv2d_POST, AArch64::qsub0);
3603 case AArch64ISD::LD2DUPpost: {
3604 if (VT == MVT::v8i8) {
3605 SelectPostLoad(Node, 2, AArch64::LD2Rv8b_POST, AArch64::dsub0);
3607 } else if (VT == MVT::v16i8) {
3608 SelectPostLoad(Node, 2, AArch64::LD2Rv16b_POST, AArch64::qsub0);
3610 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3611 SelectPostLoad(Node, 2, AArch64::LD2Rv4h_POST, AArch64::dsub0);
3613 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3614 SelectPostLoad(Node, 2, AArch64::LD2Rv8h_POST, AArch64::qsub0);
3616 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3617 SelectPostLoad(Node, 2, AArch64::LD2Rv2s_POST, AArch64::dsub0);
3619 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3620 SelectPostLoad(Node, 2, AArch64::LD2Rv4s_POST, AArch64::qsub0);
3622 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3623 SelectPostLoad(Node, 2, AArch64::LD2Rv1d_POST, AArch64::dsub0);
3625 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3626 SelectPostLoad(Node, 2, AArch64::LD2Rv2d_POST, AArch64::qsub0);
3631 case AArch64ISD::LD3DUPpost: {
3632 if (VT == MVT::v8i8) {
3633 SelectPostLoad(Node, 3, AArch64::LD3Rv8b_POST, AArch64::dsub0);
3635 } else if (VT == MVT::v16i8) {
3636 SelectPostLoad(Node, 3, AArch64::LD3Rv16b_POST, AArch64::qsub0);
3638 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3639 SelectPostLoad(Node, 3, AArch64::LD3Rv4h_POST, AArch64::dsub0);
3641 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3642 SelectPostLoad(Node, 3, AArch64::LD3Rv8h_POST, AArch64::qsub0);
3644 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3645 SelectPostLoad(Node, 3, AArch64::LD3Rv2s_POST, AArch64::dsub0);
3647 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3648 SelectPostLoad(Node, 3, AArch64::LD3Rv4s_POST, AArch64::qsub0);
3650 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3651 SelectPostLoad(Node, 3, AArch64::LD3Rv1d_POST, AArch64::dsub0);
3653 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3654 SelectPostLoad(Node, 3, AArch64::LD3Rv2d_POST, AArch64::qsub0);
3659 case AArch64ISD::LD4DUPpost: {
3660 if (VT == MVT::v8i8) {
3661 SelectPostLoad(Node, 4, AArch64::LD4Rv8b_POST, AArch64::dsub0);
3663 } else if (VT == MVT::v16i8) {
3664 SelectPostLoad(Node, 4, AArch64::LD4Rv16b_POST, AArch64::qsub0);
3666 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3667 SelectPostLoad(Node, 4, AArch64::LD4Rv4h_POST, AArch64::dsub0);
3669 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3670 SelectPostLoad(Node, 4, AArch64::LD4Rv8h_POST, AArch64::qsub0);
3672 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3673 SelectPostLoad(Node, 4, AArch64::LD4Rv2s_POST, AArch64::dsub0);
3675 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3676 SelectPostLoad(Node, 4, AArch64::LD4Rv4s_POST, AArch64::qsub0);
3678 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3679 SelectPostLoad(Node, 4, AArch64::LD4Rv1d_POST, AArch64::dsub0);
3681 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3682 SelectPostLoad(Node, 4, AArch64::LD4Rv2d_POST, AArch64::qsub0);
3687 case AArch64ISD::LD1LANEpost: {
3688 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3689 SelectPostLoadLane(Node, 1, AArch64::LD1i8_POST);
3691 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3693 SelectPostLoadLane(Node, 1, AArch64::LD1i16_POST);
3695 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3697 SelectPostLoadLane(Node, 1, AArch64::LD1i32_POST);
3699 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3701 SelectPostLoadLane(Node, 1, AArch64::LD1i64_POST);
3706 case AArch64ISD::LD2LANEpost: {
3707 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3708 SelectPostLoadLane(Node, 2, AArch64::LD2i8_POST);
3710 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3712 SelectPostLoadLane(Node, 2, AArch64::LD2i16_POST);
3714 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3716 SelectPostLoadLane(Node, 2, AArch64::LD2i32_POST);
3718 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3720 SelectPostLoadLane(Node, 2, AArch64::LD2i64_POST);
3725 case AArch64ISD::LD3LANEpost: {
3726 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3727 SelectPostLoadLane(Node, 3, AArch64::LD3i8_POST);
3729 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3731 SelectPostLoadLane(Node, 3, AArch64::LD3i16_POST);
3733 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3735 SelectPostLoadLane(Node, 3, AArch64::LD3i32_POST);
3737 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3739 SelectPostLoadLane(Node, 3, AArch64::LD3i64_POST);
3744 case AArch64ISD::LD4LANEpost: {
3745 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3746 SelectPostLoadLane(Node, 4, AArch64::LD4i8_POST);
3748 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3750 SelectPostLoadLane(Node, 4, AArch64::LD4i16_POST);
3752 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3754 SelectPostLoadLane(Node, 4, AArch64::LD4i32_POST);
3756 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3758 SelectPostLoadLane(Node, 4, AArch64::LD4i64_POST);
3763 case AArch64ISD::ST2post: {
3764 VT = Node->getOperand(1).getValueType();
3765 if (VT == MVT::v8i8) {
3766 SelectPostStore(Node, 2, AArch64::ST2Twov8b_POST);
3768 } else if (VT == MVT::v16i8) {
3769 SelectPostStore(Node, 2, AArch64::ST2Twov16b_POST);
3771 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3772 SelectPostStore(Node, 2, AArch64::ST2Twov4h_POST);
3774 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3775 SelectPostStore(Node, 2, AArch64::ST2Twov8h_POST);
3777 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3778 SelectPostStore(Node, 2, AArch64::ST2Twov2s_POST);
3780 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3781 SelectPostStore(Node, 2, AArch64::ST2Twov4s_POST);
3783 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3784 SelectPostStore(Node, 2, AArch64::ST2Twov2d_POST);
3786 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3787 SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3792 case AArch64ISD::ST3post: {
3793 VT = Node->getOperand(1).getValueType();
3794 if (VT == MVT::v8i8) {
3795 SelectPostStore(Node, 3, AArch64::ST3Threev8b_POST);
3797 } else if (VT == MVT::v16i8) {
3798 SelectPostStore(Node, 3, AArch64::ST3Threev16b_POST);
3800 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3801 SelectPostStore(Node, 3, AArch64::ST3Threev4h_POST);
3803 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3804 SelectPostStore(Node, 3, AArch64::ST3Threev8h_POST);
3806 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3807 SelectPostStore(Node, 3, AArch64::ST3Threev2s_POST);
3809 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3810 SelectPostStore(Node, 3, AArch64::ST3Threev4s_POST);
3812 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3813 SelectPostStore(Node, 3, AArch64::ST3Threev2d_POST);
3815 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3816 SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3821 case AArch64ISD::ST4post: {
3822 VT = Node->getOperand(1).getValueType();
3823 if (VT == MVT::v8i8) {
3824 SelectPostStore(Node, 4, AArch64::ST4Fourv8b_POST);
3826 } else if (VT == MVT::v16i8) {
3827 SelectPostStore(Node, 4, AArch64::ST4Fourv16b_POST);
3829 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3830 SelectPostStore(Node, 4, AArch64::ST4Fourv4h_POST);
3832 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3833 SelectPostStore(Node, 4, AArch64::ST4Fourv8h_POST);
3835 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3836 SelectPostStore(Node, 4, AArch64::ST4Fourv2s_POST);
3838 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3839 SelectPostStore(Node, 4, AArch64::ST4Fourv4s_POST);
3841 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3842 SelectPostStore(Node, 4, AArch64::ST4Fourv2d_POST);
3844 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3845 SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3850 case AArch64ISD::ST1x2post: {
3851 VT = Node->getOperand(1).getValueType();
3852 if (VT == MVT::v8i8) {
3853 SelectPostStore(Node, 2, AArch64::ST1Twov8b_POST);
3855 } else if (VT == MVT::v16i8) {
3856 SelectPostStore(Node, 2, AArch64::ST1Twov16b_POST);
3858 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3859 SelectPostStore(Node, 2, AArch64::ST1Twov4h_POST);
3861 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3862 SelectPostStore(Node, 2, AArch64::ST1Twov8h_POST);
3864 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3865 SelectPostStore(Node, 2, AArch64::ST1Twov2s_POST);
3867 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3868 SelectPostStore(Node, 2, AArch64::ST1Twov4s_POST);
3870 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3871 SelectPostStore(Node, 2, AArch64::ST1Twov1d_POST);
3873 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3874 SelectPostStore(Node, 2, AArch64::ST1Twov2d_POST);
3879 case AArch64ISD::ST1x3post: {
3880 VT = Node->getOperand(1).getValueType();
3881 if (VT == MVT::v8i8) {
3882 SelectPostStore(Node, 3, AArch64::ST1Threev8b_POST);
3884 } else if (VT == MVT::v16i8) {
3885 SelectPostStore(Node, 3, AArch64::ST1Threev16b_POST);
3887 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3888 SelectPostStore(Node, 3, AArch64::ST1Threev4h_POST);
3890 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3891 SelectPostStore(Node, 3, AArch64::ST1Threev8h_POST);
3893 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3894 SelectPostStore(Node, 3, AArch64::ST1Threev2s_POST);
3896 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3897 SelectPostStore(Node, 3, AArch64::ST1Threev4s_POST);
3899 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3900 SelectPostStore(Node, 3, AArch64::ST1Threev1d_POST);
3902 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3903 SelectPostStore(Node, 3, AArch64::ST1Threev2d_POST);
3908 case AArch64ISD::ST1x4post: {
3909 VT = Node->getOperand(1).getValueType();
3910 if (VT == MVT::v8i8) {
3911 SelectPostStore(Node, 4, AArch64::ST1Fourv8b_POST);
3913 } else if (VT == MVT::v16i8) {
3914 SelectPostStore(Node, 4, AArch64::ST1Fourv16b_POST);
3916 } else if (VT == MVT::v4i16 || VT == MVT::v4f16) {
3917 SelectPostStore(Node, 4, AArch64::ST1Fourv4h_POST);
3919 } else if (VT == MVT::v8i16 || VT == MVT::v8f16) {
3920 SelectPostStore(Node, 4, AArch64::ST1Fourv8h_POST);
3922 } else if (VT == MVT::v2i32 || VT == MVT::v2f32) {
3923 SelectPostStore(Node, 4, AArch64::ST1Fourv2s_POST);
3925 } else if (VT == MVT::v4i32 || VT == MVT::v4f32) {
3926 SelectPostStore(Node, 4, AArch64::ST1Fourv4s_POST);
3928 } else if (VT == MVT::v1i64 || VT == MVT::v1f64) {
3929 SelectPostStore(Node, 4, AArch64::ST1Fourv1d_POST);
3931 } else if (VT == MVT::v2i64 || VT == MVT::v2f64) {
3932 SelectPostStore(Node, 4, AArch64::ST1Fourv2d_POST);
3937 case AArch64ISD::ST2LANEpost: {
3938 VT = Node->getOperand(1).getValueType();
3939 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3940 SelectPostStoreLane(Node, 2, AArch64::ST2i8_POST);
3942 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3944 SelectPostStoreLane(Node, 2, AArch64::ST2i16_POST);
3946 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3948 SelectPostStoreLane(Node, 2, AArch64::ST2i32_POST);
3950 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3952 SelectPostStoreLane(Node, 2, AArch64::ST2i64_POST);
3957 case AArch64ISD::ST3LANEpost: {
3958 VT = Node->getOperand(1).getValueType();
3959 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3960 SelectPostStoreLane(Node, 3, AArch64::ST3i8_POST);
3962 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3964 SelectPostStoreLane(Node, 3, AArch64::ST3i16_POST);
3966 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3968 SelectPostStoreLane(Node, 3, AArch64::ST3i32_POST);
3970 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3972 SelectPostStoreLane(Node, 3, AArch64::ST3i64_POST);
3977 case AArch64ISD::ST4LANEpost: {
3978 VT = Node->getOperand(1).getValueType();
3979 if (VT == MVT::v16i8 || VT == MVT::v8i8) {
3980 SelectPostStoreLane(Node, 4, AArch64::ST4i8_POST);
3982 } else if (VT == MVT::v8i16 || VT == MVT::v4i16 || VT == MVT::v4f16 ||
3984 SelectPostStoreLane(Node, 4, AArch64::ST4i16_POST);
3986 } else if (VT == MVT::v4i32 || VT == MVT::v2i32 || VT == MVT::v4f32 ||
3988 SelectPostStoreLane(Node, 4, AArch64::ST4i32_POST);
3990 } else if (VT == MVT::v2i64 || VT == MVT::v1i64 || VT == MVT::v2f64 ||
3992 SelectPostStoreLane(Node, 4, AArch64::ST4i64_POST);
3999 // Select the default instruction
4003 /// createAArch64ISelDag - This pass converts a legalized DAG into a
4004 /// AArch64-specific DAG, ready for instruction scheduling.
4005 FunctionPass *llvm::createAArch64ISelDag(AArch64TargetMachine &TM,
4006 CodeGenOpt::Level OptLevel) {
4007 return new AArch64DAGToDAGISel(TM, OptLevel);