1 //===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an instruction selector for the ARM target.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "arm-isel"
16 #include "ARMBaseInstrInfo.h"
17 #include "ARMAddressingModes.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/CommandLine.h"
33 #include "llvm/Support/Compiler.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/raw_ostream.h"
41 DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
46 CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
50 //===--------------------------------------------------------------------===//
51 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
52 /// instructions for SelectionDAG operations.
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
61 class ARMDAGToDAGISel : public SelectionDAGISel {
62 ARMBaseTargetMachine &TM;
63 const ARMBaseInstrInfo *TII;
65 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
70 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
73 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
77 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
81 /// getI32Imm - Return a target constant of type i32 with the specified
83 inline SDValue getI32Imm(unsigned Imm) {
84 return CurDAG->getTargetConstant(Imm, MVT::i32);
87 SDNode *Select(SDNode *N);
90 bool hasNoVMLxHazardUse(SDNode *N) const;
91 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
93 bool SelectShifterOperandReg(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C);
95 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
96 SDValue &B, SDValue &C);
97 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
98 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
100 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
101 SDValue &Offset, SDValue &Opc);
102 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
104 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
107 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
112 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
114 SelectAddrMode2Worker(N, Base, Offset, Opc);
115 // return SelectAddrMode2ShOp(N, Base, Offset, Opc);
116 // This always matches one way or another.
120 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
121 SDValue &Offset, SDValue &Opc);
122 bool SelectAddrMode3(SDValue N, SDValue &Base,
123 SDValue &Offset, SDValue &Opc);
124 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
125 SDValue &Offset, SDValue &Opc);
126 bool SelectAddrMode5(SDValue N, SDValue &Base,
128 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
130 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
132 // Thumb Addressing Modes:
133 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
134 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
136 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
137 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
141 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
143 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
145 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
147 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
149 // Thumb 2 Addressing Modes:
150 bool SelectT2ShifterOperandReg(SDValue N,
151 SDValue &BaseReg, SDValue &Opc);
152 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
153 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
155 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
157 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
158 SDValue &OffReg, SDValue &ShImm);
160 inline bool is_so_imm(unsigned Imm) const {
161 return ARM_AM::getSOImmVal(Imm) != -1;
164 inline bool is_so_imm_not(unsigned Imm) const {
165 return ARM_AM::getSOImmVal(~Imm) != -1;
168 inline bool is_t2_so_imm(unsigned Imm) const {
169 return ARM_AM::getT2SOImmVal(Imm) != -1;
172 inline bool is_t2_so_imm_not(unsigned Imm) const {
173 return ARM_AM::getT2SOImmVal(~Imm) != -1;
176 inline bool Pred_so_imm(SDNode *inN) const {
177 ConstantSDNode *N = cast<ConstantSDNode>(inN);
178 return is_so_imm(N->getZExtValue());
181 inline bool Pred_t2_so_imm(SDNode *inN) const {
182 ConstantSDNode *N = cast<ConstantSDNode>(inN);
183 return is_t2_so_imm(N->getZExtValue());
186 // Include the pieces autogenerated from the target description.
187 #include "ARMGenDAGISel.inc"
190 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
192 SDNode *SelectARMIndexedLoad(SDNode *N);
193 SDNode *SelectT2IndexedLoad(SDNode *N);
195 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
196 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
197 /// loads of D registers and even subregs and odd subregs of Q registers.
198 /// For NumVecs <= 2, QOpcodes1 is not used.
199 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
200 unsigned *QOpcodes0, unsigned *QOpcodes1);
202 /// SelectVST - Select NEON store intrinsics. NumVecs should
203 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
204 /// stores of D registers and even subregs and odd subregs of Q registers.
205 /// For NumVecs <= 2, QOpcodes1 is not used.
206 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
207 unsigned *QOpcodes0, unsigned *QOpcodes1);
209 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
210 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
211 /// load/store of D registers and Q registers.
212 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
213 unsigned *DOpcodes, unsigned *QOpcodes);
215 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
216 /// should be 2, 3 or 4. The opcode array specifies the instructions used
217 /// for loading D registers. (Q registers are not supported.)
218 SDNode *SelectVLDDup(SDNode *N, unsigned NumVecs, unsigned *Opcodes);
220 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
221 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
222 /// generated to force the table registers to be consecutive.
223 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
225 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
226 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
228 /// SelectCMOVOp - Select CMOV instructions for ARM.
229 SDNode *SelectCMOVOp(SDNode *N);
230 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
231 ARMCC::CondCodes CCVal, SDValue CCR,
233 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
234 ARMCC::CondCodes CCVal, SDValue CCR,
236 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
237 ARMCC::CondCodes CCVal, SDValue CCR,
239 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
240 ARMCC::CondCodes CCVal, SDValue CCR,
243 SDNode *SelectConcatVector(SDNode *N);
245 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
246 /// inline asm expressions.
247 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
249 std::vector<SDValue> &OutOps);
251 // Form pairs of consecutive S, D, or Q registers.
252 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
253 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
254 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
256 // Form sequences of 4 consecutive S, D, or Q registers.
257 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
258 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
259 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
261 // Get the alignment operand for a NEON VLD or VST instruction.
262 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
266 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
267 /// operand. If so Imm will receive the 32-bit value.
268 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
269 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
270 Imm = cast<ConstantSDNode>(N)->getZExtValue();
276 // isInt32Immediate - This method tests to see if a constant operand.
277 // If so Imm will receive the 32 bit value.
278 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
279 return isInt32Immediate(N.getNode(), Imm);
282 // isOpcWithIntImmediate - This method tests to see if the node is a specific
283 // opcode and that it has a immediate integer right operand.
284 // If so Imm will receive the 32 bit value.
285 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
286 return N->getOpcode() == Opc &&
287 isInt32Immediate(N->getOperand(1).getNode(), Imm);
290 /// \brief Check whether a particular node is a constant value representable as
291 /// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
293 /// \param ScaledConstant [out] - On success, the pre-scaled constant value.
294 static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
295 int RangeMin, int RangeMax,
296 int &ScaledConstant) {
297 assert(Scale && "Invalid scale!");
299 // Check that this is a constant.
300 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
304 ScaledConstant = (int) C->getZExtValue();
305 if ((ScaledConstant % Scale) != 0)
308 ScaledConstant /= Scale;
309 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
312 /// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
313 /// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
314 /// least on current ARM implementations) which should be avoidded.
315 bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
316 if (OptLevel == CodeGenOpt::None)
319 if (!CheckVMLxHazard)
322 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
328 SDNode *Use = *N->use_begin();
329 if (Use->getOpcode() == ISD::CopyToReg)
331 if (Use->isMachineOpcode()) {
332 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
335 unsigned Opcode = TID.getOpcode();
336 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
338 // vmlx feeding into another vmlx. We actually want to unfold
339 // the use later in the MLxExpansion pass. e.g.
341 // vmla (stall 8 cycles)
346 // This adds up to about 18 - 19 cycles.
349 // vmul (stall 4 cycles)
350 // vadd adds up to about 14 cycles.
351 return TII->isFpMLxInstruction(Opcode);
357 bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
358 ARM_AM::ShiftOpc ShOpcVal,
360 if (!Subtarget->isCortexA9())
362 if (Shift.hasOneUse())
365 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
368 bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
372 if (DisableShifterOp)
375 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
377 // Don't match base register only case. That is matched to a separate
378 // lower complexity pattern with explicit register operand.
379 if (ShOpcVal == ARM_AM::no_shift) return false;
381 BaseReg = N.getOperand(0);
382 unsigned ShImmVal = 0;
383 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
384 ShReg = CurDAG->getRegister(0, MVT::i32);
385 ShImmVal = RHS->getZExtValue() & 31;
387 ShReg = N.getOperand(1);
388 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
391 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
396 bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
400 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
402 // Don't match base register only case. That is matched to a separate
403 // lower complexity pattern with explicit register operand.
404 if (ShOpcVal == ARM_AM::no_shift) return false;
406 BaseReg = N.getOperand(0);
407 unsigned ShImmVal = 0;
408 // Do not check isShifterOpProfitable. This must return true.
409 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
410 ShReg = CurDAG->getRegister(0, MVT::i32);
411 ShImmVal = RHS->getZExtValue() & 31;
413 ShReg = N.getOperand(1);
415 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
420 bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
423 // Match simple R + imm12 operands.
426 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
427 if (N.getOpcode() == ISD::FrameIndex) {
428 // Match frame index...
429 int FI = cast<FrameIndexSDNode>(N)->getIndex();
430 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
431 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
433 } else if (N.getOpcode() == ARMISD::Wrapper &&
434 !(Subtarget->useMovt() &&
435 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
436 Base = N.getOperand(0);
439 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
443 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
444 int RHSC = (int)RHS->getZExtValue();
445 if (N.getOpcode() == ISD::SUB)
448 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
449 Base = N.getOperand(0);
450 if (Base.getOpcode() == ISD::FrameIndex) {
451 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
452 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
454 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
461 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
467 bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
469 if (N.getOpcode() == ISD::MUL &&
470 (!Subtarget->isCortexA9() || N.hasOneUse())) {
471 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
472 // X * [3,5,9] -> X + X * [2,4,8] etc.
473 int RHSC = (int)RHS->getZExtValue();
476 ARM_AM::AddrOpc AddSub = ARM_AM::add;
478 AddSub = ARM_AM::sub;
481 if (isPowerOf2_32(RHSC)) {
482 unsigned ShAmt = Log2_32(RHSC);
483 Base = Offset = N.getOperand(0);
484 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
493 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
496 // Leave simple R +/- imm12 operands for LDRi12
497 if (N.getOpcode() == ISD::ADD) {
499 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
500 -0x1000+1, 0x1000, RHSC)) // 12 bits.
504 if (Subtarget->isCortexA9() && !N.hasOneUse())
505 // Compute R +/- (R << N) and reuse it.
508 // Otherwise this is R +/- [possibly shifted] R.
509 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
510 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
513 Base = N.getOperand(0);
514 Offset = N.getOperand(1);
516 if (ShOpcVal != ARM_AM::no_shift) {
517 // Check to see if the RHS of the shift is a constant, if not, we can't fold
519 if (ConstantSDNode *Sh =
520 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
521 ShAmt = Sh->getZExtValue();
522 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
523 Offset = N.getOperand(1).getOperand(0);
526 ShOpcVal = ARM_AM::no_shift;
529 ShOpcVal = ARM_AM::no_shift;
533 // Try matching (R shl C) + (R).
534 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
535 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
536 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
537 if (ShOpcVal != ARM_AM::no_shift) {
538 // Check to see if the RHS of the shift is a constant, if not, we can't
540 if (ConstantSDNode *Sh =
541 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
542 ShAmt = Sh->getZExtValue();
543 if (!Subtarget->isCortexA9() ||
545 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
546 Offset = N.getOperand(0).getOperand(0);
547 Base = N.getOperand(1);
550 ShOpcVal = ARM_AM::no_shift;
553 ShOpcVal = ARM_AM::no_shift;
558 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
568 AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
572 if (N.getOpcode() == ISD::MUL &&
573 (!Subtarget->isCortexA9() || N.hasOneUse())) {
574 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
575 // X * [3,5,9] -> X + X * [2,4,8] etc.
576 int RHSC = (int)RHS->getZExtValue();
579 ARM_AM::AddrOpc AddSub = ARM_AM::add;
581 AddSub = ARM_AM::sub;
584 if (isPowerOf2_32(RHSC)) {
585 unsigned ShAmt = Log2_32(RHSC);
586 Base = Offset = N.getOperand(0);
587 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
596 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
598 if (N.getOpcode() == ISD::FrameIndex) {
599 int FI = cast<FrameIndexSDNode>(N)->getIndex();
600 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
601 } else if (N.getOpcode() == ARMISD::Wrapper &&
602 !(Subtarget->useMovt() &&
603 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
604 Base = N.getOperand(0);
606 Offset = CurDAG->getRegister(0, MVT::i32);
607 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
613 // Match simple R +/- imm12 operands.
614 if (N.getOpcode() == ISD::ADD) {
616 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
617 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
618 Base = N.getOperand(0);
619 if (Base.getOpcode() == ISD::FrameIndex) {
620 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
621 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
623 Offset = CurDAG->getRegister(0, MVT::i32);
625 ARM_AM::AddrOpc AddSub = ARM_AM::add;
627 AddSub = ARM_AM::sub;
630 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
637 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
638 // Compute R +/- (R << N) and reuse it.
640 Offset = CurDAG->getRegister(0, MVT::i32);
641 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
647 // Otherwise this is R +/- [possibly shifted] R.
648 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
649 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
652 Base = N.getOperand(0);
653 Offset = N.getOperand(1);
655 if (ShOpcVal != ARM_AM::no_shift) {
656 // Check to see if the RHS of the shift is a constant, if not, we can't fold
658 if (ConstantSDNode *Sh =
659 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
660 ShAmt = Sh->getZExtValue();
661 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
662 Offset = N.getOperand(1).getOperand(0);
665 ShOpcVal = ARM_AM::no_shift;
668 ShOpcVal = ARM_AM::no_shift;
672 // Try matching (R shl C) + (R).
673 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
674 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
675 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
676 if (ShOpcVal != ARM_AM::no_shift) {
677 // Check to see if the RHS of the shift is a constant, if not, we can't
679 if (ConstantSDNode *Sh =
680 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
681 ShAmt = Sh->getZExtValue();
682 if (!Subtarget->isCortexA9() ||
684 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
685 Offset = N.getOperand(0).getOperand(0);
686 Base = N.getOperand(1);
689 ShOpcVal = ARM_AM::no_shift;
692 ShOpcVal = ARM_AM::no_shift;
697 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
702 bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
703 SDValue &Offset, SDValue &Opc) {
704 unsigned Opcode = Op->getOpcode();
705 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
706 ? cast<LoadSDNode>(Op)->getAddressingMode()
707 : cast<StoreSDNode>(Op)->getAddressingMode();
708 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
709 ? ARM_AM::add : ARM_AM::sub;
711 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
712 Offset = CurDAG->getRegister(0, MVT::i32);
713 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
720 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
722 if (ShOpcVal != ARM_AM::no_shift) {
723 // Check to see if the RHS of the shift is a constant, if not, we can't fold
725 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
726 ShAmt = Sh->getZExtValue();
727 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
728 Offset = N.getOperand(0);
731 ShOpcVal = ARM_AM::no_shift;
734 ShOpcVal = ARM_AM::no_shift;
738 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
744 bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
745 SDValue &Base, SDValue &Offset,
747 if (N.getOpcode() == ISD::SUB) {
748 // X - C is canonicalize to X + -C, no need to handle it here.
749 Base = N.getOperand(0);
750 Offset = N.getOperand(1);
751 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
755 if (N.getOpcode() != ISD::ADD) {
757 if (N.getOpcode() == ISD::FrameIndex) {
758 int FI = cast<FrameIndexSDNode>(N)->getIndex();
759 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
761 Offset = CurDAG->getRegister(0, MVT::i32);
762 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
766 // If the RHS is +/- imm8, fold into addr mode.
768 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
769 -256 + 1, 256, RHSC)) { // 8 bits.
770 Base = N.getOperand(0);
771 if (Base.getOpcode() == ISD::FrameIndex) {
772 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
773 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
775 Offset = CurDAG->getRegister(0, MVT::i32);
777 ARM_AM::AddrOpc AddSub = ARM_AM::add;
779 AddSub = ARM_AM::sub;
782 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
786 Base = N.getOperand(0);
787 Offset = N.getOperand(1);
788 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
792 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
793 SDValue &Offset, SDValue &Opc) {
794 unsigned Opcode = Op->getOpcode();
795 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
796 ? cast<LoadSDNode>(Op)->getAddressingMode()
797 : cast<StoreSDNode>(Op)->getAddressingMode();
798 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
799 ? ARM_AM::add : ARM_AM::sub;
801 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
802 Offset = CurDAG->getRegister(0, MVT::i32);
803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
808 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
812 bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
813 SDValue &Base, SDValue &Offset) {
814 if (N.getOpcode() != ISD::ADD) {
816 if (N.getOpcode() == ISD::FrameIndex) {
817 int FI = cast<FrameIndexSDNode>(N)->getIndex();
818 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
819 } else if (N.getOpcode() == ARMISD::Wrapper &&
820 !(Subtarget->useMovt() &&
821 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
822 Base = N.getOperand(0);
824 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
829 // If the RHS is +/- imm8, fold into addr mode.
831 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
832 -256 + 1, 256, RHSC)) {
833 Base = N.getOperand(0);
834 if (Base.getOpcode() == ISD::FrameIndex) {
835 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
836 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
839 ARM_AM::AddrOpc AddSub = ARM_AM::add;
841 AddSub = ARM_AM::sub;
844 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
850 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
855 bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
859 unsigned Alignment = 0;
860 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
861 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
862 // The maximum alignment is equal to the memory size being referenced.
863 unsigned LSNAlign = LSN->getAlignment();
864 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
865 if (LSNAlign > MemSize && MemSize > 1)
868 // All other uses of addrmode6 are for intrinsics. For now just record
869 // the raw alignment value; it will be refined later based on the legal
870 // alignment operands for the intrinsic.
871 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
874 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
878 bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
879 SDValue &Offset, SDValue &Label) {
880 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
881 Offset = N.getOperand(0);
882 SDValue N1 = N.getOperand(1);
883 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
892 //===----------------------------------------------------------------------===//
893 // Thumb Addressing Modes
894 //===----------------------------------------------------------------------===//
896 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
897 SDValue &Base, SDValue &Offset){
898 // FIXME dl should come from the parent load or store, not the address
899 if (N.getOpcode() != ISD::ADD) {
900 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
901 if (!NC || !NC->isNullValue())
908 Base = N.getOperand(0);
909 Offset = N.getOperand(1);
914 ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
915 SDValue &Offset, unsigned Scale) {
917 SDValue TmpBase, TmpOffImm;
918 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
919 return false; // We want to select tLDRspi / tSTRspi instead.
921 if (N.getOpcode() == ARMISD::Wrapper &&
922 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
923 return false; // We want to select tLDRpci instead.
926 if (N.getOpcode() != ISD::ADD)
929 // Thumb does not have [sp, r] address mode.
930 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
931 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
932 if ((LHSR && LHSR->getReg() == ARM::SP) ||
933 (RHSR && RHSR->getReg() == ARM::SP))
936 // FIXME: Why do we explicitly check for a match here and then return false?
937 // Presumably to allow something else to match, but shouldn't this be
940 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
943 Base = N.getOperand(0);
944 Offset = N.getOperand(1);
949 ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
952 return SelectThumbAddrModeRI(N, Base, Offset, 1);
956 ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
959 return SelectThumbAddrModeRI(N, Base, Offset, 2);
963 ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
966 return SelectThumbAddrModeRI(N, Base, Offset, 4);
970 ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
971 SDValue &Base, SDValue &OffImm) {
973 SDValue TmpBase, TmpOffImm;
974 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
975 return false; // We want to select tLDRspi / tSTRspi instead.
977 if (N.getOpcode() == ARMISD::Wrapper &&
978 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
979 return false; // We want to select tLDRpci instead.
982 if (N.getOpcode() != ISD::ADD) {
983 if (N.getOpcode() == ARMISD::Wrapper &&
984 !(Subtarget->useMovt() &&
985 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
986 Base = N.getOperand(0);
991 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
995 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
996 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
997 if ((LHSR && LHSR->getReg() == ARM::SP) ||
998 (RHSR && RHSR->getReg() == ARM::SP)) {
999 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1000 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1001 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1002 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1004 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1005 if (LHSC != 0 || RHSC != 0) return false;
1008 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1012 // If the RHS is + imm5 * scale, fold into addr mode.
1014 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1015 Base = N.getOperand(0);
1016 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1020 Base = N.getOperand(0);
1021 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1026 ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1028 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
1032 ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1034 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
1038 ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1040 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
1043 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1044 SDValue &Base, SDValue &OffImm) {
1045 if (N.getOpcode() == ISD::FrameIndex) {
1046 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1047 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1048 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1052 if (N.getOpcode() != ISD::ADD)
1055 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1056 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1057 (LHSR && LHSR->getReg() == ARM::SP)) {
1058 // If the RHS is + imm8 * scale, fold into addr mode.
1060 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1061 Base = N.getOperand(0);
1062 if (Base.getOpcode() == ISD::FrameIndex) {
1063 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1064 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1066 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1075 //===----------------------------------------------------------------------===//
1076 // Thumb 2 Addressing Modes
1077 //===----------------------------------------------------------------------===//
1080 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
1082 if (DisableShifterOp)
1085 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1087 // Don't match base register only case. That is matched to a separate
1088 // lower complexity pattern with explicit register operand.
1089 if (ShOpcVal == ARM_AM::no_shift) return false;
1091 BaseReg = N.getOperand(0);
1092 unsigned ShImmVal = 0;
1093 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1094 ShImmVal = RHS->getZExtValue() & 31;
1095 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1102 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
1103 SDValue &Base, SDValue &OffImm) {
1104 // Match simple R + imm12 operands.
1107 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
1108 if (N.getOpcode() == ISD::FrameIndex) {
1109 // Match frame index...
1110 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1111 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1112 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1114 } else if (N.getOpcode() == ARMISD::Wrapper &&
1115 !(Subtarget->useMovt() &&
1116 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1117 Base = N.getOperand(0);
1118 if (Base.getOpcode() == ISD::TargetConstantPool)
1119 return false; // We want to select t2LDRpci instead.
1122 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1126 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1127 if (SelectT2AddrModeImm8(N, Base, OffImm))
1128 // Let t2LDRi8 handle (R - imm8).
1131 int RHSC = (int)RHS->getZExtValue();
1132 if (N.getOpcode() == ISD::SUB)
1135 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
1136 Base = N.getOperand(0);
1137 if (Base.getOpcode() == ISD::FrameIndex) {
1138 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1139 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1141 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1148 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1152 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
1153 SDValue &Base, SDValue &OffImm) {
1154 // Match simple R - imm8 operands.
1155 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
1156 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1157 int RHSC = (int)RHS->getSExtValue();
1158 if (N.getOpcode() == ISD::SUB)
1161 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1162 Base = N.getOperand(0);
1163 if (Base.getOpcode() == ISD::FrameIndex) {
1164 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1165 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1167 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1176 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
1178 unsigned Opcode = Op->getOpcode();
1179 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1180 ? cast<LoadSDNode>(Op)->getAddressingMode()
1181 : cast<StoreSDNode>(Op)->getAddressingMode();
1183 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1184 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1185 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1186 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1193 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
1195 SDValue &OffReg, SDValue &ShImm) {
1196 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1197 if (N.getOpcode() != ISD::ADD)
1200 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1201 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1202 int RHSC = (int)RHS->getZExtValue();
1203 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1205 else if (RHSC < 0 && RHSC >= -255) // 8 bits
1209 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1210 // Compute R + (R << [1,2,3]) and reuse it.
1215 // Look for (R + R) or (R + (R << [1,2,3])).
1217 Base = N.getOperand(0);
1218 OffReg = N.getOperand(1);
1220 // Swap if it is ((R << c) + R).
1221 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1222 if (ShOpcVal != ARM_AM::lsl) {
1223 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1224 if (ShOpcVal == ARM_AM::lsl)
1225 std::swap(Base, OffReg);
1228 if (ShOpcVal == ARM_AM::lsl) {
1229 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1231 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1232 ShAmt = Sh->getZExtValue();
1233 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1234 OffReg = OffReg.getOperand(0);
1237 ShOpcVal = ARM_AM::no_shift;
1240 ShOpcVal = ARM_AM::no_shift;
1244 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
1249 //===--------------------------------------------------------------------===//
1251 /// getAL - Returns a ARMCC::AL immediate node.
1252 static inline SDValue getAL(SelectionDAG *CurDAG) {
1253 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
1256 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1257 LoadSDNode *LD = cast<LoadSDNode>(N);
1258 ISD::MemIndexedMode AM = LD->getAddressingMode();
1259 if (AM == ISD::UNINDEXED)
1262 EVT LoadedVT = LD->getMemoryVT();
1263 SDValue Offset, AMOpc;
1264 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1265 unsigned Opcode = 0;
1267 if (LoadedVT == MVT::i32 &&
1268 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
1269 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1271 } else if (LoadedVT == MVT::i16 &&
1272 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1274 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1275 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1276 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
1277 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
1278 if (LD->getExtensionType() == ISD::SEXTLOAD) {
1279 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1281 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1284 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
1286 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1292 SDValue Chain = LD->getChain();
1293 SDValue Base = LD->getBasePtr();
1294 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1295 CurDAG->getRegister(0, MVT::i32), Chain };
1296 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1297 MVT::Other, Ops, 6);
1303 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1304 LoadSDNode *LD = cast<LoadSDNode>(N);
1305 ISD::MemIndexedMode AM = LD->getAddressingMode();
1306 if (AM == ISD::UNINDEXED)
1309 EVT LoadedVT = LD->getMemoryVT();
1310 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
1312 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1313 unsigned Opcode = 0;
1315 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
1316 switch (LoadedVT.getSimpleVT().SimpleTy) {
1318 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1322 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1324 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
1329 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1331 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
1340 SDValue Chain = LD->getChain();
1341 SDValue Base = LD->getBasePtr();
1342 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
1343 CurDAG->getRegister(0, MVT::i32), Chain };
1344 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1345 MVT::Other, Ops, 5);
1351 /// PairSRegs - Form a D register from a pair of S registers.
1353 SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1354 DebugLoc dl = V0.getNode()->getDebugLoc();
1355 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1356 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1357 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1358 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1361 /// PairDRegs - Form a quad register from a pair of D registers.
1363 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1364 DebugLoc dl = V0.getNode()->getDebugLoc();
1365 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1366 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1367 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1368 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1371 /// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
1373 SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1374 DebugLoc dl = V0.getNode()->getDebugLoc();
1375 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1376 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1377 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1378 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1381 /// QuadSRegs - Form 4 consecutive S registers.
1383 SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1384 SDValue V2, SDValue V3) {
1385 DebugLoc dl = V0.getNode()->getDebugLoc();
1386 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1387 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1388 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1389 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1390 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1391 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1394 /// QuadDRegs - Form 4 consecutive D registers.
1396 SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1397 SDValue V2, SDValue V3) {
1398 DebugLoc dl = V0.getNode()->getDebugLoc();
1399 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1400 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1401 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1402 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1403 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1404 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1407 /// QuadQRegs - Form 4 consecutive Q registers.
1409 SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1410 SDValue V2, SDValue V3) {
1411 DebugLoc dl = V0.getNode()->getDebugLoc();
1412 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1413 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1414 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1415 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
1416 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1417 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1420 /// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1421 /// of a NEON VLD or VST instruction. The supported values depend on the
1422 /// number of registers being loaded.
1423 SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1424 bool is64BitVector) {
1425 unsigned NumRegs = NumVecs;
1426 if (!is64BitVector && NumVecs < 3)
1429 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1430 if (Alignment >= 32 && NumRegs == 4)
1432 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1434 else if (Alignment >= 8)
1439 return CurDAG->getTargetConstant(Alignment, MVT::i32);
1442 SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
1443 unsigned *DOpcodes, unsigned *QOpcodes0,
1444 unsigned *QOpcodes1) {
1445 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1446 DebugLoc dl = N->getDebugLoc();
1448 SDValue MemAddr, Align;
1449 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1452 SDValue Chain = N->getOperand(0);
1453 EVT VT = N->getValueType(0);
1454 bool is64BitVector = VT.is64BitVector();
1455 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1457 unsigned OpcodeIndex;
1458 switch (VT.getSimpleVT().SimpleTy) {
1459 default: llvm_unreachable("unhandled vld type");
1460 // Double-register operations:
1461 case MVT::v8i8: OpcodeIndex = 0; break;
1462 case MVT::v4i16: OpcodeIndex = 1; break;
1464 case MVT::v2i32: OpcodeIndex = 2; break;
1465 case MVT::v1i64: OpcodeIndex = 3; break;
1466 // Quad-register operations:
1467 case MVT::v16i8: OpcodeIndex = 0; break;
1468 case MVT::v8i16: OpcodeIndex = 1; break;
1470 case MVT::v4i32: OpcodeIndex = 2; break;
1471 case MVT::v2i64: OpcodeIndex = 3;
1472 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
1480 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1483 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1486 SDValue Pred = getAL(CurDAG);
1487 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1489 if (is64BitVector) {
1490 unsigned Opc = DOpcodes[OpcodeIndex];
1491 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1492 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1496 SuperReg = SDValue(VLd, 0);
1497 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1498 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1499 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
1501 ReplaceUses(SDValue(N, Vec), D);
1503 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1508 // Quad registers are directly supported for VLD1 and VLD2,
1509 // loading pairs of D regs.
1510 unsigned Opc = QOpcodes0[OpcodeIndex];
1511 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1512 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1516 SuperReg = SDValue(VLd, 0);
1517 Chain = SDValue(VLd, 1);
1520 // Otherwise, quad registers are loaded with two separate instructions,
1521 // where one loads the even registers and the other loads the odd registers.
1522 EVT AddrTy = MemAddr.getValueType();
1524 // Load the even subregs.
1525 unsigned Opc = QOpcodes0[OpcodeIndex];
1527 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1528 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1530 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1531 Chain = SDValue(VLdA, 2);
1533 // Load the odd subregs.
1534 Opc = QOpcodes1[OpcodeIndex];
1535 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1536 Pred, Reg0, Chain };
1538 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1539 SuperReg = SDValue(VLdB, 0);
1540 Chain = SDValue(VLdB, 2);
1543 // Extract out the Q registers.
1544 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1545 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1546 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1548 ReplaceUses(SDValue(N, Vec), Q);
1550 ReplaceUses(SDValue(N, NumVecs), Chain);
1554 SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
1555 unsigned *DOpcodes, unsigned *QOpcodes0,
1556 unsigned *QOpcodes1) {
1557 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
1558 DebugLoc dl = N->getDebugLoc();
1560 SDValue MemAddr, Align;
1561 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1564 SDValue Chain = N->getOperand(0);
1565 EVT VT = N->getOperand(3).getValueType();
1566 bool is64BitVector = VT.is64BitVector();
1567 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1569 unsigned OpcodeIndex;
1570 switch (VT.getSimpleVT().SimpleTy) {
1571 default: llvm_unreachable("unhandled vst type");
1572 // Double-register operations:
1573 case MVT::v8i8: OpcodeIndex = 0; break;
1574 case MVT::v4i16: OpcodeIndex = 1; break;
1576 case MVT::v2i32: OpcodeIndex = 2; break;
1577 case MVT::v1i64: OpcodeIndex = 3; break;
1578 // Quad-register operations:
1579 case MVT::v16i8: OpcodeIndex = 0; break;
1580 case MVT::v8i16: OpcodeIndex = 1; break;
1582 case MVT::v4i32: OpcodeIndex = 2; break;
1583 case MVT::v2i64: OpcodeIndex = 3;
1584 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1588 SDValue Pred = getAL(CurDAG);
1589 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1591 SmallVector<SDValue, 7> Ops;
1592 Ops.push_back(MemAddr);
1593 Ops.push_back(Align);
1595 if (is64BitVector) {
1597 Ops.push_back(N->getOperand(3));
1600 SDValue V0 = N->getOperand(0+3);
1601 SDValue V1 = N->getOperand(1+3);
1603 // Form a REG_SEQUENCE to force register allocation.
1605 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1607 SDValue V2 = N->getOperand(2+3);
1608 // If it's a vld3, form a quad D-register and leave the last part as
1610 SDValue V3 = (NumVecs == 3)
1611 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1612 : N->getOperand(3+3);
1613 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1615 Ops.push_back(RegSeq);
1617 Ops.push_back(Pred);
1618 Ops.push_back(Reg0); // predicate register
1619 Ops.push_back(Chain);
1620 unsigned Opc = DOpcodes[OpcodeIndex];
1621 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
1625 // Quad registers are directly supported for VST1 and VST2.
1626 unsigned Opc = QOpcodes0[OpcodeIndex];
1628 Ops.push_back(N->getOperand(3));
1630 // Form a QQ register.
1631 SDValue Q0 = N->getOperand(3);
1632 SDValue Q1 = N->getOperand(4);
1633 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
1635 Ops.push_back(Pred);
1636 Ops.push_back(Reg0); // predicate register
1637 Ops.push_back(Chain);
1638 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
1641 // Otherwise, quad registers are stored with two separate instructions,
1642 // where one stores the even registers and the other stores the odd registers.
1644 // Form the QQQQ REG_SEQUENCE.
1645 SDValue V0 = N->getOperand(0+3);
1646 SDValue V1 = N->getOperand(1+3);
1647 SDValue V2 = N->getOperand(2+3);
1648 SDValue V3 = (NumVecs == 3)
1649 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1650 : N->getOperand(3+3);
1651 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1653 // Store the even D registers.
1654 Ops.push_back(Reg0); // post-access address offset
1655 Ops.push_back(RegSeq);
1656 Ops.push_back(Pred);
1657 Ops.push_back(Reg0); // predicate register
1658 Ops.push_back(Chain);
1659 unsigned Opc = QOpcodes0[OpcodeIndex];
1660 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1661 MVT::Other, Ops.data(), 7);
1662 Chain = SDValue(VStA, 1);
1664 // Store the odd D registers.
1665 Ops[0] = SDValue(VStA, 0); // MemAddr
1667 Opc = QOpcodes1[OpcodeIndex];
1668 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1669 MVT::Other, Ops.data(), 7);
1670 Chain = SDValue(VStB, 1);
1671 ReplaceUses(SDValue(N, 0), Chain);
1675 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
1676 unsigned NumVecs, unsigned *DOpcodes,
1677 unsigned *QOpcodes) {
1678 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1679 DebugLoc dl = N->getDebugLoc();
1681 SDValue MemAddr, Align;
1682 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
1685 SDValue Chain = N->getOperand(0);
1687 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
1688 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
1689 bool is64BitVector = VT.is64BitVector();
1691 unsigned Alignment = 0;
1693 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1694 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1695 if (Alignment > NumBytes)
1696 Alignment = NumBytes;
1697 if (Alignment < 8 && Alignment < NumBytes)
1699 // Alignment must be a power of two; make sure of that.
1700 Alignment = (Alignment & -Alignment);
1704 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1706 unsigned OpcodeIndex;
1707 switch (VT.getSimpleVT().SimpleTy) {
1708 default: llvm_unreachable("unhandled vld/vst lane type");
1709 // Double-register operations:
1710 case MVT::v8i8: OpcodeIndex = 0; break;
1711 case MVT::v4i16: OpcodeIndex = 1; break;
1713 case MVT::v2i32: OpcodeIndex = 2; break;
1714 // Quad-register operations:
1715 case MVT::v8i16: OpcodeIndex = 0; break;
1717 case MVT::v4i32: OpcodeIndex = 1; break;
1720 SDValue Pred = getAL(CurDAG);
1721 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1723 SmallVector<SDValue, 7> Ops;
1724 Ops.push_back(MemAddr);
1725 Ops.push_back(Align);
1727 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1728 QOpcodes[OpcodeIndex]);
1731 SDValue V0 = N->getOperand(0+3);
1732 SDValue V1 = N->getOperand(1+3);
1735 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1737 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1739 SDValue V2 = N->getOperand(2+3);
1740 SDValue V3 = (NumVecs == 3)
1741 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1742 : N->getOperand(3+3);
1744 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1746 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1748 Ops.push_back(SuperReg);
1749 Ops.push_back(getI32Imm(Lane));
1750 Ops.push_back(Pred);
1751 Ops.push_back(Reg0);
1752 Ops.push_back(Chain);
1755 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
1758 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1761 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1763 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1765 SuperReg = SDValue(VLdLn, 0);
1766 Chain = SDValue(VLdLn, 1);
1768 // Extract the subregisters.
1769 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1770 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1771 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1772 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1773 ReplaceUses(SDValue(N, Vec),
1774 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1775 ReplaceUses(SDValue(N, NumVecs), Chain);
1779 SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1780 unsigned *Opcodes) {
1781 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1782 DebugLoc dl = N->getDebugLoc();
1784 SDValue MemAddr, Align;
1785 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1788 SDValue Chain = N->getOperand(0);
1789 EVT VT = N->getValueType(0);
1791 unsigned Alignment = 0;
1793 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1794 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1795 if (Alignment > NumBytes)
1796 Alignment = NumBytes;
1797 if (Alignment < 8 && Alignment < NumBytes)
1799 // Alignment must be a power of two; make sure of that.
1800 Alignment = (Alignment & -Alignment);
1804 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1806 unsigned OpcodeIndex;
1807 switch (VT.getSimpleVT().SimpleTy) {
1808 default: llvm_unreachable("unhandled vld-dup type");
1809 case MVT::v8i8: OpcodeIndex = 0; break;
1810 case MVT::v4i16: OpcodeIndex = 1; break;
1812 case MVT::v2i32: OpcodeIndex = 2; break;
1815 SDValue Pred = getAL(CurDAG);
1816 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1818 unsigned Opc = Opcodes[OpcodeIndex];
1819 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1821 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1822 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1823 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1824 SuperReg = SDValue(VLdDup, 0);
1825 Chain = SDValue(VLdDup, 1);
1827 // Extract the subregisters.
1828 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1829 unsigned SubIdx = ARM::dsub_0;
1830 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1831 ReplaceUses(SDValue(N, Vec),
1832 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1833 ReplaceUses(SDValue(N, NumVecs), Chain);
1837 SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1839 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1840 DebugLoc dl = N->getDebugLoc();
1841 EVT VT = N->getValueType(0);
1842 unsigned FirstTblReg = IsExt ? 2 : 1;
1844 // Form a REG_SEQUENCE to force register allocation.
1846 SDValue V0 = N->getOperand(FirstTblReg + 0);
1847 SDValue V1 = N->getOperand(FirstTblReg + 1);
1849 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1851 SDValue V2 = N->getOperand(FirstTblReg + 2);
1852 // If it's a vtbl3, form a quad D-register and leave the last part as
1854 SDValue V3 = (NumVecs == 3)
1855 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1856 : N->getOperand(FirstTblReg + 3);
1857 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1860 SmallVector<SDValue, 6> Ops;
1862 Ops.push_back(N->getOperand(1));
1863 Ops.push_back(RegSeq);
1864 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
1865 Ops.push_back(getAL(CurDAG)); // predicate
1866 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
1867 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
1870 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
1872 if (!Subtarget->hasV6T2Ops())
1875 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1876 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1879 // For unsigned extracts, check for a shift right and mask
1880 unsigned And_imm = 0;
1881 if (N->getOpcode() == ISD::AND) {
1882 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1884 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1885 if (And_imm & (And_imm + 1))
1888 unsigned Srl_imm = 0;
1889 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1891 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1893 unsigned Width = CountTrailingOnes_32(And_imm);
1894 unsigned LSB = Srl_imm;
1895 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1896 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1897 CurDAG->getTargetConstant(LSB, MVT::i32),
1898 CurDAG->getTargetConstant(Width, MVT::i32),
1899 getAL(CurDAG), Reg0 };
1900 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1906 // Otherwise, we're looking for a shift of a shift
1907 unsigned Shl_imm = 0;
1908 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
1909 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1910 unsigned Srl_imm = 0;
1911 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
1912 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1913 unsigned Width = 32 - Srl_imm;
1914 int LSB = Srl_imm - Shl_imm;
1917 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1918 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1919 CurDAG->getTargetConstant(LSB, MVT::i32),
1920 CurDAG->getTargetConstant(Width, MVT::i32),
1921 getAL(CurDAG), Reg0 };
1922 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1928 SDNode *ARMDAGToDAGISel::
1929 SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1930 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1933 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
1934 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1935 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1938 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1939 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1940 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1941 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1943 llvm_unreachable("Unknown so_reg opcode!");
1947 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1948 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1949 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
1950 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
1955 SDNode *ARMDAGToDAGISel::
1956 SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1957 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1961 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
1962 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1963 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
1964 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
1969 SDNode *ARMDAGToDAGISel::
1970 SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
1971 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1972 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1977 unsigned TrueImm = T->getZExtValue();
1978 if (is_t2_so_imm(TrueImm)) {
1979 Opc = ARM::t2MOVCCi;
1980 } else if (TrueImm <= 0xffff) {
1981 Opc = ARM::t2MOVCCi16;
1982 } else if (is_t2_so_imm_not(TrueImm)) {
1984 Opc = ARM::t2MVNCCi;
1985 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
1987 Opc = ARM::t2MOVCCi32imm;
1991 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
1992 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1993 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1994 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2000 SDNode *ARMDAGToDAGISel::
2001 SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
2002 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2003 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2008 unsigned TrueImm = T->getZExtValue();
2009 bool isSoImm = is_so_imm(TrueImm);
2012 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2013 Opc = ARM::MOVCCi16;
2014 } else if (is_so_imm_not(TrueImm)) {
2017 } else if (TrueVal.getNode()->hasOneUse() &&
2018 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
2020 Opc = ARM::MOVCCi32imm;
2024 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2025 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2026 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
2027 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2033 SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2034 EVT VT = N->getValueType(0);
2035 SDValue FalseVal = N->getOperand(0);
2036 SDValue TrueVal = N->getOperand(1);
2037 SDValue CC = N->getOperand(2);
2038 SDValue CCR = N->getOperand(3);
2039 SDValue InFlag = N->getOperand(4);
2040 assert(CC.getOpcode() == ISD::Constant);
2041 assert(CCR.getOpcode() == ISD::Register);
2042 ARMCC::CondCodes CCVal =
2043 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
2045 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2046 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2047 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2048 // Pattern complexity = 18 cost = 1 size = 0
2052 if (Subtarget->isThumb()) {
2053 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
2054 CCVal, CCR, InFlag);
2056 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
2057 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2061 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
2062 CCVal, CCR, InFlag);
2064 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
2065 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2070 // Pattern: (ARMcmov:i32 GPR:i32:$false,
2071 // (imm:i32)<<P:Pred_so_imm>>:$true,
2073 // Emits: (MOVCCi:i32 GPR:i32:$false,
2074 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2075 // Pattern complexity = 10 cost = 1 size = 0
2076 if (Subtarget->isThumb()) {
2077 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
2078 CCVal, CCR, InFlag);
2080 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
2081 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2085 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
2086 CCVal, CCR, InFlag);
2088 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
2089 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2095 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2096 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2097 // Pattern complexity = 6 cost = 1 size = 0
2099 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2100 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2101 // Pattern complexity = 6 cost = 11 size = 0
2103 // Also FCPYScc and FCPYDcc.
2104 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2105 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
2107 switch (VT.getSimpleVT().SimpleTy) {
2108 default: assert(false && "Illegal conditional move type!");
2111 Opc = Subtarget->isThumb()
2112 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2122 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
2125 SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2126 // The only time a CONCAT_VECTORS operation can have legal types is when
2127 // two 64-bit vectors are concatenated to a 128-bit vector.
2128 EVT VT = N->getValueType(0);
2129 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2130 llvm_unreachable("unexpected CONCAT_VECTORS");
2131 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
2134 SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
2135 DebugLoc dl = N->getDebugLoc();
2137 if (N->isMachineOpcode())
2138 return NULL; // Already selected.
2140 switch (N->getOpcode()) {
2142 case ISD::Constant: {
2143 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
2145 if (Subtarget->hasThumb2())
2146 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2147 // be done with MOV + MOVT, at worst.
2150 if (Subtarget->isThumb()) {
2151 UseCP = (Val > 255 && // MOV
2152 ~Val > 255 && // MOV + MVN
2153 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
2155 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2156 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2157 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2162 CurDAG->getTargetConstantPool(ConstantInt::get(
2163 Type::getInt32Ty(*CurDAG->getContext()), Val),
2164 TLI.getPointerTy());
2167 if (Subtarget->isThumb1Only()) {
2168 SDValue Pred = getAL(CurDAG);
2169 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2170 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
2171 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
2176 CurDAG->getTargetConstant(0, MVT::i32),
2178 CurDAG->getRegister(0, MVT::i32),
2179 CurDAG->getEntryNode()
2181 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
2184 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
2188 // Other cases are autogenerated.
2191 case ISD::FrameIndex: {
2192 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
2193 int FI = cast<FrameIndexSDNode>(N)->getIndex();
2194 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
2195 if (Subtarget->isThumb1Only()) {
2196 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2197 CurDAG->getTargetConstant(0, MVT::i32));
2199 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2200 ARM::t2ADDri : ARM::ADDri);
2201 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2202 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2203 CurDAG->getRegister(0, MVT::i32) };
2204 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2208 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2212 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
2216 if (Subtarget->isThumb1Only())
2218 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
2219 unsigned RHSV = C->getZExtValue();
2221 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
2222 unsigned ShImm = Log2_32(RHSV-1);
2225 SDValue V = N->getOperand(0);
2226 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2227 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2228 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2229 if (Subtarget->isThumb()) {
2230 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2231 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
2233 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2234 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
2237 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
2238 unsigned ShImm = Log2_32(RHSV+1);
2241 SDValue V = N->getOperand(0);
2242 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2243 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2244 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2245 if (Subtarget->isThumb()) {
2246 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2247 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
2249 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2250 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
2256 // Check for unsigned bitfield extract
2257 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2260 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2261 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2262 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2263 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2264 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
2265 EVT VT = N->getValueType(0);
2268 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2270 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2273 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
2274 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2277 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2278 SDValue N2 = N0.getOperand(1);
2279 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2282 unsigned N1CVal = N1C->getZExtValue();
2283 unsigned N2CVal = N2C->getZExtValue();
2284 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2285 (N1CVal & 0xffffU) == 0xffffU &&
2286 (N2CVal & 0xffffU) == 0x0U) {
2287 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2289 SDValue Ops[] = { N0.getOperand(0), Imm16,
2290 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2291 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2296 case ARMISD::VMOVRRD:
2297 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
2298 N->getOperand(0), getAL(CurDAG),
2299 CurDAG->getRegister(0, MVT::i32));
2300 case ISD::UMUL_LOHI: {
2301 if (Subtarget->isThumb1Only())
2303 if (Subtarget->isThumb()) {
2304 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2305 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2306 CurDAG->getRegister(0, MVT::i32) };
2307 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
2309 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2310 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2311 CurDAG->getRegister(0, MVT::i32) };
2312 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2313 ARM::UMULL : ARM::UMULLv5,
2314 dl, MVT::i32, MVT::i32, Ops, 5);
2317 case ISD::SMUL_LOHI: {
2318 if (Subtarget->isThumb1Only())
2320 if (Subtarget->isThumb()) {
2321 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2322 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2323 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
2325 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2326 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2327 CurDAG->getRegister(0, MVT::i32) };
2328 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2329 ARM::SMULL : ARM::SMULLv5,
2330 dl, MVT::i32, MVT::i32, Ops, 5);
2334 SDNode *ResNode = 0;
2335 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2336 ResNode = SelectT2IndexedLoad(N);
2338 ResNode = SelectARMIndexedLoad(N);
2341 // Other cases are autogenerated.
2344 case ARMISD::BRCOND: {
2345 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2346 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2347 // Pattern complexity = 6 cost = 1 size = 0
2349 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2350 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2351 // Pattern complexity = 6 cost = 1 size = 0
2353 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2354 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2355 // Pattern complexity = 6 cost = 1 size = 0
2357 unsigned Opc = Subtarget->isThumb() ?
2358 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
2359 SDValue Chain = N->getOperand(0);
2360 SDValue N1 = N->getOperand(1);
2361 SDValue N2 = N->getOperand(2);
2362 SDValue N3 = N->getOperand(3);
2363 SDValue InFlag = N->getOperand(4);
2364 assert(N1.getOpcode() == ISD::BasicBlock);
2365 assert(N2.getOpcode() == ISD::Constant);
2366 assert(N3.getOpcode() == ISD::Register);
2368 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2369 cast<ConstantSDNode>(N2)->getZExtValue()),
2371 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
2372 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2374 Chain = SDValue(ResNode, 0);
2375 if (N->getNumValues() == 2) {
2376 InFlag = SDValue(ResNode, 1);
2377 ReplaceUses(SDValue(N, 1), InFlag);
2379 ReplaceUses(SDValue(N, 0),
2380 SDValue(Chain.getNode(), Chain.getResNo()));
2384 return SelectCMOVOp(N);
2385 case ARMISD::CNEG: {
2386 EVT VT = N->getValueType(0);
2387 SDValue N0 = N->getOperand(0);
2388 SDValue N1 = N->getOperand(1);
2389 SDValue N2 = N->getOperand(2);
2390 SDValue N3 = N->getOperand(3);
2391 SDValue InFlag = N->getOperand(4);
2392 assert(N2.getOpcode() == ISD::Constant);
2393 assert(N3.getOpcode() == ISD::Register);
2395 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2396 cast<ConstantSDNode>(N2)->getZExtValue()),
2398 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
2400 switch (VT.getSimpleVT().SimpleTy) {
2401 default: assert(false && "Illegal conditional move type!");
2410 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
2413 case ARMISD::VZIP: {
2415 EVT VT = N->getValueType(0);
2416 switch (VT.getSimpleVT().SimpleTy) {
2417 default: return NULL;
2418 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2419 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2421 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2422 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2423 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2425 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2427 SDValue Pred = getAL(CurDAG);
2428 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2429 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2430 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2432 case ARMISD::VUZP: {
2434 EVT VT = N->getValueType(0);
2435 switch (VT.getSimpleVT().SimpleTy) {
2436 default: return NULL;
2437 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2438 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2440 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2441 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2442 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2444 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2446 SDValue Pred = getAL(CurDAG);
2447 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2448 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2449 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2451 case ARMISD::VTRN: {
2453 EVT VT = N->getValueType(0);
2454 switch (VT.getSimpleVT().SimpleTy) {
2455 default: return NULL;
2456 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2457 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2459 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2460 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2461 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2463 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2465 SDValue Pred = getAL(CurDAG);
2466 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2467 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2468 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2470 case ARMISD::BUILD_VECTOR: {
2471 EVT VecVT = N->getValueType(0);
2472 EVT EltVT = VecVT.getVectorElementType();
2473 unsigned NumElts = VecVT.getVectorNumElements();
2474 if (EltVT == MVT::f64) {
2475 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2476 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2478 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
2480 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2481 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2482 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2483 N->getOperand(2), N->getOperand(3));
2486 case ARMISD::VLD2DUP: {
2487 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2488 ARM::VLD2DUPd32Pseudo };
2489 return SelectVLDDup(N, 2, Opcodes);
2492 case ARMISD::VLD3DUP: {
2493 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2494 ARM::VLD3DUPd32Pseudo };
2495 return SelectVLDDup(N, 3, Opcodes);
2498 case ARMISD::VLD4DUP: {
2499 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2500 ARM::VLD4DUPd32Pseudo };
2501 return SelectVLDDup(N, 4, Opcodes);
2504 case ISD::INTRINSIC_VOID:
2505 case ISD::INTRINSIC_W_CHAIN: {
2506 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
2511 case Intrinsic::arm_neon_vld1: {
2512 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2513 ARM::VLD1d32, ARM::VLD1d64 };
2514 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2515 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
2516 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2519 case Intrinsic::arm_neon_vld2: {
2520 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2521 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2522 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2523 ARM::VLD2q32Pseudo };
2524 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
2527 case Intrinsic::arm_neon_vld3: {
2528 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2529 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2530 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2531 ARM::VLD3q16Pseudo_UPD,
2532 ARM::VLD3q32Pseudo_UPD };
2533 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2534 ARM::VLD3q16oddPseudo_UPD,
2535 ARM::VLD3q32oddPseudo_UPD };
2536 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
2539 case Intrinsic::arm_neon_vld4: {
2540 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2541 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2542 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2543 ARM::VLD4q16Pseudo_UPD,
2544 ARM::VLD4q32Pseudo_UPD };
2545 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2546 ARM::VLD4q16oddPseudo_UPD,
2547 ARM::VLD4q32oddPseudo_UPD };
2548 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
2551 case Intrinsic::arm_neon_vld2lane: {
2552 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2553 ARM::VLD2LNd32Pseudo };
2554 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2555 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
2558 case Intrinsic::arm_neon_vld3lane: {
2559 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2560 ARM::VLD3LNd32Pseudo };
2561 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2562 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
2565 case Intrinsic::arm_neon_vld4lane: {
2566 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2567 ARM::VLD4LNd32Pseudo };
2568 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2569 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
2572 case Intrinsic::arm_neon_vst1: {
2573 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2574 ARM::VST1d32, ARM::VST1d64 };
2575 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2576 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
2577 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2580 case Intrinsic::arm_neon_vst2: {
2581 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2582 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2583 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2584 ARM::VST2q32Pseudo };
2585 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
2588 case Intrinsic::arm_neon_vst3: {
2589 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2590 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2591 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2592 ARM::VST3q16Pseudo_UPD,
2593 ARM::VST3q32Pseudo_UPD };
2594 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2595 ARM::VST3q16oddPseudo_UPD,
2596 ARM::VST3q32oddPseudo_UPD };
2597 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
2600 case Intrinsic::arm_neon_vst4: {
2601 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
2602 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
2603 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2604 ARM::VST4q16Pseudo_UPD,
2605 ARM::VST4q32Pseudo_UPD };
2606 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2607 ARM::VST4q16oddPseudo_UPD,
2608 ARM::VST4q32oddPseudo_UPD };
2609 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
2612 case Intrinsic::arm_neon_vst2lane: {
2613 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2614 ARM::VST2LNd32Pseudo };
2615 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2616 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
2619 case Intrinsic::arm_neon_vst3lane: {
2620 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2621 ARM::VST3LNd32Pseudo };
2622 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2623 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
2626 case Intrinsic::arm_neon_vst4lane: {
2627 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2628 ARM::VST4LNd32Pseudo };
2629 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2630 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
2636 case ISD::INTRINSIC_WO_CHAIN: {
2637 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2642 case Intrinsic::arm_neon_vtbl2:
2643 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
2644 case Intrinsic::arm_neon_vtbl3:
2645 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
2646 case Intrinsic::arm_neon_vtbl4:
2647 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
2649 case Intrinsic::arm_neon_vtbx2:
2650 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
2651 case Intrinsic::arm_neon_vtbx3:
2652 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
2653 case Intrinsic::arm_neon_vtbx4:
2654 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
2659 case ISD::CONCAT_VECTORS:
2660 return SelectConcatVector(N);
2663 return SelectCode(N);
2666 bool ARMDAGToDAGISel::
2667 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2668 std::vector<SDValue> &OutOps) {
2669 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
2670 // Require the address to be in a register. That is safe for all ARM
2671 // variants and it is hard to do anything much smarter without knowing
2672 // how the operand is used.
2673 OutOps.push_back(Op);
2677 /// createARMISelDag - This pass converts a legalized DAG into a
2678 /// ARM-specific DAG, ready for instruction scheduling.
2680 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2681 CodeGenOpt::Level OptLevel) {
2682 return new ARMDAGToDAGISel(TM, OptLevel);