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 "ARMConstantPoolValue.h"
17 #include "ARMISelLowering.h"
18 #include "ARMTargetMachine.h"
19 #include "llvm/CallingConv.h"
20 #include "llvm/Constants.h"
21 #include "llvm/DerivedTypes.h"
22 #include "llvm/Function.h"
23 #include "llvm/Intrinsics.h"
24 #include "llvm/LLVMContext.h"
25 #include "llvm/CodeGen/MachineFrameInfo.h"
26 #include "llvm/CodeGen/MachineFunction.h"
27 #include "llvm/CodeGen/MachineInstrBuilder.h"
28 #include "llvm/CodeGen/SelectionDAG.h"
29 #include "llvm/CodeGen/SelectionDAGISel.h"
30 #include "llvm/Target/TargetLowering.h"
31 #include "llvm/Target/TargetOptions.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"
39 //===--------------------------------------------------------------------===//
40 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
41 /// instructions for SelectionDAG operations.
44 class ARMDAGToDAGISel : public SelectionDAGISel {
45 ARMBaseTargetMachine &TM;
47 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
48 /// make the right decision when generating code for different targets.
49 const ARMSubtarget *Subtarget;
52 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
53 CodeGenOpt::Level OptLevel)
54 : SelectionDAGISel(tm, OptLevel), TM(tm),
55 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
58 virtual const char *getPassName() const {
59 return "ARM Instruction Selection";
62 /// getI32Imm - Return a target constant of type i32 with the specified
64 inline SDValue getI32Imm(unsigned Imm) {
65 return CurDAG->getTargetConstant(Imm, MVT::i32);
68 SDNode *Select(SDValue Op);
69 virtual void InstructionSelect();
70 bool SelectShifterOperandReg(SDValue Op, SDValue N, SDValue &A,
71 SDValue &B, SDValue &C);
72 bool SelectAddrMode2(SDValue Op, SDValue N, SDValue &Base,
73 SDValue &Offset, SDValue &Opc);
74 bool SelectAddrMode2Offset(SDValue Op, SDValue N,
75 SDValue &Offset, SDValue &Opc);
76 bool SelectAddrMode3(SDValue Op, SDValue N, SDValue &Base,
77 SDValue &Offset, SDValue &Opc);
78 bool SelectAddrMode3Offset(SDValue Op, SDValue N,
79 SDValue &Offset, SDValue &Opc);
80 bool SelectAddrMode4(SDValue Op, SDValue N, SDValue &Addr,
82 bool SelectAddrMode5(SDValue Op, SDValue N, SDValue &Base,
84 bool SelectAddrMode6(SDValue Op, SDValue N, SDValue &Addr, SDValue &Update,
87 bool SelectAddrModePC(SDValue Op, SDValue N, SDValue &Offset,
90 bool SelectThumbAddrModeRR(SDValue Op, SDValue N, SDValue &Base,
92 bool SelectThumbAddrModeRI5(SDValue Op, SDValue N, unsigned Scale,
93 SDValue &Base, SDValue &OffImm,
95 bool SelectThumbAddrModeS1(SDValue Op, SDValue N, SDValue &Base,
96 SDValue &OffImm, SDValue &Offset);
97 bool SelectThumbAddrModeS2(SDValue Op, SDValue N, SDValue &Base,
98 SDValue &OffImm, SDValue &Offset);
99 bool SelectThumbAddrModeS4(SDValue Op, SDValue N, SDValue &Base,
100 SDValue &OffImm, SDValue &Offset);
101 bool SelectThumbAddrModeSP(SDValue Op, SDValue N, SDValue &Base,
104 bool SelectT2ShifterOperandReg(SDValue Op, SDValue N,
105 SDValue &BaseReg, SDValue &Opc);
106 bool SelectT2AddrModeImm12(SDValue Op, SDValue N, SDValue &Base,
108 bool SelectT2AddrModeImm8(SDValue Op, SDValue N, SDValue &Base,
110 bool SelectT2AddrModeImm8Offset(SDValue Op, SDValue N,
112 bool SelectT2AddrModeImm8s4(SDValue Op, SDValue N, SDValue &Base,
114 bool SelectT2AddrModeSoReg(SDValue Op, SDValue N, SDValue &Base,
115 SDValue &OffReg, SDValue &ShImm);
117 // Include the pieces autogenerated from the target description.
118 #include "ARMGenDAGISel.inc"
121 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
123 SDNode *SelectARMIndexedLoad(SDValue Op);
124 SDNode *SelectT2IndexedLoad(SDValue Op);
126 /// SelectDYN_ALLOC - Select dynamic alloc for Thumb.
127 SDNode *SelectDYN_ALLOC(SDValue Op);
129 /// SelectVLD - Select NEON load intrinsics. NumVecs should
130 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
131 /// loads of D registers and even subregs and odd subregs of Q registers.
132 /// For NumVecs == 2, QOpcodes1 is not used.
133 SDNode *SelectVLD(SDValue Op, unsigned NumVecs, unsigned *DOpcodes,
134 unsigned *QOpcodes0, unsigned *QOpcodes1);
136 /// SelectVST - Select NEON store intrinsics. NumVecs should
137 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
138 /// stores of D registers and even subregs and odd subregs of Q registers.
139 /// For NumVecs == 2, QOpcodes1 is not used.
140 SDNode *SelectVST(SDValue Op, unsigned NumVecs, unsigned *DOpcodes,
141 unsigned *QOpcodes0, unsigned *QOpcodes1);
143 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
144 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
145 /// load/store of D registers and even subregs and odd subregs of Q registers.
146 SDNode *SelectVLDSTLane(SDValue Op, bool IsLoad, unsigned NumVecs,
147 unsigned *DOpcodes, unsigned *QOpcodes0,
148 unsigned *QOpcodes1);
150 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
151 SDNode *SelectV6T2BitfieldExtractOp(SDValue Op, unsigned Opc);
153 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
154 /// inline asm expressions.
155 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
157 std::vector<SDValue> &OutOps);
159 /// PairDRegs - Insert a pair of double registers into an implicit def to
160 /// form a quad register.
161 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
165 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
166 /// operand. If so Imm will receive the 32-bit value.
167 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
168 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
169 Imm = cast<ConstantSDNode>(N)->getZExtValue();
175 // isInt32Immediate - This method tests to see if a constant operand.
176 // If so Imm will receive the 32 bit value.
177 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
178 return isInt32Immediate(N.getNode(), Imm);
181 // isOpcWithIntImmediate - This method tests to see if the node is a specific
182 // opcode and that it has a immediate integer right operand.
183 // If so Imm will receive the 32 bit value.
184 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
185 return N->getOpcode() == Opc &&
186 isInt32Immediate(N->getOperand(1).getNode(), Imm);
190 void ARMDAGToDAGISel::InstructionSelect() {
194 CurDAG->RemoveDeadNodes();
197 bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue Op,
202 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
204 // Don't match base register only case. That is matched to a separate
205 // lower complexity pattern with explicit register operand.
206 if (ShOpcVal == ARM_AM::no_shift) return false;
208 BaseReg = N.getOperand(0);
209 unsigned ShImmVal = 0;
210 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
211 ShReg = CurDAG->getRegister(0, MVT::i32);
212 ShImmVal = RHS->getZExtValue() & 31;
214 ShReg = N.getOperand(1);
216 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
221 bool ARMDAGToDAGISel::SelectAddrMode2(SDValue Op, SDValue N,
222 SDValue &Base, SDValue &Offset,
224 if (N.getOpcode() == ISD::MUL) {
225 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
226 // X * [3,5,9] -> X + X * [2,4,8] etc.
227 int RHSC = (int)RHS->getZExtValue();
230 ARM_AM::AddrOpc AddSub = ARM_AM::add;
232 AddSub = ARM_AM::sub;
235 if (isPowerOf2_32(RHSC)) {
236 unsigned ShAmt = Log2_32(RHSC);
237 Base = Offset = N.getOperand(0);
238 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
247 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
249 if (N.getOpcode() == ISD::FrameIndex) {
250 int FI = cast<FrameIndexSDNode>(N)->getIndex();
251 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
252 } else if (N.getOpcode() == ARMISD::Wrapper) {
253 Base = N.getOperand(0);
255 Offset = CurDAG->getRegister(0, MVT::i32);
256 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
262 // Match simple R +/- imm12 operands.
263 if (N.getOpcode() == ISD::ADD)
264 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
265 int RHSC = (int)RHS->getZExtValue();
266 if ((RHSC >= 0 && RHSC < 0x1000) ||
267 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
268 Base = N.getOperand(0);
269 if (Base.getOpcode() == ISD::FrameIndex) {
270 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
271 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
273 Offset = CurDAG->getRegister(0, MVT::i32);
275 ARM_AM::AddrOpc AddSub = ARM_AM::add;
277 AddSub = ARM_AM::sub;
280 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
287 // Otherwise this is R +/- [possibly shifted] R.
288 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
289 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
292 Base = N.getOperand(0);
293 Offset = N.getOperand(1);
295 if (ShOpcVal != ARM_AM::no_shift) {
296 // Check to see if the RHS of the shift is a constant, if not, we can't fold
298 if (ConstantSDNode *Sh =
299 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
300 ShAmt = Sh->getZExtValue();
301 Offset = N.getOperand(1).getOperand(0);
303 ShOpcVal = ARM_AM::no_shift;
307 // Try matching (R shl C) + (R).
308 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
309 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
310 if (ShOpcVal != ARM_AM::no_shift) {
311 // Check to see if the RHS of the shift is a constant, if not, we can't
313 if (ConstantSDNode *Sh =
314 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
315 ShAmt = Sh->getZExtValue();
316 Offset = N.getOperand(0).getOperand(0);
317 Base = N.getOperand(1);
319 ShOpcVal = ARM_AM::no_shift;
324 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
329 bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDValue Op, SDValue N,
330 SDValue &Offset, SDValue &Opc) {
331 unsigned Opcode = Op.getOpcode();
332 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
333 ? cast<LoadSDNode>(Op)->getAddressingMode()
334 : cast<StoreSDNode>(Op)->getAddressingMode();
335 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
336 ? ARM_AM::add : ARM_AM::sub;
337 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
338 int Val = (int)C->getZExtValue();
339 if (Val >= 0 && Val < 0x1000) { // 12 bits.
340 Offset = CurDAG->getRegister(0, MVT::i32);
341 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
349 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
351 if (ShOpcVal != ARM_AM::no_shift) {
352 // Check to see if the RHS of the shift is a constant, if not, we can't fold
354 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
355 ShAmt = Sh->getZExtValue();
356 Offset = N.getOperand(0);
358 ShOpcVal = ARM_AM::no_shift;
362 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
368 bool ARMDAGToDAGISel::SelectAddrMode3(SDValue Op, SDValue N,
369 SDValue &Base, SDValue &Offset,
371 if (N.getOpcode() == ISD::SUB) {
372 // X - C is canonicalize to X + -C, no need to handle it here.
373 Base = N.getOperand(0);
374 Offset = N.getOperand(1);
375 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
379 if (N.getOpcode() != ISD::ADD) {
381 if (N.getOpcode() == ISD::FrameIndex) {
382 int FI = cast<FrameIndexSDNode>(N)->getIndex();
383 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
385 Offset = CurDAG->getRegister(0, MVT::i32);
386 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
390 // If the RHS is +/- imm8, fold into addr mode.
391 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
392 int RHSC = (int)RHS->getZExtValue();
393 if ((RHSC >= 0 && RHSC < 256) ||
394 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
395 Base = N.getOperand(0);
396 if (Base.getOpcode() == ISD::FrameIndex) {
397 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
398 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
400 Offset = CurDAG->getRegister(0, MVT::i32);
402 ARM_AM::AddrOpc AddSub = ARM_AM::add;
404 AddSub = ARM_AM::sub;
407 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
412 Base = N.getOperand(0);
413 Offset = N.getOperand(1);
414 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
418 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDValue Op, SDValue N,
419 SDValue &Offset, SDValue &Opc) {
420 unsigned Opcode = Op.getOpcode();
421 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
422 ? cast<LoadSDNode>(Op)->getAddressingMode()
423 : cast<StoreSDNode>(Op)->getAddressingMode();
424 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
425 ? ARM_AM::add : ARM_AM::sub;
426 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
427 int Val = (int)C->getZExtValue();
428 if (Val >= 0 && Val < 256) {
429 Offset = CurDAG->getRegister(0, MVT::i32);
430 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
436 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
440 bool ARMDAGToDAGISel::SelectAddrMode4(SDValue Op, SDValue N,
441 SDValue &Addr, SDValue &Mode) {
443 Mode = CurDAG->getTargetConstant(0, MVT::i32);
447 bool ARMDAGToDAGISel::SelectAddrMode5(SDValue Op, SDValue N,
448 SDValue &Base, SDValue &Offset) {
449 if (N.getOpcode() != ISD::ADD) {
451 if (N.getOpcode() == ISD::FrameIndex) {
452 int FI = cast<FrameIndexSDNode>(N)->getIndex();
453 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
454 } else if (N.getOpcode() == ARMISD::Wrapper) {
455 Base = N.getOperand(0);
457 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
462 // If the RHS is +/- imm8, fold into addr mode.
463 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
464 int RHSC = (int)RHS->getZExtValue();
465 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
467 if ((RHSC >= 0 && RHSC < 256) ||
468 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
469 Base = N.getOperand(0);
470 if (Base.getOpcode() == ISD::FrameIndex) {
471 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
472 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
475 ARM_AM::AddrOpc AddSub = ARM_AM::add;
477 AddSub = ARM_AM::sub;
480 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
488 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
493 bool ARMDAGToDAGISel::SelectAddrMode6(SDValue Op, SDValue N,
494 SDValue &Addr, SDValue &Update,
497 // Default to no writeback.
498 Update = CurDAG->getRegister(0, MVT::i32);
499 Opc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(false), MVT::i32);
503 bool ARMDAGToDAGISel::SelectAddrModePC(SDValue Op, SDValue N,
504 SDValue &Offset, SDValue &Label) {
505 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
506 Offset = N.getOperand(0);
507 SDValue N1 = N.getOperand(1);
508 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
515 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue Op, SDValue N,
516 SDValue &Base, SDValue &Offset){
517 // FIXME dl should come from the parent load or store, not the address
518 DebugLoc dl = Op.getDebugLoc();
519 if (N.getOpcode() != ISD::ADD) {
520 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
521 if (!NC || NC->getZExtValue() != 0)
528 Base = N.getOperand(0);
529 Offset = N.getOperand(1);
534 ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue Op, SDValue N,
535 unsigned Scale, SDValue &Base,
536 SDValue &OffImm, SDValue &Offset) {
538 SDValue TmpBase, TmpOffImm;
539 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
540 return false; // We want to select tLDRspi / tSTRspi instead.
541 if (N.getOpcode() == ARMISD::Wrapper &&
542 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
543 return false; // We want to select tLDRpci instead.
546 if (N.getOpcode() != ISD::ADD) {
547 Base = (N.getOpcode() == ARMISD::Wrapper) ? N.getOperand(0) : N;
548 Offset = CurDAG->getRegister(0, MVT::i32);
549 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
553 // Thumb does not have [sp, r] address mode.
554 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
555 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
556 if ((LHSR && LHSR->getReg() == ARM::SP) ||
557 (RHSR && RHSR->getReg() == ARM::SP)) {
559 Offset = CurDAG->getRegister(0, MVT::i32);
560 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
564 // If the RHS is + imm5 * scale, fold into addr mode.
565 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
566 int RHSC = (int)RHS->getZExtValue();
567 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
569 if (RHSC >= 0 && RHSC < 32) {
570 Base = N.getOperand(0);
571 Offset = CurDAG->getRegister(0, MVT::i32);
572 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
578 Base = N.getOperand(0);
579 Offset = N.getOperand(1);
580 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
584 bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue Op, SDValue N,
585 SDValue &Base, SDValue &OffImm,
587 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
590 bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue Op, SDValue N,
591 SDValue &Base, SDValue &OffImm,
593 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
596 bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue Op, SDValue N,
597 SDValue &Base, SDValue &OffImm,
599 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
602 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue Op, SDValue N,
603 SDValue &Base, SDValue &OffImm) {
604 if (N.getOpcode() == ISD::FrameIndex) {
605 int FI = cast<FrameIndexSDNode>(N)->getIndex();
606 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
607 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
611 if (N.getOpcode() != ISD::ADD)
614 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
615 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
616 (LHSR && LHSR->getReg() == ARM::SP)) {
617 // If the RHS is + imm8 * scale, fold into addr mode.
618 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
619 int RHSC = (int)RHS->getZExtValue();
620 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
622 if (RHSC >= 0 && RHSC < 256) {
623 Base = N.getOperand(0);
624 if (Base.getOpcode() == ISD::FrameIndex) {
625 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
626 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
628 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
638 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue Op, SDValue N,
641 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
643 // Don't match base register only case. That is matched to a separate
644 // lower complexity pattern with explicit register operand.
645 if (ShOpcVal == ARM_AM::no_shift) return false;
647 BaseReg = N.getOperand(0);
648 unsigned ShImmVal = 0;
649 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
650 ShImmVal = RHS->getZExtValue() & 31;
651 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
658 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue Op, SDValue N,
659 SDValue &Base, SDValue &OffImm) {
660 // Match simple R + imm12 operands.
663 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
664 if (N.getOpcode() == ISD::FrameIndex) {
665 // Match frame index...
666 int FI = cast<FrameIndexSDNode>(N)->getIndex();
667 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
668 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
670 } else if (N.getOpcode() == ARMISD::Wrapper) {
671 Base = N.getOperand(0);
672 if (Base.getOpcode() == ISD::TargetConstantPool)
673 return false; // We want to select t2LDRpci instead.
676 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
680 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
681 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
682 // Let t2LDRi8 handle (R - imm8).
685 int RHSC = (int)RHS->getZExtValue();
686 if (N.getOpcode() == ISD::SUB)
689 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
690 Base = N.getOperand(0);
691 if (Base.getOpcode() == ISD::FrameIndex) {
692 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
693 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
695 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
702 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
706 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue Op, SDValue N,
707 SDValue &Base, SDValue &OffImm) {
708 // Match simple R - imm8 operands.
709 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
710 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
711 int RHSC = (int)RHS->getSExtValue();
712 if (N.getOpcode() == ISD::SUB)
715 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
716 Base = N.getOperand(0);
717 if (Base.getOpcode() == ISD::FrameIndex) {
718 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
719 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
721 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
730 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDValue Op, SDValue N,
732 unsigned Opcode = Op.getOpcode();
733 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
734 ? cast<LoadSDNode>(Op)->getAddressingMode()
735 : cast<StoreSDNode>(Op)->getAddressingMode();
736 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
737 int RHSC = (int)RHS->getZExtValue();
738 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
739 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
740 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
741 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
749 bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDValue Op, SDValue N,
750 SDValue &Base, SDValue &OffImm) {
751 if (N.getOpcode() == ISD::ADD) {
752 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
753 int RHSC = (int)RHS->getZExtValue();
754 if (((RHSC & 0x3) == 0) &&
755 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
756 Base = N.getOperand(0);
757 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
761 } else if (N.getOpcode() == ISD::SUB) {
762 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
763 int RHSC = (int)RHS->getZExtValue();
764 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
765 Base = N.getOperand(0);
766 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
775 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue Op, SDValue N,
777 SDValue &OffReg, SDValue &ShImm) {
778 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
779 if (N.getOpcode() != ISD::ADD)
782 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
783 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
784 int RHSC = (int)RHS->getZExtValue();
785 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
787 else if (RHSC < 0 && RHSC >= -255) // 8 bits
791 // Look for (R + R) or (R + (R << [1,2,3])).
793 Base = N.getOperand(0);
794 OffReg = N.getOperand(1);
796 // Swap if it is ((R << c) + R).
797 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
798 if (ShOpcVal != ARM_AM::lsl) {
799 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
800 if (ShOpcVal == ARM_AM::lsl)
801 std::swap(Base, OffReg);
804 if (ShOpcVal == ARM_AM::lsl) {
805 // Check to see if the RHS of the shift is a constant, if not, we can't fold
807 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
808 ShAmt = Sh->getZExtValue();
811 ShOpcVal = ARM_AM::no_shift;
813 OffReg = OffReg.getOperand(0);
815 ShOpcVal = ARM_AM::no_shift;
819 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
824 //===--------------------------------------------------------------------===//
826 /// getAL - Returns a ARMCC::AL immediate node.
827 static inline SDValue getAL(SelectionDAG *CurDAG) {
828 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
831 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDValue Op) {
832 LoadSDNode *LD = cast<LoadSDNode>(Op);
833 ISD::MemIndexedMode AM = LD->getAddressingMode();
834 if (AM == ISD::UNINDEXED)
837 EVT LoadedVT = LD->getMemoryVT();
838 SDValue Offset, AMOpc;
839 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
842 if (LoadedVT == MVT::i32 &&
843 SelectAddrMode2Offset(Op, LD->getOffset(), Offset, AMOpc)) {
844 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
846 } else if (LoadedVT == MVT::i16 &&
847 SelectAddrMode3Offset(Op, LD->getOffset(), Offset, AMOpc)) {
849 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
850 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
851 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
852 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
853 if (LD->getExtensionType() == ISD::SEXTLOAD) {
854 if (SelectAddrMode3Offset(Op, LD->getOffset(), Offset, AMOpc)) {
856 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
859 if (SelectAddrMode2Offset(Op, LD->getOffset(), Offset, AMOpc)) {
861 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
867 SDValue Chain = LD->getChain();
868 SDValue Base = LD->getBasePtr();
869 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
870 CurDAG->getRegister(0, MVT::i32), Chain };
871 return CurDAG->getMachineNode(Opcode, Op.getDebugLoc(), MVT::i32, MVT::i32,
878 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDValue Op) {
879 LoadSDNode *LD = cast<LoadSDNode>(Op);
880 ISD::MemIndexedMode AM = LD->getAddressingMode();
881 if (AM == ISD::UNINDEXED)
884 EVT LoadedVT = LD->getMemoryVT();
885 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
887 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
890 if (SelectT2AddrModeImm8Offset(Op, LD->getOffset(), Offset)) {
891 switch (LoadedVT.getSimpleVT().SimpleTy) {
893 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
897 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
899 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
904 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
906 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
915 SDValue Chain = LD->getChain();
916 SDValue Base = LD->getBasePtr();
917 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
918 CurDAG->getRegister(0, MVT::i32), Chain };
919 return CurDAG->getMachineNode(Opcode, Op.getDebugLoc(), MVT::i32, MVT::i32,
926 SDNode *ARMDAGToDAGISel::SelectDYN_ALLOC(SDValue Op) {
927 SDNode *N = Op.getNode();
928 DebugLoc dl = N->getDebugLoc();
929 EVT VT = Op.getValueType();
930 SDValue Chain = Op.getOperand(0);
931 SDValue Size = Op.getOperand(1);
932 SDValue Align = Op.getOperand(2);
933 SDValue SP = CurDAG->getRegister(ARM::SP, MVT::i32);
934 int32_t AlignVal = cast<ConstantSDNode>(Align)->getSExtValue();
936 // We need to align the stack. Use Thumb1 tAND which is the only thumb
937 // instruction that can read and write SP. This matches to a pseudo
938 // instruction that has a chain to ensure the result is written back to
939 // the stack pointer.
940 SP = SDValue(CurDAG->getMachineNode(ARM::tANDsp, dl, VT, SP, Align), 0);
942 bool isC = isa<ConstantSDNode>(Size);
943 uint32_t C = isC ? cast<ConstantSDNode>(Size)->getZExtValue() : ~0UL;
944 // Handle the most common case for both Thumb1 and Thumb2:
945 // tSUBspi - immediate is between 0 ... 508 inclusive.
946 if (C <= 508 && ((C & 3) == 0))
947 // FIXME: tSUBspi encode scale 4 implicitly.
948 return CurDAG->SelectNodeTo(N, ARM::tSUBspi_, VT, MVT::Other, SP,
949 CurDAG->getTargetConstant(C/4, MVT::i32),
952 if (Subtarget->isThumb1Only()) {
953 // Use tADDspr since Thumb1 does not have a sub r, sp, r. ARMISelLowering
954 // should have negated the size operand already. FIXME: We can't insert
955 // new target independent node at this stage so we are forced to negate
956 // it earlier. Is there a better solution?
957 return CurDAG->SelectNodeTo(N, ARM::tADDspr_, VT, MVT::Other, SP, Size,
959 } else if (Subtarget->isThumb2()) {
960 if (isC && Predicate_t2_so_imm(Size.getNode())) {
962 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
963 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi_, VT, MVT::Other, Ops, 3);
964 } else if (isC && Predicate_imm0_4095(Size.getNode())) {
966 SDValue Ops[] = { SP, CurDAG->getTargetConstant(C, MVT::i32), Chain };
967 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPi12_, VT, MVT::Other, Ops, 3);
970 SDValue Ops[] = { SP, Size,
971 getI32Imm(ARM_AM::getSORegOpc(ARM_AM::lsl,0)), Chain };
972 return CurDAG->SelectNodeTo(N, ARM::t2SUBrSPs_, VT, MVT::Other, Ops, 4);
976 // FIXME: Add ADD / SUB sp instructions for ARM.
980 /// PairDRegs - Insert a pair of double registers into an implicit def to
981 /// form a quad register.
982 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
983 DebugLoc dl = V0.getNode()->getDebugLoc();
985 SDValue(CurDAG->getMachineNode(TargetInstrInfo::IMPLICIT_DEF, dl, VT), 0);
986 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
987 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
988 SDNode *Pair = CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
989 VT, Undef, V0, SubReg0);
990 return CurDAG->getMachineNode(TargetInstrInfo::INSERT_SUBREG, dl,
991 VT, SDValue(Pair, 0), V1, SubReg1);
994 /// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
995 /// for a 64-bit subregister of the vector.
996 static EVT GetNEONSubregVT(EVT VT) {
997 switch (VT.getSimpleVT().SimpleTy) {
998 default: llvm_unreachable("unhandled NEON type");
999 case MVT::v16i8: return MVT::v8i8;
1000 case MVT::v8i16: return MVT::v4i16;
1001 case MVT::v4f32: return MVT::v2f32;
1002 case MVT::v4i32: return MVT::v2i32;
1003 case MVT::v2i64: return MVT::v1i64;
1007 SDNode *ARMDAGToDAGISel::SelectVLD(SDValue Op, unsigned NumVecs,
1008 unsigned *DOpcodes, unsigned *QOpcodes0,
1009 unsigned *QOpcodes1) {
1010 assert(NumVecs >=2 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1011 SDNode *N = Op.getNode();
1012 DebugLoc dl = N->getDebugLoc();
1014 SDValue MemAddr, MemUpdate, MemOpc;
1015 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1018 SDValue Chain = N->getOperand(0);
1019 EVT VT = N->getValueType(0);
1020 bool is64BitVector = VT.is64BitVector();
1022 unsigned OpcodeIndex;
1023 switch (VT.getSimpleVT().SimpleTy) {
1024 default: llvm_unreachable("unhandled vld type");
1025 // Double-register operations:
1026 case MVT::v8i8: OpcodeIndex = 0; break;
1027 case MVT::v4i16: OpcodeIndex = 1; break;
1029 case MVT::v2i32: OpcodeIndex = 2; break;
1030 case MVT::v1i64: OpcodeIndex = 3; break;
1031 // Quad-register operations:
1032 case MVT::v16i8: OpcodeIndex = 0; break;
1033 case MVT::v8i16: OpcodeIndex = 1; break;
1035 case MVT::v4i32: OpcodeIndex = 2; break;
1038 if (is64BitVector) {
1039 unsigned Opc = DOpcodes[OpcodeIndex];
1040 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Chain };
1041 std::vector<EVT> ResTys(NumVecs, VT);
1042 ResTys.push_back(MVT::Other);
1043 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 4);
1046 EVT RegVT = GetNEONSubregVT(VT);
1048 // Quad registers are directly supported for VLD2,
1049 // loading 2 pairs of D regs.
1050 unsigned Opc = QOpcodes0[OpcodeIndex];
1051 const SDValue Ops[] = { MemAddr, MemUpdate, MemOpc, Chain };
1052 std::vector<EVT> ResTys(4, VT);
1053 ResTys.push_back(MVT::Other);
1054 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 4);
1055 Chain = SDValue(VLd, 4);
1057 // Combine the even and odd subregs to produce the result.
1058 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1059 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1060 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1063 // Otherwise, quad registers are loaded with two separate instructions,
1064 // where one loads the even registers and the other loads the odd registers.
1066 // Enable writeback to the address register.
1067 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1069 std::vector<EVT> ResTys(NumVecs, RegVT);
1070 ResTys.push_back(MemAddr.getValueType());
1071 ResTys.push_back(MVT::Other);
1073 // Load the even subregs.
1074 unsigned Opc = QOpcodes0[OpcodeIndex];
1075 const SDValue OpsA[] = { MemAddr, MemUpdate, MemOpc, Chain };
1076 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 4);
1077 Chain = SDValue(VLdA, NumVecs+1);
1079 // Load the odd subregs.
1080 Opc = QOpcodes1[OpcodeIndex];
1081 const SDValue OpsB[] = { SDValue(VLdA, NumVecs), MemUpdate, MemOpc, Chain };
1082 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 4);
1083 Chain = SDValue(VLdB, NumVecs+1);
1085 // Combine the even and odd subregs to produce the result.
1086 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1087 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1088 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1091 ReplaceUses(SDValue(N, NumVecs), Chain);
1095 SDNode *ARMDAGToDAGISel::SelectVST(SDValue Op, unsigned NumVecs,
1096 unsigned *DOpcodes, unsigned *QOpcodes0,
1097 unsigned *QOpcodes1) {
1098 assert(NumVecs >=2 && NumVecs <= 4 && "VST NumVecs out-of-range");
1099 SDNode *N = Op.getNode();
1100 DebugLoc dl = N->getDebugLoc();
1102 SDValue MemAddr, MemUpdate, MemOpc;
1103 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1106 SDValue Chain = N->getOperand(0);
1107 EVT VT = N->getOperand(3).getValueType();
1108 bool is64BitVector = VT.is64BitVector();
1110 unsigned OpcodeIndex;
1111 switch (VT.getSimpleVT().SimpleTy) {
1112 default: llvm_unreachable("unhandled vst type");
1113 // Double-register operations:
1114 case MVT::v8i8: OpcodeIndex = 0; break;
1115 case MVT::v4i16: OpcodeIndex = 1; break;
1117 case MVT::v2i32: OpcodeIndex = 2; break;
1118 case MVT::v1i64: OpcodeIndex = 3; break;
1119 // Quad-register operations:
1120 case MVT::v16i8: OpcodeIndex = 0; break;
1121 case MVT::v8i16: OpcodeIndex = 1; break;
1123 case MVT::v4i32: OpcodeIndex = 2; break;
1126 SmallVector<SDValue, 8> Ops;
1127 Ops.push_back(MemAddr);
1128 Ops.push_back(MemUpdate);
1129 Ops.push_back(MemOpc);
1131 if (is64BitVector) {
1132 unsigned Opc = DOpcodes[OpcodeIndex];
1133 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1134 Ops.push_back(N->getOperand(Vec+3));
1135 Ops.push_back(Chain);
1136 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+4);
1139 EVT RegVT = GetNEONSubregVT(VT);
1141 // Quad registers are directly supported for VST2,
1142 // storing 2 pairs of D regs.
1143 unsigned Opc = QOpcodes0[OpcodeIndex];
1144 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1145 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1146 N->getOperand(Vec+3)));
1147 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1148 N->getOperand(Vec+3)));
1150 Ops.push_back(Chain);
1151 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 8);
1154 // Otherwise, quad registers are stored with two separate instructions,
1155 // where one stores the even registers and the other stores the odd registers.
1157 // Enable writeback to the address register.
1158 MemOpc = CurDAG->getTargetConstant(ARM_AM::getAM6Opc(true), MVT::i32);
1160 // Store the even subregs.
1161 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1162 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1163 N->getOperand(Vec+3)));
1164 Ops.push_back(Chain);
1165 unsigned Opc = QOpcodes0[OpcodeIndex];
1166 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1167 MVT::Other, Ops.data(), NumVecs+4);
1168 Chain = SDValue(VStA, 1);
1170 // Store the odd subregs.
1171 Ops[0] = SDValue(VStA, 0); // MemAddr
1172 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1173 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1174 N->getOperand(Vec+3));
1175 Ops[NumVecs+3] = Chain;
1176 Opc = QOpcodes1[OpcodeIndex];
1177 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1178 MVT::Other, Ops.data(), NumVecs+4);
1179 Chain = SDValue(VStB, 1);
1180 ReplaceUses(SDValue(N, 0), Chain);
1184 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDValue Op, bool IsLoad,
1185 unsigned NumVecs, unsigned *DOpcodes,
1186 unsigned *QOpcodes0,
1187 unsigned *QOpcodes1) {
1188 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1189 SDNode *N = Op.getNode();
1190 DebugLoc dl = N->getDebugLoc();
1192 SDValue MemAddr, MemUpdate, MemOpc;
1193 if (!SelectAddrMode6(Op, N->getOperand(2), MemAddr, MemUpdate, MemOpc))
1196 SDValue Chain = N->getOperand(0);
1198 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
1199 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
1200 bool is64BitVector = VT.is64BitVector();
1202 // Quad registers are handled by load/store of subregs. Find the subreg info.
1203 unsigned NumElts = 0;
1206 if (!is64BitVector) {
1207 RegVT = GetNEONSubregVT(VT);
1208 NumElts = RegVT.getVectorNumElements();
1209 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1212 unsigned OpcodeIndex;
1213 switch (VT.getSimpleVT().SimpleTy) {
1214 default: llvm_unreachable("unhandled vld/vst lane type");
1215 // Double-register operations:
1216 case MVT::v8i8: OpcodeIndex = 0; break;
1217 case MVT::v4i16: OpcodeIndex = 1; break;
1219 case MVT::v2i32: OpcodeIndex = 2; break;
1220 // Quad-register operations:
1221 case MVT::v8i16: OpcodeIndex = 0; break;
1223 case MVT::v4i32: OpcodeIndex = 1; break;
1226 SmallVector<SDValue, 9> Ops;
1227 Ops.push_back(MemAddr);
1228 Ops.push_back(MemUpdate);
1229 Ops.push_back(MemOpc);
1232 if (is64BitVector) {
1233 Opc = DOpcodes[OpcodeIndex];
1234 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1235 Ops.push_back(N->getOperand(Vec+3));
1237 // Check if this is loading the even or odd subreg of a Q register.
1238 if (Lane < NumElts) {
1239 Opc = QOpcodes0[OpcodeIndex];
1242 Opc = QOpcodes1[OpcodeIndex];
1244 // Extract the subregs of the input vector.
1245 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1246 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1247 N->getOperand(Vec+3)));
1249 Ops.push_back(getI32Imm(Lane));
1250 Ops.push_back(Chain);
1253 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
1255 std::vector<EVT> ResTys(NumVecs, RegVT);
1256 ResTys.push_back(MVT::Other);
1258 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+5);
1259 // For a 64-bit vector load to D registers, nothing more needs to be done.
1263 // For 128-bit vectors, take the 64-bit results of the load and insert them
1264 // as subregs into the result.
1265 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1266 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1267 N->getOperand(Vec+3),
1268 SDValue(VLdLn, Vec));
1269 ReplaceUses(SDValue(N, Vec), QuadVec);
1272 Chain = SDValue(VLdLn, NumVecs);
1273 ReplaceUses(SDValue(N, NumVecs), Chain);
1277 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDValue Op,
1279 if (!Subtarget->hasV6T2Ops())
1282 unsigned Shl_imm = 0;
1283 if (isOpcWithIntImmediate(Op.getOperand(0).getNode(), ISD::SHL, Shl_imm)){
1284 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1285 unsigned Srl_imm = 0;
1286 if (isInt32Immediate(Op.getOperand(1), Srl_imm)) {
1287 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1288 unsigned Width = 32 - Srl_imm;
1289 int LSB = Srl_imm - Shl_imm;
1292 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1293 SDValue Ops[] = { Op.getOperand(0).getOperand(0),
1294 CurDAG->getTargetConstant(LSB, MVT::i32),
1295 CurDAG->getTargetConstant(Width, MVT::i32),
1296 getAL(CurDAG), Reg0 };
1297 return CurDAG->SelectNodeTo(Op.getNode(), Opc, MVT::i32, Ops, 5);
1303 SDNode *ARMDAGToDAGISel::Select(SDValue Op) {
1304 SDNode *N = Op.getNode();
1305 DebugLoc dl = N->getDebugLoc();
1307 if (N->isMachineOpcode())
1308 return NULL; // Already selected.
1310 switch (N->getOpcode()) {
1312 case ISD::Constant: {
1313 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
1315 if (Subtarget->hasThumb2())
1316 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1317 // be done with MOV + MOVT, at worst.
1320 if (Subtarget->isThumb()) {
1321 UseCP = (Val > 255 && // MOV
1322 ~Val > 255 && // MOV + MVN
1323 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
1325 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1326 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1327 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1332 CurDAG->getTargetConstantPool(ConstantInt::get(
1333 Type::getInt32Ty(*CurDAG->getContext()), Val),
1334 TLI.getPointerTy());
1337 if (Subtarget->isThumb1Only()) {
1338 SDValue Pred = CurDAG->getTargetConstant(0xEULL, MVT::i32);
1339 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1340 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
1341 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1346 CurDAG->getRegister(0, MVT::i32),
1347 CurDAG->getTargetConstant(0, MVT::i32),
1349 CurDAG->getRegister(0, MVT::i32),
1350 CurDAG->getEntryNode()
1352 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1355 ReplaceUses(Op, SDValue(ResNode, 0));
1359 // Other cases are autogenerated.
1362 case ISD::FrameIndex: {
1363 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
1364 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1365 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1366 if (Subtarget->isThumb1Only()) {
1367 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1368 CurDAG->getTargetConstant(0, MVT::i32));
1370 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1371 ARM::t2ADDri : ARM::ADDri);
1372 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1373 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1374 CurDAG->getRegister(0, MVT::i32) };
1375 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1378 case ARMISD::DYN_ALLOC:
1379 return SelectDYN_ALLOC(Op);
1381 if (SDNode *I = SelectV6T2BitfieldExtractOp(Op,
1382 Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX))
1386 if (SDNode *I = SelectV6T2BitfieldExtractOp(Op,
1387 Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX))
1391 if (Subtarget->isThumb1Only())
1393 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
1394 unsigned RHSV = C->getZExtValue();
1396 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
1397 unsigned ShImm = Log2_32(RHSV-1);
1400 SDValue V = Op.getOperand(0);
1401 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1402 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1403 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1404 if (Subtarget->isThumb()) {
1405 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1406 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
1408 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1409 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
1412 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
1413 unsigned ShImm = Log2_32(RHSV+1);
1416 SDValue V = Op.getOperand(0);
1417 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
1418 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1419 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1420 if (Subtarget->isThumb()) {
1421 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
1422 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
1424 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1425 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
1431 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1432 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1433 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1434 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1435 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
1436 EVT VT = Op.getValueType();
1439 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1441 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1444 SDValue N0 = Op.getOperand(0), N1 = Op.getOperand(1);
1445 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1448 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1449 SDValue N2 = N0.getOperand(1);
1450 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1453 unsigned N1CVal = N1C->getZExtValue();
1454 unsigned N2CVal = N2C->getZExtValue();
1455 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1456 (N1CVal & 0xffffU) == 0xffffU &&
1457 (N2CVal & 0xffffU) == 0x0U) {
1458 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1460 SDValue Ops[] = { N0.getOperand(0), Imm16,
1461 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1462 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1468 return CurDAG->getMachineNode(ARM::FMRRD, dl, MVT::i32, MVT::i32,
1469 Op.getOperand(0), getAL(CurDAG),
1470 CurDAG->getRegister(0, MVT::i32));
1471 case ISD::UMUL_LOHI: {
1472 if (Subtarget->isThumb1Only())
1474 if (Subtarget->isThumb()) {
1475 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1476 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1477 CurDAG->getRegister(0, MVT::i32) };
1478 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
1480 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1481 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1482 CurDAG->getRegister(0, MVT::i32) };
1483 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1486 case ISD::SMUL_LOHI: {
1487 if (Subtarget->isThumb1Only())
1489 if (Subtarget->isThumb()) {
1490 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1491 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1492 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
1494 SDValue Ops[] = { Op.getOperand(0), Op.getOperand(1),
1495 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1496 CurDAG->getRegister(0, MVT::i32) };
1497 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
1501 SDNode *ResNode = 0;
1502 if (Subtarget->isThumb() && Subtarget->hasThumb2())
1503 ResNode = SelectT2IndexedLoad(Op);
1505 ResNode = SelectARMIndexedLoad(Op);
1508 // Other cases are autogenerated.
1511 case ARMISD::BRCOND: {
1512 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1513 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1514 // Pattern complexity = 6 cost = 1 size = 0
1516 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1517 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1518 // Pattern complexity = 6 cost = 1 size = 0
1520 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1521 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1522 // Pattern complexity = 6 cost = 1 size = 0
1524 unsigned Opc = Subtarget->isThumb() ?
1525 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
1526 SDValue Chain = Op.getOperand(0);
1527 SDValue N1 = Op.getOperand(1);
1528 SDValue N2 = Op.getOperand(2);
1529 SDValue N3 = Op.getOperand(3);
1530 SDValue InFlag = Op.getOperand(4);
1531 assert(N1.getOpcode() == ISD::BasicBlock);
1532 assert(N2.getOpcode() == ISD::Constant);
1533 assert(N3.getOpcode() == ISD::Register);
1535 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1536 cast<ConstantSDNode>(N2)->getZExtValue()),
1538 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
1539 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1541 Chain = SDValue(ResNode, 0);
1542 if (Op.getNode()->getNumValues() == 2) {
1543 InFlag = SDValue(ResNode, 1);
1544 ReplaceUses(SDValue(Op.getNode(), 1), InFlag);
1546 ReplaceUses(SDValue(Op.getNode(), 0), SDValue(Chain.getNode(), Chain.getResNo()));
1549 case ARMISD::CMOV: {
1550 EVT VT = Op.getValueType();
1551 SDValue N0 = Op.getOperand(0);
1552 SDValue N1 = Op.getOperand(1);
1553 SDValue N2 = Op.getOperand(2);
1554 SDValue N3 = Op.getOperand(3);
1555 SDValue InFlag = Op.getOperand(4);
1556 assert(N2.getOpcode() == ISD::Constant);
1557 assert(N3.getOpcode() == ISD::Register);
1559 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1560 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1561 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1562 // Pattern complexity = 18 cost = 1 size = 0
1566 if (Subtarget->isThumb()) {
1567 if (SelectT2ShifterOperandReg(Op, N1, CPTmp0, CPTmp1)) {
1568 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1569 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1572 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1573 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1574 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1575 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1577 llvm_unreachable("Unknown so_reg opcode!");
1581 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1582 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1583 cast<ConstantSDNode>(N2)->getZExtValue()),
1585 SDValue Ops[] = { N0, CPTmp0, SOShImm, Tmp2, N3, InFlag };
1586 return CurDAG->SelectNodeTo(Op.getNode(), Opc, MVT::i32,Ops, 6);
1589 if (SelectShifterOperandReg(Op, N1, CPTmp0, CPTmp1, CPTmp2)) {
1590 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1591 cast<ConstantSDNode>(N2)->getZExtValue()),
1593 SDValue Ops[] = { N0, CPTmp0, CPTmp1, CPTmp2, Tmp2, N3, InFlag };
1594 return CurDAG->SelectNodeTo(Op.getNode(),
1595 ARM::MOVCCs, MVT::i32, Ops, 7);
1599 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1600 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1602 // Emits: (MOVCCi:i32 GPR:i32:$false,
1603 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1604 // Pattern complexity = 10 cost = 1 size = 0
1605 if (N3.getOpcode() == ISD::Constant) {
1606 if (Subtarget->isThumb()) {
1607 if (Predicate_t2_so_imm(N3.getNode())) {
1608 SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned)
1609 cast<ConstantSDNode>(N1)->getZExtValue()),
1611 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1612 cast<ConstantSDNode>(N2)->getZExtValue()),
1614 SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag };
1615 return CurDAG->SelectNodeTo(Op.getNode(),
1616 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1619 if (Predicate_so_imm(N3.getNode())) {
1620 SDValue Tmp1 = CurDAG->getTargetConstant(((unsigned)
1621 cast<ConstantSDNode>(N1)->getZExtValue()),
1623 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1624 cast<ConstantSDNode>(N2)->getZExtValue()),
1626 SDValue Ops[] = { N0, Tmp1, Tmp2, N3, InFlag };
1627 return CurDAG->SelectNodeTo(Op.getNode(),
1628 ARM::MOVCCi, MVT::i32, Ops, 5);
1634 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1635 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1636 // Pattern complexity = 6 cost = 1 size = 0
1638 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1639 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1640 // Pattern complexity = 6 cost = 11 size = 0
1642 // Also FCPYScc and FCPYDcc.
1643 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1644 cast<ConstantSDNode>(N2)->getZExtValue()),
1646 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
1648 switch (VT.getSimpleVT().SimpleTy) {
1649 default: assert(false && "Illegal conditional move type!");
1652 Opc = Subtarget->isThumb()
1653 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1663 return CurDAG->SelectNodeTo(Op.getNode(), Opc, VT, Ops, 5);
1665 case ARMISD::CNEG: {
1666 EVT VT = Op.getValueType();
1667 SDValue N0 = Op.getOperand(0);
1668 SDValue N1 = Op.getOperand(1);
1669 SDValue N2 = Op.getOperand(2);
1670 SDValue N3 = Op.getOperand(3);
1671 SDValue InFlag = Op.getOperand(4);
1672 assert(N2.getOpcode() == ISD::Constant);
1673 assert(N3.getOpcode() == ISD::Register);
1675 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
1676 cast<ConstantSDNode>(N2)->getZExtValue()),
1678 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
1680 switch (VT.getSimpleVT().SimpleTy) {
1681 default: assert(false && "Illegal conditional move type!");
1690 return CurDAG->SelectNodeTo(Op.getNode(), Opc, VT, Ops, 5);
1693 case ARMISD::VZIP: {
1695 EVT VT = N->getValueType(0);
1696 switch (VT.getSimpleVT().SimpleTy) {
1697 default: return NULL;
1698 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1699 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1701 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1702 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1703 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1705 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1707 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1708 N->getOperand(0), N->getOperand(1));
1710 case ARMISD::VUZP: {
1712 EVT VT = N->getValueType(0);
1713 switch (VT.getSimpleVT().SimpleTy) {
1714 default: return NULL;
1715 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1716 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1718 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1719 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1720 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1722 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1724 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1725 N->getOperand(0), N->getOperand(1));
1727 case ARMISD::VTRN: {
1729 EVT VT = N->getValueType(0);
1730 switch (VT.getSimpleVT().SimpleTy) {
1731 default: return NULL;
1732 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1733 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1735 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1736 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1737 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1739 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1741 return CurDAG->getMachineNode(Opc, dl, VT, VT,
1742 N->getOperand(0), N->getOperand(1));
1745 case ISD::INTRINSIC_VOID:
1746 case ISD::INTRINSIC_W_CHAIN: {
1747 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
1752 case Intrinsic::arm_neon_vld2: {
1753 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
1754 ARM::VLD2d32, ARM::VLD2d64 };
1755 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
1756 return SelectVLD(Op, 2, DOpcodes, QOpcodes, 0);
1759 case Intrinsic::arm_neon_vld3: {
1760 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
1761 ARM::VLD3d32, ARM::VLD3d64 };
1762 unsigned QOpcodes0[] = { ARM::VLD3q8a, ARM::VLD3q16a, ARM::VLD3q32a };
1763 unsigned QOpcodes1[] = { ARM::VLD3q8b, ARM::VLD3q16b, ARM::VLD3q32b };
1764 return SelectVLD(Op, 3, DOpcodes, QOpcodes0, QOpcodes1);
1767 case Intrinsic::arm_neon_vld4: {
1768 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
1769 ARM::VLD4d32, ARM::VLD4d64 };
1770 unsigned QOpcodes0[] = { ARM::VLD4q8a, ARM::VLD4q16a, ARM::VLD4q32a };
1771 unsigned QOpcodes1[] = { ARM::VLD4q8b, ARM::VLD4q16b, ARM::VLD4q32b };
1772 return SelectVLD(Op, 4, DOpcodes, QOpcodes0, QOpcodes1);
1775 case Intrinsic::arm_neon_vld2lane: {
1776 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
1777 unsigned QOpcodes0[] = { ARM::VLD2LNq16a, ARM::VLD2LNq32a };
1778 unsigned QOpcodes1[] = { ARM::VLD2LNq16b, ARM::VLD2LNq32b };
1779 return SelectVLDSTLane(Op, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
1782 case Intrinsic::arm_neon_vld3lane: {
1783 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
1784 unsigned QOpcodes0[] = { ARM::VLD3LNq16a, ARM::VLD3LNq32a };
1785 unsigned QOpcodes1[] = { ARM::VLD3LNq16b, ARM::VLD3LNq32b };
1786 return SelectVLDSTLane(Op, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
1789 case Intrinsic::arm_neon_vld4lane: {
1790 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
1791 unsigned QOpcodes0[] = { ARM::VLD4LNq16a, ARM::VLD4LNq32a };
1792 unsigned QOpcodes1[] = { ARM::VLD4LNq16b, ARM::VLD4LNq32b };
1793 return SelectVLDSTLane(Op, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
1796 case Intrinsic::arm_neon_vst2: {
1797 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
1798 ARM::VST2d32, ARM::VST2d64 };
1799 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
1800 return SelectVST(Op, 2, DOpcodes, QOpcodes, 0);
1803 case Intrinsic::arm_neon_vst3: {
1804 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
1805 ARM::VST3d32, ARM::VST3d64 };
1806 unsigned QOpcodes0[] = { ARM::VST3q8a, ARM::VST3q16a, ARM::VST3q32a };
1807 unsigned QOpcodes1[] = { ARM::VST3q8b, ARM::VST3q16b, ARM::VST3q32b };
1808 return SelectVST(Op, 3, DOpcodes, QOpcodes0, QOpcodes1);
1811 case Intrinsic::arm_neon_vst4: {
1812 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
1813 ARM::VST4d32, ARM::VST4d64 };
1814 unsigned QOpcodes0[] = { ARM::VST4q8a, ARM::VST4q16a, ARM::VST4q32a };
1815 unsigned QOpcodes1[] = { ARM::VST4q8b, ARM::VST4q16b, ARM::VST4q32b };
1816 return SelectVST(Op, 4, DOpcodes, QOpcodes0, QOpcodes1);
1819 case Intrinsic::arm_neon_vst2lane: {
1820 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
1821 unsigned QOpcodes0[] = { ARM::VST2LNq16a, ARM::VST2LNq32a };
1822 unsigned QOpcodes1[] = { ARM::VST2LNq16b, ARM::VST2LNq32b };
1823 return SelectVLDSTLane(Op, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
1826 case Intrinsic::arm_neon_vst3lane: {
1827 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
1828 unsigned QOpcodes0[] = { ARM::VST3LNq16a, ARM::VST3LNq32a };
1829 unsigned QOpcodes1[] = { ARM::VST3LNq16b, ARM::VST3LNq32b };
1830 return SelectVLDSTLane(Op, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
1833 case Intrinsic::arm_neon_vst4lane: {
1834 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
1835 unsigned QOpcodes0[] = { ARM::VST4LNq16a, ARM::VST4LNq32a };
1836 unsigned QOpcodes1[] = { ARM::VST4LNq16b, ARM::VST4LNq32b };
1837 return SelectVLDSTLane(Op, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
1843 return SelectCode(Op);
1846 bool ARMDAGToDAGISel::
1847 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1848 std::vector<SDValue> &OutOps) {
1849 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
1850 // Require the address to be in a register. That is safe for all ARM
1851 // variants and it is hard to do anything much smarter without knowing
1852 // how the operand is used.
1853 OutOps.push_back(Op);
1857 /// createARMISelDag - This pass converts a legalized DAG into a
1858 /// ARM-specific DAG, ready for instruction scheduling.
1860 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1861 CodeGenOpt::Level OptLevel) {
1862 return new ARMDAGToDAGISel(TM, OptLevel);