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 "ARMTargetMachine.h"
18 #include "MCTargetDesc/ARMAddressingModes.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 SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
97 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
99 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
101 return SelectRegShifterOperand(N, A, B, C, false);
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
127 // return SelectAddrMode2ShOp(N, Base, Offset, Opc);
128 // This always matches one way or another.
132 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
133 SDValue &Offset, SDValue &Opc);
134 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
135 SDValue &Offset, SDValue &Opc);
136 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
137 SDValue &Offset, SDValue &Opc);
138 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
139 bool SelectAddrMode3(SDValue N, SDValue &Base,
140 SDValue &Offset, SDValue &Opc);
141 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
142 SDValue &Offset, SDValue &Opc);
143 bool SelectAddrMode5(SDValue N, SDValue &Base,
145 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
146 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
148 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
150 // Thumb Addressing Modes:
151 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
152 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
154 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
156 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
157 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
159 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
161 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
163 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
165 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
167 // Thumb 2 Addressing Modes:
168 bool SelectT2ShifterOperandReg(SDValue N,
169 SDValue &BaseReg, SDValue &Opc);
170 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
171 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
173 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
175 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
176 SDValue &OffReg, SDValue &ShImm);
178 inline bool is_so_imm(unsigned Imm) const {
179 return ARM_AM::getSOImmVal(Imm) != -1;
182 inline bool is_so_imm_not(unsigned Imm) const {
183 return ARM_AM::getSOImmVal(~Imm) != -1;
186 inline bool is_t2_so_imm(unsigned Imm) const {
187 return ARM_AM::getT2SOImmVal(Imm) != -1;
190 inline bool is_t2_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getT2SOImmVal(~Imm) != -1;
194 // Include the pieces autogenerated from the target description.
195 #include "ARMGenDAGISel.inc"
198 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
200 SDNode *SelectARMIndexedLoad(SDNode *N);
201 SDNode *SelectT2IndexedLoad(SDNode *N);
203 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
204 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
205 /// loads of D registers and even subregs and odd subregs of Q registers.
206 /// For NumVecs <= 2, QOpcodes1 is not used.
207 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
208 const uint16_t *DOpcodes,
209 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
211 /// SelectVST - Select NEON store intrinsics. NumVecs should
212 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
213 /// stores of D registers and even subregs and odd subregs of Q registers.
214 /// For NumVecs <= 2, QOpcodes1 is not used.
215 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
216 const uint16_t *DOpcodes,
217 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
219 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
220 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
221 /// load/store of D registers and Q registers.
222 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
223 bool isUpdating, unsigned NumVecs,
224 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
226 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
227 /// should be 2, 3 or 4. The opcode array specifies the instructions used
228 /// for loading D registers. (Q registers are not supported.)
229 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
230 const uint16_t *Opcodes);
232 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
233 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
234 /// generated to force the table registers to be consecutive.
235 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
237 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
238 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
240 /// SelectCMOVOp - Select CMOV instructions for ARM.
241 SDNode *SelectCMOVOp(SDNode *N);
242 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
243 ARMCC::CondCodes CCVal, SDValue CCR,
245 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
246 ARMCC::CondCodes CCVal, SDValue CCR,
248 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
249 ARMCC::CondCodes CCVal, SDValue CCR,
251 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
252 ARMCC::CondCodes CCVal, SDValue CCR,
255 // Select special operations if node forms integer ABS pattern
256 SDNode *SelectABSOp(SDNode *N);
258 SDNode *SelectConcatVector(SDNode *N);
260 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
262 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
263 /// inline asm expressions.
264 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
266 std::vector<SDValue> &OutOps);
268 // Form pairs of consecutive S, D, or Q registers.
269 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
270 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
271 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
273 // Form sequences of 4 consecutive S, D, or Q registers.
274 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
275 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
276 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
278 // Get the alignment operand for a NEON VLD or VST instruction.
279 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
283 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
284 /// operand. If so Imm will receive the 32-bit value.
285 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
286 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
287 Imm = cast<ConstantSDNode>(N)->getZExtValue();
293 // isInt32Immediate - This method tests to see if a constant operand.
294 // If so Imm will receive the 32 bit value.
295 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
296 return isInt32Immediate(N.getNode(), Imm);
299 // isOpcWithIntImmediate - This method tests to see if the node is a specific
300 // opcode and that it has a immediate integer right operand.
301 // If so Imm will receive the 32 bit value.
302 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
303 return N->getOpcode() == Opc &&
304 isInt32Immediate(N->getOperand(1).getNode(), Imm);
307 /// \brief Check whether a particular node is a constant value representable as
308 /// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
310 /// \param ScaledConstant [out] - On success, the pre-scaled constant value.
311 static bool isScaledConstantInRange(SDValue Node, int Scale,
312 int RangeMin, int RangeMax,
313 int &ScaledConstant) {
314 assert(Scale > 0 && "Invalid scale!");
316 // Check that this is a constant.
317 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
321 ScaledConstant = (int) C->getZExtValue();
322 if ((ScaledConstant % Scale) != 0)
325 ScaledConstant /= Scale;
326 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
329 /// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
330 /// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
331 /// least on current ARM implementations) which should be avoidded.
332 bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
333 if (OptLevel == CodeGenOpt::None)
336 if (!CheckVMLxHazard)
339 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
345 SDNode *Use = *N->use_begin();
346 if (Use->getOpcode() == ISD::CopyToReg)
348 if (Use->isMachineOpcode()) {
349 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
352 unsigned Opcode = MCID.getOpcode();
353 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
355 // vmlx feeding into another vmlx. We actually want to unfold
356 // the use later in the MLxExpansion pass. e.g.
358 // vmla (stall 8 cycles)
363 // This adds up to about 18 - 19 cycles.
366 // vmul (stall 4 cycles)
367 // vadd adds up to about 14 cycles.
368 return TII->isFpMLxInstruction(Opcode);
374 bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
375 ARM_AM::ShiftOpc ShOpcVal,
377 if (!Subtarget->isCortexA9())
379 if (Shift.hasOneUse())
382 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
385 bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
388 bool CheckProfitability) {
389 if (DisableShifterOp)
392 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
394 // Don't match base register only case. That is matched to a separate
395 // lower complexity pattern with explicit register operand.
396 if (ShOpcVal == ARM_AM::no_shift) return false;
398 BaseReg = N.getOperand(0);
399 unsigned ShImmVal = 0;
400 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
401 if (!RHS) return false;
402 ShImmVal = RHS->getZExtValue() & 31;
403 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
408 bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
412 bool CheckProfitability) {
413 if (DisableShifterOp)
416 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
418 // Don't match base register only case. That is matched to a separate
419 // lower complexity pattern with explicit register operand.
420 if (ShOpcVal == ARM_AM::no_shift) return false;
422 BaseReg = N.getOperand(0);
423 unsigned ShImmVal = 0;
424 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
425 if (RHS) return false;
427 ShReg = N.getOperand(1);
428 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
430 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
436 bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
439 // Match simple R + imm12 operands.
442 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
443 !CurDAG->isBaseWithConstantOffset(N)) {
444 if (N.getOpcode() == ISD::FrameIndex) {
445 // Match frame index.
446 int FI = cast<FrameIndexSDNode>(N)->getIndex();
447 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
448 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
452 if (N.getOpcode() == ARMISD::Wrapper &&
453 !(Subtarget->useMovt() &&
454 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
455 Base = N.getOperand(0);
458 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
462 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
463 int RHSC = (int)RHS->getZExtValue();
464 if (N.getOpcode() == ISD::SUB)
467 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
468 Base = N.getOperand(0);
469 if (Base.getOpcode() == ISD::FrameIndex) {
470 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
471 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
473 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
480 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
486 bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
488 if (N.getOpcode() == ISD::MUL &&
489 (!Subtarget->isCortexA9() || N.hasOneUse())) {
490 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
491 // X * [3,5,9] -> X + X * [2,4,8] etc.
492 int RHSC = (int)RHS->getZExtValue();
495 ARM_AM::AddrOpc AddSub = ARM_AM::add;
497 AddSub = ARM_AM::sub;
500 if (isPowerOf2_32(RHSC)) {
501 unsigned ShAmt = Log2_32(RHSC);
502 Base = Offset = N.getOperand(0);
503 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
512 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
513 // ISD::OR that is equivalent to an ISD::ADD.
514 !CurDAG->isBaseWithConstantOffset(N))
517 // Leave simple R +/- imm12 operands for LDRi12
518 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
520 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
521 -0x1000+1, 0x1000, RHSC)) // 12 bits.
525 // Otherwise this is R +/- [possibly shifted] R.
526 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
527 ARM_AM::ShiftOpc ShOpcVal =
528 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
531 Base = N.getOperand(0);
532 Offset = N.getOperand(1);
534 if (ShOpcVal != ARM_AM::no_shift) {
535 // Check to see if the RHS of the shift is a constant, if not, we can't fold
537 if (ConstantSDNode *Sh =
538 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
539 ShAmt = Sh->getZExtValue();
540 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
541 Offset = N.getOperand(1).getOperand(0);
544 ShOpcVal = ARM_AM::no_shift;
547 ShOpcVal = ARM_AM::no_shift;
551 // Try matching (R shl C) + (R).
552 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
553 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
554 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
555 if (ShOpcVal != ARM_AM::no_shift) {
556 // Check to see if the RHS of the shift is a constant, if not, we can't
558 if (ConstantSDNode *Sh =
559 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
560 ShAmt = Sh->getZExtValue();
561 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
562 Offset = N.getOperand(0).getOperand(0);
563 Base = N.getOperand(1);
566 ShOpcVal = ARM_AM::no_shift;
569 ShOpcVal = ARM_AM::no_shift;
574 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
582 AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
586 if (N.getOpcode() == ISD::MUL &&
587 (!Subtarget->isCortexA9() || N.hasOneUse())) {
588 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
589 // X * [3,5,9] -> X + X * [2,4,8] etc.
590 int RHSC = (int)RHS->getZExtValue();
593 ARM_AM::AddrOpc AddSub = ARM_AM::add;
595 AddSub = ARM_AM::sub;
598 if (isPowerOf2_32(RHSC)) {
599 unsigned ShAmt = Log2_32(RHSC);
600 Base = Offset = N.getOperand(0);
601 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
610 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
611 // ISD::OR that is equivalent to an ADD.
612 !CurDAG->isBaseWithConstantOffset(N)) {
614 if (N.getOpcode() == ISD::FrameIndex) {
615 int FI = cast<FrameIndexSDNode>(N)->getIndex();
616 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
617 } else if (N.getOpcode() == ARMISD::Wrapper &&
618 !(Subtarget->useMovt() &&
619 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
620 Base = N.getOperand(0);
622 Offset = CurDAG->getRegister(0, MVT::i32);
623 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
629 // Match simple R +/- imm12 operands.
630 if (N.getOpcode() != ISD::SUB) {
632 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
633 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
634 Base = N.getOperand(0);
635 if (Base.getOpcode() == ISD::FrameIndex) {
636 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
637 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
639 Offset = CurDAG->getRegister(0, MVT::i32);
641 ARM_AM::AddrOpc AddSub = ARM_AM::add;
643 AddSub = ARM_AM::sub;
646 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
653 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
654 // Compute R +/- (R << N) and reuse it.
656 Offset = CurDAG->getRegister(0, MVT::i32);
657 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
663 // Otherwise this is R +/- [possibly shifted] R.
664 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
665 ARM_AM::ShiftOpc ShOpcVal =
666 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
669 Base = N.getOperand(0);
670 Offset = N.getOperand(1);
672 if (ShOpcVal != ARM_AM::no_shift) {
673 // Check to see if the RHS of the shift is a constant, if not, we can't fold
675 if (ConstantSDNode *Sh =
676 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
677 ShAmt = Sh->getZExtValue();
678 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
679 Offset = N.getOperand(1).getOperand(0);
682 ShOpcVal = ARM_AM::no_shift;
685 ShOpcVal = ARM_AM::no_shift;
689 // Try matching (R shl C) + (R).
690 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
691 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
692 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
693 if (ShOpcVal != ARM_AM::no_shift) {
694 // Check to see if the RHS of the shift is a constant, if not, we can't
696 if (ConstantSDNode *Sh =
697 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
698 ShAmt = Sh->getZExtValue();
699 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
700 Offset = N.getOperand(0).getOperand(0);
701 Base = N.getOperand(1);
704 ShOpcVal = ARM_AM::no_shift;
707 ShOpcVal = ARM_AM::no_shift;
712 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
717 bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
718 SDValue &Offset, SDValue &Opc) {
719 unsigned Opcode = Op->getOpcode();
720 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
721 ? cast<LoadSDNode>(Op)->getAddressingMode()
722 : cast<StoreSDNode>(Op)->getAddressingMode();
723 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
724 ? ARM_AM::add : ARM_AM::sub;
726 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
730 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
732 if (ShOpcVal != ARM_AM::no_shift) {
733 // Check to see if the RHS of the shift is a constant, if not, we can't fold
735 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
736 ShAmt = Sh->getZExtValue();
737 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
738 Offset = N.getOperand(0);
741 ShOpcVal = ARM_AM::no_shift;
744 ShOpcVal = ARM_AM::no_shift;
748 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
753 bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
754 SDValue &Offset, SDValue &Opc) {
755 unsigned Opcode = Op->getOpcode();
756 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
757 ? cast<LoadSDNode>(Op)->getAddressingMode()
758 : cast<StoreSDNode>(Op)->getAddressingMode();
759 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
760 ? ARM_AM::add : ARM_AM::sub;
762 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
763 if (AddSub == ARM_AM::sub) Val *= -1;
764 Offset = CurDAG->getRegister(0, MVT::i32);
765 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
773 bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
774 SDValue &Offset, SDValue &Opc) {
775 unsigned Opcode = Op->getOpcode();
776 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
777 ? cast<LoadSDNode>(Op)->getAddressingMode()
778 : cast<StoreSDNode>(Op)->getAddressingMode();
779 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
780 ? ARM_AM::add : ARM_AM::sub;
782 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
783 Offset = CurDAG->getRegister(0, MVT::i32);
784 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
793 bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
798 bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
799 SDValue &Base, SDValue &Offset,
801 if (N.getOpcode() == ISD::SUB) {
802 // X - C is canonicalize to X + -C, no need to handle it here.
803 Base = N.getOperand(0);
804 Offset = N.getOperand(1);
805 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
809 if (!CurDAG->isBaseWithConstantOffset(N)) {
811 if (N.getOpcode() == ISD::FrameIndex) {
812 int FI = cast<FrameIndexSDNode>(N)->getIndex();
813 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
815 Offset = CurDAG->getRegister(0, MVT::i32);
816 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
820 // If the RHS is +/- imm8, fold into addr mode.
822 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
823 -256 + 1, 256, RHSC)) { // 8 bits.
824 Base = N.getOperand(0);
825 if (Base.getOpcode() == ISD::FrameIndex) {
826 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
827 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
829 Offset = CurDAG->getRegister(0, MVT::i32);
831 ARM_AM::AddrOpc AddSub = ARM_AM::add;
833 AddSub = ARM_AM::sub;
836 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
840 Base = N.getOperand(0);
841 Offset = N.getOperand(1);
842 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
846 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
847 SDValue &Offset, SDValue &Opc) {
848 unsigned Opcode = Op->getOpcode();
849 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
850 ? cast<LoadSDNode>(Op)->getAddressingMode()
851 : cast<StoreSDNode>(Op)->getAddressingMode();
852 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
853 ? ARM_AM::add : ARM_AM::sub;
855 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
856 Offset = CurDAG->getRegister(0, MVT::i32);
857 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
862 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
866 bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
867 SDValue &Base, SDValue &Offset) {
868 if (!CurDAG->isBaseWithConstantOffset(N)) {
870 if (N.getOpcode() == ISD::FrameIndex) {
871 int FI = cast<FrameIndexSDNode>(N)->getIndex();
872 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
873 } else if (N.getOpcode() == ARMISD::Wrapper &&
874 !(Subtarget->useMovt() &&
875 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
876 Base = N.getOperand(0);
878 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
883 // If the RHS is +/- imm8, fold into addr mode.
885 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
886 -256 + 1, 256, RHSC)) {
887 Base = N.getOperand(0);
888 if (Base.getOpcode() == ISD::FrameIndex) {
889 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
890 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
893 ARM_AM::AddrOpc AddSub = ARM_AM::add;
895 AddSub = ARM_AM::sub;
898 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
904 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
909 bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
913 unsigned Alignment = 0;
914 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
915 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
916 // The maximum alignment is equal to the memory size being referenced.
917 unsigned LSNAlign = LSN->getAlignment();
918 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
919 if (LSNAlign >= MemSize && MemSize > 1)
922 // All other uses of addrmode6 are for intrinsics. For now just record
923 // the raw alignment value; it will be refined later based on the legal
924 // alignment operands for the intrinsic.
925 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
928 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
932 bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
934 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
935 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
936 if (AM != ISD::POST_INC)
939 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
940 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
941 Offset = CurDAG->getRegister(0, MVT::i32);
946 bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
947 SDValue &Offset, SDValue &Label) {
948 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
949 Offset = N.getOperand(0);
950 SDValue N1 = N.getOperand(1);
951 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
960 //===----------------------------------------------------------------------===//
961 // Thumb Addressing Modes
962 //===----------------------------------------------------------------------===//
964 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
965 SDValue &Base, SDValue &Offset){
966 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
967 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
968 if (!NC || !NC->isNullValue())
975 Base = N.getOperand(0);
976 Offset = N.getOperand(1);
981 ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
982 SDValue &Offset, unsigned Scale) {
984 SDValue TmpBase, TmpOffImm;
985 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
986 return false; // We want to select tLDRspi / tSTRspi instead.
988 if (N.getOpcode() == ARMISD::Wrapper &&
989 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
990 return false; // We want to select tLDRpci instead.
993 if (!CurDAG->isBaseWithConstantOffset(N))
996 // Thumb does not have [sp, r] address mode.
997 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
998 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
999 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1000 (RHSR && RHSR->getReg() == ARM::SP))
1003 // FIXME: Why do we explicitly check for a match here and then return false?
1004 // Presumably to allow something else to match, but shouldn't this be
1007 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1010 Base = N.getOperand(0);
1011 Offset = N.getOperand(1);
1016 ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1019 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1023 ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1026 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1030 ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1033 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1037 ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1038 SDValue &Base, SDValue &OffImm) {
1040 SDValue TmpBase, TmpOffImm;
1041 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1042 return false; // We want to select tLDRspi / tSTRspi instead.
1044 if (N.getOpcode() == ARMISD::Wrapper &&
1045 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1046 return false; // We want to select tLDRpci instead.
1049 if (!CurDAG->isBaseWithConstantOffset(N)) {
1050 if (N.getOpcode() == ARMISD::Wrapper &&
1051 !(Subtarget->useMovt() &&
1052 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1053 Base = N.getOperand(0);
1058 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1062 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1063 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1064 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1065 (RHSR && RHSR->getReg() == ARM::SP)) {
1066 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1067 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1068 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1069 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1071 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1072 if (LHSC != 0 || RHSC != 0) return false;
1075 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1079 // If the RHS is + imm5 * scale, fold into addr mode.
1081 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1082 Base = N.getOperand(0);
1083 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1087 Base = N.getOperand(0);
1088 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1093 ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1095 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
1099 ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1101 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
1105 ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1107 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
1110 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1111 SDValue &Base, SDValue &OffImm) {
1112 if (N.getOpcode() == ISD::FrameIndex) {
1113 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1114 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1115 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1119 if (!CurDAG->isBaseWithConstantOffset(N))
1122 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1123 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1124 (LHSR && LHSR->getReg() == ARM::SP)) {
1125 // If the RHS is + imm8 * scale, fold into addr mode.
1127 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1128 Base = N.getOperand(0);
1129 if (Base.getOpcode() == ISD::FrameIndex) {
1130 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1131 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1133 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1142 //===----------------------------------------------------------------------===//
1143 // Thumb 2 Addressing Modes
1144 //===----------------------------------------------------------------------===//
1147 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
1149 if (DisableShifterOp)
1152 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
1154 // Don't match base register only case. That is matched to a separate
1155 // lower complexity pattern with explicit register operand.
1156 if (ShOpcVal == ARM_AM::no_shift) return false;
1158 BaseReg = N.getOperand(0);
1159 unsigned ShImmVal = 0;
1160 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1161 ShImmVal = RHS->getZExtValue() & 31;
1162 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1169 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
1170 SDValue &Base, SDValue &OffImm) {
1171 // Match simple R + imm12 operands.
1174 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1175 !CurDAG->isBaseWithConstantOffset(N)) {
1176 if (N.getOpcode() == ISD::FrameIndex) {
1177 // Match frame index.
1178 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1179 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1180 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1184 if (N.getOpcode() == ARMISD::Wrapper &&
1185 !(Subtarget->useMovt() &&
1186 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1187 Base = N.getOperand(0);
1188 if (Base.getOpcode() == ISD::TargetConstantPool)
1189 return false; // We want to select t2LDRpci instead.
1192 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1196 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1197 if (SelectT2AddrModeImm8(N, Base, OffImm))
1198 // Let t2LDRi8 handle (R - imm8).
1201 int RHSC = (int)RHS->getZExtValue();
1202 if (N.getOpcode() == ISD::SUB)
1205 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
1206 Base = N.getOperand(0);
1207 if (Base.getOpcode() == ISD::FrameIndex) {
1208 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1209 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1211 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1218 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1222 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
1223 SDValue &Base, SDValue &OffImm) {
1224 // Match simple R - imm8 operands.
1225 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1226 !CurDAG->isBaseWithConstantOffset(N))
1229 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1230 int RHSC = (int)RHS->getSExtValue();
1231 if (N.getOpcode() == ISD::SUB)
1234 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1235 Base = N.getOperand(0);
1236 if (Base.getOpcode() == ISD::FrameIndex) {
1237 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1238 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1240 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1248 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
1250 unsigned Opcode = Op->getOpcode();
1251 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1252 ? cast<LoadSDNode>(Op)->getAddressingMode()
1253 : cast<StoreSDNode>(Op)->getAddressingMode();
1255 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1256 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1257 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1258 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1265 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
1267 SDValue &OffReg, SDValue &ShImm) {
1268 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1269 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
1272 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1274 int RHSC = (int)RHS->getZExtValue();
1275 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1277 else if (RHSC < 0 && RHSC >= -255) // 8 bits
1281 // Look for (R + R) or (R + (R << [1,2,3])).
1283 Base = N.getOperand(0);
1284 OffReg = N.getOperand(1);
1286 // Swap if it is ((R << c) + R).
1287 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
1288 if (ShOpcVal != ARM_AM::lsl) {
1289 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
1290 if (ShOpcVal == ARM_AM::lsl)
1291 std::swap(Base, OffReg);
1294 if (ShOpcVal == ARM_AM::lsl) {
1295 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1297 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1298 ShAmt = Sh->getZExtValue();
1299 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1300 OffReg = OffReg.getOperand(0);
1303 ShOpcVal = ARM_AM::no_shift;
1306 ShOpcVal = ARM_AM::no_shift;
1310 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
1315 //===--------------------------------------------------------------------===//
1317 /// getAL - Returns a ARMCC::AL immediate node.
1318 static inline SDValue getAL(SelectionDAG *CurDAG) {
1319 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
1322 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1323 LoadSDNode *LD = cast<LoadSDNode>(N);
1324 ISD::MemIndexedMode AM = LD->getAddressingMode();
1325 if (AM == ISD::UNINDEXED)
1328 EVT LoadedVT = LD->getMemoryVT();
1329 SDValue Offset, AMOpc;
1330 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1331 unsigned Opcode = 0;
1333 if (LoadedVT == MVT::i32 && isPre &&
1334 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1335 Opcode = ARM::LDR_PRE_IMM;
1337 } else if (LoadedVT == MVT::i32 && !isPre &&
1338 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1339 Opcode = ARM::LDR_POST_IMM;
1341 } else if (LoadedVT == MVT::i32 &&
1342 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1343 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
1346 } else if (LoadedVT == MVT::i16 &&
1347 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1349 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1350 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1351 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
1352 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
1353 if (LD->getExtensionType() == ISD::SEXTLOAD) {
1354 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1356 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1360 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1362 Opcode = ARM::LDRB_PRE_IMM;
1363 } else if (!isPre &&
1364 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1366 Opcode = ARM::LDRB_POST_IMM;
1367 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1369 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
1375 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1376 SDValue Chain = LD->getChain();
1377 SDValue Base = LD->getBasePtr();
1378 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1379 CurDAG->getRegister(0, MVT::i32), Chain };
1380 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1381 MVT::i32, MVT::Other, Ops, 5);
1383 SDValue Chain = LD->getChain();
1384 SDValue Base = LD->getBasePtr();
1385 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1386 CurDAG->getRegister(0, MVT::i32), Chain };
1387 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1388 MVT::i32, MVT::Other, Ops, 6);
1395 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1396 LoadSDNode *LD = cast<LoadSDNode>(N);
1397 ISD::MemIndexedMode AM = LD->getAddressingMode();
1398 if (AM == ISD::UNINDEXED)
1401 EVT LoadedVT = LD->getMemoryVT();
1402 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
1404 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1405 unsigned Opcode = 0;
1407 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
1408 switch (LoadedVT.getSimpleVT().SimpleTy) {
1410 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1414 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1416 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
1421 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1423 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
1432 SDValue Chain = LD->getChain();
1433 SDValue Base = LD->getBasePtr();
1434 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
1435 CurDAG->getRegister(0, MVT::i32), Chain };
1436 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1437 MVT::Other, Ops, 5);
1443 /// PairSRegs - Form a D register from a pair of S registers.
1445 SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1446 DebugLoc dl = V0.getNode()->getDebugLoc();
1448 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
1449 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1450 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1451 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1452 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
1455 /// PairDRegs - Form a quad register from a pair of D registers.
1457 SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1458 DebugLoc dl = V0.getNode()->getDebugLoc();
1459 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
1460 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1461 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1462 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1463 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
1466 /// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
1468 SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1469 DebugLoc dl = V0.getNode()->getDebugLoc();
1470 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
1471 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1472 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1473 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1474 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
1477 /// QuadSRegs - Form 4 consecutive S registers.
1479 SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1480 SDValue V2, SDValue V3) {
1481 DebugLoc dl = V0.getNode()->getDebugLoc();
1483 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
1484 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1485 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1486 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1487 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1488 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1489 V2, SubReg2, V3, SubReg3 };
1490 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
1493 /// QuadDRegs - Form 4 consecutive D registers.
1495 SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1496 SDValue V2, SDValue V3) {
1497 DebugLoc dl = V0.getNode()->getDebugLoc();
1498 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
1499 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1500 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1501 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1502 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1503 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1504 V2, SubReg2, V3, SubReg3 };
1505 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
1508 /// QuadQRegs - Form 4 consecutive Q registers.
1510 SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1511 SDValue V2, SDValue V3) {
1512 DebugLoc dl = V0.getNode()->getDebugLoc();
1513 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
1514 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1515 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1516 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1517 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
1518 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1519 V2, SubReg2, V3, SubReg3 };
1520 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
1523 /// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1524 /// of a NEON VLD or VST instruction. The supported values depend on the
1525 /// number of registers being loaded.
1526 SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1527 bool is64BitVector) {
1528 unsigned NumRegs = NumVecs;
1529 if (!is64BitVector && NumVecs < 3)
1532 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1533 if (Alignment >= 32 && NumRegs == 4)
1535 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1537 else if (Alignment >= 8)
1542 return CurDAG->getTargetConstant(Alignment, MVT::i32);
1545 // Get the register stride update opcode of a VLD/VST instruction that
1546 // is otherwise equivalent to the given fixed stride updating instruction.
1547 static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1550 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1551 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1552 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1553 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1554 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1555 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1556 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1557 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
1559 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1560 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1561 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1562 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1563 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1564 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1565 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1566 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
1567 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
1568 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
1570 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1571 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1572 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
1573 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1574 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1575 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1577 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1578 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1579 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
1580 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1581 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1582 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
1584 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1585 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1586 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
1588 return Opc; // If not one we handle, return it unchanged.
1591 SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
1592 const uint16_t *DOpcodes,
1593 const uint16_t *QOpcodes0,
1594 const uint16_t *QOpcodes1) {
1595 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1596 DebugLoc dl = N->getDebugLoc();
1598 SDValue MemAddr, Align;
1599 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1600 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
1603 SDValue Chain = N->getOperand(0);
1604 EVT VT = N->getValueType(0);
1605 bool is64BitVector = VT.is64BitVector();
1606 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1608 unsigned OpcodeIndex;
1609 switch (VT.getSimpleVT().SimpleTy) {
1610 default: llvm_unreachable("unhandled vld type");
1611 // Double-register operations:
1612 case MVT::v8i8: OpcodeIndex = 0; break;
1613 case MVT::v4i16: OpcodeIndex = 1; break;
1615 case MVT::v2i32: OpcodeIndex = 2; break;
1616 case MVT::v1i64: OpcodeIndex = 3; break;
1617 // Quad-register operations:
1618 case MVT::v16i8: OpcodeIndex = 0; break;
1619 case MVT::v8i16: OpcodeIndex = 1; break;
1621 case MVT::v4i32: OpcodeIndex = 2; break;
1622 case MVT::v2i64: OpcodeIndex = 3;
1623 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
1631 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1634 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1636 std::vector<EVT> ResTys;
1637 ResTys.push_back(ResTy);
1639 ResTys.push_back(MVT::i32);
1640 ResTys.push_back(MVT::Other);
1642 SDValue Pred = getAL(CurDAG);
1643 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1645 SmallVector<SDValue, 7> Ops;
1647 // Double registers and VLD1/VLD2 quad registers are directly supported.
1648 if (is64BitVector || NumVecs <= 2) {
1649 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1650 QOpcodes0[OpcodeIndex]);
1651 Ops.push_back(MemAddr);
1652 Ops.push_back(Align);
1654 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1655 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
1656 // case entirely when the rest are updated to that form, too.
1657 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
1658 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1659 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
1660 // check for that explicitly too. Horribly hacky, but temporary.
1661 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
1662 !isa<ConstantSDNode>(Inc.getNode()))
1663 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1665 Ops.push_back(Pred);
1666 Ops.push_back(Reg0);
1667 Ops.push_back(Chain);
1668 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1671 // Otherwise, quad registers are loaded with two separate instructions,
1672 // where one loads the even registers and the other loads the odd registers.
1673 EVT AddrTy = MemAddr.getValueType();
1675 // Load the even subregs. This is always an updating load, so that it
1676 // provides the address to the second load for the odd subregs.
1678 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1679 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1680 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1681 ResTy, AddrTy, MVT::Other, OpsA, 7);
1682 Chain = SDValue(VLdA, 2);
1684 // Load the odd subregs.
1685 Ops.push_back(SDValue(VLdA, 1));
1686 Ops.push_back(Align);
1688 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1689 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1690 "only constant post-increment update allowed for VLD3/4");
1692 Ops.push_back(Reg0);
1694 Ops.push_back(SDValue(VLdA, 0));
1695 Ops.push_back(Pred);
1696 Ops.push_back(Reg0);
1697 Ops.push_back(Chain);
1698 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1699 Ops.data(), Ops.size());
1702 // Transfer memoperands.
1703 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1704 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1705 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1710 // Extract out the subregisters.
1711 SDValue SuperReg = SDValue(VLd, 0);
1712 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1713 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1714 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1715 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1716 ReplaceUses(SDValue(N, Vec),
1717 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1718 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1720 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
1724 SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
1725 const uint16_t *DOpcodes,
1726 const uint16_t *QOpcodes0,
1727 const uint16_t *QOpcodes1) {
1728 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
1729 DebugLoc dl = N->getDebugLoc();
1731 SDValue MemAddr, Align;
1732 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1733 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1734 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
1737 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1738 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1740 SDValue Chain = N->getOperand(0);
1741 EVT VT = N->getOperand(Vec0Idx).getValueType();
1742 bool is64BitVector = VT.is64BitVector();
1743 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1745 unsigned OpcodeIndex;
1746 switch (VT.getSimpleVT().SimpleTy) {
1747 default: llvm_unreachable("unhandled vst type");
1748 // Double-register operations:
1749 case MVT::v8i8: OpcodeIndex = 0; break;
1750 case MVT::v4i16: OpcodeIndex = 1; break;
1752 case MVT::v2i32: OpcodeIndex = 2; break;
1753 case MVT::v1i64: OpcodeIndex = 3; break;
1754 // Quad-register operations:
1755 case MVT::v16i8: OpcodeIndex = 0; break;
1756 case MVT::v8i16: OpcodeIndex = 1; break;
1758 case MVT::v4i32: OpcodeIndex = 2; break;
1759 case MVT::v2i64: OpcodeIndex = 3;
1760 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1764 std::vector<EVT> ResTys;
1766 ResTys.push_back(MVT::i32);
1767 ResTys.push_back(MVT::Other);
1769 SDValue Pred = getAL(CurDAG);
1770 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1771 SmallVector<SDValue, 7> Ops;
1773 // Double registers and VST1/VST2 quad registers are directly supported.
1774 if (is64BitVector || NumVecs <= 2) {
1777 SrcReg = N->getOperand(Vec0Idx);
1778 } else if (is64BitVector) {
1779 // Form a REG_SEQUENCE to force register allocation.
1780 SDValue V0 = N->getOperand(Vec0Idx + 0);
1781 SDValue V1 = N->getOperand(Vec0Idx + 1);
1783 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1785 SDValue V2 = N->getOperand(Vec0Idx + 2);
1786 // If it's a vst3, form a quad D-register and leave the last part as
1788 SDValue V3 = (NumVecs == 3)
1789 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1790 : N->getOperand(Vec0Idx + 3);
1791 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1794 // Form a QQ register.
1795 SDValue Q0 = N->getOperand(Vec0Idx);
1796 SDValue Q1 = N->getOperand(Vec0Idx + 1);
1797 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1800 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1801 QOpcodes0[OpcodeIndex]);
1802 Ops.push_back(MemAddr);
1803 Ops.push_back(Align);
1805 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1806 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
1807 // case entirely when the rest are updated to that form, too.
1808 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
1809 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1810 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1811 // check for that explicitly too. Horribly hacky, but temporary.
1812 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
1813 !isa<ConstantSDNode>(Inc.getNode()))
1814 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1816 Ops.push_back(SrcReg);
1817 Ops.push_back(Pred);
1818 Ops.push_back(Reg0);
1819 Ops.push_back(Chain);
1821 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1823 // Transfer memoperands.
1824 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1829 // Otherwise, quad registers are stored with two separate instructions,
1830 // where one stores the even registers and the other stores the odd registers.
1832 // Form the QQQQ REG_SEQUENCE.
1833 SDValue V0 = N->getOperand(Vec0Idx + 0);
1834 SDValue V1 = N->getOperand(Vec0Idx + 1);
1835 SDValue V2 = N->getOperand(Vec0Idx + 2);
1836 SDValue V3 = (NumVecs == 3)
1837 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1838 : N->getOperand(Vec0Idx + 3);
1839 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1841 // Store the even D registers. This is always an updating store, so that it
1842 // provides the address to the second store for the odd subregs.
1843 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1844 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1845 MemAddr.getValueType(),
1846 MVT::Other, OpsA, 7);
1847 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
1848 Chain = SDValue(VStA, 1);
1850 // Store the odd D registers.
1851 Ops.push_back(SDValue(VStA, 0));
1852 Ops.push_back(Align);
1854 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1855 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1856 "only constant post-increment update allowed for VST3/4");
1858 Ops.push_back(Reg0);
1860 Ops.push_back(RegSeq);
1861 Ops.push_back(Pred);
1862 Ops.push_back(Reg0);
1863 Ops.push_back(Chain);
1864 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1865 Ops.data(), Ops.size());
1866 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1870 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
1871 bool isUpdating, unsigned NumVecs,
1872 const uint16_t *DOpcodes,
1873 const uint16_t *QOpcodes) {
1874 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
1875 DebugLoc dl = N->getDebugLoc();
1877 SDValue MemAddr, Align;
1878 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1879 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1880 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
1883 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1884 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1886 SDValue Chain = N->getOperand(0);
1888 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1889 EVT VT = N->getOperand(Vec0Idx).getValueType();
1890 bool is64BitVector = VT.is64BitVector();
1892 unsigned Alignment = 0;
1894 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1895 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1896 if (Alignment > NumBytes)
1897 Alignment = NumBytes;
1898 if (Alignment < 8 && Alignment < NumBytes)
1900 // Alignment must be a power of two; make sure of that.
1901 Alignment = (Alignment & -Alignment);
1905 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1907 unsigned OpcodeIndex;
1908 switch (VT.getSimpleVT().SimpleTy) {
1909 default: llvm_unreachable("unhandled vld/vst lane type");
1910 // Double-register operations:
1911 case MVT::v8i8: OpcodeIndex = 0; break;
1912 case MVT::v4i16: OpcodeIndex = 1; break;
1914 case MVT::v2i32: OpcodeIndex = 2; break;
1915 // Quad-register operations:
1916 case MVT::v8i16: OpcodeIndex = 0; break;
1918 case MVT::v4i32: OpcodeIndex = 1; break;
1921 std::vector<EVT> ResTys;
1923 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1926 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1927 MVT::i64, ResTyElts));
1930 ResTys.push_back(MVT::i32);
1931 ResTys.push_back(MVT::Other);
1933 SDValue Pred = getAL(CurDAG);
1934 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1936 SmallVector<SDValue, 8> Ops;
1937 Ops.push_back(MemAddr);
1938 Ops.push_back(Align);
1940 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1941 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1945 SDValue V0 = N->getOperand(Vec0Idx + 0);
1946 SDValue V1 = N->getOperand(Vec0Idx + 1);
1949 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1951 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1953 SDValue V2 = N->getOperand(Vec0Idx + 2);
1954 SDValue V3 = (NumVecs == 3)
1955 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1956 : N->getOperand(Vec0Idx + 3);
1958 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1960 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1962 Ops.push_back(SuperReg);
1963 Ops.push_back(getI32Imm(Lane));
1964 Ops.push_back(Pred);
1965 Ops.push_back(Reg0);
1966 Ops.push_back(Chain);
1968 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1969 QOpcodes[OpcodeIndex]);
1970 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1971 Ops.data(), Ops.size());
1972 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
1976 // Extract the subregisters.
1977 SuperReg = SDValue(VLdLn, 0);
1978 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1979 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1980 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1981 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1982 ReplaceUses(SDValue(N, Vec),
1983 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1984 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1986 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
1990 SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1992 const uint16_t *Opcodes) {
1993 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1994 DebugLoc dl = N->getDebugLoc();
1996 SDValue MemAddr, Align;
1997 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2000 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2001 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2003 SDValue Chain = N->getOperand(0);
2004 EVT VT = N->getValueType(0);
2006 unsigned Alignment = 0;
2008 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2009 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2010 if (Alignment > NumBytes)
2011 Alignment = NumBytes;
2012 if (Alignment < 8 && Alignment < NumBytes)
2014 // Alignment must be a power of two; make sure of that.
2015 Alignment = (Alignment & -Alignment);
2019 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2021 unsigned OpcodeIndex;
2022 switch (VT.getSimpleVT().SimpleTy) {
2023 default: llvm_unreachable("unhandled vld-dup type");
2024 case MVT::v8i8: OpcodeIndex = 0; break;
2025 case MVT::v4i16: OpcodeIndex = 1; break;
2027 case MVT::v2i32: OpcodeIndex = 2; break;
2030 SDValue Pred = getAL(CurDAG);
2031 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2033 unsigned Opc = Opcodes[OpcodeIndex];
2034 SmallVector<SDValue, 6> Ops;
2035 Ops.push_back(MemAddr);
2036 Ops.push_back(Align);
2038 // fixed-stride update instructions don't have an explicit writeback
2039 // operand. It's implicit in the opcode itself.
2040 SDValue Inc = N->getOperand(2);
2041 if (!isa<ConstantSDNode>(Inc.getNode()))
2043 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2044 else if (NumVecs > 2)
2045 Ops.push_back(Reg0);
2047 Ops.push_back(Pred);
2048 Ops.push_back(Reg0);
2049 Ops.push_back(Chain);
2051 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2052 std::vector<EVT> ResTys;
2053 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
2055 ResTys.push_back(MVT::i32);
2056 ResTys.push_back(MVT::Other);
2058 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
2059 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
2060 SuperReg = SDValue(VLdDup, 0);
2062 // Extract the subregisters.
2063 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2064 unsigned SubIdx = ARM::dsub_0;
2065 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2066 ReplaceUses(SDValue(N, Vec),
2067 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
2068 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2070 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
2074 SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2076 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2077 DebugLoc dl = N->getDebugLoc();
2078 EVT VT = N->getValueType(0);
2079 unsigned FirstTblReg = IsExt ? 2 : 1;
2081 // Form a REG_SEQUENCE to force register allocation.
2083 SDValue V0 = N->getOperand(FirstTblReg + 0);
2084 SDValue V1 = N->getOperand(FirstTblReg + 1);
2086 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2088 SDValue V2 = N->getOperand(FirstTblReg + 2);
2089 // If it's a vtbl3, form a quad D-register and leave the last part as
2091 SDValue V3 = (NumVecs == 3)
2092 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2093 : N->getOperand(FirstTblReg + 3);
2094 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2097 SmallVector<SDValue, 6> Ops;
2099 Ops.push_back(N->getOperand(1));
2100 Ops.push_back(RegSeq);
2101 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
2102 Ops.push_back(getAL(CurDAG)); // predicate
2103 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
2104 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
2107 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
2109 if (!Subtarget->hasV6T2Ops())
2112 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2113 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2116 // For unsigned extracts, check for a shift right and mask
2117 unsigned And_imm = 0;
2118 if (N->getOpcode() == ISD::AND) {
2119 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2121 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2122 if (And_imm & (And_imm + 1))
2125 unsigned Srl_imm = 0;
2126 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2128 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2130 // Note: The width operand is encoded as width-1.
2131 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
2132 unsigned LSB = Srl_imm;
2133 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2134 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2135 CurDAG->getTargetConstant(LSB, MVT::i32),
2136 CurDAG->getTargetConstant(Width, MVT::i32),
2137 getAL(CurDAG), Reg0 };
2138 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2144 // Otherwise, we're looking for a shift of a shift
2145 unsigned Shl_imm = 0;
2146 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
2147 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2148 unsigned Srl_imm = 0;
2149 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
2150 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2151 // Note: The width operand is encoded as width-1.
2152 unsigned Width = 32 - Srl_imm - 1;
2153 int LSB = Srl_imm - Shl_imm;
2156 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2157 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2158 CurDAG->getTargetConstant(LSB, MVT::i32),
2159 CurDAG->getTargetConstant(Width, MVT::i32),
2160 getAL(CurDAG), Reg0 };
2161 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2167 SDNode *ARMDAGToDAGISel::
2168 SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
2169 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2172 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
2173 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2174 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2177 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2178 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2179 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2180 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2182 llvm_unreachable("Unknown so_reg opcode!");
2185 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2186 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2187 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
2188 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
2193 SDNode *ARMDAGToDAGISel::
2194 SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
2195 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2199 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
2200 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2201 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2202 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
2205 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2206 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2207 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2208 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
2213 SDNode *ARMDAGToDAGISel::
2214 SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
2215 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2216 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2221 unsigned TrueImm = T->getZExtValue();
2222 if (is_t2_so_imm(TrueImm)) {
2223 Opc = ARM::t2MOVCCi;
2224 } else if (TrueImm <= 0xffff) {
2225 Opc = ARM::t2MOVCCi16;
2226 } else if (is_t2_so_imm_not(TrueImm)) {
2228 Opc = ARM::t2MVNCCi;
2229 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
2231 Opc = ARM::t2MOVCCi32imm;
2235 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2236 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2237 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
2238 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2244 SDNode *ARMDAGToDAGISel::
2245 SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
2246 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2247 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2252 unsigned TrueImm = T->getZExtValue();
2253 bool isSoImm = is_so_imm(TrueImm);
2256 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2257 Opc = ARM::MOVCCi16;
2258 } else if (is_so_imm_not(TrueImm)) {
2261 } else if (TrueVal.getNode()->hasOneUse() &&
2262 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
2264 Opc = ARM::MOVCCi32imm;
2268 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2269 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2270 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
2271 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2277 SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2278 EVT VT = N->getValueType(0);
2279 SDValue FalseVal = N->getOperand(0);
2280 SDValue TrueVal = N->getOperand(1);
2281 SDValue CC = N->getOperand(2);
2282 SDValue CCR = N->getOperand(3);
2283 SDValue InFlag = N->getOperand(4);
2284 assert(CC.getOpcode() == ISD::Constant);
2285 assert(CCR.getOpcode() == ISD::Register);
2286 ARMCC::CondCodes CCVal =
2287 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
2289 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2290 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2291 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2292 // Pattern complexity = 18 cost = 1 size = 0
2293 if (Subtarget->isThumb()) {
2294 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
2295 CCVal, CCR, InFlag);
2297 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
2298 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2302 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
2303 CCVal, CCR, InFlag);
2305 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
2306 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2311 // Pattern: (ARMcmov:i32 GPR:i32:$false,
2312 // (imm:i32)<<P:Pred_so_imm>>:$true,
2314 // Emits: (MOVCCi:i32 GPR:i32:$false,
2315 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2316 // Pattern complexity = 10 cost = 1 size = 0
2317 if (Subtarget->isThumb()) {
2318 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
2319 CCVal, CCR, InFlag);
2321 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
2322 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2326 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
2327 CCVal, CCR, InFlag);
2329 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
2330 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2336 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2337 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2338 // Pattern complexity = 6 cost = 1 size = 0
2340 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2341 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2342 // Pattern complexity = 6 cost = 11 size = 0
2344 // Also VMOVScc and VMOVDcc.
2345 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2346 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
2348 switch (VT.getSimpleVT().SimpleTy) {
2349 default: llvm_unreachable("Illegal conditional move type!");
2351 Opc = Subtarget->isThumb()
2352 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2362 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
2365 /// Target-specific DAG combining for ISD::XOR.
2366 /// Target-independent combining lowers SELECT_CC nodes of the form
2367 /// select_cc setg[ge] X, 0, X, -X
2368 /// select_cc setgt X, -1, X, -X
2369 /// select_cc setl[te] X, 0, -X, X
2370 /// select_cc setlt X, 1, -X, X
2371 /// which represent Integer ABS into:
2372 /// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2373 /// ARM instruction selection detects the latter and matches it to
2374 /// ARM::ABS or ARM::t2ABS machine node.
2375 SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2376 SDValue XORSrc0 = N->getOperand(0);
2377 SDValue XORSrc1 = N->getOperand(1);
2378 EVT VT = N->getValueType(0);
2380 if (Subtarget->isThumb1Only())
2383 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
2386 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2387 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2388 SDValue SRASrc0 = XORSrc1.getOperand(0);
2389 SDValue SRASrc1 = XORSrc1.getOperand(1);
2390 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2391 EVT XType = SRASrc0.getValueType();
2392 unsigned Size = XType.getSizeInBits() - 1;
2394 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2395 XType.isInteger() && SRAConstant != NULL &&
2396 Size == SRAConstant->getZExtValue()) {
2397 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
2398 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2404 SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2405 // The only time a CONCAT_VECTORS operation can have legal types is when
2406 // two 64-bit vectors are concatenated to a 128-bit vector.
2407 EVT VT = N->getValueType(0);
2408 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2409 llvm_unreachable("unexpected CONCAT_VECTORS");
2410 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
2413 SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
2414 SmallVector<SDValue, 6> Ops;
2415 Ops.push_back(Node->getOperand(1)); // Ptr
2416 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2417 Ops.push_back(Node->getOperand(3)); // High part of Val1
2418 if (Opc == ARM::ATOMCMPXCHG6432) {
2419 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2420 Ops.push_back(Node->getOperand(5)); // High part of Val2
2422 Ops.push_back(Node->getOperand(0)); // Chain
2423 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2424 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
2425 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
2426 MVT::i32, MVT::i32, MVT::Other,
2427 Ops.data() ,Ops.size());
2428 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2432 SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
2433 DebugLoc dl = N->getDebugLoc();
2435 if (N->isMachineOpcode())
2436 return NULL; // Already selected.
2438 switch (N->getOpcode()) {
2441 // Select special operations if XOR node forms integer ABS pattern
2442 SDNode *ResNode = SelectABSOp(N);
2445 // Other cases are autogenerated.
2448 case ISD::Constant: {
2449 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
2451 if (Subtarget->hasThumb2())
2452 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2453 // be done with MOV + MOVT, at worst.
2456 if (Subtarget->isThumb()) {
2457 UseCP = (Val > 255 && // MOV
2458 ~Val > 255 && // MOV + MVN
2459 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
2461 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2462 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2463 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2468 CurDAG->getTargetConstantPool(ConstantInt::get(
2469 Type::getInt32Ty(*CurDAG->getContext()), Val),
2470 TLI.getPointerTy());
2473 if (Subtarget->isThumb1Only()) {
2474 SDValue Pred = getAL(CurDAG);
2475 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2476 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
2477 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
2482 CurDAG->getTargetConstant(0, MVT::i32),
2484 CurDAG->getRegister(0, MVT::i32),
2485 CurDAG->getEntryNode()
2487 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
2490 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
2494 // Other cases are autogenerated.
2497 case ISD::FrameIndex: {
2498 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
2499 int FI = cast<FrameIndexSDNode>(N)->getIndex();
2500 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
2501 if (Subtarget->isThumb1Only()) {
2502 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2503 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2504 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
2506 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2507 ARM::t2ADDri : ARM::ADDri);
2508 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2509 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2510 CurDAG->getRegister(0, MVT::i32) };
2511 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2515 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2519 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
2523 if (Subtarget->isThumb1Only())
2525 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
2526 unsigned RHSV = C->getZExtValue();
2528 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
2529 unsigned ShImm = Log2_32(RHSV-1);
2532 SDValue V = N->getOperand(0);
2533 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2534 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2535 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2536 if (Subtarget->isThumb()) {
2537 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2538 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
2540 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2541 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
2544 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
2545 unsigned ShImm = Log2_32(RHSV+1);
2548 SDValue V = N->getOperand(0);
2549 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2550 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2551 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2552 if (Subtarget->isThumb()) {
2553 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2554 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
2556 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2557 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
2563 // Check for unsigned bitfield extract
2564 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2567 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2568 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2569 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2570 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2571 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
2572 EVT VT = N->getValueType(0);
2575 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2577 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2580 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
2581 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2584 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2585 SDValue N2 = N0.getOperand(1);
2586 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2589 unsigned N1CVal = N1C->getZExtValue();
2590 unsigned N2CVal = N2C->getZExtValue();
2591 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2592 (N1CVal & 0xffffU) == 0xffffU &&
2593 (N2CVal & 0xffffU) == 0x0U) {
2594 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2596 SDValue Ops[] = { N0.getOperand(0), Imm16,
2597 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2598 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2603 case ARMISD::VMOVRRD:
2604 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
2605 N->getOperand(0), getAL(CurDAG),
2606 CurDAG->getRegister(0, MVT::i32));
2607 case ISD::UMUL_LOHI: {
2608 if (Subtarget->isThumb1Only())
2610 if (Subtarget->isThumb()) {
2611 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2612 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2613 CurDAG->getRegister(0, MVT::i32) };
2614 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
2616 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2617 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2618 CurDAG->getRegister(0, MVT::i32) };
2619 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2620 ARM::UMULL : ARM::UMULLv5,
2621 dl, MVT::i32, MVT::i32, Ops, 5);
2624 case ISD::SMUL_LOHI: {
2625 if (Subtarget->isThumb1Only())
2627 if (Subtarget->isThumb()) {
2628 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2629 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2630 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
2632 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2633 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2634 CurDAG->getRegister(0, MVT::i32) };
2635 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2636 ARM::SMULL : ARM::SMULLv5,
2637 dl, MVT::i32, MVT::i32, Ops, 5);
2641 SDNode *ResNode = 0;
2642 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2643 ResNode = SelectT2IndexedLoad(N);
2645 ResNode = SelectARMIndexedLoad(N);
2648 // Other cases are autogenerated.
2651 case ARMISD::BRCOND: {
2652 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2653 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2654 // Pattern complexity = 6 cost = 1 size = 0
2656 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2657 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2658 // Pattern complexity = 6 cost = 1 size = 0
2660 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2661 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2662 // Pattern complexity = 6 cost = 1 size = 0
2664 unsigned Opc = Subtarget->isThumb() ?
2665 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
2666 SDValue Chain = N->getOperand(0);
2667 SDValue N1 = N->getOperand(1);
2668 SDValue N2 = N->getOperand(2);
2669 SDValue N3 = N->getOperand(3);
2670 SDValue InFlag = N->getOperand(4);
2671 assert(N1.getOpcode() == ISD::BasicBlock);
2672 assert(N2.getOpcode() == ISD::Constant);
2673 assert(N3.getOpcode() == ISD::Register);
2675 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2676 cast<ConstantSDNode>(N2)->getZExtValue()),
2678 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
2679 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2681 Chain = SDValue(ResNode, 0);
2682 if (N->getNumValues() == 2) {
2683 InFlag = SDValue(ResNode, 1);
2684 ReplaceUses(SDValue(N, 1), InFlag);
2686 ReplaceUses(SDValue(N, 0),
2687 SDValue(Chain.getNode(), Chain.getResNo()));
2691 return SelectCMOVOp(N);
2692 case ARMISD::VZIP: {
2694 EVT VT = N->getValueType(0);
2695 switch (VT.getSimpleVT().SimpleTy) {
2696 default: return NULL;
2697 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2698 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2700 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2701 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2702 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2703 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2705 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2707 SDValue Pred = getAL(CurDAG);
2708 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2709 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2710 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2712 case ARMISD::VUZP: {
2714 EVT VT = N->getValueType(0);
2715 switch (VT.getSimpleVT().SimpleTy) {
2716 default: return NULL;
2717 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2718 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2720 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2721 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2722 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2723 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2725 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2727 SDValue Pred = getAL(CurDAG);
2728 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2729 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2730 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2732 case ARMISD::VTRN: {
2734 EVT VT = N->getValueType(0);
2735 switch (VT.getSimpleVT().SimpleTy) {
2736 default: return NULL;
2737 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2738 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2740 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2741 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2742 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2744 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2746 SDValue Pred = getAL(CurDAG);
2747 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2748 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2749 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
2751 case ARMISD::BUILD_VECTOR: {
2752 EVT VecVT = N->getValueType(0);
2753 EVT EltVT = VecVT.getVectorElementType();
2754 unsigned NumElts = VecVT.getVectorNumElements();
2755 if (EltVT == MVT::f64) {
2756 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2757 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2759 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
2761 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2762 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2763 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2764 N->getOperand(2), N->getOperand(3));
2767 case ARMISD::VLD2DUP: {
2768 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2770 return SelectVLDDup(N, false, 2, Opcodes);
2773 case ARMISD::VLD3DUP: {
2774 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2775 ARM::VLD3DUPd16Pseudo,
2776 ARM::VLD3DUPd32Pseudo };
2777 return SelectVLDDup(N, false, 3, Opcodes);
2780 case ARMISD::VLD4DUP: {
2781 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2782 ARM::VLD4DUPd16Pseudo,
2783 ARM::VLD4DUPd32Pseudo };
2784 return SelectVLDDup(N, false, 4, Opcodes);
2787 case ARMISD::VLD2DUP_UPD: {
2788 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2789 ARM::VLD2DUPd16wb_fixed,
2790 ARM::VLD2DUPd32wb_fixed };
2791 return SelectVLDDup(N, true, 2, Opcodes);
2794 case ARMISD::VLD3DUP_UPD: {
2795 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2796 ARM::VLD3DUPd16Pseudo_UPD,
2797 ARM::VLD3DUPd32Pseudo_UPD };
2798 return SelectVLDDup(N, true, 3, Opcodes);
2801 case ARMISD::VLD4DUP_UPD: {
2802 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2803 ARM::VLD4DUPd16Pseudo_UPD,
2804 ARM::VLD4DUPd32Pseudo_UPD };
2805 return SelectVLDDup(N, true, 4, Opcodes);
2808 case ARMISD::VLD1_UPD: {
2809 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2810 ARM::VLD1d16wb_fixed,
2811 ARM::VLD1d32wb_fixed,
2812 ARM::VLD1d64wb_fixed };
2813 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2814 ARM::VLD1q16wb_fixed,
2815 ARM::VLD1q32wb_fixed,
2816 ARM::VLD1q64wb_fixed };
2817 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2820 case ARMISD::VLD2_UPD: {
2821 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2822 ARM::VLD2d16wb_fixed,
2823 ARM::VLD2d32wb_fixed,
2824 ARM::VLD1q64wb_fixed};
2825 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2826 ARM::VLD2q16PseudoWB_fixed,
2827 ARM::VLD2q32PseudoWB_fixed };
2828 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2831 case ARMISD::VLD3_UPD: {
2832 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2833 ARM::VLD3d16Pseudo_UPD,
2834 ARM::VLD3d32Pseudo_UPD,
2835 ARM::VLD1q64wb_fixed};
2836 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2837 ARM::VLD3q16Pseudo_UPD,
2838 ARM::VLD3q32Pseudo_UPD };
2839 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2840 ARM::VLD3q16oddPseudo_UPD,
2841 ARM::VLD3q32oddPseudo_UPD };
2842 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2845 case ARMISD::VLD4_UPD: {
2846 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2847 ARM::VLD4d16Pseudo_UPD,
2848 ARM::VLD4d32Pseudo_UPD,
2849 ARM::VLD1q64wb_fixed};
2850 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2851 ARM::VLD4q16Pseudo_UPD,
2852 ARM::VLD4q32Pseudo_UPD };
2853 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2854 ARM::VLD4q16oddPseudo_UPD,
2855 ARM::VLD4q32oddPseudo_UPD };
2856 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2859 case ARMISD::VLD2LN_UPD: {
2860 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2861 ARM::VLD2LNd16Pseudo_UPD,
2862 ARM::VLD2LNd32Pseudo_UPD };
2863 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2864 ARM::VLD2LNq32Pseudo_UPD };
2865 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2868 case ARMISD::VLD3LN_UPD: {
2869 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2870 ARM::VLD3LNd16Pseudo_UPD,
2871 ARM::VLD3LNd32Pseudo_UPD };
2872 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2873 ARM::VLD3LNq32Pseudo_UPD };
2874 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2877 case ARMISD::VLD4LN_UPD: {
2878 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2879 ARM::VLD4LNd16Pseudo_UPD,
2880 ARM::VLD4LNd32Pseudo_UPD };
2881 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2882 ARM::VLD4LNq32Pseudo_UPD };
2883 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2886 case ARMISD::VST1_UPD: {
2887 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2888 ARM::VST1d16wb_fixed,
2889 ARM::VST1d32wb_fixed,
2890 ARM::VST1d64wb_fixed };
2891 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2892 ARM::VST1q16wb_fixed,
2893 ARM::VST1q32wb_fixed,
2894 ARM::VST1q64wb_fixed };
2895 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2898 case ARMISD::VST2_UPD: {
2899 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2900 ARM::VST2d16wb_fixed,
2901 ARM::VST2d32wb_fixed,
2902 ARM::VST1q64wb_fixed};
2903 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2904 ARM::VST2q16PseudoWB_fixed,
2905 ARM::VST2q32PseudoWB_fixed };
2906 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2909 case ARMISD::VST3_UPD: {
2910 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2911 ARM::VST3d16Pseudo_UPD,
2912 ARM::VST3d32Pseudo_UPD,
2913 ARM::VST1d64TPseudoWB_fixed};
2914 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2915 ARM::VST3q16Pseudo_UPD,
2916 ARM::VST3q32Pseudo_UPD };
2917 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2918 ARM::VST3q16oddPseudo_UPD,
2919 ARM::VST3q32oddPseudo_UPD };
2920 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2923 case ARMISD::VST4_UPD: {
2924 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2925 ARM::VST4d16Pseudo_UPD,
2926 ARM::VST4d32Pseudo_UPD,
2927 ARM::VST1d64QPseudoWB_fixed};
2928 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2929 ARM::VST4q16Pseudo_UPD,
2930 ARM::VST4q32Pseudo_UPD };
2931 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2932 ARM::VST4q16oddPseudo_UPD,
2933 ARM::VST4q32oddPseudo_UPD };
2934 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2937 case ARMISD::VST2LN_UPD: {
2938 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2939 ARM::VST2LNd16Pseudo_UPD,
2940 ARM::VST2LNd32Pseudo_UPD };
2941 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2942 ARM::VST2LNq32Pseudo_UPD };
2943 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2946 case ARMISD::VST3LN_UPD: {
2947 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2948 ARM::VST3LNd16Pseudo_UPD,
2949 ARM::VST3LNd32Pseudo_UPD };
2950 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2951 ARM::VST3LNq32Pseudo_UPD };
2952 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2955 case ARMISD::VST4LN_UPD: {
2956 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2957 ARM::VST4LNd16Pseudo_UPD,
2958 ARM::VST4LNd32Pseudo_UPD };
2959 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2960 ARM::VST4LNq32Pseudo_UPD };
2961 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
2964 case ISD::INTRINSIC_VOID:
2965 case ISD::INTRINSIC_W_CHAIN: {
2966 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
2971 case Intrinsic::arm_ldrexd: {
2972 SDValue MemAddr = N->getOperand(2);
2973 DebugLoc dl = N->getDebugLoc();
2974 SDValue Chain = N->getOperand(0);
2976 unsigned NewOpc = ARM::LDREXD;
2977 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2978 NewOpc = ARM::t2LDREXD;
2980 // arm_ldrexd returns a i64 value in {i32, i32}
2981 std::vector<EVT> ResTys;
2982 ResTys.push_back(MVT::i32);
2983 ResTys.push_back(MVT::i32);
2984 ResTys.push_back(MVT::Other);
2986 // place arguments in the right order
2987 SmallVector<SDValue, 7> Ops;
2988 Ops.push_back(MemAddr);
2989 Ops.push_back(getAL(CurDAG));
2990 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2991 Ops.push_back(Chain);
2992 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2994 // Transfer memoperands.
2995 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2996 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2997 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2999 // Until there's support for specifing explicit register constraints
3000 // like the use of even/odd register pair, hardcode ldrexd to always
3001 // use the pair [R0, R1] to hold the load result.
3002 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3003 SDValue(Ld, 0), SDValue(0,0));
3004 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3005 SDValue(Ld, 1), Chain.getValue(1));
3008 SDValue Glue = Chain.getValue(1);
3009 if (!SDValue(N, 0).use_empty()) {
3010 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3011 ARM::R0, MVT::i32, Glue);
3012 Glue = Result.getValue(2);
3013 ReplaceUses(SDValue(N, 0), Result);
3015 if (!SDValue(N, 1).use_empty()) {
3016 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3017 ARM::R1, MVT::i32, Glue);
3018 Glue = Result.getValue(2);
3019 ReplaceUses(SDValue(N, 1), Result);
3022 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3026 case Intrinsic::arm_strexd: {
3027 DebugLoc dl = N->getDebugLoc();
3028 SDValue Chain = N->getOperand(0);
3029 SDValue Val0 = N->getOperand(2);
3030 SDValue Val1 = N->getOperand(3);
3031 SDValue MemAddr = N->getOperand(4);
3033 // Until there's support for specifing explicit register constraints
3034 // like the use of even/odd register pair, hardcode strexd to always
3035 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3036 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3038 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3040 SDValue Glue = Chain.getValue(1);
3041 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3042 ARM::R2, MVT::i32, Glue);
3043 Glue = Val0.getValue(1);
3044 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3045 ARM::R3, MVT::i32, Glue);
3047 // Store exclusive double return a i32 value which is the return status
3048 // of the issued store.
3049 std::vector<EVT> ResTys;
3050 ResTys.push_back(MVT::i32);
3051 ResTys.push_back(MVT::Other);
3053 // place arguments in the right order
3054 SmallVector<SDValue, 7> Ops;
3055 Ops.push_back(Val0);
3056 Ops.push_back(Val1);
3057 Ops.push_back(MemAddr);
3058 Ops.push_back(getAL(CurDAG));
3059 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3060 Ops.push_back(Chain);
3062 unsigned NewOpc = ARM::STREXD;
3063 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3064 NewOpc = ARM::t2STREXD;
3066 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3068 // Transfer memoperands.
3069 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3070 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3071 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3076 case Intrinsic::arm_neon_vld1: {
3077 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3078 ARM::VLD1d32, ARM::VLD1d64 };
3079 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3080 ARM::VLD1q32, ARM::VLD1q64};
3081 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
3084 case Intrinsic::arm_neon_vld2: {
3085 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3086 ARM::VLD2d32, ARM::VLD1q64 };
3087 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3088 ARM::VLD2q32Pseudo };
3089 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
3092 case Intrinsic::arm_neon_vld3: {
3093 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3096 ARM::VLD1d64TPseudo };
3097 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3098 ARM::VLD3q16Pseudo_UPD,
3099 ARM::VLD3q32Pseudo_UPD };
3100 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3101 ARM::VLD3q16oddPseudo,
3102 ARM::VLD3q32oddPseudo };
3103 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
3106 case Intrinsic::arm_neon_vld4: {
3107 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3110 ARM::VLD1d64QPseudo };
3111 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3112 ARM::VLD4q16Pseudo_UPD,
3113 ARM::VLD4q32Pseudo_UPD };
3114 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3115 ARM::VLD4q16oddPseudo,
3116 ARM::VLD4q32oddPseudo };
3117 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
3120 case Intrinsic::arm_neon_vld2lane: {
3121 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3122 ARM::VLD2LNd16Pseudo,
3123 ARM::VLD2LNd32Pseudo };
3124 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3125 ARM::VLD2LNq32Pseudo };
3126 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
3129 case Intrinsic::arm_neon_vld3lane: {
3130 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3131 ARM::VLD3LNd16Pseudo,
3132 ARM::VLD3LNd32Pseudo };
3133 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3134 ARM::VLD3LNq32Pseudo };
3135 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
3138 case Intrinsic::arm_neon_vld4lane: {
3139 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3140 ARM::VLD4LNd16Pseudo,
3141 ARM::VLD4LNd32Pseudo };
3142 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3143 ARM::VLD4LNq32Pseudo };
3144 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
3147 case Intrinsic::arm_neon_vst1: {
3148 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3149 ARM::VST1d32, ARM::VST1d64 };
3150 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3151 ARM::VST1q32, ARM::VST1q64 };
3152 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
3155 case Intrinsic::arm_neon_vst2: {
3156 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3157 ARM::VST2d32, ARM::VST1q64 };
3158 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3159 ARM::VST2q32Pseudo };
3160 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
3163 case Intrinsic::arm_neon_vst3: {
3164 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3167 ARM::VST1d64TPseudo };
3168 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3169 ARM::VST3q16Pseudo_UPD,
3170 ARM::VST3q32Pseudo_UPD };
3171 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3172 ARM::VST3q16oddPseudo,
3173 ARM::VST3q32oddPseudo };
3174 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
3177 case Intrinsic::arm_neon_vst4: {
3178 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3181 ARM::VST1d64QPseudo };
3182 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3183 ARM::VST4q16Pseudo_UPD,
3184 ARM::VST4q32Pseudo_UPD };
3185 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3186 ARM::VST4q16oddPseudo,
3187 ARM::VST4q32oddPseudo };
3188 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
3191 case Intrinsic::arm_neon_vst2lane: {
3192 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3193 ARM::VST2LNd16Pseudo,
3194 ARM::VST2LNd32Pseudo };
3195 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3196 ARM::VST2LNq32Pseudo };
3197 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
3200 case Intrinsic::arm_neon_vst3lane: {
3201 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3202 ARM::VST3LNd16Pseudo,
3203 ARM::VST3LNd32Pseudo };
3204 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3205 ARM::VST3LNq32Pseudo };
3206 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
3209 case Intrinsic::arm_neon_vst4lane: {
3210 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3211 ARM::VST4LNd16Pseudo,
3212 ARM::VST4LNd32Pseudo };
3213 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3214 ARM::VST4LNq32Pseudo };
3215 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
3221 case ISD::INTRINSIC_WO_CHAIN: {
3222 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3227 case Intrinsic::arm_neon_vtbl2:
3228 return SelectVTBL(N, false, 2, ARM::VTBL2);
3229 case Intrinsic::arm_neon_vtbl3:
3230 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
3231 case Intrinsic::arm_neon_vtbl4:
3232 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
3234 case Intrinsic::arm_neon_vtbx2:
3235 return SelectVTBL(N, true, 2, ARM::VTBX2);
3236 case Intrinsic::arm_neon_vtbx3:
3237 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
3238 case Intrinsic::arm_neon_vtbx4:
3239 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
3244 case ARMISD::VTBL1: {
3245 DebugLoc dl = N->getDebugLoc();
3246 EVT VT = N->getValueType(0);
3247 SmallVector<SDValue, 6> Ops;
3249 Ops.push_back(N->getOperand(0));
3250 Ops.push_back(N->getOperand(1));
3251 Ops.push_back(getAL(CurDAG)); // Predicate
3252 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3253 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3255 case ARMISD::VTBL2: {
3256 DebugLoc dl = N->getDebugLoc();
3257 EVT VT = N->getValueType(0);
3259 // Form a REG_SEQUENCE to force register allocation.
3260 SDValue V0 = N->getOperand(0);
3261 SDValue V1 = N->getOperand(1);
3262 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3264 SmallVector<SDValue, 6> Ops;
3265 Ops.push_back(RegSeq);
3266 Ops.push_back(N->getOperand(2));
3267 Ops.push_back(getAL(CurDAG)); // Predicate
3268 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3269 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT,
3270 Ops.data(), Ops.size());
3273 case ISD::CONCAT_VECTORS:
3274 return SelectConcatVector(N);
3276 case ARMISD::ATOMOR64_DAG:
3277 return SelectAtomic64(N, ARM::ATOMOR6432);
3278 case ARMISD::ATOMXOR64_DAG:
3279 return SelectAtomic64(N, ARM::ATOMXOR6432);
3280 case ARMISD::ATOMADD64_DAG:
3281 return SelectAtomic64(N, ARM::ATOMADD6432);
3282 case ARMISD::ATOMSUB64_DAG:
3283 return SelectAtomic64(N, ARM::ATOMSUB6432);
3284 case ARMISD::ATOMNAND64_DAG:
3285 return SelectAtomic64(N, ARM::ATOMNAND6432);
3286 case ARMISD::ATOMAND64_DAG:
3287 return SelectAtomic64(N, ARM::ATOMAND6432);
3288 case ARMISD::ATOMSWAP64_DAG:
3289 return SelectAtomic64(N, ARM::ATOMSWAP6432);
3290 case ARMISD::ATOMCMPXCHG64_DAG:
3291 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
3294 return SelectCode(N);
3297 bool ARMDAGToDAGISel::
3298 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3299 std::vector<SDValue> &OutOps) {
3300 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
3301 // Require the address to be in a register. That is safe for all ARM
3302 // variants and it is hard to do anything much smarter without knowing
3303 // how the operand is used.
3304 OutOps.push_back(Op);
3308 /// createARMISelDag - This pass converts a legalized DAG into a
3309 /// ARM-specific DAG, ready for instruction scheduling.
3311 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3312 CodeGenOpt::Level OptLevel) {
3313 return new ARMDAGToDAGISel(TM, OptLevel);