1 //===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
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 ARM target.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "arm-isel"
16 #include "ARMAddressingModes.h"
17 #include "ARMTargetMachine.h"
18 #include "llvm/CallingConv.h"
19 #include "llvm/Constants.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Function.h"
22 #include "llvm/Intrinsics.h"
23 #include "llvm/LLVMContext.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineFunction.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/SelectionDAG.h"
28 #include "llvm/CodeGen/SelectionDAGISel.h"
29 #include "llvm/Target/TargetLowering.h"
30 #include "llvm/Target/TargetOptions.h"
31 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/Compiler.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/raw_ostream.h"
40 UseRegSeq("neon-reg-sequence", cl::Hidden,
41 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"),
44 //===--------------------------------------------------------------------===//
45 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
46 /// instructions for SelectionDAG operations.
49 class ARMDAGToDAGISel : public SelectionDAGISel {
50 ARMBaseTargetMachine &TM;
52 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
53 /// make the right decision when generating code for different targets.
54 const ARMSubtarget *Subtarget;
57 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
58 CodeGenOpt::Level OptLevel)
59 : SelectionDAGISel(tm, OptLevel), TM(tm),
60 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
63 virtual const char *getPassName() const {
64 return "ARM Instruction Selection";
67 /// getI32Imm - Return a target constant of type i32 with the specified
69 inline SDValue getI32Imm(unsigned Imm) {
70 return CurDAG->getTargetConstant(Imm, MVT::i32);
73 SDNode *Select(SDNode *N);
75 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
76 SDValue &B, SDValue &C);
77 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
78 SDValue &Offset, SDValue &Opc);
79 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
80 SDValue &Offset, SDValue &Opc);
81 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
82 SDValue &Offset, SDValue &Opc);
83 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
84 SDValue &Offset, SDValue &Opc);
85 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
87 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
89 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
91 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
94 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
96 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
97 SDValue &Base, SDValue &OffImm,
99 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
100 SDValue &OffImm, SDValue &Offset);
101 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
102 SDValue &OffImm, SDValue &Offset);
103 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
104 SDValue &OffImm, SDValue &Offset);
105 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
108 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
109 SDValue &BaseReg, SDValue &Opc);
110 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
112 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
114 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
116 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
118 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
119 SDValue &OffReg, SDValue &ShImm);
121 // Include the pieces autogenerated from the target description.
122 #include "ARMGenDAGISel.inc"
125 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
127 SDNode *SelectARMIndexedLoad(SDNode *N);
128 SDNode *SelectT2IndexedLoad(SDNode *N);
130 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
131 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
132 /// loads of D registers and even subregs and odd subregs of Q registers.
133 /// For NumVecs <= 2, QOpcodes1 is not used.
134 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
135 unsigned *QOpcodes0, unsigned *QOpcodes1);
137 /// SelectVST - Select NEON store intrinsics. NumVecs should
138 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
139 /// stores of D registers and even subregs and odd subregs of Q registers.
140 /// For NumVecs <= 2, QOpcodes1 is not used.
141 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
142 unsigned *QOpcodes0, unsigned *QOpcodes1);
144 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
145 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
146 /// load/store of D registers and even subregs and odd subregs of Q registers.
147 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
148 unsigned *DOpcodes, unsigned *QOpcodes0,
149 unsigned *QOpcodes1);
151 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
152 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
154 /// SelectCMOVOp - Select CMOV instructions for ARM.
155 SDNode *SelectCMOVOp(SDNode *N);
156 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
157 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
160 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
163 ARMCC::CondCodes CCVal, SDValue CCR,
165 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
166 ARMCC::CondCodes CCVal, SDValue CCR,
169 SDNode *SelectConcatVector(SDNode *N);
171 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
172 /// inline asm expressions.
173 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
175 std::vector<SDValue> &OutOps);
177 /// PairDRegs - Form a quad register from a pair of D registers.
179 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
181 /// PairDRegs - Form a quad register pair from a pair of Q registers.
183 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
185 /// QuadDRegs - Form a quad register pair from a quad of D registers.
187 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
189 /// QuadQRegs - Form 4 consecutive Q registers.
191 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
193 /// OctoDRegs - Form 8 consecutive D registers.
195 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
196 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
200 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
201 /// operand. If so Imm will receive the 32-bit value.
202 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
203 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
204 Imm = cast<ConstantSDNode>(N)->getZExtValue();
210 // isInt32Immediate - This method tests to see if a constant operand.
211 // If so Imm will receive the 32 bit value.
212 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
213 return isInt32Immediate(N.getNode(), Imm);
216 // isOpcWithIntImmediate - This method tests to see if the node is a specific
217 // opcode and that it has a immediate integer right operand.
218 // If so Imm will receive the 32 bit value.
219 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
220 return N->getOpcode() == Opc &&
221 isInt32Immediate(N->getOperand(1).getNode(), Imm);
225 bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
230 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
232 // Don't match base register only case. That is matched to a separate
233 // lower complexity pattern with explicit register operand.
234 if (ShOpcVal == ARM_AM::no_shift) return false;
236 BaseReg = N.getOperand(0);
237 unsigned ShImmVal = 0;
238 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
239 ShReg = CurDAG->getRegister(0, MVT::i32);
240 ShImmVal = RHS->getZExtValue() & 31;
242 ShReg = N.getOperand(1);
244 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
249 bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
250 SDValue &Base, SDValue &Offset,
252 if (N.getOpcode() == ISD::MUL) {
253 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
254 // X * [3,5,9] -> X + X * [2,4,8] etc.
255 int RHSC = (int)RHS->getZExtValue();
258 ARM_AM::AddrOpc AddSub = ARM_AM::add;
260 AddSub = ARM_AM::sub;
263 if (isPowerOf2_32(RHSC)) {
264 unsigned ShAmt = Log2_32(RHSC);
265 Base = Offset = N.getOperand(0);
266 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
275 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
277 if (N.getOpcode() == ISD::FrameIndex) {
278 int FI = cast<FrameIndexSDNode>(N)->getIndex();
279 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
280 } else if (N.getOpcode() == ARMISD::Wrapper &&
281 !(Subtarget->useMovt() &&
282 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
283 Base = N.getOperand(0);
285 Offset = CurDAG->getRegister(0, MVT::i32);
286 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
292 // Match simple R +/- imm12 operands.
293 if (N.getOpcode() == ISD::ADD)
294 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
295 int RHSC = (int)RHS->getZExtValue();
296 if ((RHSC >= 0 && RHSC < 0x1000) ||
297 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
298 Base = N.getOperand(0);
299 if (Base.getOpcode() == ISD::FrameIndex) {
300 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
301 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
303 Offset = CurDAG->getRegister(0, MVT::i32);
305 ARM_AM::AddrOpc AddSub = ARM_AM::add;
307 AddSub = ARM_AM::sub;
310 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
317 // Otherwise this is R +/- [possibly shifted] R.
318 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
319 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
322 Base = N.getOperand(0);
323 Offset = N.getOperand(1);
325 if (ShOpcVal != ARM_AM::no_shift) {
326 // Check to see if the RHS of the shift is a constant, if not, we can't fold
328 if (ConstantSDNode *Sh =
329 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
330 ShAmt = Sh->getZExtValue();
331 Offset = N.getOperand(1).getOperand(0);
333 ShOpcVal = ARM_AM::no_shift;
337 // Try matching (R shl C) + (R).
338 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
339 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
340 if (ShOpcVal != ARM_AM::no_shift) {
341 // Check to see if the RHS of the shift is a constant, if not, we can't
343 if (ConstantSDNode *Sh =
344 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
345 ShAmt = Sh->getZExtValue();
346 Offset = N.getOperand(0).getOperand(0);
347 Base = N.getOperand(1);
349 ShOpcVal = ARM_AM::no_shift;
354 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
359 bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
360 SDValue &Offset, SDValue &Opc) {
361 unsigned Opcode = Op->getOpcode();
362 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
363 ? cast<LoadSDNode>(Op)->getAddressingMode()
364 : cast<StoreSDNode>(Op)->getAddressingMode();
365 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
366 ? ARM_AM::add : ARM_AM::sub;
367 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
368 int Val = (int)C->getZExtValue();
369 if (Val >= 0 && Val < 0x1000) { // 12 bits.
370 Offset = CurDAG->getRegister(0, MVT::i32);
371 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
379 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
381 if (ShOpcVal != ARM_AM::no_shift) {
382 // Check to see if the RHS of the shift is a constant, if not, we can't fold
384 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
385 ShAmt = Sh->getZExtValue();
386 Offset = N.getOperand(0);
388 ShOpcVal = ARM_AM::no_shift;
392 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
398 bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
399 SDValue &Base, SDValue &Offset,
401 if (N.getOpcode() == ISD::SUB) {
402 // X - C is canonicalize to X + -C, no need to handle it here.
403 Base = N.getOperand(0);
404 Offset = N.getOperand(1);
405 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
409 if (N.getOpcode() != ISD::ADD) {
411 if (N.getOpcode() == ISD::FrameIndex) {
412 int FI = cast<FrameIndexSDNode>(N)->getIndex();
413 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
415 Offset = CurDAG->getRegister(0, MVT::i32);
416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
420 // If the RHS is +/- imm8, fold into addr mode.
421 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
422 int RHSC = (int)RHS->getZExtValue();
423 if ((RHSC >= 0 && RHSC < 256) ||
424 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
425 Base = N.getOperand(0);
426 if (Base.getOpcode() == ISD::FrameIndex) {
427 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
428 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
430 Offset = CurDAG->getRegister(0, MVT::i32);
432 ARM_AM::AddrOpc AddSub = ARM_AM::add;
434 AddSub = ARM_AM::sub;
437 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
442 Base = N.getOperand(0);
443 Offset = N.getOperand(1);
444 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
448 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
449 SDValue &Offset, SDValue &Opc) {
450 unsigned Opcode = Op->getOpcode();
451 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
452 ? cast<LoadSDNode>(Op)->getAddressingMode()
453 : cast<StoreSDNode>(Op)->getAddressingMode();
454 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
455 ? ARM_AM::add : ARM_AM::sub;
456 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
457 int Val = (int)C->getZExtValue();
458 if (Val >= 0 && Val < 256) {
459 Offset = CurDAG->getRegister(0, MVT::i32);
460 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
466 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
470 bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
471 SDValue &Addr, SDValue &Mode) {
473 Mode = CurDAG->getTargetConstant(0, MVT::i32);
477 bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
478 SDValue &Base, SDValue &Offset) {
479 if (N.getOpcode() != ISD::ADD) {
481 if (N.getOpcode() == ISD::FrameIndex) {
482 int FI = cast<FrameIndexSDNode>(N)->getIndex();
483 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
484 } else if (N.getOpcode() == ARMISD::Wrapper &&
485 !(Subtarget->useMovt() &&
486 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
487 Base = N.getOperand(0);
489 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
494 // If the RHS is +/- imm8, fold into addr mode.
495 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
496 int RHSC = (int)RHS->getZExtValue();
497 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
499 if ((RHSC >= 0 && RHSC < 256) ||
500 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
501 Base = N.getOperand(0);
502 if (Base.getOpcode() == ISD::FrameIndex) {
503 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
504 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
507 ARM_AM::AddrOpc AddSub = ARM_AM::add;
509 AddSub = ARM_AM::sub;
512 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
520 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
525 bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
526 SDValue &Addr, SDValue &Align) {
528 // Default to no alignment.
529 Align = CurDAG->getTargetConstant(0, MVT::i32);
533 bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
534 SDValue &Offset, SDValue &Label) {
535 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
536 Offset = N.getOperand(0);
537 SDValue N1 = N.getOperand(1);
538 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
545 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
546 SDValue &Base, SDValue &Offset){
547 // FIXME dl should come from the parent load or store, not the address
548 DebugLoc dl = Op->getDebugLoc();
549 if (N.getOpcode() != ISD::ADD) {
550 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
551 if (!NC || NC->getZExtValue() != 0)
558 Base = N.getOperand(0);
559 Offset = N.getOperand(1);
564 ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
565 unsigned Scale, SDValue &Base,
566 SDValue &OffImm, SDValue &Offset) {
568 SDValue TmpBase, TmpOffImm;
569 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
570 return false; // We want to select tLDRspi / tSTRspi instead.
571 if (N.getOpcode() == ARMISD::Wrapper &&
572 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
573 return false; // We want to select tLDRpci instead.
576 if (N.getOpcode() != ISD::ADD) {
577 if (N.getOpcode() == ARMISD::Wrapper &&
578 !(Subtarget->useMovt() &&
579 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
580 Base = N.getOperand(0);
584 Offset = CurDAG->getRegister(0, MVT::i32);
585 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
589 // Thumb does not have [sp, r] address mode.
590 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
591 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
592 if ((LHSR && LHSR->getReg() == ARM::SP) ||
593 (RHSR && RHSR->getReg() == ARM::SP)) {
595 Offset = CurDAG->getRegister(0, MVT::i32);
596 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
600 // If the RHS is + imm5 * scale, fold into addr mode.
601 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
602 int RHSC = (int)RHS->getZExtValue();
603 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
605 if (RHSC >= 0 && RHSC < 32) {
606 Base = N.getOperand(0);
607 Offset = CurDAG->getRegister(0, MVT::i32);
608 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
614 Base = N.getOperand(0);
615 Offset = N.getOperand(1);
616 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
620 bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
621 SDValue &Base, SDValue &OffImm,
623 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
626 bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
627 SDValue &Base, SDValue &OffImm,
629 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
632 bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
633 SDValue &Base, SDValue &OffImm,
635 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
638 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
639 SDValue &Base, SDValue &OffImm) {
640 if (N.getOpcode() == ISD::FrameIndex) {
641 int FI = cast<FrameIndexSDNode>(N)->getIndex();
642 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
643 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
647 if (N.getOpcode() != ISD::ADD)
650 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
651 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
652 (LHSR && LHSR->getReg() == ARM::SP)) {
653 // If the RHS is + imm8 * scale, fold into addr mode.
654 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
655 int RHSC = (int)RHS->getZExtValue();
656 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
658 if (RHSC >= 0 && RHSC < 256) {
659 Base = N.getOperand(0);
660 if (Base.getOpcode() == ISD::FrameIndex) {
661 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
662 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
664 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
674 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
677 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
679 // Don't match base register only case. That is matched to a separate
680 // lower complexity pattern with explicit register operand.
681 if (ShOpcVal == ARM_AM::no_shift) return false;
683 BaseReg = N.getOperand(0);
684 unsigned ShImmVal = 0;
685 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
686 ShImmVal = RHS->getZExtValue() & 31;
687 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
694 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
695 SDValue &Base, SDValue &OffImm) {
696 // Match simple R + imm12 operands.
699 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
700 if (N.getOpcode() == ISD::FrameIndex) {
701 // Match frame index...
702 int FI = cast<FrameIndexSDNode>(N)->getIndex();
703 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
704 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
706 } else if (N.getOpcode() == ARMISD::Wrapper &&
707 !(Subtarget->useMovt() &&
708 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
709 Base = N.getOperand(0);
710 if (Base.getOpcode() == ISD::TargetConstantPool)
711 return false; // We want to select t2LDRpci instead.
714 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
718 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
719 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
720 // Let t2LDRi8 handle (R - imm8).
723 int RHSC = (int)RHS->getZExtValue();
724 if (N.getOpcode() == ISD::SUB)
727 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
728 Base = N.getOperand(0);
729 if (Base.getOpcode() == ISD::FrameIndex) {
730 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
731 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
733 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
740 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
744 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
745 SDValue &Base, SDValue &OffImm) {
746 // Match simple R - imm8 operands.
747 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
748 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
749 int RHSC = (int)RHS->getSExtValue();
750 if (N.getOpcode() == ISD::SUB)
753 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
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());
759 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
768 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
770 unsigned Opcode = Op->getOpcode();
771 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
772 ? cast<LoadSDNode>(Op)->getAddressingMode()
773 : cast<StoreSDNode>(Op)->getAddressingMode();
774 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
775 int RHSC = (int)RHS->getZExtValue();
776 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
777 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
778 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
779 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
787 bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
788 SDValue &Base, SDValue &OffImm) {
789 if (N.getOpcode() == ISD::ADD) {
790 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
791 int RHSC = (int)RHS->getZExtValue();
793 if (((RHSC & 0x3) == 0) &&
794 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
795 Base = N.getOperand(0);
796 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
800 } else if (N.getOpcode() == ISD::SUB) {
801 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
802 int RHSC = (int)RHS->getZExtValue();
804 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
805 Base = N.getOperand(0);
806 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
815 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
817 SDValue &OffReg, SDValue &ShImm) {
818 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
819 if (N.getOpcode() != ISD::ADD)
822 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
823 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
824 int RHSC = (int)RHS->getZExtValue();
825 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
827 else if (RHSC < 0 && RHSC >= -255) // 8 bits
831 // Look for (R + R) or (R + (R << [1,2,3])).
833 Base = N.getOperand(0);
834 OffReg = N.getOperand(1);
836 // Swap if it is ((R << c) + R).
837 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
838 if (ShOpcVal != ARM_AM::lsl) {
839 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
840 if (ShOpcVal == ARM_AM::lsl)
841 std::swap(Base, OffReg);
844 if (ShOpcVal == ARM_AM::lsl) {
845 // Check to see if the RHS of the shift is a constant, if not, we can't fold
847 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
848 ShAmt = Sh->getZExtValue();
851 ShOpcVal = ARM_AM::no_shift;
853 OffReg = OffReg.getOperand(0);
855 ShOpcVal = ARM_AM::no_shift;
859 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
864 //===--------------------------------------------------------------------===//
866 /// getAL - Returns a ARMCC::AL immediate node.
867 static inline SDValue getAL(SelectionDAG *CurDAG) {
868 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
871 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
872 LoadSDNode *LD = cast<LoadSDNode>(N);
873 ISD::MemIndexedMode AM = LD->getAddressingMode();
874 if (AM == ISD::UNINDEXED)
877 EVT LoadedVT = LD->getMemoryVT();
878 SDValue Offset, AMOpc;
879 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
882 if (LoadedVT == MVT::i32 &&
883 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
884 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
886 } else if (LoadedVT == MVT::i16 &&
887 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
889 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
890 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
891 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
892 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
893 if (LD->getExtensionType() == ISD::SEXTLOAD) {
894 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
896 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
899 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
901 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
907 SDValue Chain = LD->getChain();
908 SDValue Base = LD->getBasePtr();
909 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
910 CurDAG->getRegister(0, MVT::i32), Chain };
911 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
918 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
919 LoadSDNode *LD = cast<LoadSDNode>(N);
920 ISD::MemIndexedMode AM = LD->getAddressingMode();
921 if (AM == ISD::UNINDEXED)
924 EVT LoadedVT = LD->getMemoryVT();
925 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
927 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
930 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
931 switch (LoadedVT.getSimpleVT().SimpleTy) {
933 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
937 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
939 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
944 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
946 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
955 SDValue Chain = LD->getChain();
956 SDValue Base = LD->getBasePtr();
957 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
958 CurDAG->getRegister(0, MVT::i32), Chain };
959 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
966 /// PairDRegs - Form a quad register from a pair of D registers.
968 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
969 DebugLoc dl = V0.getNode()->getDebugLoc();
970 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
971 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
972 if (llvm::ModelWithRegSequence()) {
973 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
974 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
977 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
978 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
979 VT, Undef, V0, SubReg0);
980 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
981 VT, SDValue(Pair, 0), V1, SubReg1);
984 /// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
986 SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
987 DebugLoc dl = V0.getNode()->getDebugLoc();
988 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
989 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
990 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
991 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
994 /// QuadDRegs - Form 4 consecutive D registers.
996 SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
997 SDValue V2, SDValue V3) {
998 DebugLoc dl = V0.getNode()->getDebugLoc();
999 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1000 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1001 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1002 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1003 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1004 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1007 /// QuadQRegs - Form 4 consecutive Q registers.
1009 SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1010 SDValue V2, SDValue V3) {
1011 DebugLoc dl = V0.getNode()->getDebugLoc();
1012 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1013 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1014 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1015 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
1016 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1017 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1020 /// OctoDRegs - Form 8 consecutive D registers.
1022 SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1023 SDValue V2, SDValue V3,
1024 SDValue V4, SDValue V5,
1025 SDValue V6, SDValue V7) {
1026 DebugLoc dl = V0.getNode()->getDebugLoc();
1027 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1028 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1029 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1030 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1031 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1032 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1033 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1034 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
1035 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1036 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1037 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1040 /// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1041 /// for a 64-bit subregister of the vector.
1042 static EVT GetNEONSubregVT(EVT VT) {
1043 switch (VT.getSimpleVT().SimpleTy) {
1044 default: llvm_unreachable("unhandled NEON type");
1045 case MVT::v16i8: return MVT::v8i8;
1046 case MVT::v8i16: return MVT::v4i16;
1047 case MVT::v4f32: return MVT::v2f32;
1048 case MVT::v4i32: return MVT::v2i32;
1049 case MVT::v2i64: return MVT::v1i64;
1053 SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
1054 unsigned *DOpcodes, unsigned *QOpcodes0,
1055 unsigned *QOpcodes1) {
1056 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1057 DebugLoc dl = N->getDebugLoc();
1059 SDValue MemAddr, Align;
1060 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1063 SDValue Chain = N->getOperand(0);
1064 EVT VT = N->getValueType(0);
1065 bool is64BitVector = VT.is64BitVector();
1067 unsigned OpcodeIndex;
1068 switch (VT.getSimpleVT().SimpleTy) {
1069 default: llvm_unreachable("unhandled vld type");
1070 // Double-register operations:
1071 case MVT::v8i8: OpcodeIndex = 0; break;
1072 case MVT::v4i16: OpcodeIndex = 1; break;
1074 case MVT::v2i32: OpcodeIndex = 2; break;
1075 case MVT::v1i64: OpcodeIndex = 3; break;
1076 // Quad-register operations:
1077 case MVT::v16i8: OpcodeIndex = 0; break;
1078 case MVT::v8i16: OpcodeIndex = 1; break;
1080 case MVT::v4i32: OpcodeIndex = 2; break;
1081 case MVT::v2i64: OpcodeIndex = 3;
1082 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
1086 SDValue Pred = getAL(CurDAG);
1087 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1088 if (is64BitVector) {
1089 unsigned Opc = DOpcodes[OpcodeIndex];
1090 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1091 std::vector<EVT> ResTys(NumVecs, VT);
1092 ResTys.push_back(MVT::Other);
1093 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1094 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1098 SDValue V0 = SDValue(VLd, 0);
1099 SDValue V1 = SDValue(VLd, 1);
1101 // Form a REG_SEQUENCE to force register allocation.
1103 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1105 SDValue V2 = SDValue(VLd, 2);
1106 // If it's a vld3, form a quad D-register but discard the last part.
1107 SDValue V3 = (NumVecs == 3)
1108 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1110 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1113 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1114 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1115 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
1117 ReplaceUses(SDValue(N, Vec), D);
1119 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1123 EVT RegVT = GetNEONSubregVT(VT);
1125 // Quad registers are directly supported for VLD1 and VLD2,
1126 // loading pairs of D regs.
1127 unsigned Opc = QOpcodes0[OpcodeIndex];
1128 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1129 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
1130 ResTys.push_back(MVT::Other);
1131 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1132 Chain = SDValue(VLd, 2 * NumVecs);
1134 // Combine the even and odd subregs to produce the result.
1135 if (llvm::ModelWithRegSequence()) {
1137 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1138 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1140 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1141 SDValue(VLd, 0), SDValue(VLd, 1),
1142 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1143 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1144 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
1145 ReplaceUses(SDValue(N, 0), Q0);
1146 ReplaceUses(SDValue(N, 1), Q1);
1149 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1150 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1151 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1155 // Otherwise, quad registers are loaded with two separate instructions,
1156 // where one loads the even registers and the other loads the odd registers.
1158 std::vector<EVT> ResTys(NumVecs, RegVT);
1159 ResTys.push_back(MemAddr.getValueType());
1160 ResTys.push_back(MVT::Other);
1162 // Load the even subregs.
1163 unsigned Opc = QOpcodes0[OpcodeIndex];
1164 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1165 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
1166 Chain = SDValue(VLdA, NumVecs+1);
1168 // Load the odd subregs.
1169 Opc = QOpcodes1[OpcodeIndex];
1170 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1171 Align, Reg0, Pred, Reg0, Chain };
1172 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
1173 Chain = SDValue(VLdB, NumVecs+1);
1175 if (llvm::ModelWithRegSequence()) {
1176 SDValue V0 = SDValue(VLdA, 0);
1177 SDValue V1 = SDValue(VLdB, 0);
1178 SDValue V2 = SDValue(VLdA, 1);
1179 SDValue V3 = SDValue(VLdB, 1);
1180 SDValue V4 = SDValue(VLdA, 2);
1181 SDValue V5 = SDValue(VLdB, 2);
1182 SDValue V6 = (NumVecs == 3)
1183 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1186 SDValue V7 = (NumVecs == 3)
1187 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1190 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1191 V4, V5, V6, V7), 0);
1193 // Extract out the 3 / 4 Q registers.
1194 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1195 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1196 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1198 ReplaceUses(SDValue(N, Vec), Q);
1201 // Combine the even and odd subregs to produce the result.
1202 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1203 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1204 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1208 ReplaceUses(SDValue(N, NumVecs), Chain);
1212 SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
1213 unsigned *DOpcodes, unsigned *QOpcodes0,
1214 unsigned *QOpcodes1) {
1215 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
1216 DebugLoc dl = N->getDebugLoc();
1218 SDValue MemAddr, Align;
1219 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1222 SDValue Chain = N->getOperand(0);
1223 EVT VT = N->getOperand(3).getValueType();
1224 bool is64BitVector = VT.is64BitVector();
1226 unsigned OpcodeIndex;
1227 switch (VT.getSimpleVT().SimpleTy) {
1228 default: llvm_unreachable("unhandled vst type");
1229 // Double-register operations:
1230 case MVT::v8i8: OpcodeIndex = 0; break;
1231 case MVT::v4i16: OpcodeIndex = 1; break;
1233 case MVT::v2i32: OpcodeIndex = 2; break;
1234 case MVT::v1i64: OpcodeIndex = 3; break;
1235 // Quad-register operations:
1236 case MVT::v16i8: OpcodeIndex = 0; break;
1237 case MVT::v8i16: OpcodeIndex = 1; break;
1239 case MVT::v4i32: OpcodeIndex = 2; break;
1240 case MVT::v2i64: OpcodeIndex = 3;
1241 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1245 SDValue Pred = getAL(CurDAG);
1246 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1248 SmallVector<SDValue, 10> Ops;
1249 Ops.push_back(MemAddr);
1250 Ops.push_back(Align);
1252 if (is64BitVector) {
1253 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
1255 SDValue V0 = N->getOperand(0+3);
1256 SDValue V1 = N->getOperand(1+3);
1258 // Form a REG_SEQUENCE to force register allocation.
1260 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1262 SDValue V2 = N->getOperand(2+3);
1263 // If it's a vld3, form a quad D-register and leave the last part as
1265 SDValue V3 = (NumVecs == 3)
1266 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1267 : N->getOperand(3+3);
1268 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1271 // Now extract the D registers back out.
1272 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
1274 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
1277 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
1280 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
1283 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1284 Ops.push_back(N->getOperand(Vec+3));
1286 Ops.push_back(Pred);
1287 Ops.push_back(Reg0); // predicate register
1288 Ops.push_back(Chain);
1289 unsigned Opc = DOpcodes[OpcodeIndex];
1290 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
1293 EVT RegVT = GetNEONSubregVT(VT);
1295 // Quad registers are directly supported for VST1 and VST2,
1296 // storing pairs of D regs.
1297 unsigned Opc = QOpcodes0[OpcodeIndex];
1298 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
1299 // First extract the pair of Q registers.
1300 SDValue Q0 = N->getOperand(3);
1301 SDValue Q1 = N->getOperand(4);
1303 // Form a QQ register.
1304 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1306 // Now extract the D registers back out.
1307 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1309 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1311 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
1313 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
1315 Ops.push_back(Pred);
1316 Ops.push_back(Reg0); // predicate register
1317 Ops.push_back(Chain);
1318 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1320 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1321 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1322 N->getOperand(Vec+3)));
1323 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1324 N->getOperand(Vec+3)));
1326 Ops.push_back(Pred);
1327 Ops.push_back(Reg0); // predicate register
1328 Ops.push_back(Chain);
1329 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1334 // Otherwise, quad registers are stored with two separate instructions,
1335 // where one stores the even registers and the other stores the odd registers.
1336 if (llvm::ModelWithRegSequence()) {
1337 // Form the QQQQ REG_SEQUENCE.
1339 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1340 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1341 N->getOperand(Vec+3));
1342 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1343 N->getOperand(Vec+3));
1346 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1349 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1350 V[4], V[5], V[6], V[7]), 0);
1352 // Store the even D registers.
1353 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1354 Ops.push_back(Reg0); // post-access address offset
1355 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1356 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1358 Ops.push_back(Pred);
1359 Ops.push_back(Reg0); // predicate register
1360 Ops.push_back(Chain);
1361 unsigned Opc = QOpcodes0[OpcodeIndex];
1362 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1363 MVT::Other, Ops.data(), NumVecs+6);
1364 Chain = SDValue(VStA, 1);
1366 // Store the odd D registers.
1367 Ops[0] = SDValue(VStA, 0); // MemAddr
1368 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1369 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1371 Ops[NumVecs+5] = Chain;
1372 Opc = QOpcodes1[OpcodeIndex];
1373 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1374 MVT::Other, Ops.data(), NumVecs+6);
1375 Chain = SDValue(VStB, 1);
1376 ReplaceUses(SDValue(N, 0), Chain);
1379 Ops.push_back(Reg0); // post-access address offset
1381 // Store the even subregs.
1382 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1383 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1384 N->getOperand(Vec+3)));
1385 Ops.push_back(Pred);
1386 Ops.push_back(Reg0); // predicate register
1387 Ops.push_back(Chain);
1388 unsigned Opc = QOpcodes0[OpcodeIndex];
1389 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1390 MVT::Other, Ops.data(), NumVecs+6);
1391 Chain = SDValue(VStA, 1);
1393 // Store the odd subregs.
1394 Ops[0] = SDValue(VStA, 0); // MemAddr
1395 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1396 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1397 N->getOperand(Vec+3));
1398 Ops[NumVecs+5] = Chain;
1399 Opc = QOpcodes1[OpcodeIndex];
1400 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1401 MVT::Other, Ops.data(), NumVecs+6);
1402 Chain = SDValue(VStB, 1);
1403 ReplaceUses(SDValue(N, 0), Chain);
1408 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
1409 unsigned NumVecs, unsigned *DOpcodes,
1410 unsigned *QOpcodes0,
1411 unsigned *QOpcodes1) {
1412 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1413 DebugLoc dl = N->getDebugLoc();
1415 SDValue MemAddr, Align;
1416 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1419 SDValue Chain = N->getOperand(0);
1421 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
1422 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
1423 bool is64BitVector = VT.is64BitVector();
1425 // Quad registers are handled by load/store of subregs. Find the subreg info.
1426 unsigned NumElts = 0;
1430 if (!is64BitVector) {
1431 RegVT = GetNEONSubregVT(VT);
1432 NumElts = RegVT.getVectorNumElements();
1433 SubregIdx = (Lane < NumElts) ? ARM::dsub_0 : ARM::dsub_1;
1434 Even = Lane < NumElts;
1437 unsigned OpcodeIndex;
1438 switch (VT.getSimpleVT().SimpleTy) {
1439 default: llvm_unreachable("unhandled vld/vst lane type");
1440 // Double-register operations:
1441 case MVT::v8i8: OpcodeIndex = 0; break;
1442 case MVT::v4i16: OpcodeIndex = 1; break;
1444 case MVT::v2i32: OpcodeIndex = 2; break;
1445 // Quad-register operations:
1446 case MVT::v8i16: OpcodeIndex = 0; break;
1448 case MVT::v4i32: OpcodeIndex = 1; break;
1451 SDValue Pred = getAL(CurDAG);
1452 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1454 SmallVector<SDValue, 10> Ops;
1455 Ops.push_back(MemAddr);
1456 Ops.push_back(Align);
1459 if (is64BitVector) {
1460 Opc = DOpcodes[OpcodeIndex];
1461 if (llvm::ModelWithRegSequence()) {
1463 SDValue V0 = N->getOperand(0+3);
1464 SDValue V1 = N->getOperand(1+3);
1466 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1468 SDValue V2 = N->getOperand(2+3);
1469 SDValue V3 = (NumVecs == 3)
1470 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1471 : N->getOperand(3+3);
1472 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1475 // Now extract the D registers back out.
1476 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
1478 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
1481 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
1484 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
1487 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1488 Ops.push_back(N->getOperand(Vec+3));
1491 // Check if this is loading the even or odd subreg of a Q register.
1492 if (Lane < NumElts) {
1493 Opc = QOpcodes0[OpcodeIndex];
1496 Opc = QOpcodes1[OpcodeIndex];
1499 if (llvm::ModelWithRegSequence()) {
1501 SDValue V0 = N->getOperand(0+3);
1502 SDValue V1 = N->getOperand(1+3);
1504 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1506 SDValue V2 = N->getOperand(2+3);
1507 SDValue V3 = (NumVecs == 3)
1508 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1509 : N->getOperand(3+3);
1510 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1513 // Extract the subregs of the input vector.
1514 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1515 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1516 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1519 // Extract the subregs of the input vector.
1520 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1521 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1522 N->getOperand(Vec+3)));
1525 Ops.push_back(getI32Imm(Lane));
1526 Ops.push_back(Pred);
1527 Ops.push_back(Reg0);
1528 Ops.push_back(Chain);
1531 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
1533 std::vector<EVT> ResTys(NumVecs, RegVT);
1534 ResTys.push_back(MVT::Other);
1535 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1537 if (llvm::ModelWithRegSequence()) {
1538 // Form a REG_SEQUENCE to force register allocation.
1540 if (is64BitVector) {
1541 SDValue V0 = SDValue(VLdLn, 0);
1542 SDValue V1 = SDValue(VLdLn, 1);
1544 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1546 SDValue V2 = SDValue(VLdLn, 2);
1547 // If it's a vld3, form a quad D-register but discard the last part.
1548 SDValue V3 = (NumVecs == 3)
1549 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1550 : SDValue(VLdLn, 3);
1551 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1554 // For 128-bit vectors, take the 64-bit results of the load and insert
1555 // them as subregs into the result.
1557 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1559 V[i] = SDValue(VLdLn, Vec);
1560 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1563 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1565 V[i+1] = SDValue(VLdLn, Vec);
1569 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1573 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1575 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1576 V[4], V[5], V[6], V[7]), 0);
1579 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1580 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1581 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1582 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1583 ReplaceUses(SDValue(N, Vec),
1584 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1585 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1589 // For a 64-bit vector load to D registers, nothing more needs to be done.
1593 // For 128-bit vectors, take the 64-bit results of the load and insert them
1594 // as subregs into the result.
1595 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1596 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1597 N->getOperand(Vec+3),
1598 SDValue(VLdLn, Vec));
1599 ReplaceUses(SDValue(N, Vec), QuadVec);
1602 Chain = SDValue(VLdLn, NumVecs);
1603 ReplaceUses(SDValue(N, NumVecs), Chain);
1607 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
1609 if (!Subtarget->hasV6T2Ops())
1612 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1613 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1616 // For unsigned extracts, check for a shift right and mask
1617 unsigned And_imm = 0;
1618 if (N->getOpcode() == ISD::AND) {
1619 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1621 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1622 if (And_imm & (And_imm + 1))
1625 unsigned Srl_imm = 0;
1626 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1628 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1630 unsigned Width = CountTrailingOnes_32(And_imm);
1631 unsigned LSB = Srl_imm;
1632 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1633 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1634 CurDAG->getTargetConstant(LSB, MVT::i32),
1635 CurDAG->getTargetConstant(Width, MVT::i32),
1636 getAL(CurDAG), Reg0 };
1637 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1643 // Otherwise, we're looking for a shift of a shift
1644 unsigned Shl_imm = 0;
1645 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
1646 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1647 unsigned Srl_imm = 0;
1648 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
1649 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1650 unsigned Width = 32 - Srl_imm;
1651 int LSB = Srl_imm - Shl_imm;
1654 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1655 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1656 CurDAG->getTargetConstant(LSB, MVT::i32),
1657 CurDAG->getTargetConstant(Width, MVT::i32),
1658 getAL(CurDAG), Reg0 };
1659 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1665 SDNode *ARMDAGToDAGISel::
1666 SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1667 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1670 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
1671 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1672 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1675 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1676 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1677 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1678 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1680 llvm_unreachable("Unknown so_reg opcode!");
1684 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1685 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1686 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
1687 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
1692 SDNode *ARMDAGToDAGISel::
1693 SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1694 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1698 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
1699 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1700 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
1701 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
1706 SDNode *ARMDAGToDAGISel::
1707 SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1708 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1709 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1713 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1714 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1715 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1716 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1717 return CurDAG->SelectNodeTo(N,
1718 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1723 SDNode *ARMDAGToDAGISel::
1724 SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1725 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1726 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1730 if (Predicate_so_imm(TrueVal.getNode())) {
1731 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1732 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1733 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1734 return CurDAG->SelectNodeTo(N,
1735 ARM::MOVCCi, MVT::i32, Ops, 5);
1740 SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1741 EVT VT = N->getValueType(0);
1742 SDValue FalseVal = N->getOperand(0);
1743 SDValue TrueVal = N->getOperand(1);
1744 SDValue CC = N->getOperand(2);
1745 SDValue CCR = N->getOperand(3);
1746 SDValue InFlag = N->getOperand(4);
1747 assert(CC.getOpcode() == ISD::Constant);
1748 assert(CCR.getOpcode() == ISD::Register);
1749 ARMCC::CondCodes CCVal =
1750 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
1752 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1753 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1754 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1755 // Pattern complexity = 18 cost = 1 size = 0
1759 if (Subtarget->isThumb()) {
1760 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
1761 CCVal, CCR, InFlag);
1763 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
1764 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1768 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
1769 CCVal, CCR, InFlag);
1771 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
1772 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1777 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1778 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1780 // Emits: (MOVCCi:i32 GPR:i32:$false,
1781 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1782 // Pattern complexity = 10 cost = 1 size = 0
1783 if (Subtarget->isThumb()) {
1784 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
1785 CCVal, CCR, InFlag);
1787 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
1788 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1792 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
1793 CCVal, CCR, InFlag);
1795 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
1796 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1802 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1803 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1804 // Pattern complexity = 6 cost = 1 size = 0
1806 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1807 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1808 // Pattern complexity = 6 cost = 11 size = 0
1810 // Also FCPYScc and FCPYDcc.
1811 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1812 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
1814 switch (VT.getSimpleVT().SimpleTy) {
1815 default: assert(false && "Illegal conditional move type!");
1818 Opc = Subtarget->isThumb()
1819 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1829 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
1832 SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1833 // The only time a CONCAT_VECTORS operation can have legal types is when
1834 // two 64-bit vectors are concatenated to a 128-bit vector.
1835 EVT VT = N->getValueType(0);
1836 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1837 llvm_unreachable("unexpected CONCAT_VECTORS");
1838 DebugLoc dl = N->getDebugLoc();
1839 SDValue V0 = N->getOperand(0);
1840 SDValue V1 = N->getOperand(1);
1841 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1842 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1843 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1844 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1847 SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
1848 DebugLoc dl = N->getDebugLoc();
1850 if (N->isMachineOpcode())
1851 return NULL; // Already selected.
1853 switch (N->getOpcode()) {
1855 case ISD::Constant: {
1856 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
1858 if (Subtarget->hasThumb2())
1859 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1860 // be done with MOV + MOVT, at worst.
1863 if (Subtarget->isThumb()) {
1864 UseCP = (Val > 255 && // MOV
1865 ~Val > 255 && // MOV + MVN
1866 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
1868 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1869 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1870 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1875 CurDAG->getTargetConstantPool(ConstantInt::get(
1876 Type::getInt32Ty(*CurDAG->getContext()), Val),
1877 TLI.getPointerTy());
1880 if (Subtarget->isThumb1Only()) {
1881 SDValue Pred = getAL(CurDAG);
1882 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1883 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
1884 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1889 CurDAG->getRegister(0, MVT::i32),
1890 CurDAG->getTargetConstant(0, MVT::i32),
1892 CurDAG->getRegister(0, MVT::i32),
1893 CurDAG->getEntryNode()
1895 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1898 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
1902 // Other cases are autogenerated.
1905 case ISD::FrameIndex: {
1906 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
1907 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1908 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1909 if (Subtarget->isThumb1Only()) {
1910 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1911 CurDAG->getTargetConstant(0, MVT::i32));
1913 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1914 ARM::t2ADDri : ARM::ADDri);
1915 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1916 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1917 CurDAG->getRegister(0, MVT::i32) };
1918 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1922 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1926 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
1930 if (Subtarget->isThumb1Only())
1932 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1933 unsigned RHSV = C->getZExtValue();
1935 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
1936 unsigned ShImm = Log2_32(RHSV-1);
1939 SDValue V = N->getOperand(0);
1940 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1941 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1942 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1943 if (Subtarget->isThumb()) {
1944 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1945 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
1947 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1948 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
1951 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
1952 unsigned ShImm = Log2_32(RHSV+1);
1955 SDValue V = N->getOperand(0);
1956 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1957 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1958 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1959 if (Subtarget->isThumb()) {
1960 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1961 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
1963 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1964 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
1970 // Check for unsigned bitfield extract
1971 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1974 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1975 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1976 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1977 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1978 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
1979 EVT VT = N->getValueType(0);
1982 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1984 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1987 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
1988 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1991 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1992 SDValue N2 = N0.getOperand(1);
1993 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1996 unsigned N1CVal = N1C->getZExtValue();
1997 unsigned N2CVal = N2C->getZExtValue();
1998 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1999 (N1CVal & 0xffffU) == 0xffffU &&
2000 (N2CVal & 0xffffU) == 0x0U) {
2001 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2003 SDValue Ops[] = { N0.getOperand(0), Imm16,
2004 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2005 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2010 case ARMISD::VMOVRRD:
2011 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
2012 N->getOperand(0), getAL(CurDAG),
2013 CurDAG->getRegister(0, MVT::i32));
2014 case ISD::UMUL_LOHI: {
2015 if (Subtarget->isThumb1Only())
2017 if (Subtarget->isThumb()) {
2018 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2019 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2020 CurDAG->getRegister(0, MVT::i32) };
2021 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
2023 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2024 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2025 CurDAG->getRegister(0, MVT::i32) };
2026 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
2029 case ISD::SMUL_LOHI: {
2030 if (Subtarget->isThumb1Only())
2032 if (Subtarget->isThumb()) {
2033 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2034 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2035 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
2037 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2038 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2039 CurDAG->getRegister(0, MVT::i32) };
2040 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
2044 SDNode *ResNode = 0;
2045 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2046 ResNode = SelectT2IndexedLoad(N);
2048 ResNode = SelectARMIndexedLoad(N);
2052 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2053 if (Subtarget->hasVFP2() &&
2054 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2055 SDValue Chain = N->getOperand(0);
2057 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
2058 SDValue Pred = getAL(CurDAG);
2059 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2060 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
2061 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2062 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2063 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2064 MVT::v2f64, MVT::Other, Ops, 5);
2065 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2068 // Other cases are autogenerated.
2072 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2073 if (Subtarget->hasVFP2() &&
2074 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2075 SDValue Chain = N->getOperand(0);
2077 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
2078 SDValue Pred = getAL(CurDAG);
2079 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2080 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2081 AM5Opc, Pred, PredReg, Chain };
2082 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2083 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2084 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2085 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2088 // Other cases are autogenerated.
2091 case ARMISD::BRCOND: {
2092 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2093 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2094 // Pattern complexity = 6 cost = 1 size = 0
2096 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2097 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2098 // Pattern complexity = 6 cost = 1 size = 0
2100 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2101 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2102 // Pattern complexity = 6 cost = 1 size = 0
2104 unsigned Opc = Subtarget->isThumb() ?
2105 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
2106 SDValue Chain = N->getOperand(0);
2107 SDValue N1 = N->getOperand(1);
2108 SDValue N2 = N->getOperand(2);
2109 SDValue N3 = N->getOperand(3);
2110 SDValue InFlag = N->getOperand(4);
2111 assert(N1.getOpcode() == ISD::BasicBlock);
2112 assert(N2.getOpcode() == ISD::Constant);
2113 assert(N3.getOpcode() == ISD::Register);
2115 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2116 cast<ConstantSDNode>(N2)->getZExtValue()),
2118 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
2119 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2121 Chain = SDValue(ResNode, 0);
2122 if (N->getNumValues() == 2) {
2123 InFlag = SDValue(ResNode, 1);
2124 ReplaceUses(SDValue(N, 1), InFlag);
2126 ReplaceUses(SDValue(N, 0),
2127 SDValue(Chain.getNode(), Chain.getResNo()));
2131 return SelectCMOVOp(N);
2132 case ARMISD::CNEG: {
2133 EVT VT = N->getValueType(0);
2134 SDValue N0 = N->getOperand(0);
2135 SDValue N1 = N->getOperand(1);
2136 SDValue N2 = N->getOperand(2);
2137 SDValue N3 = N->getOperand(3);
2138 SDValue InFlag = N->getOperand(4);
2139 assert(N2.getOpcode() == ISD::Constant);
2140 assert(N3.getOpcode() == ISD::Register);
2142 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2143 cast<ConstantSDNode>(N2)->getZExtValue()),
2145 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
2147 switch (VT.getSimpleVT().SimpleTy) {
2148 default: assert(false && "Illegal conditional move type!");
2157 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
2160 case ARMISD::VZIP: {
2162 EVT VT = N->getValueType(0);
2163 switch (VT.getSimpleVT().SimpleTy) {
2164 default: return NULL;
2165 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2166 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2168 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2169 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2170 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2172 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2174 SDValue Pred = getAL(CurDAG);
2175 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2176 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2177 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2179 case ARMISD::VUZP: {
2181 EVT VT = N->getValueType(0);
2182 switch (VT.getSimpleVT().SimpleTy) {
2183 default: return NULL;
2184 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2185 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2187 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2188 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2189 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2191 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2193 SDValue Pred = getAL(CurDAG);
2194 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2195 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2196 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2198 case ARMISD::VTRN: {
2200 EVT VT = N->getValueType(0);
2201 switch (VT.getSimpleVT().SimpleTy) {
2202 default: return NULL;
2203 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2204 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2206 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2207 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2208 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2210 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2212 SDValue Pred = getAL(CurDAG);
2213 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2214 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2215 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2218 case ISD::INTRINSIC_VOID:
2219 case ISD::INTRINSIC_W_CHAIN: {
2220 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
2225 case Intrinsic::arm_neon_vld1: {
2226 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2227 ARM::VLD1d32, ARM::VLD1d64 };
2228 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2229 ARM::VLD1q32, ARM::VLD1q64 };
2230 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2233 case Intrinsic::arm_neon_vld2: {
2234 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
2235 ARM::VLD2d32, ARM::VLD1q64 };
2236 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
2237 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
2240 case Intrinsic::arm_neon_vld3: {
2241 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
2242 ARM::VLD3d32, ARM::VLD1d64T };
2243 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2246 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2247 ARM::VLD3q16odd_UPD,
2248 ARM::VLD3q32odd_UPD };
2249 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
2252 case Intrinsic::arm_neon_vld4: {
2253 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
2254 ARM::VLD4d32, ARM::VLD1d64Q };
2255 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2258 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2259 ARM::VLD4q16odd_UPD,
2260 ARM::VLD4q32odd_UPD };
2261 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
2264 case Intrinsic::arm_neon_vld2lane: {
2265 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
2266 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2267 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
2268 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
2271 case Intrinsic::arm_neon_vld3lane: {
2272 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
2273 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2274 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
2275 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2278 case Intrinsic::arm_neon_vld4lane: {
2279 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
2280 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2281 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
2282 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2285 case Intrinsic::arm_neon_vst1: {
2286 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2287 ARM::VST1d32, ARM::VST1d64 };
2288 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2289 ARM::VST1q32, ARM::VST1q64 };
2290 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2293 case Intrinsic::arm_neon_vst2: {
2294 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
2295 ARM::VST2d32, ARM::VST1q64 };
2296 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
2297 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
2300 case Intrinsic::arm_neon_vst3: {
2301 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
2302 ARM::VST3d32, ARM::VST1d64T };
2303 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2306 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2307 ARM::VST3q16odd_UPD,
2308 ARM::VST3q32odd_UPD };
2309 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
2312 case Intrinsic::arm_neon_vst4: {
2313 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
2314 ARM::VST4d32, ARM::VST1d64Q };
2315 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2318 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2319 ARM::VST4q16odd_UPD,
2320 ARM::VST4q32odd_UPD };
2321 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
2324 case Intrinsic::arm_neon_vst2lane: {
2325 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
2326 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2327 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
2328 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
2331 case Intrinsic::arm_neon_vst3lane: {
2332 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
2333 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2334 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
2335 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
2338 case Intrinsic::arm_neon_vst4lane: {
2339 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
2340 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2341 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
2342 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
2348 case ISD::CONCAT_VECTORS:
2349 return SelectConcatVector(N);
2352 return SelectCode(N);
2355 bool ARMDAGToDAGISel::
2356 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2357 std::vector<SDValue> &OutOps) {
2358 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
2359 // Require the address to be in a register. That is safe for all ARM
2360 // variants and it is hard to do anything much smarter without knowing
2361 // how the operand is used.
2362 OutOps.push_back(Op);
2366 /// createARMISelDag - This pass converts a legalized DAG into a
2367 /// ARM-specific DAG, ready for instruction scheduling.
2369 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2370 CodeGenOpt::Level OptLevel) {
2371 return new ARMDAGToDAGISel(TM, OptLevel);
2374 /// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2375 /// operations involving sub-registers.
2376 bool llvm::ModelWithRegSequence() {