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/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #include "llvm/CodeGen/SelectionDAG.h"
24 #include "llvm/CodeGen/SelectionDAGISel.h"
25 #include "llvm/IR/CallingConv.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/Intrinsics.h"
30 #include "llvm/IR/LLVMContext.h"
31 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/Compiler.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/Target/TargetLowering.h"
37 #include "llvm/Target/TargetOptions.h"
42 DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
47 CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
51 //===--------------------------------------------------------------------===//
52 /// ARMDAGToDAGISel - ARM specific code to select ARM machine
53 /// instructions for SelectionDAG operations.
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
62 class ARMDAGToDAGISel : public SelectionDAGISel {
63 ARMBaseTargetMachine &TM;
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 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
76 virtual const char *getPassName() const {
77 return "ARM Instruction Selection";
80 virtual void PreprocessISelDAG();
82 /// getI32Imm - Return a target constant of type i32 with the specified
84 inline SDValue getI32Imm(unsigned Imm) {
85 return CurDAG->getTargetConstant(Imm, MVT::i32);
88 SDNode *Select(SDNode *N);
91 bool hasNoVMLxHazardUse(SDNode *N) const;
92 bool isShifterOpProfitable(const SDValue &Shift,
93 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
94 bool SelectRegShifterOperand(SDValue N, SDValue &A,
95 SDValue &B, SDValue &C,
96 bool CheckProfitability = true);
97 bool SelectImmShifterOperand(SDValue N, SDValue &A,
98 SDValue &B, bool CheckProfitability = true);
99 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
100 SDValue &B, SDValue &C) {
101 // Don't apply the profitability check
102 return SelectRegShifterOperand(N, A, B, C, false);
104 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
106 // Don't apply the profitability check
107 return SelectImmShifterOperand(N, A, B, false);
110 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
111 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
113 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
114 SDValue &Offset, SDValue &Opc);
115 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
117 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
120 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
122 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
125 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
127 SelectAddrMode2Worker(N, Base, Offset, Opc);
128 // return SelectAddrMode2ShOp(N, Base, Offset, Opc);
129 // This always matches one way or another.
133 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
134 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
135 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
136 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
140 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
141 SDValue &Offset, SDValue &Opc);
142 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
143 SDValue &Offset, SDValue &Opc);
144 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
145 SDValue &Offset, SDValue &Opc);
146 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
147 bool SelectAddrMode3(SDValue N, SDValue &Base,
148 SDValue &Offset, SDValue &Opc);
149 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
150 SDValue &Offset, SDValue &Opc);
151 bool SelectAddrMode5(SDValue N, SDValue &Base,
153 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
154 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
156 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
158 // Thumb Addressing Modes:
159 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
160 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
162 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
163 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
164 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
165 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
167 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
169 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
171 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
173 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
175 // Thumb 2 Addressing Modes:
176 bool SelectT2ShifterOperandReg(SDValue N,
177 SDValue &BaseReg, SDValue &Opc);
178 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
179 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
181 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
183 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
184 SDValue &OffReg, SDValue &ShImm);
185 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
187 inline bool is_so_imm(unsigned Imm) const {
188 return ARM_AM::getSOImmVal(Imm) != -1;
191 inline bool is_so_imm_not(unsigned Imm) const {
192 return ARM_AM::getSOImmVal(~Imm) != -1;
195 inline bool is_t2_so_imm(unsigned Imm) const {
196 return ARM_AM::getT2SOImmVal(Imm) != -1;
199 inline bool is_t2_so_imm_not(unsigned Imm) const {
200 return ARM_AM::getT2SOImmVal(~Imm) != -1;
203 // Include the pieces autogenerated from the target description.
204 #include "ARMGenDAGISel.inc"
207 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
209 SDNode *SelectARMIndexedLoad(SDNode *N);
210 SDNode *SelectT2IndexedLoad(SDNode *N);
212 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
213 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
214 /// loads of D registers and even subregs and odd subregs of Q registers.
215 /// For NumVecs <= 2, QOpcodes1 is not used.
216 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
217 const uint16_t *DOpcodes,
218 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
220 /// SelectVST - Select NEON store intrinsics. NumVecs should
221 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
222 /// stores of D registers and even subregs and odd subregs of Q registers.
223 /// For NumVecs <= 2, QOpcodes1 is not used.
224 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
225 const uint16_t *DOpcodes,
226 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
228 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
229 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
230 /// load/store of D registers and Q registers.
231 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
232 bool isUpdating, unsigned NumVecs,
233 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
235 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
236 /// should be 2, 3 or 4. The opcode array specifies the instructions used
237 /// for loading D registers. (Q registers are not supported.)
238 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
239 const uint16_t *Opcodes);
241 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
242 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
243 /// generated to force the table registers to be consecutive.
244 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
246 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
247 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
249 // Select special operations if node forms integer ABS pattern
250 SDNode *SelectABSOp(SDNode *N);
252 SDNode *SelectInlineAsm(SDNode *N);
254 SDNode *SelectConcatVector(SDNode *N);
256 SDNode *SelectAtomic(SDNode *N, unsigned Op8, unsigned Op16, unsigned Op32, unsigned Op64);
258 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
259 /// inline asm expressions.
260 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
262 std::vector<SDValue> &OutOps);
264 // Form pairs of consecutive R, S, D, or Q registers.
265 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
266 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
267 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
268 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
270 // Form sequences of 4 consecutive S, D, or Q registers.
271 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
272 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
273 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
275 // Get the alignment operand for a NEON VLD or VST instruction.
276 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
280 /// isInt32Immediate - This method tests to see if the node is a 32-bit constant
281 /// operand. If so Imm will receive the 32-bit value.
282 static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
283 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
284 Imm = cast<ConstantSDNode>(N)->getZExtValue();
290 // isInt32Immediate - This method tests to see if a constant operand.
291 // If so Imm will receive the 32 bit value.
292 static bool isInt32Immediate(SDValue N, unsigned &Imm) {
293 return isInt32Immediate(N.getNode(), Imm);
296 // isOpcWithIntImmediate - This method tests to see if the node is a specific
297 // opcode and that it has a immediate integer right operand.
298 // If so Imm will receive the 32 bit value.
299 static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
300 return N->getOpcode() == Opc &&
301 isInt32Immediate(N->getOperand(1).getNode(), Imm);
304 /// \brief Check whether a particular node is a constant value representable as
305 /// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
307 /// \param ScaledConstant [out] - On success, the pre-scaled constant value.
308 static bool isScaledConstantInRange(SDValue Node, int Scale,
309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
311 assert(Scale > 0 && "Invalid scale!");
313 // Check that this is a constant.
314 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
318 ScaledConstant = (int) C->getZExtValue();
319 if ((ScaledConstant % Scale) != 0)
322 ScaledConstant /= Scale;
323 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
326 void ARMDAGToDAGISel::PreprocessISelDAG() {
327 if (!Subtarget->hasV6T2Ops())
330 bool isThumb2 = Subtarget->isThumb();
331 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
332 E = CurDAG->allnodes_end(); I != E; ) {
333 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
335 if (N->getOpcode() != ISD::ADD)
338 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
339 // leading zeros, followed by consecutive set bits, followed by 1 or 2
340 // trailing zeros, e.g. 1020.
341 // Transform the expression to
342 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
343 // of trailing zeros of c2. The left shift would be folded as an shifter
344 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
347 SDValue N0 = N->getOperand(0);
348 SDValue N1 = N->getOperand(1);
349 unsigned And_imm = 0;
350 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
351 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
357 // Check if the AND mask is an immediate of the form: 000.....1111111100
358 unsigned TZ = countTrailingZeros(And_imm);
359 if (TZ != 1 && TZ != 2)
360 // Be conservative here. Shifter operands aren't always free. e.g. On
361 // Swift, left shifter operand of 1 / 2 for free but others are not.
363 // ubfx r3, r1, #16, #8
364 // ldr.w r3, [r0, r3, lsl #2]
367 // and.w r2, r9, r1, lsr #14
371 if (And_imm & (And_imm + 1))
374 // Look for (and (srl X, c1), c2).
375 SDValue Srl = N1.getOperand(0);
376 unsigned Srl_imm = 0;
377 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
381 // Make sure first operand is not a shifter operand which would prevent
382 // folding of the left shift.
387 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
390 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
391 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
395 // Now make the transformation.
396 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
398 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
399 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
400 Srl, CurDAG->getConstant(And_imm, MVT::i32));
401 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
402 N1, CurDAG->getConstant(TZ, MVT::i32));
403 CurDAG->UpdateNodeOperands(N, N0, N1);
407 /// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
408 /// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
409 /// least on current ARM implementations) which should be avoidded.
410 bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
411 if (OptLevel == CodeGenOpt::None)
414 if (!CheckVMLxHazard)
417 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9() &&
418 !Subtarget->isSwift())
424 SDNode *Use = *N->use_begin();
425 if (Use->getOpcode() == ISD::CopyToReg)
427 if (Use->isMachineOpcode()) {
428 const ARMBaseInstrInfo *TII =
429 static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
431 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
434 unsigned Opcode = MCID.getOpcode();
435 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
437 // vmlx feeding into another vmlx. We actually want to unfold
438 // the use later in the MLxExpansion pass. e.g.
440 // vmla (stall 8 cycles)
445 // This adds up to about 18 - 19 cycles.
448 // vmul (stall 4 cycles)
449 // vadd adds up to about 14 cycles.
450 return TII->isFpMLxInstruction(Opcode);
456 bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
457 ARM_AM::ShiftOpc ShOpcVal,
459 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
461 if (Shift.hasOneUse())
464 return ShOpcVal == ARM_AM::lsl &&
465 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
468 bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
471 bool CheckProfitability) {
472 if (DisableShifterOp)
475 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
477 // Don't match base register only case. That is matched to a separate
478 // lower complexity pattern with explicit register operand.
479 if (ShOpcVal == ARM_AM::no_shift) return false;
481 BaseReg = N.getOperand(0);
482 unsigned ShImmVal = 0;
483 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
484 if (!RHS) return false;
485 ShImmVal = RHS->getZExtValue() & 31;
486 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
491 bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
495 bool CheckProfitability) {
496 if (DisableShifterOp)
499 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
501 // Don't match base register only case. That is matched to a separate
502 // lower complexity pattern with explicit register operand.
503 if (ShOpcVal == ARM_AM::no_shift) return false;
505 BaseReg = N.getOperand(0);
506 unsigned ShImmVal = 0;
507 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
508 if (RHS) return false;
510 ShReg = N.getOperand(1);
511 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
513 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
519 bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
522 // Match simple R + imm12 operands.
525 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
526 !CurDAG->isBaseWithConstantOffset(N)) {
527 if (N.getOpcode() == ISD::FrameIndex) {
528 // Match frame index.
529 int FI = cast<FrameIndexSDNode>(N)->getIndex();
530 Base = CurDAG->getTargetFrameIndex(FI,
531 getTargetLowering()->getPointerTy());
532 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
536 if (N.getOpcode() == ARMISD::Wrapper &&
537 !(Subtarget->useMovt() &&
538 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
539 Base = N.getOperand(0);
542 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
546 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
547 int RHSC = (int)RHS->getZExtValue();
548 if (N.getOpcode() == ISD::SUB)
551 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
552 Base = N.getOperand(0);
553 if (Base.getOpcode() == ISD::FrameIndex) {
554 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
555 Base = CurDAG->getTargetFrameIndex(FI,
556 getTargetLowering()->getPointerTy());
558 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
565 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
571 bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
573 if (N.getOpcode() == ISD::MUL &&
574 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
575 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
576 // X * [3,5,9] -> X + X * [2,4,8] etc.
577 int RHSC = (int)RHS->getZExtValue();
580 ARM_AM::AddrOpc AddSub = ARM_AM::add;
582 AddSub = ARM_AM::sub;
585 if (isPowerOf2_32(RHSC)) {
586 unsigned ShAmt = Log2_32(RHSC);
587 Base = Offset = N.getOperand(0);
588 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
597 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
598 // ISD::OR that is equivalent to an ISD::ADD.
599 !CurDAG->isBaseWithConstantOffset(N))
602 // Leave simple R +/- imm12 operands for LDRi12
603 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
605 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
606 -0x1000+1, 0x1000, RHSC)) // 12 bits.
610 // Otherwise this is R +/- [possibly shifted] R.
611 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
612 ARM_AM::ShiftOpc ShOpcVal =
613 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
616 Base = N.getOperand(0);
617 Offset = N.getOperand(1);
619 if (ShOpcVal != ARM_AM::no_shift) {
620 // Check to see if the RHS of the shift is a constant, if not, we can't fold
622 if (ConstantSDNode *Sh =
623 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
624 ShAmt = Sh->getZExtValue();
625 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
626 Offset = N.getOperand(1).getOperand(0);
629 ShOpcVal = ARM_AM::no_shift;
632 ShOpcVal = ARM_AM::no_shift;
636 // Try matching (R shl C) + (R).
637 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
638 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
639 N.getOperand(0).hasOneUse())) {
640 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
641 if (ShOpcVal != ARM_AM::no_shift) {
642 // Check to see if the RHS of the shift is a constant, if not, we can't
644 if (ConstantSDNode *Sh =
645 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
646 ShAmt = Sh->getZExtValue();
647 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
648 Offset = N.getOperand(0).getOperand(0);
649 Base = N.getOperand(1);
652 ShOpcVal = ARM_AM::no_shift;
655 ShOpcVal = ARM_AM::no_shift;
660 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
668 AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
672 if (N.getOpcode() == ISD::MUL &&
673 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
674 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
675 // X * [3,5,9] -> X + X * [2,4,8] etc.
676 int RHSC = (int)RHS->getZExtValue();
679 ARM_AM::AddrOpc AddSub = ARM_AM::add;
681 AddSub = ARM_AM::sub;
684 if (isPowerOf2_32(RHSC)) {
685 unsigned ShAmt = Log2_32(RHSC);
686 Base = Offset = N.getOperand(0);
687 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
696 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
697 // ISD::OR that is equivalent to an ADD.
698 !CurDAG->isBaseWithConstantOffset(N)) {
700 if (N.getOpcode() == ISD::FrameIndex) {
701 int FI = cast<FrameIndexSDNode>(N)->getIndex();
702 Base = CurDAG->getTargetFrameIndex(FI,
703 getTargetLowering()->getPointerTy());
704 } else if (N.getOpcode() == ARMISD::Wrapper &&
705 !(Subtarget->useMovt() &&
706 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
707 Base = N.getOperand(0);
709 Offset = CurDAG->getRegister(0, MVT::i32);
710 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
716 // Match simple R +/- imm12 operands.
717 if (N.getOpcode() != ISD::SUB) {
719 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
720 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
721 Base = N.getOperand(0);
722 if (Base.getOpcode() == ISD::FrameIndex) {
723 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
724 Base = CurDAG->getTargetFrameIndex(FI,
725 getTargetLowering()->getPointerTy());
727 Offset = CurDAG->getRegister(0, MVT::i32);
729 ARM_AM::AddrOpc AddSub = ARM_AM::add;
731 AddSub = ARM_AM::sub;
734 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
741 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
742 // Compute R +/- (R << N) and reuse it.
744 Offset = CurDAG->getRegister(0, MVT::i32);
745 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
751 // Otherwise this is R +/- [possibly shifted] R.
752 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
753 ARM_AM::ShiftOpc ShOpcVal =
754 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
757 Base = N.getOperand(0);
758 Offset = N.getOperand(1);
760 if (ShOpcVal != ARM_AM::no_shift) {
761 // Check to see if the RHS of the shift is a constant, if not, we can't fold
763 if (ConstantSDNode *Sh =
764 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
765 ShAmt = Sh->getZExtValue();
766 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
767 Offset = N.getOperand(1).getOperand(0);
770 ShOpcVal = ARM_AM::no_shift;
773 ShOpcVal = ARM_AM::no_shift;
777 // Try matching (R shl C) + (R).
778 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
779 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
780 N.getOperand(0).hasOneUse())) {
781 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
782 if (ShOpcVal != ARM_AM::no_shift) {
783 // Check to see if the RHS of the shift is a constant, if not, we can't
785 if (ConstantSDNode *Sh =
786 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
787 ShAmt = Sh->getZExtValue();
788 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
789 Offset = N.getOperand(0).getOperand(0);
790 Base = N.getOperand(1);
793 ShOpcVal = ARM_AM::no_shift;
796 ShOpcVal = ARM_AM::no_shift;
801 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
806 bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
807 SDValue &Offset, SDValue &Opc) {
808 unsigned Opcode = Op->getOpcode();
809 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
810 ? cast<LoadSDNode>(Op)->getAddressingMode()
811 : cast<StoreSDNode>(Op)->getAddressingMode();
812 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
813 ? ARM_AM::add : ARM_AM::sub;
815 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
819 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
821 if (ShOpcVal != ARM_AM::no_shift) {
822 // Check to see if the RHS of the shift is a constant, if not, we can't fold
824 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
825 ShAmt = Sh->getZExtValue();
826 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
827 Offset = N.getOperand(0);
830 ShOpcVal = ARM_AM::no_shift;
833 ShOpcVal = ARM_AM::no_shift;
837 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
842 bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
843 SDValue &Offset, SDValue &Opc) {
844 unsigned Opcode = Op->getOpcode();
845 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
846 ? cast<LoadSDNode>(Op)->getAddressingMode()
847 : cast<StoreSDNode>(Op)->getAddressingMode();
848 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
849 ? ARM_AM::add : ARM_AM::sub;
851 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
852 if (AddSub == ARM_AM::sub) Val *= -1;
853 Offset = CurDAG->getRegister(0, MVT::i32);
854 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
862 bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
863 SDValue &Offset, SDValue &Opc) {
864 unsigned Opcode = Op->getOpcode();
865 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
866 ? cast<LoadSDNode>(Op)->getAddressingMode()
867 : cast<StoreSDNode>(Op)->getAddressingMode();
868 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
869 ? ARM_AM::add : ARM_AM::sub;
871 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
872 Offset = CurDAG->getRegister(0, MVT::i32);
873 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
882 bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
887 bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
888 SDValue &Base, SDValue &Offset,
890 if (N.getOpcode() == ISD::SUB) {
891 // X - C is canonicalize to X + -C, no need to handle it here.
892 Base = N.getOperand(0);
893 Offset = N.getOperand(1);
894 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
898 if (!CurDAG->isBaseWithConstantOffset(N)) {
900 if (N.getOpcode() == ISD::FrameIndex) {
901 int FI = cast<FrameIndexSDNode>(N)->getIndex();
902 Base = CurDAG->getTargetFrameIndex(FI,
903 getTargetLowering()->getPointerTy());
905 Offset = CurDAG->getRegister(0, MVT::i32);
906 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
910 // If the RHS is +/- imm8, fold into addr mode.
912 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
913 -256 + 1, 256, RHSC)) { // 8 bits.
914 Base = N.getOperand(0);
915 if (Base.getOpcode() == ISD::FrameIndex) {
916 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
917 Base = CurDAG->getTargetFrameIndex(FI,
918 getTargetLowering()->getPointerTy());
920 Offset = CurDAG->getRegister(0, MVT::i32);
922 ARM_AM::AddrOpc AddSub = ARM_AM::add;
924 AddSub = ARM_AM::sub;
927 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
931 Base = N.getOperand(0);
932 Offset = N.getOperand(1);
933 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
937 bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
938 SDValue &Offset, SDValue &Opc) {
939 unsigned Opcode = Op->getOpcode();
940 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
941 ? cast<LoadSDNode>(Op)->getAddressingMode()
942 : cast<StoreSDNode>(Op)->getAddressingMode();
943 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
944 ? ARM_AM::add : ARM_AM::sub;
946 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
947 Offset = CurDAG->getRegister(0, MVT::i32);
948 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
953 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
957 bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
958 SDValue &Base, SDValue &Offset) {
959 if (!CurDAG->isBaseWithConstantOffset(N)) {
961 if (N.getOpcode() == ISD::FrameIndex) {
962 int FI = cast<FrameIndexSDNode>(N)->getIndex();
963 Base = CurDAG->getTargetFrameIndex(FI,
964 getTargetLowering()->getPointerTy());
965 } else if (N.getOpcode() == ARMISD::Wrapper &&
966 !(Subtarget->useMovt() &&
967 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
968 Base = N.getOperand(0);
970 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
975 // If the RHS is +/- imm8, fold into addr mode.
977 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
978 -256 + 1, 256, RHSC)) {
979 Base = N.getOperand(0);
980 if (Base.getOpcode() == ISD::FrameIndex) {
981 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
982 Base = CurDAG->getTargetFrameIndex(FI,
983 getTargetLowering()->getPointerTy());
986 ARM_AM::AddrOpc AddSub = ARM_AM::add;
988 AddSub = ARM_AM::sub;
991 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
997 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
1002 bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
1006 unsigned Alignment = 0;
1007 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1008 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1009 // The maximum alignment is equal to the memory size being referenced.
1010 unsigned LSNAlign = LSN->getAlignment();
1011 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
1012 if (LSNAlign >= MemSize && MemSize > 1)
1013 Alignment = MemSize;
1015 // All other uses of addrmode6 are for intrinsics. For now just record
1016 // the raw alignment value; it will be refined later based on the legal
1017 // alignment operands for the intrinsic.
1018 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1021 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1025 bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1027 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1028 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1029 if (AM != ISD::POST_INC)
1032 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1033 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1034 Offset = CurDAG->getRegister(0, MVT::i32);
1039 bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
1040 SDValue &Offset, SDValue &Label) {
1041 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1042 Offset = N.getOperand(0);
1043 SDValue N1 = N.getOperand(1);
1044 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1053 //===----------------------------------------------------------------------===//
1054 // Thumb Addressing Modes
1055 //===----------------------------------------------------------------------===//
1057 bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
1058 SDValue &Base, SDValue &Offset){
1059 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
1060 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
1061 if (!NC || !NC->isNullValue())
1068 Base = N.getOperand(0);
1069 Offset = N.getOperand(1);
1074 ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1075 SDValue &Offset, unsigned Scale) {
1077 SDValue TmpBase, TmpOffImm;
1078 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1079 return false; // We want to select tLDRspi / tSTRspi instead.
1081 if (N.getOpcode() == ARMISD::Wrapper &&
1082 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1083 return false; // We want to select tLDRpci instead.
1086 if (!CurDAG->isBaseWithConstantOffset(N))
1089 // Thumb does not have [sp, r] address mode.
1090 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1091 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1092 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1093 (RHSR && RHSR->getReg() == ARM::SP))
1096 // FIXME: Why do we explicitly check for a match here and then return false?
1097 // Presumably to allow something else to match, but shouldn't this be
1100 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1103 Base = N.getOperand(0);
1104 Offset = N.getOperand(1);
1109 ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1112 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1116 ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1119 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1123 ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1126 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1130 ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1131 SDValue &Base, SDValue &OffImm) {
1133 SDValue TmpBase, TmpOffImm;
1134 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1135 return false; // We want to select tLDRspi / tSTRspi instead.
1137 if (N.getOpcode() == ARMISD::Wrapper &&
1138 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1139 return false; // We want to select tLDRpci instead.
1142 if (!CurDAG->isBaseWithConstantOffset(N)) {
1143 if (N.getOpcode() == ARMISD::Wrapper &&
1144 !(Subtarget->useMovt() &&
1145 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1146 Base = N.getOperand(0);
1151 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1155 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1156 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1157 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1158 (RHSR && RHSR->getReg() == ARM::SP)) {
1159 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1160 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1161 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1162 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1164 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1165 if (LHSC != 0 || RHSC != 0) return false;
1168 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1172 // If the RHS is + imm5 * scale, fold into addr mode.
1174 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1175 Base = N.getOperand(0);
1176 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1180 Base = N.getOperand(0);
1181 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1186 ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1188 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
1192 ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1194 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
1198 ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1200 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
1203 bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1204 SDValue &Base, SDValue &OffImm) {
1205 if (N.getOpcode() == ISD::FrameIndex) {
1206 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1207 Base = CurDAG->getTargetFrameIndex(FI,
1208 getTargetLowering()->getPointerTy());
1209 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1213 if (!CurDAG->isBaseWithConstantOffset(N))
1216 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1217 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1218 (LHSR && LHSR->getReg() == ARM::SP)) {
1219 // If the RHS is + imm8 * scale, fold into addr mode.
1221 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1222 Base = N.getOperand(0);
1223 if (Base.getOpcode() == ISD::FrameIndex) {
1224 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1225 Base = CurDAG->getTargetFrameIndex(FI,
1226 getTargetLowering()->getPointerTy());
1228 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1237 //===----------------------------------------------------------------------===//
1238 // Thumb 2 Addressing Modes
1239 //===----------------------------------------------------------------------===//
1242 bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
1244 if (DisableShifterOp)
1247 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
1249 // Don't match base register only case. That is matched to a separate
1250 // lower complexity pattern with explicit register operand.
1251 if (ShOpcVal == ARM_AM::no_shift) return false;
1253 BaseReg = N.getOperand(0);
1254 unsigned ShImmVal = 0;
1255 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1256 ShImmVal = RHS->getZExtValue() & 31;
1257 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1264 bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
1265 SDValue &Base, SDValue &OffImm) {
1266 // Match simple R + imm12 operands.
1269 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1270 !CurDAG->isBaseWithConstantOffset(N)) {
1271 if (N.getOpcode() == ISD::FrameIndex) {
1272 // Match frame index.
1273 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1274 Base = CurDAG->getTargetFrameIndex(FI,
1275 getTargetLowering()->getPointerTy());
1276 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1280 if (N.getOpcode() == ARMISD::Wrapper &&
1281 !(Subtarget->useMovt() &&
1282 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1283 Base = N.getOperand(0);
1284 if (Base.getOpcode() == ISD::TargetConstantPool)
1285 return false; // We want to select t2LDRpci instead.
1288 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1292 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1293 if (SelectT2AddrModeImm8(N, Base, OffImm))
1294 // Let t2LDRi8 handle (R - imm8).
1297 int RHSC = (int)RHS->getZExtValue();
1298 if (N.getOpcode() == ISD::SUB)
1301 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
1302 Base = N.getOperand(0);
1303 if (Base.getOpcode() == ISD::FrameIndex) {
1304 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1305 Base = CurDAG->getTargetFrameIndex(FI,
1306 getTargetLowering()->getPointerTy());
1308 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1315 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1319 bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
1320 SDValue &Base, SDValue &OffImm) {
1321 // Match simple R - imm8 operands.
1322 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1323 !CurDAG->isBaseWithConstantOffset(N))
1326 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1327 int RHSC = (int)RHS->getSExtValue();
1328 if (N.getOpcode() == ISD::SUB)
1331 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1332 Base = N.getOperand(0);
1333 if (Base.getOpcode() == ISD::FrameIndex) {
1334 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1335 Base = CurDAG->getTargetFrameIndex(FI,
1336 getTargetLowering()->getPointerTy());
1338 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1346 bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
1348 unsigned Opcode = Op->getOpcode();
1349 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1350 ? cast<LoadSDNode>(Op)->getAddressingMode()
1351 : cast<StoreSDNode>(Op)->getAddressingMode();
1353 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1354 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1355 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1356 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1363 bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
1365 SDValue &OffReg, SDValue &ShImm) {
1366 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1367 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
1370 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1371 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1372 int RHSC = (int)RHS->getZExtValue();
1373 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1375 else if (RHSC < 0 && RHSC >= -255) // 8 bits
1379 // Look for (R + R) or (R + (R << [1,2,3])).
1381 Base = N.getOperand(0);
1382 OffReg = N.getOperand(1);
1384 // Swap if it is ((R << c) + R).
1385 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
1386 if (ShOpcVal != ARM_AM::lsl) {
1387 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
1388 if (ShOpcVal == ARM_AM::lsl)
1389 std::swap(Base, OffReg);
1392 if (ShOpcVal == ARM_AM::lsl) {
1393 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1395 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1396 ShAmt = Sh->getZExtValue();
1397 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1398 OffReg = OffReg.getOperand(0);
1401 ShOpcVal = ARM_AM::no_shift;
1404 ShOpcVal = ARM_AM::no_shift;
1408 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
1413 bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1415 // This *must* succeed since it's used for the irreplacable ldrex and strex
1418 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1420 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1423 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1427 uint32_t RHSC = (int)RHS->getZExtValue();
1428 if (RHSC > 1020 || RHSC % 4 != 0)
1431 Base = N.getOperand(0);
1432 if (Base.getOpcode() == ISD::FrameIndex) {
1433 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1434 Base = CurDAG->getTargetFrameIndex(FI, getTargetLowering()->getPointerTy());
1437 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1441 //===--------------------------------------------------------------------===//
1443 /// getAL - Returns a ARMCC::AL immediate node.
1444 static inline SDValue getAL(SelectionDAG *CurDAG) {
1445 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
1448 SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1449 LoadSDNode *LD = cast<LoadSDNode>(N);
1450 ISD::MemIndexedMode AM = LD->getAddressingMode();
1451 if (AM == ISD::UNINDEXED)
1454 EVT LoadedVT = LD->getMemoryVT();
1455 SDValue Offset, AMOpc;
1456 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1457 unsigned Opcode = 0;
1459 if (LoadedVT == MVT::i32 && isPre &&
1460 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1461 Opcode = ARM::LDR_PRE_IMM;
1463 } else if (LoadedVT == MVT::i32 && !isPre &&
1464 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1465 Opcode = ARM::LDR_POST_IMM;
1467 } else if (LoadedVT == MVT::i32 &&
1468 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1469 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
1472 } else if (LoadedVT == MVT::i16 &&
1473 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1475 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1476 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1477 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
1478 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
1479 if (LD->getExtensionType() == ISD::SEXTLOAD) {
1480 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
1482 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1486 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1488 Opcode = ARM::LDRB_PRE_IMM;
1489 } else if (!isPre &&
1490 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1492 Opcode = ARM::LDRB_POST_IMM;
1493 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1495 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
1501 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1502 SDValue Chain = LD->getChain();
1503 SDValue Base = LD->getBasePtr();
1504 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1505 CurDAG->getRegister(0, MVT::i32), Chain };
1506 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
1507 MVT::i32, MVT::Other, Ops);
1509 SDValue Chain = LD->getChain();
1510 SDValue Base = LD->getBasePtr();
1511 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1512 CurDAG->getRegister(0, MVT::i32), Chain };
1513 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
1514 MVT::i32, MVT::Other, Ops);
1521 SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1522 LoadSDNode *LD = cast<LoadSDNode>(N);
1523 ISD::MemIndexedMode AM = LD->getAddressingMode();
1524 if (AM == ISD::UNINDEXED)
1527 EVT LoadedVT = LD->getMemoryVT();
1528 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
1530 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1531 unsigned Opcode = 0;
1533 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
1534 switch (LoadedVT.getSimpleVT().SimpleTy) {
1536 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1540 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1542 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
1547 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1549 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
1558 SDValue Chain = LD->getChain();
1559 SDValue Base = LD->getBasePtr();
1560 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
1561 CurDAG->getRegister(0, MVT::i32), Chain };
1562 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
1569 /// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1570 SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
1571 SDLoc dl(V0.getNode());
1573 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1574 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1575 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1576 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1577 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1580 /// \brief Form a D register from a pair of S registers.
1581 SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
1582 SDLoc dl(V0.getNode());
1584 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
1585 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1586 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1587 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1588 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1591 /// \brief Form a quad register from a pair of D registers.
1592 SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
1593 SDLoc dl(V0.getNode());
1594 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
1595 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1596 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1597 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1598 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1601 /// \brief Form 4 consecutive D registers from a pair of Q registers.
1602 SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
1603 SDLoc dl(V0.getNode());
1604 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
1605 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1606 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1607 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1608 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1611 /// \brief Form 4 consecutive S registers.
1612 SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
1613 SDValue V2, SDValue V3) {
1614 SDLoc dl(V0.getNode());
1616 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
1617 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1618 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1619 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1620 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1621 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1622 V2, SubReg2, V3, SubReg3 };
1623 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1626 /// \brief Form 4 consecutive D registers.
1627 SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
1628 SDValue V2, SDValue V3) {
1629 SDLoc dl(V0.getNode());
1630 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
1631 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1632 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1633 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1634 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1635 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1636 V2, SubReg2, V3, SubReg3 };
1637 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1640 /// \brief Form 4 consecutive Q registers.
1641 SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
1642 SDValue V2, SDValue V3) {
1643 SDLoc dl(V0.getNode());
1644 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
1645 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1646 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1647 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1648 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
1649 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1650 V2, SubReg2, V3, SubReg3 };
1651 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
1654 /// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1655 /// of a NEON VLD or VST instruction. The supported values depend on the
1656 /// number of registers being loaded.
1657 SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1658 bool is64BitVector) {
1659 unsigned NumRegs = NumVecs;
1660 if (!is64BitVector && NumVecs < 3)
1663 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1664 if (Alignment >= 32 && NumRegs == 4)
1666 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1668 else if (Alignment >= 8)
1673 return CurDAG->getTargetConstant(Alignment, MVT::i32);
1676 static bool isVLDfixed(unsigned Opc)
1679 default: return false;
1680 case ARM::VLD1d8wb_fixed : return true;
1681 case ARM::VLD1d16wb_fixed : return true;
1682 case ARM::VLD1d64Qwb_fixed : return true;
1683 case ARM::VLD1d32wb_fixed : return true;
1684 case ARM::VLD1d64wb_fixed : return true;
1685 case ARM::VLD1d64TPseudoWB_fixed : return true;
1686 case ARM::VLD1d64QPseudoWB_fixed : return true;
1687 case ARM::VLD1q8wb_fixed : return true;
1688 case ARM::VLD1q16wb_fixed : return true;
1689 case ARM::VLD1q32wb_fixed : return true;
1690 case ARM::VLD1q64wb_fixed : return true;
1691 case ARM::VLD2d8wb_fixed : return true;
1692 case ARM::VLD2d16wb_fixed : return true;
1693 case ARM::VLD2d32wb_fixed : return true;
1694 case ARM::VLD2q8PseudoWB_fixed : return true;
1695 case ARM::VLD2q16PseudoWB_fixed : return true;
1696 case ARM::VLD2q32PseudoWB_fixed : return true;
1697 case ARM::VLD2DUPd8wb_fixed : return true;
1698 case ARM::VLD2DUPd16wb_fixed : return true;
1699 case ARM::VLD2DUPd32wb_fixed : return true;
1703 static bool isVSTfixed(unsigned Opc)
1706 default: return false;
1707 case ARM::VST1d8wb_fixed : return true;
1708 case ARM::VST1d16wb_fixed : return true;
1709 case ARM::VST1d32wb_fixed : return true;
1710 case ARM::VST1d64wb_fixed : return true;
1711 case ARM::VST1q8wb_fixed : return true;
1712 case ARM::VST1q16wb_fixed : return true;
1713 case ARM::VST1q32wb_fixed : return true;
1714 case ARM::VST1q64wb_fixed : return true;
1715 case ARM::VST1d64TPseudoWB_fixed : return true;
1716 case ARM::VST1d64QPseudoWB_fixed : return true;
1717 case ARM::VST2d8wb_fixed : return true;
1718 case ARM::VST2d16wb_fixed : return true;
1719 case ARM::VST2d32wb_fixed : return true;
1720 case ARM::VST2q8PseudoWB_fixed : return true;
1721 case ARM::VST2q16PseudoWB_fixed : return true;
1722 case ARM::VST2q32PseudoWB_fixed : return true;
1726 // Get the register stride update opcode of a VLD/VST instruction that
1727 // is otherwise equivalent to the given fixed stride updating instruction.
1728 static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1729 assert((isVLDfixed(Opc) || isVSTfixed(Opc))
1730 && "Incorrect fixed stride updating instruction.");
1733 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1734 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1735 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1736 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1737 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1738 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1739 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1740 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
1741 case ARM::VLD1d64Twb_fixed: return ARM::VLD1d64Twb_register;
1742 case ARM::VLD1d64Qwb_fixed: return ARM::VLD1d64Qwb_register;
1743 case ARM::VLD1d64TPseudoWB_fixed: return ARM::VLD1d64TPseudoWB_register;
1744 case ARM::VLD1d64QPseudoWB_fixed: return ARM::VLD1d64QPseudoWB_register;
1746 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1747 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1748 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1749 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1750 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1751 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1752 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1753 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
1754 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
1755 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
1757 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1758 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1759 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
1760 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1761 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1762 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1764 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1765 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1766 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
1767 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1768 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1769 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
1771 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1772 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1773 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
1775 return Opc; // If not one we handle, return it unchanged.
1778 SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
1779 const uint16_t *DOpcodes,
1780 const uint16_t *QOpcodes0,
1781 const uint16_t *QOpcodes1) {
1782 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
1785 SDValue MemAddr, Align;
1786 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1787 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
1790 SDValue Chain = N->getOperand(0);
1791 EVT VT = N->getValueType(0);
1792 bool is64BitVector = VT.is64BitVector();
1793 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1795 unsigned OpcodeIndex;
1796 switch (VT.getSimpleVT().SimpleTy) {
1797 default: llvm_unreachable("unhandled vld type");
1798 // Double-register operations:
1799 case MVT::v8i8: OpcodeIndex = 0; break;
1800 case MVT::v4i16: OpcodeIndex = 1; break;
1802 case MVT::v2i32: OpcodeIndex = 2; break;
1803 case MVT::v1i64: OpcodeIndex = 3; break;
1804 // Quad-register operations:
1805 case MVT::v16i8: OpcodeIndex = 0; break;
1806 case MVT::v8i16: OpcodeIndex = 1; break;
1808 case MVT::v4i32: OpcodeIndex = 2; break;
1809 case MVT::v2i64: OpcodeIndex = 3;
1810 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
1818 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1821 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1823 std::vector<EVT> ResTys;
1824 ResTys.push_back(ResTy);
1826 ResTys.push_back(MVT::i32);
1827 ResTys.push_back(MVT::Other);
1829 SDValue Pred = getAL(CurDAG);
1830 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1832 SmallVector<SDValue, 7> Ops;
1834 // Double registers and VLD1/VLD2 quad registers are directly supported.
1835 if (is64BitVector || NumVecs <= 2) {
1836 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1837 QOpcodes0[OpcodeIndex]);
1838 Ops.push_back(MemAddr);
1839 Ops.push_back(Align);
1841 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1842 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
1843 // case entirely when the rest are updated to that form, too.
1844 if ((NumVecs <= 2) && !isa<ConstantSDNode>(Inc.getNode()))
1845 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1846 // FIXME: We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
1847 // check for that explicitly too. Horribly hacky, but temporary.
1848 if ((NumVecs > 2 && !isVLDfixed(Opc)) ||
1849 !isa<ConstantSDNode>(Inc.getNode()))
1850 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1852 Ops.push_back(Pred);
1853 Ops.push_back(Reg0);
1854 Ops.push_back(Chain);
1855 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
1858 // Otherwise, quad registers are loaded with two separate instructions,
1859 // where one loads the even registers and the other loads the odd registers.
1860 EVT AddrTy = MemAddr.getValueType();
1862 // Load the even subregs. This is always an updating load, so that it
1863 // provides the address to the second load for the odd subregs.
1865 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1866 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1867 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1868 ResTy, AddrTy, MVT::Other, OpsA);
1869 Chain = SDValue(VLdA, 2);
1871 // Load the odd subregs.
1872 Ops.push_back(SDValue(VLdA, 1));
1873 Ops.push_back(Align);
1875 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1876 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1877 "only constant post-increment update allowed for VLD3/4");
1879 Ops.push_back(Reg0);
1881 Ops.push_back(SDValue(VLdA, 0));
1882 Ops.push_back(Pred);
1883 Ops.push_back(Reg0);
1884 Ops.push_back(Chain);
1885 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
1888 // Transfer memoperands.
1889 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1890 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1891 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1896 // Extract out the subregisters.
1897 SDValue SuperReg = SDValue(VLd, 0);
1898 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1899 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1900 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1901 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1902 ReplaceUses(SDValue(N, Vec),
1903 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1904 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1906 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
1910 SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
1911 const uint16_t *DOpcodes,
1912 const uint16_t *QOpcodes0,
1913 const uint16_t *QOpcodes1) {
1914 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
1917 SDValue MemAddr, Align;
1918 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1919 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1920 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
1923 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1924 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1926 SDValue Chain = N->getOperand(0);
1927 EVT VT = N->getOperand(Vec0Idx).getValueType();
1928 bool is64BitVector = VT.is64BitVector();
1929 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
1931 unsigned OpcodeIndex;
1932 switch (VT.getSimpleVT().SimpleTy) {
1933 default: llvm_unreachable("unhandled vst type");
1934 // Double-register operations:
1935 case MVT::v8i8: OpcodeIndex = 0; break;
1936 case MVT::v4i16: OpcodeIndex = 1; break;
1938 case MVT::v2i32: OpcodeIndex = 2; break;
1939 case MVT::v1i64: OpcodeIndex = 3; break;
1940 // Quad-register operations:
1941 case MVT::v16i8: OpcodeIndex = 0; break;
1942 case MVT::v8i16: OpcodeIndex = 1; break;
1944 case MVT::v4i32: OpcodeIndex = 2; break;
1945 case MVT::v2i64: OpcodeIndex = 3;
1946 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1950 std::vector<EVT> ResTys;
1952 ResTys.push_back(MVT::i32);
1953 ResTys.push_back(MVT::Other);
1955 SDValue Pred = getAL(CurDAG);
1956 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1957 SmallVector<SDValue, 7> Ops;
1959 // Double registers and VST1/VST2 quad registers are directly supported.
1960 if (is64BitVector || NumVecs <= 2) {
1963 SrcReg = N->getOperand(Vec0Idx);
1964 } else if (is64BitVector) {
1965 // Form a REG_SEQUENCE to force register allocation.
1966 SDValue V0 = N->getOperand(Vec0Idx + 0);
1967 SDValue V1 = N->getOperand(Vec0Idx + 1);
1969 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
1971 SDValue V2 = N->getOperand(Vec0Idx + 2);
1972 // If it's a vst3, form a quad D-register and leave the last part as
1974 SDValue V3 = (NumVecs == 3)
1975 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1976 : N->getOperand(Vec0Idx + 3);
1977 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
1980 // Form a QQ register.
1981 SDValue Q0 = N->getOperand(Vec0Idx);
1982 SDValue Q1 = N->getOperand(Vec0Idx + 1);
1983 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
1986 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1987 QOpcodes0[OpcodeIndex]);
1988 Ops.push_back(MemAddr);
1989 Ops.push_back(Align);
1991 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1992 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
1993 // case entirely when the rest are updated to that form, too.
1994 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
1995 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1996 // FIXME: We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1997 // check for that explicitly too. Horribly hacky, but temporary.
1998 if (!isa<ConstantSDNode>(Inc.getNode()))
2000 else if (NumVecs > 2 && !isVSTfixed(Opc))
2001 Ops.push_back(Reg0);
2003 Ops.push_back(SrcReg);
2004 Ops.push_back(Pred);
2005 Ops.push_back(Reg0);
2006 Ops.push_back(Chain);
2007 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
2009 // Transfer memoperands.
2010 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
2015 // Otherwise, quad registers are stored with two separate instructions,
2016 // where one stores the even registers and the other stores the odd registers.
2018 // Form the QQQQ REG_SEQUENCE.
2019 SDValue V0 = N->getOperand(Vec0Idx + 0);
2020 SDValue V1 = N->getOperand(Vec0Idx + 1);
2021 SDValue V2 = N->getOperand(Vec0Idx + 2);
2022 SDValue V3 = (NumVecs == 3)
2023 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2024 : N->getOperand(Vec0Idx + 3);
2025 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
2027 // Store the even D registers. This is always an updating store, so that it
2028 // provides the address to the second store for the odd subregs.
2029 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
2030 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
2031 MemAddr.getValueType(),
2033 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
2034 Chain = SDValue(VStA, 1);
2036 // Store the odd D registers.
2037 Ops.push_back(SDValue(VStA, 0));
2038 Ops.push_back(Align);
2040 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2041 assert(isa<ConstantSDNode>(Inc.getNode()) &&
2042 "only constant post-increment update allowed for VST3/4");
2044 Ops.push_back(Reg0);
2046 Ops.push_back(RegSeq);
2047 Ops.push_back(Pred);
2048 Ops.push_back(Reg0);
2049 Ops.push_back(Chain);
2050 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
2052 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
2056 SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
2057 bool isUpdating, unsigned NumVecs,
2058 const uint16_t *DOpcodes,
2059 const uint16_t *QOpcodes) {
2060 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
2063 SDValue MemAddr, Align;
2064 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2065 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2066 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
2069 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2070 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2072 SDValue Chain = N->getOperand(0);
2074 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2075 EVT VT = N->getOperand(Vec0Idx).getValueType();
2076 bool is64BitVector = VT.is64BitVector();
2078 unsigned Alignment = 0;
2080 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2081 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2082 if (Alignment > NumBytes)
2083 Alignment = NumBytes;
2084 if (Alignment < 8 && Alignment < NumBytes)
2086 // Alignment must be a power of two; make sure of that.
2087 Alignment = (Alignment & -Alignment);
2091 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2093 unsigned OpcodeIndex;
2094 switch (VT.getSimpleVT().SimpleTy) {
2095 default: llvm_unreachable("unhandled vld/vst lane type");
2096 // Double-register operations:
2097 case MVT::v8i8: OpcodeIndex = 0; break;
2098 case MVT::v4i16: OpcodeIndex = 1; break;
2100 case MVT::v2i32: OpcodeIndex = 2; break;
2101 // Quad-register operations:
2102 case MVT::v8i16: OpcodeIndex = 0; break;
2104 case MVT::v4i32: OpcodeIndex = 1; break;
2107 std::vector<EVT> ResTys;
2109 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2112 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2113 MVT::i64, ResTyElts));
2116 ResTys.push_back(MVT::i32);
2117 ResTys.push_back(MVT::Other);
2119 SDValue Pred = getAL(CurDAG);
2120 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2122 SmallVector<SDValue, 8> Ops;
2123 Ops.push_back(MemAddr);
2124 Ops.push_back(Align);
2126 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2127 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2131 SDValue V0 = N->getOperand(Vec0Idx + 0);
2132 SDValue V1 = N->getOperand(Vec0Idx + 1);
2135 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
2137 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
2139 SDValue V2 = N->getOperand(Vec0Idx + 2);
2140 SDValue V3 = (NumVecs == 3)
2141 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2142 : N->getOperand(Vec0Idx + 3);
2144 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
2146 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
2148 Ops.push_back(SuperReg);
2149 Ops.push_back(getI32Imm(Lane));
2150 Ops.push_back(Pred);
2151 Ops.push_back(Reg0);
2152 Ops.push_back(Chain);
2154 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2155 QOpcodes[OpcodeIndex]);
2156 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
2157 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
2161 // Extract the subregisters.
2162 SuperReg = SDValue(VLdLn, 0);
2163 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2164 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2165 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
2166 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2167 ReplaceUses(SDValue(N, Vec),
2168 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2169 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2171 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
2175 SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
2177 const uint16_t *Opcodes) {
2178 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
2181 SDValue MemAddr, Align;
2182 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2185 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2186 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2188 SDValue Chain = N->getOperand(0);
2189 EVT VT = N->getValueType(0);
2191 unsigned Alignment = 0;
2193 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2194 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2195 if (Alignment > NumBytes)
2196 Alignment = NumBytes;
2197 if (Alignment < 8 && Alignment < NumBytes)
2199 // Alignment must be a power of two; make sure of that.
2200 Alignment = (Alignment & -Alignment);
2204 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2206 unsigned OpcodeIndex;
2207 switch (VT.getSimpleVT().SimpleTy) {
2208 default: llvm_unreachable("unhandled vld-dup type");
2209 case MVT::v8i8: OpcodeIndex = 0; break;
2210 case MVT::v4i16: OpcodeIndex = 1; break;
2212 case MVT::v2i32: OpcodeIndex = 2; break;
2215 SDValue Pred = getAL(CurDAG);
2216 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2218 unsigned Opc = Opcodes[OpcodeIndex];
2219 SmallVector<SDValue, 6> Ops;
2220 Ops.push_back(MemAddr);
2221 Ops.push_back(Align);
2223 // fixed-stride update instructions don't have an explicit writeback
2224 // operand. It's implicit in the opcode itself.
2225 SDValue Inc = N->getOperand(2);
2226 if (!isa<ConstantSDNode>(Inc.getNode()))
2228 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2229 else if (NumVecs > 2)
2230 Ops.push_back(Reg0);
2232 Ops.push_back(Pred);
2233 Ops.push_back(Reg0);
2234 Ops.push_back(Chain);
2236 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2237 std::vector<EVT> ResTys;
2238 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
2240 ResTys.push_back(MVT::i32);
2241 ResTys.push_back(MVT::Other);
2242 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
2243 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
2244 SuperReg = SDValue(VLdDup, 0);
2246 // Extract the subregisters.
2247 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2248 unsigned SubIdx = ARM::dsub_0;
2249 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2250 ReplaceUses(SDValue(N, Vec),
2251 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
2252 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2254 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
2258 SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2260 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2262 EVT VT = N->getValueType(0);
2263 unsigned FirstTblReg = IsExt ? 2 : 1;
2265 // Form a REG_SEQUENCE to force register allocation.
2267 SDValue V0 = N->getOperand(FirstTblReg + 0);
2268 SDValue V1 = N->getOperand(FirstTblReg + 1);
2270 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
2272 SDValue V2 = N->getOperand(FirstTblReg + 2);
2273 // If it's a vtbl3, form a quad D-register and leave the last part as
2275 SDValue V3 = (NumVecs == 3)
2276 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2277 : N->getOperand(FirstTblReg + 3);
2278 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
2281 SmallVector<SDValue, 6> Ops;
2283 Ops.push_back(N->getOperand(1));
2284 Ops.push_back(RegSeq);
2285 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
2286 Ops.push_back(getAL(CurDAG)); // predicate
2287 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
2288 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
2291 SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
2293 if (!Subtarget->hasV6T2Ops())
2296 unsigned Opc = isSigned
2297 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2298 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2300 // For unsigned extracts, check for a shift right and mask
2301 unsigned And_imm = 0;
2302 if (N->getOpcode() == ISD::AND) {
2303 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2305 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2306 if (And_imm & (And_imm + 1))
2309 unsigned Srl_imm = 0;
2310 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2312 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2314 // Note: The width operand is encoded as width-1.
2315 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
2316 unsigned LSB = Srl_imm;
2318 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2320 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2321 // It's cheaper to use a right shift to extract the top bits.
2322 if (Subtarget->isThumb()) {
2323 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2324 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2325 CurDAG->getTargetConstant(LSB, MVT::i32),
2326 getAL(CurDAG), Reg0, Reg0 };
2327 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2330 // ARM models shift instructions as MOVsi with shifter operand.
2331 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2333 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2335 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2336 getAL(CurDAG), Reg0, Reg0 };
2337 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops, 5);
2340 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2341 CurDAG->getTargetConstant(LSB, MVT::i32),
2342 CurDAG->getTargetConstant(Width, MVT::i32),
2343 getAL(CurDAG), Reg0 };
2344 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2350 // Otherwise, we're looking for a shift of a shift
2351 unsigned Shl_imm = 0;
2352 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
2353 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2354 unsigned Srl_imm = 0;
2355 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
2356 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2357 // Note: The width operand is encoded as width-1.
2358 unsigned Width = 32 - Srl_imm - 1;
2359 int LSB = Srl_imm - Shl_imm;
2362 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2363 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2364 CurDAG->getTargetConstant(LSB, MVT::i32),
2365 CurDAG->getTargetConstant(Width, MVT::i32),
2366 getAL(CurDAG), Reg0 };
2367 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2373 /// Target-specific DAG combining for ISD::XOR.
2374 /// Target-independent combining lowers SELECT_CC nodes of the form
2375 /// select_cc setg[ge] X, 0, X, -X
2376 /// select_cc setgt X, -1, X, -X
2377 /// select_cc setl[te] X, 0, -X, X
2378 /// select_cc setlt X, 1, -X, X
2379 /// which represent Integer ABS into:
2380 /// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2381 /// ARM instruction selection detects the latter and matches it to
2382 /// ARM::ABS or ARM::t2ABS machine node.
2383 SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2384 SDValue XORSrc0 = N->getOperand(0);
2385 SDValue XORSrc1 = N->getOperand(1);
2386 EVT VT = N->getValueType(0);
2388 if (Subtarget->isThumb1Only())
2391 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
2394 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2395 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2396 SDValue SRASrc0 = XORSrc1.getOperand(0);
2397 SDValue SRASrc1 = XORSrc1.getOperand(1);
2398 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2399 EVT XType = SRASrc0.getValueType();
2400 unsigned Size = XType.getSizeInBits() - 1;
2402 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2403 XType.isInteger() && SRAConstant != NULL &&
2404 Size == SRAConstant->getZExtValue()) {
2405 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
2406 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2412 SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2413 // The only time a CONCAT_VECTORS operation can have legal types is when
2414 // two 64-bit vectors are concatenated to a 128-bit vector.
2415 EVT VT = N->getValueType(0);
2416 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2417 llvm_unreachable("unexpected CONCAT_VECTORS");
2418 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
2421 SDNode *ARMDAGToDAGISel::SelectAtomic(SDNode *Node, unsigned Op8,
2422 unsigned Op16,unsigned Op32,
2424 // Mostly direct translation to the given operations, except that we preserve
2425 // the AtomicOrdering for use later on.
2426 AtomicSDNode *AN = cast<AtomicSDNode>(Node);
2427 EVT VT = AN->getMemoryVT();
2430 SDVTList VTs = CurDAG->getVTList(AN->getValueType(0), MVT::Other);
2433 else if (VT == MVT::i16)
2435 else if (VT == MVT::i32)
2437 else if (VT == MVT::i64) {
2439 VTs = CurDAG->getVTList(MVT::i32, MVT::i32, MVT::Other);
2441 llvm_unreachable("Unexpected atomic operation");
2443 SmallVector<SDValue, 6> Ops;
2444 for (unsigned i = 1; i < AN->getNumOperands(); ++i)
2445 Ops.push_back(AN->getOperand(i));
2447 Ops.push_back(CurDAG->getTargetConstant(AN->getOrdering(), MVT::i32));
2448 Ops.push_back(AN->getOperand(0)); // Chain moves to the end
2450 return CurDAG->SelectNodeTo(Node, Op, VTs, &Ops[0], Ops.size());
2453 SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
2456 if (N->isMachineOpcode()) {
2458 return NULL; // Already selected.
2461 switch (N->getOpcode()) {
2463 case ISD::INLINEASM: {
2464 SDNode *ResNode = SelectInlineAsm(N);
2470 // Select special operations if XOR node forms integer ABS pattern
2471 SDNode *ResNode = SelectABSOp(N);
2474 // Other cases are autogenerated.
2477 case ISD::Constant: {
2478 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
2480 if (Subtarget->hasThumb2())
2481 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2482 // be done with MOV + MOVT, at worst.
2485 if (Subtarget->isThumb()) {
2486 UseCP = (Val > 255 && // MOV
2487 ~Val > 255 && // MOV + MVN
2488 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
2490 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2491 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2492 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2497 CurDAG->getTargetConstantPool(ConstantInt::get(
2498 Type::getInt32Ty(*CurDAG->getContext()), Val),
2499 getTargetLowering()->getPointerTy());
2502 if (Subtarget->isThumb1Only()) {
2503 SDValue Pred = getAL(CurDAG);
2504 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2505 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
2506 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
2511 CurDAG->getTargetConstant(0, MVT::i32),
2513 CurDAG->getRegister(0, MVT::i32),
2514 CurDAG->getEntryNode()
2516 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
2519 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
2523 // Other cases are autogenerated.
2526 case ISD::FrameIndex: {
2527 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
2528 int FI = cast<FrameIndexSDNode>(N)->getIndex();
2529 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
2530 getTargetLowering()->getPointerTy());
2531 if (Subtarget->isThumb1Only()) {
2532 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2533 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2534 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
2536 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2537 ARM::t2ADDri : ARM::ADDri);
2538 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2539 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2540 CurDAG->getRegister(0, MVT::i32) };
2541 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2545 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2549 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
2553 if (Subtarget->isThumb1Only())
2555 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
2556 unsigned RHSV = C->getZExtValue();
2558 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
2559 unsigned ShImm = Log2_32(RHSV-1);
2562 SDValue V = N->getOperand(0);
2563 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2564 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2565 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2566 if (Subtarget->isThumb()) {
2567 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2568 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
2570 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2571 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
2574 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
2575 unsigned ShImm = Log2_32(RHSV+1);
2578 SDValue V = N->getOperand(0);
2579 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
2580 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2581 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2582 if (Subtarget->isThumb()) {
2583 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2584 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
2586 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2587 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
2593 // Check for unsigned bitfield extract
2594 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2597 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2598 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2599 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2600 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2601 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
2602 EVT VT = N->getValueType(0);
2605 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2607 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2610 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
2611 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2614 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2615 SDValue N2 = N0.getOperand(1);
2616 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2619 unsigned N1CVal = N1C->getZExtValue();
2620 unsigned N2CVal = N2C->getZExtValue();
2621 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2622 (N1CVal & 0xffffU) == 0xffffU &&
2623 (N2CVal & 0xffffU) == 0x0U) {
2624 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2626 SDValue Ops[] = { N0.getOperand(0), Imm16,
2627 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2628 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
2633 case ARMISD::VMOVRRD:
2634 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
2635 N->getOperand(0), getAL(CurDAG),
2636 CurDAG->getRegister(0, MVT::i32));
2637 case ISD::UMUL_LOHI: {
2638 if (Subtarget->isThumb1Only())
2640 if (Subtarget->isThumb()) {
2641 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2642 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2643 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
2645 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2646 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2647 CurDAG->getRegister(0, MVT::i32) };
2648 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2649 ARM::UMULL : ARM::UMULLv5,
2650 dl, MVT::i32, MVT::i32, Ops);
2653 case ISD::SMUL_LOHI: {
2654 if (Subtarget->isThumb1Only())
2656 if (Subtarget->isThumb()) {
2657 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2658 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2659 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
2661 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
2662 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2663 CurDAG->getRegister(0, MVT::i32) };
2664 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2665 ARM::SMULL : ARM::SMULLv5,
2666 dl, MVT::i32, MVT::i32, Ops);
2669 case ARMISD::UMLAL:{
2670 if (Subtarget->isThumb()) {
2671 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2672 N->getOperand(3), getAL(CurDAG),
2673 CurDAG->getRegister(0, MVT::i32)};
2674 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
2676 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2677 N->getOperand(3), getAL(CurDAG),
2678 CurDAG->getRegister(0, MVT::i32),
2679 CurDAG->getRegister(0, MVT::i32) };
2680 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2681 ARM::UMLAL : ARM::UMLALv5,
2682 dl, MVT::i32, MVT::i32, Ops);
2685 case ARMISD::SMLAL:{
2686 if (Subtarget->isThumb()) {
2687 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2688 N->getOperand(3), getAL(CurDAG),
2689 CurDAG->getRegister(0, MVT::i32)};
2690 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
2692 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2693 N->getOperand(3), getAL(CurDAG),
2694 CurDAG->getRegister(0, MVT::i32),
2695 CurDAG->getRegister(0, MVT::i32) };
2696 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2697 ARM::SMLAL : ARM::SMLALv5,
2698 dl, MVT::i32, MVT::i32, Ops);
2702 SDNode *ResNode = 0;
2703 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2704 ResNode = SelectT2IndexedLoad(N);
2706 ResNode = SelectARMIndexedLoad(N);
2709 // Other cases are autogenerated.
2712 case ARMISD::BRCOND: {
2713 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2714 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2715 // Pattern complexity = 6 cost = 1 size = 0
2717 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2718 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2719 // Pattern complexity = 6 cost = 1 size = 0
2721 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2722 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2723 // Pattern complexity = 6 cost = 1 size = 0
2725 unsigned Opc = Subtarget->isThumb() ?
2726 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
2727 SDValue Chain = N->getOperand(0);
2728 SDValue N1 = N->getOperand(1);
2729 SDValue N2 = N->getOperand(2);
2730 SDValue N3 = N->getOperand(3);
2731 SDValue InFlag = N->getOperand(4);
2732 assert(N1.getOpcode() == ISD::BasicBlock);
2733 assert(N2.getOpcode() == ISD::Constant);
2734 assert(N3.getOpcode() == ISD::Register);
2736 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
2737 cast<ConstantSDNode>(N2)->getZExtValue()),
2739 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
2740 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2742 Chain = SDValue(ResNode, 0);
2743 if (N->getNumValues() == 2) {
2744 InFlag = SDValue(ResNode, 1);
2745 ReplaceUses(SDValue(N, 1), InFlag);
2747 ReplaceUses(SDValue(N, 0),
2748 SDValue(Chain.getNode(), Chain.getResNo()));
2751 case ARMISD::VZIP: {
2753 EVT VT = N->getValueType(0);
2754 switch (VT.getSimpleVT().SimpleTy) {
2755 default: return NULL;
2756 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2757 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2759 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2760 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2761 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2762 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2764 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2766 SDValue Pred = getAL(CurDAG);
2767 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2768 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2769 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
2771 case ARMISD::VUZP: {
2773 EVT VT = N->getValueType(0);
2774 switch (VT.getSimpleVT().SimpleTy) {
2775 default: return NULL;
2776 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2777 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2779 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2780 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2781 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2782 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2784 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2786 SDValue Pred = getAL(CurDAG);
2787 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2788 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2789 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
2791 case ARMISD::VTRN: {
2793 EVT VT = N->getValueType(0);
2794 switch (VT.getSimpleVT().SimpleTy) {
2795 default: return NULL;
2796 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2797 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2799 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2800 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2801 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2803 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2805 SDValue Pred = getAL(CurDAG);
2806 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2807 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2808 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
2810 case ARMISD::BUILD_VECTOR: {
2811 EVT VecVT = N->getValueType(0);
2812 EVT EltVT = VecVT.getVectorElementType();
2813 unsigned NumElts = VecVT.getVectorNumElements();
2814 if (EltVT == MVT::f64) {
2815 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2816 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
2818 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
2820 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
2821 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2822 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
2823 N->getOperand(2), N->getOperand(3));
2826 case ARMISD::VLD2DUP: {
2827 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2829 return SelectVLDDup(N, false, 2, Opcodes);
2832 case ARMISD::VLD3DUP: {
2833 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2834 ARM::VLD3DUPd16Pseudo,
2835 ARM::VLD3DUPd32Pseudo };
2836 return SelectVLDDup(N, false, 3, Opcodes);
2839 case ARMISD::VLD4DUP: {
2840 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2841 ARM::VLD4DUPd16Pseudo,
2842 ARM::VLD4DUPd32Pseudo };
2843 return SelectVLDDup(N, false, 4, Opcodes);
2846 case ARMISD::VLD2DUP_UPD: {
2847 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2848 ARM::VLD2DUPd16wb_fixed,
2849 ARM::VLD2DUPd32wb_fixed };
2850 return SelectVLDDup(N, true, 2, Opcodes);
2853 case ARMISD::VLD3DUP_UPD: {
2854 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2855 ARM::VLD3DUPd16Pseudo_UPD,
2856 ARM::VLD3DUPd32Pseudo_UPD };
2857 return SelectVLDDup(N, true, 3, Opcodes);
2860 case ARMISD::VLD4DUP_UPD: {
2861 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2862 ARM::VLD4DUPd16Pseudo_UPD,
2863 ARM::VLD4DUPd32Pseudo_UPD };
2864 return SelectVLDDup(N, true, 4, Opcodes);
2867 case ARMISD::VLD1_UPD: {
2868 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2869 ARM::VLD1d16wb_fixed,
2870 ARM::VLD1d32wb_fixed,
2871 ARM::VLD1d64wb_fixed };
2872 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2873 ARM::VLD1q16wb_fixed,
2874 ARM::VLD1q32wb_fixed,
2875 ARM::VLD1q64wb_fixed };
2876 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2879 case ARMISD::VLD2_UPD: {
2880 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2881 ARM::VLD2d16wb_fixed,
2882 ARM::VLD2d32wb_fixed,
2883 ARM::VLD1q64wb_fixed};
2884 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2885 ARM::VLD2q16PseudoWB_fixed,
2886 ARM::VLD2q32PseudoWB_fixed };
2887 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2890 case ARMISD::VLD3_UPD: {
2891 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2892 ARM::VLD3d16Pseudo_UPD,
2893 ARM::VLD3d32Pseudo_UPD,
2894 ARM::VLD1d64TPseudoWB_fixed};
2895 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2896 ARM::VLD3q16Pseudo_UPD,
2897 ARM::VLD3q32Pseudo_UPD };
2898 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2899 ARM::VLD3q16oddPseudo_UPD,
2900 ARM::VLD3q32oddPseudo_UPD };
2901 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2904 case ARMISD::VLD4_UPD: {
2905 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2906 ARM::VLD4d16Pseudo_UPD,
2907 ARM::VLD4d32Pseudo_UPD,
2908 ARM::VLD1d64QPseudoWB_fixed};
2909 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2910 ARM::VLD4q16Pseudo_UPD,
2911 ARM::VLD4q32Pseudo_UPD };
2912 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2913 ARM::VLD4q16oddPseudo_UPD,
2914 ARM::VLD4q32oddPseudo_UPD };
2915 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2918 case ARMISD::VLD2LN_UPD: {
2919 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2920 ARM::VLD2LNd16Pseudo_UPD,
2921 ARM::VLD2LNd32Pseudo_UPD };
2922 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2923 ARM::VLD2LNq32Pseudo_UPD };
2924 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2927 case ARMISD::VLD3LN_UPD: {
2928 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2929 ARM::VLD3LNd16Pseudo_UPD,
2930 ARM::VLD3LNd32Pseudo_UPD };
2931 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2932 ARM::VLD3LNq32Pseudo_UPD };
2933 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2936 case ARMISD::VLD4LN_UPD: {
2937 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2938 ARM::VLD4LNd16Pseudo_UPD,
2939 ARM::VLD4LNd32Pseudo_UPD };
2940 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2941 ARM::VLD4LNq32Pseudo_UPD };
2942 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2945 case ARMISD::VST1_UPD: {
2946 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2947 ARM::VST1d16wb_fixed,
2948 ARM::VST1d32wb_fixed,
2949 ARM::VST1d64wb_fixed };
2950 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2951 ARM::VST1q16wb_fixed,
2952 ARM::VST1q32wb_fixed,
2953 ARM::VST1q64wb_fixed };
2954 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2957 case ARMISD::VST2_UPD: {
2958 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2959 ARM::VST2d16wb_fixed,
2960 ARM::VST2d32wb_fixed,
2961 ARM::VST1q64wb_fixed};
2962 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2963 ARM::VST2q16PseudoWB_fixed,
2964 ARM::VST2q32PseudoWB_fixed };
2965 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2968 case ARMISD::VST3_UPD: {
2969 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2970 ARM::VST3d16Pseudo_UPD,
2971 ARM::VST3d32Pseudo_UPD,
2972 ARM::VST1d64TPseudoWB_fixed};
2973 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2974 ARM::VST3q16Pseudo_UPD,
2975 ARM::VST3q32Pseudo_UPD };
2976 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2977 ARM::VST3q16oddPseudo_UPD,
2978 ARM::VST3q32oddPseudo_UPD };
2979 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2982 case ARMISD::VST4_UPD: {
2983 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2984 ARM::VST4d16Pseudo_UPD,
2985 ARM::VST4d32Pseudo_UPD,
2986 ARM::VST1d64QPseudoWB_fixed};
2987 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2988 ARM::VST4q16Pseudo_UPD,
2989 ARM::VST4q32Pseudo_UPD };
2990 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2991 ARM::VST4q16oddPseudo_UPD,
2992 ARM::VST4q32oddPseudo_UPD };
2993 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2996 case ARMISD::VST2LN_UPD: {
2997 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2998 ARM::VST2LNd16Pseudo_UPD,
2999 ARM::VST2LNd32Pseudo_UPD };
3000 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
3001 ARM::VST2LNq32Pseudo_UPD };
3002 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
3005 case ARMISD::VST3LN_UPD: {
3006 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
3007 ARM::VST3LNd16Pseudo_UPD,
3008 ARM::VST3LNd32Pseudo_UPD };
3009 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
3010 ARM::VST3LNq32Pseudo_UPD };
3011 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
3014 case ARMISD::VST4LN_UPD: {
3015 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
3016 ARM::VST4LNd16Pseudo_UPD,
3017 ARM::VST4LNd32Pseudo_UPD };
3018 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
3019 ARM::VST4LNq32Pseudo_UPD };
3020 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
3023 case ISD::INTRINSIC_VOID:
3024 case ISD::INTRINSIC_W_CHAIN: {
3025 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
3030 case Intrinsic::arm_ldrexd: {
3031 SDValue MemAddr = N->getOperand(2);
3033 SDValue Chain = N->getOperand(0);
3035 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3036 unsigned NewOpc = isThumb ? ARM::t2LDREXD :ARM::LDREXD;
3038 // arm_ldrexd returns a i64 value in {i32, i32}
3039 std::vector<EVT> ResTys;
3041 ResTys.push_back(MVT::i32);
3042 ResTys.push_back(MVT::i32);
3044 ResTys.push_back(MVT::Untyped);
3045 ResTys.push_back(MVT::Other);
3047 // Place arguments in the right order.
3048 SmallVector<SDValue, 7> Ops;
3049 Ops.push_back(MemAddr);
3050 Ops.push_back(getAL(CurDAG));
3051 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3052 Ops.push_back(Chain);
3053 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
3054 // Transfer memoperands.
3055 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3056 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3057 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3060 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
3061 if (!SDValue(N, 0).use_empty()) {
3064 Result = SDValue(Ld, 0);
3066 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
3067 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3068 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
3069 Result = SDValue(ResNode,0);
3071 ReplaceUses(SDValue(N, 0), Result);
3073 if (!SDValue(N, 1).use_empty()) {
3076 Result = SDValue(Ld, 1);
3078 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3079 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
3080 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
3081 Result = SDValue(ResNode,0);
3083 ReplaceUses(SDValue(N, 1), Result);
3085 ReplaceUses(SDValue(N, 2), OutChain);
3089 case Intrinsic::arm_strexd: {
3091 SDValue Chain = N->getOperand(0);
3092 SDValue Val0 = N->getOperand(2);
3093 SDValue Val1 = N->getOperand(3);
3094 SDValue MemAddr = N->getOperand(4);
3096 // Store exclusive double return a i32 value which is the return status
3097 // of the issued store.
3098 EVT ResTys[] = { MVT::i32, MVT::Other };
3100 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3101 // Place arguments in the right order.
3102 SmallVector<SDValue, 7> Ops;
3104 Ops.push_back(Val0);
3105 Ops.push_back(Val1);
3107 // arm_strexd uses GPRPair.
3108 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
3109 Ops.push_back(MemAddr);
3110 Ops.push_back(getAL(CurDAG));
3111 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3112 Ops.push_back(Chain);
3114 unsigned NewOpc = isThumb ? ARM::t2STREXD : ARM::STREXD;
3116 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
3117 // Transfer memoperands.
3118 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3119 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3120 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3125 case Intrinsic::arm_neon_vld1: {
3126 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3127 ARM::VLD1d32, ARM::VLD1d64 };
3128 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3129 ARM::VLD1q32, ARM::VLD1q64};
3130 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
3133 case Intrinsic::arm_neon_vld2: {
3134 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3135 ARM::VLD2d32, ARM::VLD1q64 };
3136 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3137 ARM::VLD2q32Pseudo };
3138 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
3141 case Intrinsic::arm_neon_vld3: {
3142 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3145 ARM::VLD1d64TPseudo };
3146 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3147 ARM::VLD3q16Pseudo_UPD,
3148 ARM::VLD3q32Pseudo_UPD };
3149 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3150 ARM::VLD3q16oddPseudo,
3151 ARM::VLD3q32oddPseudo };
3152 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
3155 case Intrinsic::arm_neon_vld4: {
3156 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3159 ARM::VLD1d64QPseudo };
3160 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3161 ARM::VLD4q16Pseudo_UPD,
3162 ARM::VLD4q32Pseudo_UPD };
3163 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3164 ARM::VLD4q16oddPseudo,
3165 ARM::VLD4q32oddPseudo };
3166 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
3169 case Intrinsic::arm_neon_vld2lane: {
3170 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3171 ARM::VLD2LNd16Pseudo,
3172 ARM::VLD2LNd32Pseudo };
3173 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3174 ARM::VLD2LNq32Pseudo };
3175 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
3178 case Intrinsic::arm_neon_vld3lane: {
3179 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3180 ARM::VLD3LNd16Pseudo,
3181 ARM::VLD3LNd32Pseudo };
3182 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3183 ARM::VLD3LNq32Pseudo };
3184 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
3187 case Intrinsic::arm_neon_vld4lane: {
3188 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3189 ARM::VLD4LNd16Pseudo,
3190 ARM::VLD4LNd32Pseudo };
3191 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3192 ARM::VLD4LNq32Pseudo };
3193 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
3196 case Intrinsic::arm_neon_vst1: {
3197 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3198 ARM::VST1d32, ARM::VST1d64 };
3199 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3200 ARM::VST1q32, ARM::VST1q64 };
3201 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
3204 case Intrinsic::arm_neon_vst2: {
3205 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3206 ARM::VST2d32, ARM::VST1q64 };
3207 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3208 ARM::VST2q32Pseudo };
3209 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
3212 case Intrinsic::arm_neon_vst3: {
3213 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3216 ARM::VST1d64TPseudo };
3217 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3218 ARM::VST3q16Pseudo_UPD,
3219 ARM::VST3q32Pseudo_UPD };
3220 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3221 ARM::VST3q16oddPseudo,
3222 ARM::VST3q32oddPseudo };
3223 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
3226 case Intrinsic::arm_neon_vst4: {
3227 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3230 ARM::VST1d64QPseudo };
3231 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3232 ARM::VST4q16Pseudo_UPD,
3233 ARM::VST4q32Pseudo_UPD };
3234 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3235 ARM::VST4q16oddPseudo,
3236 ARM::VST4q32oddPseudo };
3237 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
3240 case Intrinsic::arm_neon_vst2lane: {
3241 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3242 ARM::VST2LNd16Pseudo,
3243 ARM::VST2LNd32Pseudo };
3244 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3245 ARM::VST2LNq32Pseudo };
3246 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
3249 case Intrinsic::arm_neon_vst3lane: {
3250 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3251 ARM::VST3LNd16Pseudo,
3252 ARM::VST3LNd32Pseudo };
3253 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3254 ARM::VST3LNq32Pseudo };
3255 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
3258 case Intrinsic::arm_neon_vst4lane: {
3259 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3260 ARM::VST4LNd16Pseudo,
3261 ARM::VST4LNd32Pseudo };
3262 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3263 ARM::VST4LNq32Pseudo };
3264 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
3270 case ISD::INTRINSIC_WO_CHAIN: {
3271 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3276 case Intrinsic::arm_neon_vtbl2:
3277 return SelectVTBL(N, false, 2, ARM::VTBL2);
3278 case Intrinsic::arm_neon_vtbl3:
3279 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
3280 case Intrinsic::arm_neon_vtbl4:
3281 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
3283 case Intrinsic::arm_neon_vtbx2:
3284 return SelectVTBL(N, true, 2, ARM::VTBX2);
3285 case Intrinsic::arm_neon_vtbx3:
3286 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
3287 case Intrinsic::arm_neon_vtbx4:
3288 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
3293 case ARMISD::VTBL1: {
3295 EVT VT = N->getValueType(0);
3296 SmallVector<SDValue, 6> Ops;
3298 Ops.push_back(N->getOperand(0));
3299 Ops.push_back(N->getOperand(1));
3300 Ops.push_back(getAL(CurDAG)); // Predicate
3301 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3302 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
3304 case ARMISD::VTBL2: {
3306 EVT VT = N->getValueType(0);
3308 // Form a REG_SEQUENCE to force register allocation.
3309 SDValue V0 = N->getOperand(0);
3310 SDValue V1 = N->getOperand(1);
3311 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
3313 SmallVector<SDValue, 6> Ops;
3314 Ops.push_back(RegSeq);
3315 Ops.push_back(N->getOperand(2));
3316 Ops.push_back(getAL(CurDAG)); // Predicate
3317 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3318 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
3321 case ISD::CONCAT_VECTORS:
3322 return SelectConcatVector(N);
3324 case ISD::ATOMIC_LOAD:
3325 if (cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64)
3326 return SelectAtomic(N, 0, 0, 0, ARM::ATOMIC_LOAD_I64);
3330 case ISD::ATOMIC_STORE:
3331 if (cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64)
3332 return SelectAtomic(N, 0, 0, 0, ARM::ATOMIC_STORE_I64);
3336 case ISD::ATOMIC_LOAD_ADD:
3337 return SelectAtomic(N,
3338 ARM::ATOMIC_LOAD_ADD_I8,
3339 ARM::ATOMIC_LOAD_ADD_I16,
3340 ARM::ATOMIC_LOAD_ADD_I32,
3341 ARM::ATOMIC_LOAD_ADD_I64);
3342 case ISD::ATOMIC_LOAD_SUB:
3343 return SelectAtomic(N,
3344 ARM::ATOMIC_LOAD_SUB_I8,
3345 ARM::ATOMIC_LOAD_SUB_I16,
3346 ARM::ATOMIC_LOAD_SUB_I32,
3347 ARM::ATOMIC_LOAD_SUB_I64);
3348 case ISD::ATOMIC_LOAD_AND:
3349 return SelectAtomic(N,
3350 ARM::ATOMIC_LOAD_AND_I8,
3351 ARM::ATOMIC_LOAD_AND_I16,
3352 ARM::ATOMIC_LOAD_AND_I32,
3353 ARM::ATOMIC_LOAD_AND_I64);
3354 case ISD::ATOMIC_LOAD_OR:
3355 return SelectAtomic(N,
3356 ARM::ATOMIC_LOAD_OR_I8,
3357 ARM::ATOMIC_LOAD_OR_I16,
3358 ARM::ATOMIC_LOAD_OR_I32,
3359 ARM::ATOMIC_LOAD_OR_I64);
3360 case ISD::ATOMIC_LOAD_XOR:
3361 return SelectAtomic(N,
3362 ARM::ATOMIC_LOAD_XOR_I8,
3363 ARM::ATOMIC_LOAD_XOR_I16,
3364 ARM::ATOMIC_LOAD_XOR_I32,
3365 ARM::ATOMIC_LOAD_XOR_I64);
3366 case ISD::ATOMIC_LOAD_NAND:
3367 return SelectAtomic(N,
3368 ARM::ATOMIC_LOAD_NAND_I8,
3369 ARM::ATOMIC_LOAD_NAND_I16,
3370 ARM::ATOMIC_LOAD_NAND_I32,
3371 ARM::ATOMIC_LOAD_NAND_I64);
3372 case ISD::ATOMIC_LOAD_MIN:
3373 return SelectAtomic(N,
3374 ARM::ATOMIC_LOAD_MIN_I8,
3375 ARM::ATOMIC_LOAD_MIN_I16,
3376 ARM::ATOMIC_LOAD_MIN_I32,
3377 ARM::ATOMIC_LOAD_MIN_I64);
3378 case ISD::ATOMIC_LOAD_MAX:
3379 return SelectAtomic(N,
3380 ARM::ATOMIC_LOAD_MAX_I8,
3381 ARM::ATOMIC_LOAD_MAX_I16,
3382 ARM::ATOMIC_LOAD_MAX_I32,
3383 ARM::ATOMIC_LOAD_MAX_I64);
3384 case ISD::ATOMIC_LOAD_UMIN:
3385 return SelectAtomic(N,
3386 ARM::ATOMIC_LOAD_UMIN_I8,
3387 ARM::ATOMIC_LOAD_UMIN_I16,
3388 ARM::ATOMIC_LOAD_UMIN_I32,
3389 ARM::ATOMIC_LOAD_UMIN_I64);
3390 case ISD::ATOMIC_LOAD_UMAX:
3391 return SelectAtomic(N,
3392 ARM::ATOMIC_LOAD_UMAX_I8,
3393 ARM::ATOMIC_LOAD_UMAX_I16,
3394 ARM::ATOMIC_LOAD_UMAX_I32,
3395 ARM::ATOMIC_LOAD_UMAX_I64);
3396 case ISD::ATOMIC_SWAP:
3397 return SelectAtomic(N,
3398 ARM::ATOMIC_SWAP_I8,
3399 ARM::ATOMIC_SWAP_I16,
3400 ARM::ATOMIC_SWAP_I32,
3401 ARM::ATOMIC_SWAP_I64);
3402 case ISD::ATOMIC_CMP_SWAP:
3403 return SelectAtomic(N,
3404 ARM::ATOMIC_CMP_SWAP_I8,
3405 ARM::ATOMIC_CMP_SWAP_I16,
3406 ARM::ATOMIC_CMP_SWAP_I32,
3407 ARM::ATOMIC_CMP_SWAP_I64);
3410 return SelectCode(N);
3413 SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3414 std::vector<SDValue> AsmNodeOperands;
3415 unsigned Flag, Kind;
3416 bool Changed = false;
3417 unsigned NumOps = N->getNumOperands();
3419 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3420 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3421 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3422 // respectively. Since there is no constraint to explicitly specify a
3423 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3424 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3425 // them into a GPRPair.
3428 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1) : SDValue(0,0);
3430 SmallVector<bool, 8> OpChanged;
3431 // Glue node will be appended late.
3432 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
3433 SDValue op = N->getOperand(i);
3434 AsmNodeOperands.push_back(op);
3436 if (i < InlineAsm::Op_FirstOperand)
3439 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3440 Flag = C->getZExtValue();
3441 Kind = InlineAsm::getKind(Flag);
3446 // Immediate operands to inline asm in the SelectionDAG are modeled with
3447 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3448 // the second is a constant with the value of the immediate. If we get here
3449 // and we have a Kind_Imm, skip the next operand, and continue.
3450 if (Kind == InlineAsm::Kind_Imm) {
3451 SDValue op = N->getOperand(++i);
3452 AsmNodeOperands.push_back(op);
3456 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3458 OpChanged.push_back(false);
3460 unsigned DefIdx = 0;
3461 bool IsTiedToChangedOp = false;
3462 // If it's a use that is tied with a previous def, it has no
3463 // reg class constraint.
3464 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3465 IsTiedToChangedOp = OpChanged[DefIdx];
3467 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3468 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3472 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
3473 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3477 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
3478 SDValue V0 = N->getOperand(i+1);
3479 SDValue V1 = N->getOperand(i+2);
3480 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3481 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3483 MachineRegisterInfo &MRI = MF->getRegInfo();
3485 if (Kind == InlineAsm::Kind_RegDef ||
3486 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3487 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3488 // the original GPRs.
3490 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3491 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3492 SDValue Chain = SDValue(N,0);
3494 SDNode *GU = N->getGluedUser();
3495 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3498 // Extract values from a GPRPair reg and copy to the original GPR reg.
3499 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3501 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3503 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3504 RegCopy.getValue(1));
3505 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3507 // Update the original glue user.
3508 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3509 Ops.push_back(T1.getValue(1));
3510 CurDAG->UpdateNodeOperands(GU, &Ops[0], Ops.size());
3514 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3515 // GPRPair and then pass the GPRPair to the inline asm.
3516 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3518 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3519 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3521 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3523 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3525 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3526 // i32 VRs of inline asm with it.
3527 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3528 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3529 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3531 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3532 Glue = Chain.getValue(1);
3537 if(PairedReg.getNode()) {
3538 OpChanged[OpChanged.size() -1 ] = true;
3539 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
3540 if (IsTiedToChangedOp)
3541 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3543 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
3544 // Replace the current flag.
3545 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3547 // Add the new register node and skip the original two GPRs.
3548 AsmNodeOperands.push_back(PairedReg);
3549 // Skip the next two GPRs.
3555 AsmNodeOperands.push_back(Glue);
3559 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
3560 CurDAG->getVTList(MVT::Other, MVT::Glue), &AsmNodeOperands[0],
3561 AsmNodeOperands.size());
3563 return New.getNode();
3567 bool ARMDAGToDAGISel::
3568 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3569 std::vector<SDValue> &OutOps) {
3570 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
3571 // Require the address to be in a register. That is safe for all ARM
3572 // variants and it is hard to do anything much smarter without knowing
3573 // how the operand is used.
3574 OutOps.push_back(Op);
3578 /// createARMISelDag - This pass converts a legalized DAG into a
3579 /// ARM-specific DAG, ready for instruction scheduling.
3581 FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3582 CodeGenOpt::Level OptLevel) {
3583 return new ARMDAGToDAGISel(TM, OptLevel);