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 //===----------------------------------------------------------------------===//
15 #include "ARMAddressingModes.h"
16 #include "ARMTargetMachine.h"
17 #include "llvm/CallingConv.h"
18 #include "llvm/Constants.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/Function.h"
21 #include "llvm/Intrinsics.h"
22 #include "llvm/LLVMContext.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineFunction.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/SelectionDAG.h"
27 #include "llvm/CodeGen/SelectionDAGISel.h"
28 #include "llvm/Target/TargetLowering.h"
29 #include "llvm/Target/TargetOptions.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/Compiler.h"
32 #include "llvm/Support/Debug.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
39 UseRegSeq("neon-reg-sequence", cl::Hidden,
40 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"));
42 //===--------------------------------------------------------------------===//
43 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
44 /// instructions for SelectionDAG operations.
47 class ARMDAGToDAGISel : public SelectionDAGISel {
48 ARMBaseTargetMachine &TM;
50 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
51 /// make the right decision when generating code for different targets.
52 const ARMSubtarget *Subtarget;
55 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
56 CodeGenOpt::Level OptLevel)
57 : SelectionDAGISel(tm, OptLevel), TM(tm),
58 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
61 virtual const char *getPassName() const {
62 return "ARM Instruction Selection";
65 /// getI32Imm - Return a target constant of type i32 with the specified
67 inline SDValue getI32Imm(unsigned Imm) {
68 return CurDAG->getTargetConstant(Imm, MVT::i32);
71 SDNode *Select(SDNode *N);
73 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
74 SDValue &B, SDValue &C);
75 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
76 SDValue &Offset, SDValue &Opc);
77 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
78 SDValue &Offset, SDValue &Opc);
79 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
80 SDValue &Offset, SDValue &Opc);
81 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
82 SDValue &Offset, SDValue &Opc);
83 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
85 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
87 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
89 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
92 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
94 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
95 SDValue &Base, SDValue &OffImm,
97 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
98 SDValue &OffImm, SDValue &Offset);
99 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
100 SDValue &OffImm, SDValue &Offset);
101 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
102 SDValue &OffImm, SDValue &Offset);
103 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
106 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
107 SDValue &BaseReg, SDValue &Opc);
108 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
110 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
112 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
114 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
116 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
117 SDValue &OffReg, SDValue &ShImm);
119 // Include the pieces autogenerated from the target description.
120 #include "ARMGenDAGISel.inc"
123 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
125 SDNode *SelectARMIndexedLoad(SDNode *N);
126 SDNode *SelectT2IndexedLoad(SDNode *N);
128 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
129 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
130 /// loads of D registers and even subregs and odd subregs of Q registers.
131 /// For NumVecs <= 2, QOpcodes1 is not used.
132 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
133 unsigned *QOpcodes0, unsigned *QOpcodes1);
135 /// SelectVST - Select NEON store intrinsics. NumVecs should
136 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
137 /// stores of D registers and even subregs and odd subregs of Q registers.
138 /// For NumVecs <= 2, QOpcodes1 is not used.
139 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
140 unsigned *QOpcodes0, unsigned *QOpcodes1);
142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
144 /// load/store of D registers and even subregs and odd subregs of Q registers.
145 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
150 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
152 /// SelectCMOVOp - Select CMOV instructions for ARM.
153 SDNode *SelectCMOVOp(SDNode *N);
154 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
155 ARMCC::CondCodes CCVal, SDValue CCR,
157 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
158 ARMCC::CondCodes CCVal, SDValue CCR,
160 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
161 ARMCC::CondCodes CCVal, SDValue CCR,
163 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
164 ARMCC::CondCodes CCVal, SDValue CCR,
167 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
168 /// inline asm expressions.
169 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
171 std::vector<SDValue> &OutOps);
173 /// PairDRegs - Insert a pair of double registers into an implicit def to
174 /// form a quad register.
175 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
179 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
180 /// operand. If so Imm will receive the 32-bit value.
181 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
182 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
183 Imm = cast<ConstantSDNode>(N)->getZExtValue();
189 // isInt32Immediate - This method tests to see if a constant operand.
190 // If so Imm will receive the 32 bit value.
191 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
192 return isInt32Immediate(N.getNode(), Imm);
195 // isOpcWithIntImmediate - This method tests to see if the node is a specific
196 // opcode and that it has a immediate integer right operand.
197 // If so Imm will receive the 32 bit value.
198 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
199 return N->getOpcode() == Opc &&
200 isInt32Immediate(N->getOperand(1).getNode(), Imm);
204 bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
209 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
211 // Don't match base register only case. That is matched to a separate
212 // lower complexity pattern with explicit register operand.
213 if (ShOpcVal == ARM_AM::no_shift) return false;
215 BaseReg = N.getOperand(0);
216 unsigned ShImmVal = 0;
217 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
218 ShReg = CurDAG->getRegister(0, MVT::i32);
219 ShImmVal = RHS->getZExtValue() & 31;
221 ShReg = N.getOperand(1);
223 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
228 bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
229 SDValue &Base, SDValue &Offset,
231 if (N.getOpcode() == ISD::MUL) {
232 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
233 // X * [3,5,9] -> X + X * [2,4,8] etc.
234 int RHSC = (int)RHS->getZExtValue();
237 ARM_AM::AddrOpc AddSub = ARM_AM::add;
239 AddSub = ARM_AM::sub;
242 if (isPowerOf2_32(RHSC)) {
243 unsigned ShAmt = Log2_32(RHSC);
244 Base = Offset = N.getOperand(0);
245 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
254 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
256 if (N.getOpcode() == ISD::FrameIndex) {
257 int FI = cast<FrameIndexSDNode>(N)->getIndex();
258 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
259 } else if (N.getOpcode() == ARMISD::Wrapper &&
260 !(Subtarget->useMovt() &&
261 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
262 Base = N.getOperand(0);
264 Offset = CurDAG->getRegister(0, MVT::i32);
265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
271 // Match simple R +/- imm12 operands.
272 if (N.getOpcode() == ISD::ADD)
273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
274 int RHSC = (int)RHS->getZExtValue();
275 if ((RHSC >= 0 && RHSC < 0x1000) ||
276 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
277 Base = N.getOperand(0);
278 if (Base.getOpcode() == ISD::FrameIndex) {
279 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
280 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
282 Offset = CurDAG->getRegister(0, MVT::i32);
284 ARM_AM::AddrOpc AddSub = ARM_AM::add;
286 AddSub = ARM_AM::sub;
289 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
296 // Otherwise this is R +/- [possibly shifted] R.
297 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
298 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
301 Base = N.getOperand(0);
302 Offset = N.getOperand(1);
304 if (ShOpcVal != ARM_AM::no_shift) {
305 // Check to see if the RHS of the shift is a constant, if not, we can't fold
307 if (ConstantSDNode *Sh =
308 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
309 ShAmt = Sh->getZExtValue();
310 Offset = N.getOperand(1).getOperand(0);
312 ShOpcVal = ARM_AM::no_shift;
316 // Try matching (R shl C) + (R).
317 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
318 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
319 if (ShOpcVal != ARM_AM::no_shift) {
320 // Check to see if the RHS of the shift is a constant, if not, we can't
322 if (ConstantSDNode *Sh =
323 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
324 ShAmt = Sh->getZExtValue();
325 Offset = N.getOperand(0).getOperand(0);
326 Base = N.getOperand(1);
328 ShOpcVal = ARM_AM::no_shift;
333 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
338 bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
339 SDValue &Offset, SDValue &Opc) {
340 unsigned Opcode = Op->getOpcode();
341 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
342 ? cast<LoadSDNode>(Op)->getAddressingMode()
343 : cast<StoreSDNode>(Op)->getAddressingMode();
344 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
345 ? ARM_AM::add : ARM_AM::sub;
346 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
347 int Val = (int)C->getZExtValue();
348 if (Val >= 0 && Val < 0x1000) { // 12 bits.
349 Offset = CurDAG->getRegister(0, MVT::i32);
350 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
358 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
360 if (ShOpcVal != ARM_AM::no_shift) {
361 // Check to see if the RHS of the shift is a constant, if not, we can't fold
363 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
364 ShAmt = Sh->getZExtValue();
365 Offset = N.getOperand(0);
367 ShOpcVal = ARM_AM::no_shift;
371 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
377 bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
378 SDValue &Base, SDValue &Offset,
380 if (N.getOpcode() == ISD::SUB) {
381 // X - C is canonicalize to X + -C, no need to handle it here.
382 Base = N.getOperand(0);
383 Offset = N.getOperand(1);
384 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
388 if (N.getOpcode() != ISD::ADD) {
390 if (N.getOpcode() == ISD::FrameIndex) {
391 int FI = cast<FrameIndexSDNode>(N)->getIndex();
392 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
394 Offset = CurDAG->getRegister(0, MVT::i32);
395 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
399 // If the RHS is +/- imm8, fold into addr mode.
400 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
401 int RHSC = (int)RHS->getZExtValue();
402 if ((RHSC >= 0 && RHSC < 256) ||
403 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
404 Base = N.getOperand(0);
405 if (Base.getOpcode() == ISD::FrameIndex) {
406 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
407 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
409 Offset = CurDAG->getRegister(0, MVT::i32);
411 ARM_AM::AddrOpc AddSub = ARM_AM::add;
413 AddSub = ARM_AM::sub;
416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
421 Base = N.getOperand(0);
422 Offset = N.getOperand(1);
423 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
427 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
428 SDValue &Offset, SDValue &Opc) {
429 unsigned Opcode = Op->getOpcode();
430 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
431 ? cast<LoadSDNode>(Op)->getAddressingMode()
432 : cast<StoreSDNode>(Op)->getAddressingMode();
433 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
434 ? ARM_AM::add : ARM_AM::sub;
435 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
436 int Val = (int)C->getZExtValue();
437 if (Val >= 0 && Val < 256) {
438 Offset = CurDAG->getRegister(0, MVT::i32);
439 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
445 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
449 bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
450 SDValue &Addr, SDValue &Mode) {
452 Mode = CurDAG->getTargetConstant(0, MVT::i32);
456 bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
457 SDValue &Base, SDValue &Offset) {
458 if (N.getOpcode() != ISD::ADD) {
460 if (N.getOpcode() == ISD::FrameIndex) {
461 int FI = cast<FrameIndexSDNode>(N)->getIndex();
462 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
463 } else if (N.getOpcode() == ARMISD::Wrapper &&
464 !(Subtarget->useMovt() &&
465 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
466 Base = N.getOperand(0);
468 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
473 // If the RHS is +/- imm8, fold into addr mode.
474 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
475 int RHSC = (int)RHS->getZExtValue();
476 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
478 if ((RHSC >= 0 && RHSC < 256) ||
479 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
480 Base = N.getOperand(0);
481 if (Base.getOpcode() == ISD::FrameIndex) {
482 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
483 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
486 ARM_AM::AddrOpc AddSub = ARM_AM::add;
488 AddSub = ARM_AM::sub;
491 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
499 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
504 bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
505 SDValue &Addr, SDValue &Align) {
507 // Default to no alignment.
508 Align = CurDAG->getTargetConstant(0, MVT::i32);
512 bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
513 SDValue &Offset, SDValue &Label) {
514 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
515 Offset = N.getOperand(0);
516 SDValue N1 = N.getOperand(1);
517 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
524 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
525 SDValue &Base, SDValue &Offset){
526 // FIXME dl should come from the parent load or store, not the address
527 DebugLoc dl = Op->getDebugLoc();
528 if (N.getOpcode() != ISD::ADD) {
529 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
530 if (!NC || NC->getZExtValue() != 0)
537 Base = N.getOperand(0);
538 Offset = N.getOperand(1);
543 ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
544 unsigned Scale, SDValue &Base,
545 SDValue &OffImm, SDValue &Offset) {
547 SDValue TmpBase, TmpOffImm;
548 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
549 return false; // We want to select tLDRspi / tSTRspi instead.
550 if (N.getOpcode() == ARMISD::Wrapper &&
551 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
552 return false; // We want to select tLDRpci instead.
555 if (N.getOpcode() != ISD::ADD) {
556 if (N.getOpcode() == ARMISD::Wrapper &&
557 !(Subtarget->useMovt() &&
558 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
559 Base = N.getOperand(0);
563 Offset = CurDAG->getRegister(0, MVT::i32);
564 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
568 // Thumb does not have [sp, r] address mode.
569 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
570 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
571 if ((LHSR && LHSR->getReg() == ARM::SP) ||
572 (RHSR && RHSR->getReg() == ARM::SP)) {
574 Offset = CurDAG->getRegister(0, MVT::i32);
575 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
579 // If the RHS is + imm5 * scale, fold into addr mode.
580 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
581 int RHSC = (int)RHS->getZExtValue();
582 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
584 if (RHSC >= 0 && RHSC < 32) {
585 Base = N.getOperand(0);
586 Offset = CurDAG->getRegister(0, MVT::i32);
587 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
593 Base = N.getOperand(0);
594 Offset = N.getOperand(1);
595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
599 bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
600 SDValue &Base, SDValue &OffImm,
602 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
605 bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
606 SDValue &Base, SDValue &OffImm,
608 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
611 bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
612 SDValue &Base, SDValue &OffImm,
614 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
617 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
618 SDValue &Base, SDValue &OffImm) {
619 if (N.getOpcode() == ISD::FrameIndex) {
620 int FI = cast<FrameIndexSDNode>(N)->getIndex();
621 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
622 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
626 if (N.getOpcode() != ISD::ADD)
629 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
630 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
631 (LHSR && LHSR->getReg() == ARM::SP)) {
632 // If the RHS is + imm8 * scale, fold into addr mode.
633 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
634 int RHSC = (int)RHS->getZExtValue();
635 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
637 if (RHSC >= 0 && RHSC < 256) {
638 Base = N.getOperand(0);
639 if (Base.getOpcode() == ISD::FrameIndex) {
640 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
641 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
643 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
653 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
656 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
658 // Don't match base register only case. That is matched to a separate
659 // lower complexity pattern with explicit register operand.
660 if (ShOpcVal == ARM_AM::no_shift) return false;
662 BaseReg = N.getOperand(0);
663 unsigned ShImmVal = 0;
664 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
665 ShImmVal = RHS->getZExtValue() & 31;
666 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
673 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
674 SDValue &Base, SDValue &OffImm) {
675 // Match simple R + imm12 operands.
678 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
679 if (N.getOpcode() == ISD::FrameIndex) {
680 // Match frame index...
681 int FI = cast<FrameIndexSDNode>(N)->getIndex();
682 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
683 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
685 } else if (N.getOpcode() == ARMISD::Wrapper &&
686 !(Subtarget->useMovt() &&
687 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
688 Base = N.getOperand(0);
689 if (Base.getOpcode() == ISD::TargetConstantPool)
690 return false; // We want to select t2LDRpci instead.
693 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
697 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
698 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
699 // Let t2LDRi8 handle (R - imm8).
702 int RHSC = (int)RHS->getZExtValue();
703 if (N.getOpcode() == ISD::SUB)
706 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
707 Base = N.getOperand(0);
708 if (Base.getOpcode() == ISD::FrameIndex) {
709 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
710 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
712 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
719 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
723 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
724 SDValue &Base, SDValue &OffImm) {
725 // Match simple R - imm8 operands.
726 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
727 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
728 int RHSC = (int)RHS->getSExtValue();
729 if (N.getOpcode() == ISD::SUB)
732 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
733 Base = N.getOperand(0);
734 if (Base.getOpcode() == ISD::FrameIndex) {
735 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
736 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
738 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
747 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
749 unsigned Opcode = Op->getOpcode();
750 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
751 ? cast<LoadSDNode>(Op)->getAddressingMode()
752 : cast<StoreSDNode>(Op)->getAddressingMode();
753 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
754 int RHSC = (int)RHS->getZExtValue();
755 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
756 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
757 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
758 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
766 bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
767 SDValue &Base, SDValue &OffImm) {
768 if (N.getOpcode() == ISD::ADD) {
769 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
770 int RHSC = (int)RHS->getZExtValue();
771 if (((RHSC & 0x3) == 0) &&
772 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
773 Base = N.getOperand(0);
774 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
778 } else if (N.getOpcode() == ISD::SUB) {
779 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
780 int RHSC = (int)RHS->getZExtValue();
781 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
782 Base = N.getOperand(0);
783 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
792 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
794 SDValue &OffReg, SDValue &ShImm) {
795 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
796 if (N.getOpcode() != ISD::ADD)
799 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
800 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
801 int RHSC = (int)RHS->getZExtValue();
802 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
804 else if (RHSC < 0 && RHSC >= -255) // 8 bits
808 // Look for (R + R) or (R + (R << [1,2,3])).
810 Base = N.getOperand(0);
811 OffReg = N.getOperand(1);
813 // Swap if it is ((R << c) + R).
814 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
815 if (ShOpcVal != ARM_AM::lsl) {
816 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
817 if (ShOpcVal == ARM_AM::lsl)
818 std::swap(Base, OffReg);
821 if (ShOpcVal == ARM_AM::lsl) {
822 // Check to see if the RHS of the shift is a constant, if not, we can't fold
824 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
825 ShAmt = Sh->getZExtValue();
828 ShOpcVal = ARM_AM::no_shift;
830 OffReg = OffReg.getOperand(0);
832 ShOpcVal = ARM_AM::no_shift;
836 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
841 //===--------------------------------------------------------------------===//
843 /// getAL - Returns a ARMCC::AL immediate node.
844 static inline SDValue getAL(SelectionDAG *CurDAG) {
845 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
848 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
849 LoadSDNode *LD = cast<LoadSDNode>(N);
850 ISD::MemIndexedMode AM = LD->getAddressingMode();
851 if (AM == ISD::UNINDEXED)
854 EVT LoadedVT = LD->getMemoryVT();
855 SDValue Offset, AMOpc;
856 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
859 if (LoadedVT == MVT::i32 &&
860 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
861 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
863 } else if (LoadedVT == MVT::i16 &&
864 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
866 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
867 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
868 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
869 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
870 if (LD->getExtensionType() == ISD::SEXTLOAD) {
871 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
873 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
876 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
878 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
884 SDValue Chain = LD->getChain();
885 SDValue Base = LD->getBasePtr();
886 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
887 CurDAG->getRegister(0, MVT::i32), Chain };
888 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
895 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
896 LoadSDNode *LD = cast<LoadSDNode>(N);
897 ISD::MemIndexedMode AM = LD->getAddressingMode();
898 if (AM == ISD::UNINDEXED)
901 EVT LoadedVT = LD->getMemoryVT();
902 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
904 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
907 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
908 switch (LoadedVT.getSimpleVT().SimpleTy) {
910 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
914 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
916 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
921 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
923 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
932 SDValue Chain = LD->getChain();
933 SDValue Base = LD->getBasePtr();
934 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
935 CurDAG->getRegister(0, MVT::i32), Chain };
936 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
943 /// PairDRegs - Insert a pair of double registers into an implicit def to
944 /// form a quad register.
945 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
946 DebugLoc dl = V0.getNode()->getDebugLoc();
947 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
948 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
950 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
951 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
954 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
955 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
956 VT, Undef, V0, SubReg0);
957 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
958 VT, SDValue(Pair, 0), V1, SubReg1);
961 /// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
962 /// for a 64-bit subregister of the vector.
963 static EVT GetNEONSubregVT(EVT VT) {
964 switch (VT.getSimpleVT().SimpleTy) {
965 default: llvm_unreachable("unhandled NEON type");
966 case MVT::v16i8: return MVT::v8i8;
967 case MVT::v8i16: return MVT::v4i16;
968 case MVT::v4f32: return MVT::v2f32;
969 case MVT::v4i32: return MVT::v2i32;
970 case MVT::v2i64: return MVT::v1i64;
974 SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
975 unsigned *DOpcodes, unsigned *QOpcodes0,
976 unsigned *QOpcodes1) {
977 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
978 DebugLoc dl = N->getDebugLoc();
980 SDValue MemAddr, Align;
981 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
984 SDValue Chain = N->getOperand(0);
985 EVT VT = N->getValueType(0);
986 bool is64BitVector = VT.is64BitVector();
988 unsigned OpcodeIndex;
989 switch (VT.getSimpleVT().SimpleTy) {
990 default: llvm_unreachable("unhandled vld type");
991 // Double-register operations:
992 case MVT::v8i8: OpcodeIndex = 0; break;
993 case MVT::v4i16: OpcodeIndex = 1; break;
995 case MVT::v2i32: OpcodeIndex = 2; break;
996 case MVT::v1i64: OpcodeIndex = 3; break;
997 // Quad-register operations:
998 case MVT::v16i8: OpcodeIndex = 0; break;
999 case MVT::v8i16: OpcodeIndex = 1; break;
1001 case MVT::v4i32: OpcodeIndex = 2; break;
1002 case MVT::v2i64: OpcodeIndex = 3;
1003 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
1007 SDValue Pred = getAL(CurDAG);
1008 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1009 if (is64BitVector) {
1010 unsigned Opc = DOpcodes[OpcodeIndex];
1011 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1012 std::vector<EVT> ResTys(NumVecs, VT);
1013 ResTys.push_back(MVT::Other);
1014 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1017 EVT RegVT = GetNEONSubregVT(VT);
1019 // Quad registers are directly supported for VLD1 and VLD2,
1020 // loading pairs of D regs.
1021 unsigned Opc = QOpcodes0[OpcodeIndex];
1022 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1023 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
1024 ResTys.push_back(MVT::Other);
1025 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1026 Chain = SDValue(VLd, 2 * NumVecs);
1028 // Combine the even and odd subregs to produce the result.
1029 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1030 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1031 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1034 // Otherwise, quad registers are loaded with two separate instructions,
1035 // where one loads the even registers and the other loads the odd registers.
1037 std::vector<EVT> ResTys(NumVecs, RegVT);
1038 ResTys.push_back(MemAddr.getValueType());
1039 ResTys.push_back(MVT::Other);
1041 // Load the even subregs.
1042 unsigned Opc = QOpcodes0[OpcodeIndex];
1043 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1044 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
1045 Chain = SDValue(VLdA, NumVecs+1);
1047 // Load the odd subregs.
1048 Opc = QOpcodes1[OpcodeIndex];
1049 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1050 Align, Reg0, Pred, Reg0, Chain };
1051 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
1052 Chain = SDValue(VLdB, NumVecs+1);
1054 // Combine the even and odd subregs to produce the result.
1055 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1056 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1057 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1060 ReplaceUses(SDValue(N, NumVecs), Chain);
1064 SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
1065 unsigned *DOpcodes, unsigned *QOpcodes0,
1066 unsigned *QOpcodes1) {
1067 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
1068 DebugLoc dl = N->getDebugLoc();
1070 SDValue MemAddr, Align;
1071 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1074 SDValue Chain = N->getOperand(0);
1075 EVT VT = N->getOperand(3).getValueType();
1076 bool is64BitVector = VT.is64BitVector();
1078 unsigned OpcodeIndex;
1079 switch (VT.getSimpleVT().SimpleTy) {
1080 default: llvm_unreachable("unhandled vst type");
1081 // Double-register operations:
1082 case MVT::v8i8: OpcodeIndex = 0; break;
1083 case MVT::v4i16: OpcodeIndex = 1; break;
1085 case MVT::v2i32: OpcodeIndex = 2; break;
1086 case MVT::v1i64: OpcodeIndex = 3; break;
1087 // Quad-register operations:
1088 case MVT::v16i8: OpcodeIndex = 0; break;
1089 case MVT::v8i16: OpcodeIndex = 1; break;
1091 case MVT::v4i32: OpcodeIndex = 2; break;
1092 case MVT::v2i64: OpcodeIndex = 3;
1093 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1097 SDValue Pred = getAL(CurDAG);
1098 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1100 SmallVector<SDValue, 10> Ops;
1101 Ops.push_back(MemAddr);
1102 Ops.push_back(Align);
1104 if (is64BitVector) {
1105 unsigned Opc = DOpcodes[OpcodeIndex];
1106 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1107 Ops.push_back(N->getOperand(Vec+3));
1108 Ops.push_back(Pred);
1109 Ops.push_back(Reg0); // predicate register
1110 Ops.push_back(Chain);
1111 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
1114 EVT RegVT = GetNEONSubregVT(VT);
1116 // Quad registers are directly supported for VST1 and VST2,
1117 // storing pairs of D regs.
1118 unsigned Opc = QOpcodes0[OpcodeIndex];
1119 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1120 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1121 N->getOperand(Vec+3)));
1122 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1123 N->getOperand(Vec+3)));
1125 Ops.push_back(Pred);
1126 Ops.push_back(Reg0); // predicate register
1127 Ops.push_back(Chain);
1128 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1132 // Otherwise, quad registers are stored with two separate instructions,
1133 // where one stores the even registers and the other stores the odd registers.
1135 Ops.push_back(Reg0); // post-access address offset
1137 // Store the even subregs.
1138 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1139 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1140 N->getOperand(Vec+3)));
1141 Ops.push_back(Pred);
1142 Ops.push_back(Reg0); // predicate register
1143 Ops.push_back(Chain);
1144 unsigned Opc = QOpcodes0[OpcodeIndex];
1145 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1146 MVT::Other, Ops.data(), NumVecs+6);
1147 Chain = SDValue(VStA, 1);
1149 // Store the odd subregs.
1150 Ops[0] = SDValue(VStA, 0); // MemAddr
1151 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1152 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1153 N->getOperand(Vec+3));
1154 Ops[NumVecs+5] = Chain;
1155 Opc = QOpcodes1[OpcodeIndex];
1156 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1157 MVT::Other, Ops.data(), NumVecs+6);
1158 Chain = SDValue(VStB, 1);
1159 ReplaceUses(SDValue(N, 0), Chain);
1163 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
1164 unsigned NumVecs, unsigned *DOpcodes,
1165 unsigned *QOpcodes0,
1166 unsigned *QOpcodes1) {
1167 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1168 DebugLoc dl = N->getDebugLoc();
1170 SDValue MemAddr, Align;
1171 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1174 SDValue Chain = N->getOperand(0);
1176 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
1177 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
1178 bool is64BitVector = VT.is64BitVector();
1180 // Quad registers are handled by load/store of subregs. Find the subreg info.
1181 unsigned NumElts = 0;
1184 if (!is64BitVector) {
1185 RegVT = GetNEONSubregVT(VT);
1186 NumElts = RegVT.getVectorNumElements();
1187 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1190 unsigned OpcodeIndex;
1191 switch (VT.getSimpleVT().SimpleTy) {
1192 default: llvm_unreachable("unhandled vld/vst lane type");
1193 // Double-register operations:
1194 case MVT::v8i8: OpcodeIndex = 0; break;
1195 case MVT::v4i16: OpcodeIndex = 1; break;
1197 case MVT::v2i32: OpcodeIndex = 2; break;
1198 // Quad-register operations:
1199 case MVT::v8i16: OpcodeIndex = 0; break;
1201 case MVT::v4i32: OpcodeIndex = 1; break;
1204 SDValue Pred = getAL(CurDAG);
1205 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1207 SmallVector<SDValue, 10> Ops;
1208 Ops.push_back(MemAddr);
1209 Ops.push_back(Align);
1212 if (is64BitVector) {
1213 Opc = DOpcodes[OpcodeIndex];
1214 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1215 Ops.push_back(N->getOperand(Vec+3));
1217 // Check if this is loading the even or odd subreg of a Q register.
1218 if (Lane < NumElts) {
1219 Opc = QOpcodes0[OpcodeIndex];
1222 Opc = QOpcodes1[OpcodeIndex];
1224 // Extract the subregs of the input vector.
1225 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1226 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1227 N->getOperand(Vec+3)));
1229 Ops.push_back(getI32Imm(Lane));
1230 Ops.push_back(Pred);
1231 Ops.push_back(Reg0);
1232 Ops.push_back(Chain);
1235 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
1237 std::vector<EVT> ResTys(NumVecs, RegVT);
1238 ResTys.push_back(MVT::Other);
1240 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
1241 // For a 64-bit vector load to D registers, nothing more needs to be done.
1245 // For 128-bit vectors, take the 64-bit results of the load and insert them
1246 // as subregs into the result.
1247 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1248 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1249 N->getOperand(Vec+3),
1250 SDValue(VLdLn, Vec));
1251 ReplaceUses(SDValue(N, Vec), QuadVec);
1254 Chain = SDValue(VLdLn, NumVecs);
1255 ReplaceUses(SDValue(N, NumVecs), Chain);
1259 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
1261 if (!Subtarget->hasV6T2Ops())
1264 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1265 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1268 // For unsigned extracts, check for a shift right and mask
1269 unsigned And_imm = 0;
1270 if (N->getOpcode() == ISD::AND) {
1271 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1273 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1274 if (And_imm & (And_imm + 1))
1277 unsigned Srl_imm = 0;
1278 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1280 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1282 unsigned Width = CountTrailingOnes_32(And_imm);
1283 unsigned LSB = Srl_imm;
1284 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1285 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1286 CurDAG->getTargetConstant(LSB, MVT::i32),
1287 CurDAG->getTargetConstant(Width, MVT::i32),
1288 getAL(CurDAG), Reg0 };
1289 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1295 // Otherwise, we're looking for a shift of a shift
1296 unsigned Shl_imm = 0;
1297 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
1298 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1299 unsigned Srl_imm = 0;
1300 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
1301 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1302 unsigned Width = 32 - Srl_imm;
1303 int LSB = Srl_imm - Shl_imm;
1306 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1307 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1308 CurDAG->getTargetConstant(LSB, MVT::i32),
1309 CurDAG->getTargetConstant(Width, MVT::i32),
1310 getAL(CurDAG), Reg0 };
1311 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1317 SDNode *ARMDAGToDAGISel::
1318 SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1319 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1322 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
1323 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1324 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1327 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1328 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1329 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1330 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1332 llvm_unreachable("Unknown so_reg opcode!");
1336 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1337 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1338 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
1339 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
1344 SDNode *ARMDAGToDAGISel::
1345 SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1346 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1350 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
1351 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1352 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
1353 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
1358 SDNode *ARMDAGToDAGISel::
1359 SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1360 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1361 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1365 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1366 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1367 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1368 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1369 return CurDAG->SelectNodeTo(N,
1370 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1375 SDNode *ARMDAGToDAGISel::
1376 SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1377 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1378 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1382 if (Predicate_so_imm(TrueVal.getNode())) {
1383 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1384 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1385 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1386 return CurDAG->SelectNodeTo(N,
1387 ARM::MOVCCi, MVT::i32, Ops, 5);
1392 SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1393 EVT VT = N->getValueType(0);
1394 SDValue FalseVal = N->getOperand(0);
1395 SDValue TrueVal = N->getOperand(1);
1396 SDValue CC = N->getOperand(2);
1397 SDValue CCR = N->getOperand(3);
1398 SDValue InFlag = N->getOperand(4);
1399 assert(CC.getOpcode() == ISD::Constant);
1400 assert(CCR.getOpcode() == ISD::Register);
1401 ARMCC::CondCodes CCVal =
1402 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
1404 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1405 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1406 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1407 // Pattern complexity = 18 cost = 1 size = 0
1411 if (Subtarget->isThumb()) {
1412 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
1413 CCVal, CCR, InFlag);
1415 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
1416 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1420 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
1421 CCVal, CCR, InFlag);
1423 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
1424 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1429 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1430 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1432 // Emits: (MOVCCi:i32 GPR:i32:$false,
1433 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1434 // Pattern complexity = 10 cost = 1 size = 0
1435 if (Subtarget->isThumb()) {
1436 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
1437 CCVal, CCR, InFlag);
1439 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
1440 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1444 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
1445 CCVal, CCR, InFlag);
1447 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
1448 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1454 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1455 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1456 // Pattern complexity = 6 cost = 1 size = 0
1458 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1459 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1460 // Pattern complexity = 6 cost = 11 size = 0
1462 // Also FCPYScc and FCPYDcc.
1463 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1464 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
1466 switch (VT.getSimpleVT().SimpleTy) {
1467 default: assert(false && "Illegal conditional move type!");
1470 Opc = Subtarget->isThumb()
1471 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1481 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
1484 SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
1485 DebugLoc dl = N->getDebugLoc();
1487 if (N->isMachineOpcode())
1488 return NULL; // Already selected.
1490 switch (N->getOpcode()) {
1492 case ISD::Constant: {
1493 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
1495 if (Subtarget->hasThumb2())
1496 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1497 // be done with MOV + MOVT, at worst.
1500 if (Subtarget->isThumb()) {
1501 UseCP = (Val > 255 && // MOV
1502 ~Val > 255 && // MOV + MVN
1503 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
1505 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1506 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1507 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1512 CurDAG->getTargetConstantPool(ConstantInt::get(
1513 Type::getInt32Ty(*CurDAG->getContext()), Val),
1514 TLI.getPointerTy());
1517 if (Subtarget->isThumb1Only()) {
1518 SDValue Pred = getAL(CurDAG);
1519 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1520 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
1521 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1526 CurDAG->getRegister(0, MVT::i32),
1527 CurDAG->getTargetConstant(0, MVT::i32),
1529 CurDAG->getRegister(0, MVT::i32),
1530 CurDAG->getEntryNode()
1532 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1535 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
1539 // Other cases are autogenerated.
1542 case ISD::FrameIndex: {
1543 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
1544 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1545 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1546 if (Subtarget->isThumb1Only()) {
1547 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1548 CurDAG->getTargetConstant(0, MVT::i32));
1550 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1551 ARM::t2ADDri : ARM::ADDri);
1552 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1553 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1554 CurDAG->getRegister(0, MVT::i32) };
1555 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1559 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1563 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
1567 if (Subtarget->isThumb1Only())
1569 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1570 unsigned RHSV = C->getZExtValue();
1572 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
1573 unsigned ShImm = Log2_32(RHSV-1);
1576 SDValue V = N->getOperand(0);
1577 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1578 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1579 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1580 if (Subtarget->isThumb()) {
1581 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1582 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
1584 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1585 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
1588 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
1589 unsigned ShImm = Log2_32(RHSV+1);
1592 SDValue V = N->getOperand(0);
1593 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1594 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1595 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1596 if (Subtarget->isThumb()) {
1597 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
1598 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
1600 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1601 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
1607 // Check for unsigned bitfield extract
1608 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1611 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1612 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1613 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1614 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1615 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
1616 EVT VT = N->getValueType(0);
1619 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1621 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1624 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
1625 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1628 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1629 SDValue N2 = N0.getOperand(1);
1630 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1633 unsigned N1CVal = N1C->getZExtValue();
1634 unsigned N2CVal = N2C->getZExtValue();
1635 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1636 (N1CVal & 0xffffU) == 0xffffU &&
1637 (N2CVal & 0xffffU) == 0x0U) {
1638 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1640 SDValue Ops[] = { N0.getOperand(0), Imm16,
1641 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1642 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1647 case ARMISD::VMOVRRD:
1648 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
1649 N->getOperand(0), getAL(CurDAG),
1650 CurDAG->getRegister(0, MVT::i32));
1651 case ISD::UMUL_LOHI: {
1652 if (Subtarget->isThumb1Only())
1654 if (Subtarget->isThumb()) {
1655 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
1656 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1657 CurDAG->getRegister(0, MVT::i32) };
1658 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
1660 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
1661 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1662 CurDAG->getRegister(0, MVT::i32) };
1663 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1666 case ISD::SMUL_LOHI: {
1667 if (Subtarget->isThumb1Only())
1669 if (Subtarget->isThumb()) {
1670 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
1671 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1672 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
1674 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
1675 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1676 CurDAG->getRegister(0, MVT::i32) };
1677 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1681 SDNode *ResNode = 0;
1682 if (Subtarget->isThumb() && Subtarget->hasThumb2())
1683 ResNode = SelectT2IndexedLoad(N);
1685 ResNode = SelectARMIndexedLoad(N);
1689 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1690 if (Subtarget->hasVFP2() &&
1691 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1692 SDValue Chain = N->getOperand(0);
1694 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
1695 SDValue Pred = getAL(CurDAG);
1696 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1697 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1698 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1701 // Other cases are autogenerated.
1705 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1706 if (Subtarget->hasVFP2() &&
1707 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1708 SDValue Chain = N->getOperand(0);
1710 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
1711 SDValue Pred = getAL(CurDAG);
1712 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1713 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1714 AM5Opc, Pred, PredReg, Chain };
1715 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1717 // Other cases are autogenerated.
1720 case ARMISD::BRCOND: {
1721 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1722 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1723 // Pattern complexity = 6 cost = 1 size = 0
1725 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1726 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1727 // Pattern complexity = 6 cost = 1 size = 0
1729 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1730 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1731 // Pattern complexity = 6 cost = 1 size = 0
1733 unsigned Opc = Subtarget->isThumb() ?
1734 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
1735 SDValue Chain = N->getOperand(0);
1736 SDValue N1 = N->getOperand(1);
1737 SDValue N2 = N->getOperand(2);
1738 SDValue N3 = N->getOperand(3);
1739 SDValue InFlag = N->getOperand(4);
1740 assert(N1.getOpcode() == ISD::BasicBlock);
1741 assert(N2.getOpcode() == ISD::Constant);
1742 assert(N3.getOpcode() == ISD::Register);
1744 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1745 cast<ConstantSDNode>(N2)->getZExtValue()),
1747 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
1748 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1750 Chain = SDValue(ResNode, 0);
1751 if (N->getNumValues() == 2) {
1752 InFlag = SDValue(ResNode, 1);
1753 ReplaceUses(SDValue(N, 1), InFlag);
1755 ReplaceUses(SDValue(N, 0),
1756 SDValue(Chain.getNode(), Chain.getResNo()));
1760 return SelectCMOVOp(N);
1761 case ARMISD::CNEG: {
1762 EVT VT = N->getValueType(0);
1763 SDValue N0 = N->getOperand(0);
1764 SDValue N1 = N->getOperand(1);
1765 SDValue N2 = N->getOperand(2);
1766 SDValue N3 = N->getOperand(3);
1767 SDValue InFlag = N->getOperand(4);
1768 assert(N2.getOpcode() == ISD::Constant);
1769 assert(N3.getOpcode() == ISD::Register);
1771 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1772 cast<ConstantSDNode>(N2)->getZExtValue()),
1774 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
1776 switch (VT.getSimpleVT().SimpleTy) {
1777 default: assert(false && "Illegal conditional move type!");
1786 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
1789 case ARMISD::VZIP: {
1791 EVT VT = N->getValueType(0);
1792 switch (VT.getSimpleVT().SimpleTy) {
1793 default: return NULL;
1794 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1795 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1797 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1798 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1799 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1801 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1803 SDValue Pred = getAL(CurDAG);
1804 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1805 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1806 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
1808 case ARMISD::VUZP: {
1810 EVT VT = N->getValueType(0);
1811 switch (VT.getSimpleVT().SimpleTy) {
1812 default: return NULL;
1813 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1814 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1816 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1817 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1818 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1820 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1822 SDValue Pred = getAL(CurDAG);
1823 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1824 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1825 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
1827 case ARMISD::VTRN: {
1829 EVT VT = N->getValueType(0);
1830 switch (VT.getSimpleVT().SimpleTy) {
1831 default: return NULL;
1832 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1833 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1835 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1836 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1837 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1839 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1841 SDValue Pred = getAL(CurDAG);
1842 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1843 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1844 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
1847 case ISD::INTRINSIC_VOID:
1848 case ISD::INTRINSIC_W_CHAIN: {
1849 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
1854 case Intrinsic::arm_neon_vld1: {
1855 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1856 ARM::VLD1d32, ARM::VLD1d64 };
1857 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1858 ARM::VLD1q32, ARM::VLD1q64 };
1859 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1862 case Intrinsic::arm_neon_vld2: {
1863 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1864 ARM::VLD2d32, ARM::VLD1q64 };
1865 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
1866 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
1869 case Intrinsic::arm_neon_vld3: {
1870 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1871 ARM::VLD3d32, ARM::VLD1d64T };
1872 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1875 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1876 ARM::VLD3q16odd_UPD,
1877 ARM::VLD3q32odd_UPD };
1878 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
1881 case Intrinsic::arm_neon_vld4: {
1882 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
1883 ARM::VLD4d32, ARM::VLD1d64Q };
1884 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1887 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1888 ARM::VLD4q16odd_UPD,
1889 ARM::VLD4q32odd_UPD };
1890 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
1893 case Intrinsic::arm_neon_vld2lane: {
1894 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
1895 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1896 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
1897 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
1900 case Intrinsic::arm_neon_vld3lane: {
1901 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
1902 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1903 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
1904 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
1907 case Intrinsic::arm_neon_vld4lane: {
1908 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
1909 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1910 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
1911 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
1914 case Intrinsic::arm_neon_vst1: {
1915 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
1916 ARM::VST1d32, ARM::VST1d64 };
1917 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
1918 ARM::VST1q32, ARM::VST1q64 };
1919 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
1922 case Intrinsic::arm_neon_vst2: {
1923 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1924 ARM::VST2d32, ARM::VST1q64 };
1925 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
1926 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
1929 case Intrinsic::arm_neon_vst3: {
1930 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1931 ARM::VST3d32, ARM::VST1d64T };
1932 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1935 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1936 ARM::VST3q16odd_UPD,
1937 ARM::VST3q32odd_UPD };
1938 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
1941 case Intrinsic::arm_neon_vst4: {
1942 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1943 ARM::VST4d32, ARM::VST1d64Q };
1944 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1947 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1948 ARM::VST4q16odd_UPD,
1949 ARM::VST4q32odd_UPD };
1950 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
1953 case Intrinsic::arm_neon_vst2lane: {
1954 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
1955 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1956 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
1957 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
1960 case Intrinsic::arm_neon_vst3lane: {
1961 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
1962 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1963 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
1964 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
1967 case Intrinsic::arm_neon_vst4lane: {
1968 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
1969 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1970 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
1971 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
1977 return SelectCode(N);
1980 bool ARMDAGToDAGISel::
1981 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1982 std::vector<SDValue> &OutOps) {
1983 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
1984 // Require the address to be in a register. That is safe for all ARM
1985 // variants and it is hard to do anything much smarter without knowing
1986 // how the operand is used.
1987 OutOps.push_back(Op);
1991 /// createARMISelDag - This pass converts a legalized DAG into a
1992 /// ARM-specific DAG, ready for instruction scheduling.
1994 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1995 CodeGenOpt::Level OptLevel) {
1996 return new ARMDAGToDAGISel(TM, OptLevel);