blob: 8270c097a08b7470a83a484e68d485e1b889787c [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000017#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000022#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000029#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
35
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036using namespace llvm;
37
Evan Cheng94cc6d32010-05-04 20:39:49 +000038static cl::opt<bool>
39UseRegSeq("neon-reg-sequence", cl::Hidden,
Evan Cheng62061242010-05-17 19:51:20 +000040 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"),
41 cl::init(true));
Evan Cheng94cc6d32010-05-04 20:39:49 +000042
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000043//===--------------------------------------------------------------------===//
44/// ARMDAGToDAGISel - ARM specific code to select ARM machine
45/// instructions for SelectionDAG operations.
46///
47namespace {
48class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000049 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000050
Evan Chenga8e29892007-01-19 07:51:42 +000051 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
52 /// make the right decision when generating code for different targets.
53 const ARMSubtarget *Subtarget;
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055public:
Bob Wilson522ce972009-09-28 14:30:20 +000056 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
57 CodeGenOpt::Level OptLevel)
58 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000059 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000060 }
61
Evan Chenga8e29892007-01-19 07:51:42 +000062 virtual const char *getPassName() const {
63 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000064 }
65
Bob Wilsonaf4a8912009-10-08 18:51:31 +000066 /// getI32Imm - Return a target constant of type i32 with the specified
67 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000068 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000069 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000070 }
71
Dan Gohmaneeb3a002010-01-05 01:24:18 +000072 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000073
Dan Gohmaneeb3a002010-01-05 01:24:18 +000074 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000075 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000076 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000078 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000079 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000080 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000081 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000082 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000083 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000084 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000085 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000087 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000088 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000089
Dan Gohmaneeb3a002010-01-05 01:24:18 +000090 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000091 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000092
Dan Gohmaneeb3a002010-01-05 01:24:18 +000093 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000094 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000095 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000096 SDValue &Base, SDValue &OffImm,
97 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000103 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000104 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000105 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000106
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000108 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000114 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000115 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000116 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000117 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000118 SDValue &OffReg, SDValue &ShImm);
119
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000120 // Include the pieces autogenerated from the target description.
121#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000122
123private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
125 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000126 SDNode *SelectARMIndexedLoad(SDNode *N);
127 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000128
Bob Wilson621f1952010-03-23 05:25:43 +0000129 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
130 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000131 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000132 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000133 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000134 unsigned *QOpcodes0, unsigned *QOpcodes1);
135
Bob Wilson24f995d2009-10-14 18:32:29 +0000136 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000137 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000138 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000139 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000141 unsigned *QOpcodes0, unsigned *QOpcodes1);
142
Bob Wilson96493442009-10-14 16:46:45 +0000143 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000144 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000145 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000146 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000147 unsigned *DOpcodes, unsigned *QOpcodes0,
148 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000149
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000150 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000151 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000152
Evan Cheng07ba9062009-11-19 21:45:22 +0000153 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000154 SDNode *SelectCMOVOp(SDNode *N);
155 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000156 ARMCC::CondCodes CCVal, SDValue CCR,
157 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000158 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000159 ARMCC::CondCodes CCVal, SDValue CCR,
160 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000162 ARMCC::CondCodes CCVal, SDValue CCR,
163 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000164 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000165 ARMCC::CondCodes CCVal, SDValue CCR,
166 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000167
Evan Chengde8aa4e2010-05-05 18:28:36 +0000168 SDNode *SelectConcatVector(SDNode *N);
169
Evan Chengaf4550f2009-07-02 01:23:32 +0000170 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
171 /// inline asm expressions.
172 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
173 char ConstraintCode,
174 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000175
Evan Cheng603afbf2010-05-10 17:34:18 +0000176 /// PairDRegs - Form a quad register from a pair of D registers.
177 ///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000178 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000179
180 /// PairDRegs - Form a quad register pair from a pair of Q registers.
181 ///
182 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
183
184 /// QuadDRegs - Form a quad register pair from a quad of D registers.
185 ///
186 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng5c6aba22010-05-14 18:54:59 +0000187
Evan Cheng8f6de382010-05-16 03:27:48 +0000188 /// QuadQRegs - Form 4 consecutive Q registers.
189 ///
190 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
191
Evan Cheng5c6aba22010-05-14 18:54:59 +0000192 /// OctoDRegs - Form 8 consecutive D registers.
193 ///
194 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
195 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000196};
Evan Chenga8e29892007-01-19 07:51:42 +0000197}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000198
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000199/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
200/// operand. If so Imm will receive the 32-bit value.
201static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
202 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
203 Imm = cast<ConstantSDNode>(N)->getZExtValue();
204 return true;
205 }
206 return false;
207}
208
209// isInt32Immediate - This method tests to see if a constant operand.
210// If so Imm will receive the 32 bit value.
211static bool isInt32Immediate(SDValue N, unsigned &Imm) {
212 return isInt32Immediate(N.getNode(), Imm);
213}
214
215// isOpcWithIntImmediate - This method tests to see if the node is a specific
216// opcode and that it has a immediate integer right operand.
217// If so Imm will receive the 32 bit value.
218static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
219 return N->getOpcode() == Opc &&
220 isInt32Immediate(N->getOperand(1).getNode(), Imm);
221}
222
223
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000224bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000225 SDValue N,
226 SDValue &BaseReg,
227 SDValue &ShReg,
228 SDValue &Opc) {
229 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
230
231 // Don't match base register only case. That is matched to a separate
232 // lower complexity pattern with explicit register operand.
233 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000234
Evan Cheng055b0312009-06-29 07:51:04 +0000235 BaseReg = N.getOperand(0);
236 unsigned ShImmVal = 0;
237 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000238 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000239 ShImmVal = RHS->getZExtValue() & 31;
240 } else {
241 ShReg = N.getOperand(1);
242 }
243 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000244 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000245 return true;
246}
247
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000248bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000249 SDValue &Base, SDValue &Offset,
250 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000251 if (N.getOpcode() == ISD::MUL) {
252 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
253 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000254 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000255 if (RHSC & 1) {
256 RHSC = RHSC & ~1;
257 ARM_AM::AddrOpc AddSub = ARM_AM::add;
258 if (RHSC < 0) {
259 AddSub = ARM_AM::sub;
260 RHSC = - RHSC;
261 }
262 if (isPowerOf2_32(RHSC)) {
263 unsigned ShAmt = Log2_32(RHSC);
264 Base = Offset = N.getOperand(0);
265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
266 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000268 return true;
269 }
270 }
271 }
272 }
273
Evan Chenga8e29892007-01-19 07:51:42 +0000274 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
275 Base = N;
276 if (N.getOpcode() == ISD::FrameIndex) {
277 int FI = cast<FrameIndexSDNode>(N)->getIndex();
278 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000279 } else if (N.getOpcode() == ARMISD::Wrapper &&
280 !(Subtarget->useMovt() &&
281 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000282 Base = N.getOperand(0);
283 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000284 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000285 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
286 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000287 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000288 return true;
289 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000290
Evan Chenga8e29892007-01-19 07:51:42 +0000291 // Match simple R +/- imm12 operands.
292 if (N.getOpcode() == ISD::ADD)
293 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000294 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000295 if ((RHSC >= 0 && RHSC < 0x1000) ||
296 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000297 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000298 if (Base.getOpcode() == ISD::FrameIndex) {
299 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
300 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
301 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000302 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000303
304 ARM_AM::AddrOpc AddSub = ARM_AM::add;
305 if (RHSC < 0) {
306 AddSub = ARM_AM::sub;
307 RHSC = - RHSC;
308 }
309 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000310 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000311 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000312 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
Evan Chenga8e29892007-01-19 07:51:42 +0000314 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000316 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000317 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
318 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
319 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000320
Evan Chenga8e29892007-01-19 07:51:42 +0000321 Base = N.getOperand(0);
322 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000323
Evan Chenga8e29892007-01-19 07:51:42 +0000324 if (ShOpcVal != ARM_AM::no_shift) {
325 // Check to see if the RHS of the shift is a constant, if not, we can't fold
326 // it.
327 if (ConstantSDNode *Sh =
328 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000329 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000330 Offset = N.getOperand(1).getOperand(0);
331 } else {
332 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000333 }
334 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000335
Evan Chenga8e29892007-01-19 07:51:42 +0000336 // Try matching (R shl C) + (R).
337 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
338 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
339 if (ShOpcVal != ARM_AM::no_shift) {
340 // Check to see if the RHS of the shift is a constant, if not, we can't
341 // fold it.
342 if (ConstantSDNode *Sh =
343 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000344 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000345 Offset = N.getOperand(0).getOperand(0);
346 Base = N.getOperand(1);
347 } else {
348 ShOpcVal = ARM_AM::no_shift;
349 }
350 }
351 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000352
Evan Chenga8e29892007-01-19 07:51:42 +0000353 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000354 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000355 return true;
356}
357
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000358bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000359 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000360 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000361 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
362 ? cast<LoadSDNode>(Op)->getAddressingMode()
363 : cast<StoreSDNode>(Op)->getAddressingMode();
364 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
365 ? ARM_AM::add : ARM_AM::sub;
366 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000367 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000368 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000369 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000370 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
371 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000372 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000373 return true;
374 }
375 }
376
377 Offset = N;
378 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
379 unsigned ShAmt = 0;
380 if (ShOpcVal != ARM_AM::no_shift) {
381 // Check to see if the RHS of the shift is a constant, if not, we can't fold
382 // it.
383 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000384 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000385 Offset = N.getOperand(0);
386 } else {
387 ShOpcVal = ARM_AM::no_shift;
388 }
389 }
390
391 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000392 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000393 return true;
394}
395
Evan Chenga8e29892007-01-19 07:51:42 +0000396
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000397bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000398 SDValue &Base, SDValue &Offset,
399 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000400 if (N.getOpcode() == ISD::SUB) {
401 // X - C is canonicalize to X + -C, no need to handle it here.
402 Base = N.getOperand(0);
403 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000405 return true;
406 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000407
Evan Chenga8e29892007-01-19 07:51:42 +0000408 if (N.getOpcode() != ISD::ADD) {
409 Base = N;
410 if (N.getOpcode() == ISD::FrameIndex) {
411 int FI = cast<FrameIndexSDNode>(N)->getIndex();
412 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
413 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000414 Offset = CurDAG->getRegister(0, MVT::i32);
415 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000416 return true;
417 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000418
Evan Chenga8e29892007-01-19 07:51:42 +0000419 // If the RHS is +/- imm8, fold into addr mode.
420 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000421 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000422 if ((RHSC >= 0 && RHSC < 256) ||
423 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000424 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000425 if (Base.getOpcode() == ISD::FrameIndex) {
426 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
427 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
428 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000429 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000430
431 ARM_AM::AddrOpc AddSub = ARM_AM::add;
432 if (RHSC < 0) {
433 AddSub = ARM_AM::sub;
434 RHSC = - RHSC;
435 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000436 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000437 return true;
438 }
439 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000440
Evan Chenga8e29892007-01-19 07:51:42 +0000441 Base = N.getOperand(0);
442 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000443 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000444 return true;
445}
446
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000447bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000448 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000450 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
451 ? cast<LoadSDNode>(Op)->getAddressingMode()
452 : cast<StoreSDNode>(Op)->getAddressingMode();
453 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
454 ? ARM_AM::add : ARM_AM::sub;
455 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000456 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000457 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000458 Offset = CurDAG->getRegister(0, MVT::i32);
459 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000460 return true;
461 }
462 }
463
464 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000465 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000466 return true;
467}
468
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000469bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000470 SDValue &Addr, SDValue &Mode) {
471 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000472 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000473 return true;
474}
Evan Chenga8e29892007-01-19 07:51:42 +0000475
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000476bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000477 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000478 if (N.getOpcode() != ISD::ADD) {
479 Base = N;
480 if (N.getOpcode() == ISD::FrameIndex) {
481 int FI = cast<FrameIndexSDNode>(N)->getIndex();
482 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000483 } else if (N.getOpcode() == ARMISD::Wrapper &&
484 !(Subtarget->useMovt() &&
485 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000486 Base = N.getOperand(0);
487 }
488 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000489 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000490 return true;
491 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000492
Evan Chenga8e29892007-01-19 07:51:42 +0000493 // If the RHS is +/- imm8, fold into addr mode.
494 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000495 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000496 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
497 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000498 if ((RHSC >= 0 && RHSC < 256) ||
499 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000500 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000501 if (Base.getOpcode() == ISD::FrameIndex) {
502 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
503 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
504 }
505
506 ARM_AM::AddrOpc AddSub = ARM_AM::add;
507 if (RHSC < 0) {
508 AddSub = ARM_AM::sub;
509 RHSC = - RHSC;
510 }
511 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000512 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000513 return true;
514 }
515 }
516 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000517
Evan Chenga8e29892007-01-19 07:51:42 +0000518 Base = N;
519 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000520 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000521 return true;
522}
523
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000524bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000525 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000526 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000527 // Default to no alignment.
528 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000529 return true;
530}
531
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000532bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000533 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000534 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
535 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000536 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000537 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000538 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000539 return true;
540 }
541 return false;
542}
543
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000544bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000545 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000546 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000547 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000548 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000549 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
550 if (!NC || NC->getZExtValue() != 0)
551 return false;
552
553 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000554 return true;
555 }
556
Evan Chenga8e29892007-01-19 07:51:42 +0000557 Base = N.getOperand(0);
558 Offset = N.getOperand(1);
559 return true;
560}
561
Evan Cheng79d43262007-01-24 02:21:22 +0000562bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000563ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000564 unsigned Scale, SDValue &Base,
565 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000566 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000567 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000568 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
569 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000570 if (N.getOpcode() == ARMISD::Wrapper &&
571 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
572 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000573 }
574
Evan Chenga8e29892007-01-19 07:51:42 +0000575 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000576 if (N.getOpcode() == ARMISD::Wrapper &&
577 !(Subtarget->useMovt() &&
578 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
579 Base = N.getOperand(0);
580 } else
581 Base = N;
582
Owen Anderson825b72b2009-08-11 20:47:22 +0000583 Offset = CurDAG->getRegister(0, MVT::i32);
584 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000585 return true;
586 }
587
Evan Chengad0e4652007-02-06 00:22:06 +0000588 // Thumb does not have [sp, r] address mode.
589 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
590 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
591 if ((LHSR && LHSR->getReg() == ARM::SP) ||
592 (RHSR && RHSR->getReg() == ARM::SP)) {
593 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 Offset = CurDAG->getRegister(0, MVT::i32);
595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000596 return true;
597 }
598
Evan Chenga8e29892007-01-19 07:51:42 +0000599 // If the RHS is + imm5 * scale, fold into addr mode.
600 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000601 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000602 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
603 RHSC /= Scale;
604 if (RHSC >= 0 && RHSC < 32) {
605 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 Offset = CurDAG->getRegister(0, MVT::i32);
607 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000608 return true;
609 }
610 }
611 }
612
Evan Chengc38f2bc2007-01-23 22:59:13 +0000613 Base = N.getOperand(0);
614 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000616 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000617}
618
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000619bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000620 SDValue &Base, SDValue &OffImm,
621 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000622 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000623}
624
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000625bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000626 SDValue &Base, SDValue &OffImm,
627 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000628 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000629}
630
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000631bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000632 SDValue &Base, SDValue &OffImm,
633 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000634 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000635}
636
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000637bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000638 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000639 if (N.getOpcode() == ISD::FrameIndex) {
640 int FI = cast<FrameIndexSDNode>(N)->getIndex();
641 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000642 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000643 return true;
644 }
Evan Cheng79d43262007-01-24 02:21:22 +0000645
Evan Chengad0e4652007-02-06 00:22:06 +0000646 if (N.getOpcode() != ISD::ADD)
647 return false;
648
649 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000650 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
651 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000652 // If the RHS is + imm8 * scale, fold into addr mode.
653 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000654 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000655 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
656 RHSC >>= 2;
657 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000658 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000659 if (Base.getOpcode() == ISD::FrameIndex) {
660 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
661 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
662 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000663 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000664 return true;
665 }
666 }
667 }
668 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 return false;
671}
672
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000673bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000674 SDValue &BaseReg,
675 SDValue &Opc) {
676 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
677
678 // Don't match base register only case. That is matched to a separate
679 // lower complexity pattern with explicit register operand.
680 if (ShOpcVal == ARM_AM::no_shift) return false;
681
682 BaseReg = N.getOperand(0);
683 unsigned ShImmVal = 0;
684 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
685 ShImmVal = RHS->getZExtValue() & 31;
686 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
687 return true;
688 }
689
690 return false;
691}
692
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000693bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000694 SDValue &Base, SDValue &OffImm) {
695 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000696
Evan Cheng3a214252009-08-11 08:52:18 +0000697 // Base only.
698 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000699 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000700 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000701 int FI = cast<FrameIndexSDNode>(N)->getIndex();
702 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000703 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000704 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000705 } else if (N.getOpcode() == ARMISD::Wrapper &&
706 !(Subtarget->useMovt() &&
707 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000708 Base = N.getOperand(0);
709 if (Base.getOpcode() == ISD::TargetConstantPool)
710 return false; // We want to select t2LDRpci instead.
711 } else
712 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000713 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000714 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000715 }
Evan Cheng055b0312009-06-29 07:51:04 +0000716
717 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000718 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
719 // Let t2LDRi8 handle (R - imm8).
720 return false;
721
Evan Cheng055b0312009-06-29 07:51:04 +0000722 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000723 if (N.getOpcode() == ISD::SUB)
724 RHSC = -RHSC;
725
726 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000727 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000728 if (Base.getOpcode() == ISD::FrameIndex) {
729 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
730 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
731 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000732 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000733 return true;
734 }
735 }
736
Evan Cheng3a214252009-08-11 08:52:18 +0000737 // Base only.
738 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000739 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000740 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000741}
742
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000743bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000744 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000745 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000746 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000747 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
748 int RHSC = (int)RHS->getSExtValue();
749 if (N.getOpcode() == ISD::SUB)
750 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000751
Evan Cheng3a214252009-08-11 08:52:18 +0000752 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
753 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000754 if (Base.getOpcode() == ISD::FrameIndex) {
755 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
756 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
757 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000758 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000759 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000760 }
Evan Cheng055b0312009-06-29 07:51:04 +0000761 }
762 }
763
764 return false;
765}
766
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000767bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000768 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000769 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000770 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
771 ? cast<LoadSDNode>(Op)->getAddressingMode()
772 : cast<StoreSDNode>(Op)->getAddressingMode();
773 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
774 int RHSC = (int)RHS->getZExtValue();
775 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000776 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000777 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
778 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000779 return true;
780 }
781 }
782
783 return false;
784}
785
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000786bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000787 SDValue &Base, SDValue &OffImm) {
788 if (N.getOpcode() == ISD::ADD) {
789 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
790 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000791 if (((RHSC & 0x3) == 0) &&
792 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000793 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000794 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000795 return true;
796 }
797 }
798 } else if (N.getOpcode() == ISD::SUB) {
799 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
800 int RHSC = (int)RHS->getZExtValue();
801 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
802 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000803 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000804 return true;
805 }
806 }
807 }
808
809 return false;
810}
811
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000812bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000813 SDValue &Base,
814 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000815 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
816 if (N.getOpcode() != ISD::ADD)
817 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000818
Evan Cheng3a214252009-08-11 08:52:18 +0000819 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
820 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
821 int RHSC = (int)RHS->getZExtValue();
822 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
823 return false;
824 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000825 return false;
826 }
827
Evan Cheng055b0312009-06-29 07:51:04 +0000828 // Look for (R + R) or (R + (R << [1,2,3])).
829 unsigned ShAmt = 0;
830 Base = N.getOperand(0);
831 OffReg = N.getOperand(1);
832
833 // Swap if it is ((R << c) + R).
834 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
835 if (ShOpcVal != ARM_AM::lsl) {
836 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
837 if (ShOpcVal == ARM_AM::lsl)
838 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000839 }
840
Evan Cheng055b0312009-06-29 07:51:04 +0000841 if (ShOpcVal == ARM_AM::lsl) {
842 // Check to see if the RHS of the shift is a constant, if not, we can't fold
843 // it.
844 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
845 ShAmt = Sh->getZExtValue();
846 if (ShAmt >= 4) {
847 ShAmt = 0;
848 ShOpcVal = ARM_AM::no_shift;
849 } else
850 OffReg = OffReg.getOperand(0);
851 } else {
852 ShOpcVal = ARM_AM::no_shift;
853 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000854 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000855
Owen Anderson825b72b2009-08-11 20:47:22 +0000856 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000857
858 return true;
859}
860
861//===--------------------------------------------------------------------===//
862
Evan Chengee568cf2007-07-05 07:15:27 +0000863/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000864static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000865 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000866}
867
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000868SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
869 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 ISD::MemIndexedMode AM = LD->getAddressingMode();
871 if (AM == ISD::UNINDEXED)
872 return NULL;
873
Owen Andersone50ed302009-08-10 22:56:29 +0000874 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000875 SDValue Offset, AMOpc;
876 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
877 unsigned Opcode = 0;
878 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000880 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
882 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000883 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000884 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000885 Match = true;
886 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
887 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
888 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000889 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000890 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000891 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 Match = true;
893 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
894 }
895 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000896 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000897 Match = true;
898 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
899 }
900 }
901 }
902
903 if (Match) {
904 SDValue Chain = LD->getChain();
905 SDValue Base = LD->getBasePtr();
906 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000907 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000908 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000909 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000910 }
911
912 return NULL;
913}
914
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000915SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
916 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000917 ISD::MemIndexedMode AM = LD->getAddressingMode();
918 if (AM == ISD::UNINDEXED)
919 return NULL;
920
Owen Andersone50ed302009-08-10 22:56:29 +0000921 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000922 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000923 SDValue Offset;
924 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
925 unsigned Opcode = 0;
926 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000927 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000928 switch (LoadedVT.getSimpleVT().SimpleTy) {
929 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000930 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
931 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000932 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000933 if (isSExtLd)
934 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
935 else
936 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000937 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000938 case MVT::i8:
939 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000940 if (isSExtLd)
941 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
942 else
943 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000944 break;
945 default:
946 return NULL;
947 }
948 Match = true;
949 }
950
951 if (Match) {
952 SDValue Chain = LD->getChain();
953 SDValue Base = LD->getBasePtr();
954 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000955 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000956 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000957 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000958 }
959
960 return NULL;
961}
962
Evan Cheng603afbf2010-05-10 17:34:18 +0000963/// PairDRegs - Form a quad register from a pair of D registers.
964///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000965SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
966 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000967 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
968 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000969 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000970 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
971 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
972 }
973 SDValue Undef =
974 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000975 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000976 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000977 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000978 VT, SDValue(Pair, 0), V1, SubReg1);
979}
980
Evan Cheng7f687192010-05-14 00:21:45 +0000981/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000982///
983SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
984 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000985 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
986 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000987 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
988 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
989}
990
Evan Cheng7f687192010-05-14 00:21:45 +0000991/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000992///
993SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
994 SDValue V2, SDValue V3) {
995 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000996 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
997 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
998 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
999 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001000 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1001 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1002}
1003
Evan Cheng8f6de382010-05-16 03:27:48 +00001004/// QuadQRegs - Form 4 consecutive Q registers.
1005///
1006SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1007 SDValue V2, SDValue V3) {
1008 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001009 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1010 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1011 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1012 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001013 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1014 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1015}
1016
Evan Cheng5c6aba22010-05-14 18:54:59 +00001017/// OctoDRegs - Form 8 consecutive D registers.
1018///
1019SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1020 SDValue V2, SDValue V3,
1021 SDValue V4, SDValue V5,
1022 SDValue V6, SDValue V7) {
1023 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001024 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1025 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1026 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1027 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1028 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1029 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1030 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1031 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001032 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1033 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1034 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1035}
1036
Bob Wilsona7c397c2009-10-14 16:19:03 +00001037/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1038/// for a 64-bit subregister of the vector.
1039static EVT GetNEONSubregVT(EVT VT) {
1040 switch (VT.getSimpleVT().SimpleTy) {
1041 default: llvm_unreachable("unhandled NEON type");
1042 case MVT::v16i8: return MVT::v8i8;
1043 case MVT::v8i16: return MVT::v4i16;
1044 case MVT::v4f32: return MVT::v2f32;
1045 case MVT::v4i32: return MVT::v2i32;
1046 case MVT::v2i64: return MVT::v1i64;
1047 }
1048}
1049
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001050SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001051 unsigned *DOpcodes, unsigned *QOpcodes0,
1052 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001053 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001054 DebugLoc dl = N->getDebugLoc();
1055
Bob Wilson226036e2010-03-20 22:13:40 +00001056 SDValue MemAddr, Align;
1057 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001058 return NULL;
1059
1060 SDValue Chain = N->getOperand(0);
1061 EVT VT = N->getValueType(0);
1062 bool is64BitVector = VT.is64BitVector();
1063
1064 unsigned OpcodeIndex;
1065 switch (VT.getSimpleVT().SimpleTy) {
1066 default: llvm_unreachable("unhandled vld type");
1067 // Double-register operations:
1068 case MVT::v8i8: OpcodeIndex = 0; break;
1069 case MVT::v4i16: OpcodeIndex = 1; break;
1070 case MVT::v2f32:
1071 case MVT::v2i32: OpcodeIndex = 2; break;
1072 case MVT::v1i64: OpcodeIndex = 3; break;
1073 // Quad-register operations:
1074 case MVT::v16i8: OpcodeIndex = 0; break;
1075 case MVT::v8i16: OpcodeIndex = 1; break;
1076 case MVT::v4f32:
1077 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001078 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001079 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001080 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001081 }
1082
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001083 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001084 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 if (is64BitVector) {
1086 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001087 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001088 std::vector<EVT> ResTys(NumVecs, VT);
1089 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001090 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1091 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1092 return VLd;
1093
Evan Cheng0ce537a2010-05-11 01:19:40 +00001094 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001095 SDValue V0 = SDValue(VLd, 0);
1096 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001097
Evan Cheng0ce537a2010-05-11 01:19:40 +00001098 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001099 if (NumVecs == 2)
1100 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1101 else {
1102 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001103 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001104 SDValue V3 = (NumVecs == 3)
1105 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1106 : SDValue(VLd, 3);
1107 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1108 }
1109
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001110 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001111 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001112 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001113 dl, VT, RegSeq);
1114 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001115 }
1116 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1117 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001118 }
1119
1120 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001121 if (NumVecs <= 2) {
1122 // Quad registers are directly supported for VLD1 and VLD2,
1123 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001124 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001125 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001126 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001127 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001128 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001129 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001130
1131 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001132 if (llvm::ModelWithRegSequence()) {
1133 if (NumVecs == 1) {
1134 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1135 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1136 } else {
1137 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1138 SDValue(VLd, 0), SDValue(VLd, 1),
1139 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001140 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1141 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
Evan Cheng603afbf2010-05-10 17:34:18 +00001142 ReplaceUses(SDValue(N, 0), Q0);
1143 ReplaceUses(SDValue(N, 1), Q1);
1144 }
1145 } else {
1146 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1147 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1148 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1149 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001150 }
1151 } else {
1152 // Otherwise, quad registers are loaded with two separate instructions,
1153 // where one loads the even registers and the other loads the odd registers.
1154
Bob Wilson3e36f132009-10-14 17:28:52 +00001155 std::vector<EVT> ResTys(NumVecs, RegVT);
1156 ResTys.push_back(MemAddr.getValueType());
1157 ResTys.push_back(MVT::Other);
1158
Bob Wilson24f995d2009-10-14 18:32:29 +00001159 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001160 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001161 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1162 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001163 Chain = SDValue(VLdA, NumVecs+1);
1164
Bob Wilson24f995d2009-10-14 18:32:29 +00001165 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001166 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001167 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1168 Align, Reg0, Pred, Reg0, Chain };
1169 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001170 Chain = SDValue(VLdB, NumVecs+1);
1171
Evan Cheng5c6aba22010-05-14 18:54:59 +00001172 if (llvm::ModelWithRegSequence()) {
1173 SDValue V0 = SDValue(VLdA, 0);
1174 SDValue V1 = SDValue(VLdB, 0);
1175 SDValue V2 = SDValue(VLdA, 1);
1176 SDValue V3 = SDValue(VLdB, 1);
1177 SDValue V4 = SDValue(VLdA, 2);
1178 SDValue V5 = SDValue(VLdB, 2);
1179 SDValue V6 = (NumVecs == 3)
1180 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1181 0)
1182 : SDValue(VLdA, 3);
1183 SDValue V7 = (NumVecs == 3)
1184 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1185 0)
1186 : SDValue(VLdB, 3);
1187 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1188 V4, V5, V6, V7), 0);
1189
1190 // Extract out the 3 / 4 Q registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001191 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001192 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001193 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001194 dl, VT, RegSeq);
1195 ReplaceUses(SDValue(N, Vec), Q);
1196 }
1197 } else {
1198 // Combine the even and odd subregs to produce the result.
1199 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1200 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1201 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1202 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001203 }
1204 }
1205 ReplaceUses(SDValue(N, NumVecs), Chain);
1206 return NULL;
1207}
1208
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001209SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001210 unsigned *DOpcodes, unsigned *QOpcodes0,
1211 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001212 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001213 DebugLoc dl = N->getDebugLoc();
1214
Bob Wilson226036e2010-03-20 22:13:40 +00001215 SDValue MemAddr, Align;
1216 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001217 return NULL;
1218
1219 SDValue Chain = N->getOperand(0);
1220 EVT VT = N->getOperand(3).getValueType();
1221 bool is64BitVector = VT.is64BitVector();
1222
1223 unsigned OpcodeIndex;
1224 switch (VT.getSimpleVT().SimpleTy) {
1225 default: llvm_unreachable("unhandled vst type");
1226 // Double-register operations:
1227 case MVT::v8i8: OpcodeIndex = 0; break;
1228 case MVT::v4i16: OpcodeIndex = 1; break;
1229 case MVT::v2f32:
1230 case MVT::v2i32: OpcodeIndex = 2; break;
1231 case MVT::v1i64: OpcodeIndex = 3; break;
1232 // Quad-register operations:
1233 case MVT::v16i8: OpcodeIndex = 0; break;
1234 case MVT::v8i16: OpcodeIndex = 1; break;
1235 case MVT::v4f32:
1236 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001237 case MVT::v2i64: OpcodeIndex = 3;
1238 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1239 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001240 }
1241
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001242 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001243 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001244
Bob Wilson226036e2010-03-20 22:13:40 +00001245 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001246 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001247 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001248
1249 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001250 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001251 SDValue RegSeq;
1252 SDValue V0 = N->getOperand(0+3);
1253 SDValue V1 = N->getOperand(1+3);
1254
1255 // Form a REG_SEQUENCE to force register allocation.
1256 if (NumVecs == 2)
1257 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1258 else {
1259 SDValue V2 = N->getOperand(2+3);
1260 // If it's a vld3, form a quad D-register and leave the last part as
1261 // an undef.
1262 SDValue V3 = (NumVecs == 3)
1263 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1264 : N->getOperand(3+3);
1265 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1266 }
1267
1268 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001269 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001270 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001271 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001272 RegSeq));
1273 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001274 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001275 RegSeq));
1276 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001277 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001278 RegSeq));
1279 } else {
1280 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1281 Ops.push_back(N->getOperand(Vec+3));
1282 }
Evan Chengac0869d2009-11-21 06:21:52 +00001283 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001284 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001285 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001286 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001287 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001288 }
1289
1290 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001291 if (NumVecs <= 2) {
1292 // Quad registers are directly supported for VST1 and VST2,
1293 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001294 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001295 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001296 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001297 SDValue Q0 = N->getOperand(3);
1298 SDValue Q1 = N->getOperand(4);
1299
1300 // Form a QQ register.
1301 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1302
1303 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001304 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001305 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001306 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001307 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001308 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001309 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001310 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001311 QQ));
1312 Ops.push_back(Pred);
1313 Ops.push_back(Reg0); // predicate register
1314 Ops.push_back(Chain);
1315 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1316 } else {
1317 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001318 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001319 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001320 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001321 N->getOperand(Vec+3)));
1322 }
1323 Ops.push_back(Pred);
1324 Ops.push_back(Reg0); // predicate register
1325 Ops.push_back(Chain);
1326 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1327 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001328 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001329 }
1330
1331 // Otherwise, quad registers are stored with two separate instructions,
1332 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001333 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001334 // Form the QQQQ REG_SEQUENCE.
1335 SDValue V[8];
1336 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001337 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001338 N->getOperand(Vec+3));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001339 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001340 N->getOperand(Vec+3));
1341 }
1342 if (NumVecs == 3)
Evan Cheng7189fd02010-05-15 07:53:37 +00001343 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1344 dl, RegVT), 0);
1345
Evan Cheng12c24692010-05-14 22:54:52 +00001346 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1347 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001348
Evan Cheng12c24692010-05-14 22:54:52 +00001349 // Store the even D registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001350 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng12c24692010-05-14 22:54:52 +00001351 Ops.push_back(Reg0); // post-access address offset
1352 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001353 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001354 RegVT, RegSeq));
1355 Ops.push_back(Pred);
1356 Ops.push_back(Reg0); // predicate register
1357 Ops.push_back(Chain);
1358 unsigned Opc = QOpcodes0[OpcodeIndex];
1359 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1360 MVT::Other, Ops.data(), NumVecs+6);
1361 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001362
Evan Cheng12c24692010-05-14 22:54:52 +00001363 // Store the odd D registers.
1364 Ops[0] = SDValue(VStA, 0); // MemAddr
1365 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001366 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001367 RegVT, RegSeq);
1368 Ops[NumVecs+5] = Chain;
1369 Opc = QOpcodes1[OpcodeIndex];
1370 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1371 MVT::Other, Ops.data(), NumVecs+6);
1372 Chain = SDValue(VStB, 1);
1373 ReplaceUses(SDValue(N, 0), Chain);
1374 return NULL;
1375 } else {
1376 Ops.push_back(Reg0); // post-access address offset
1377
1378 // Store the even subregs.
1379 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001380 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001381 N->getOperand(Vec+3)));
1382 Ops.push_back(Pred);
1383 Ops.push_back(Reg0); // predicate register
1384 Ops.push_back(Chain);
1385 unsigned Opc = QOpcodes0[OpcodeIndex];
1386 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1387 MVT::Other, Ops.data(), NumVecs+6);
1388 Chain = SDValue(VStA, 1);
1389
1390 // Store the odd subregs.
1391 Ops[0] = SDValue(VStA, 0); // MemAddr
1392 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001393 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001394 N->getOperand(Vec+3));
1395 Ops[NumVecs+5] = Chain;
1396 Opc = QOpcodes1[OpcodeIndex];
1397 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1398 MVT::Other, Ops.data(), NumVecs+6);
1399 Chain = SDValue(VStB, 1);
1400 ReplaceUses(SDValue(N, 0), Chain);
1401 return NULL;
1402 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001403}
1404
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001405SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001406 unsigned NumVecs, unsigned *DOpcodes,
1407 unsigned *QOpcodes0,
1408 unsigned *QOpcodes1) {
1409 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001410 DebugLoc dl = N->getDebugLoc();
1411
Bob Wilson226036e2010-03-20 22:13:40 +00001412 SDValue MemAddr, Align;
1413 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001414 return NULL;
1415
1416 SDValue Chain = N->getOperand(0);
1417 unsigned Lane =
1418 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001419 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001420 bool is64BitVector = VT.is64BitVector();
1421
Bob Wilson96493442009-10-14 16:46:45 +00001422 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001423 unsigned NumElts = 0;
1424 int SubregIdx = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001425 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001426 EVT RegVT = VT;
1427 if (!is64BitVector) {
1428 RegVT = GetNEONSubregVT(VT);
1429 NumElts = RegVT.getVectorNumElements();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001430 SubregIdx = (Lane < NumElts) ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001431 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001432 }
1433
1434 unsigned OpcodeIndex;
1435 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001436 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001437 // Double-register operations:
1438 case MVT::v8i8: OpcodeIndex = 0; break;
1439 case MVT::v4i16: OpcodeIndex = 1; break;
1440 case MVT::v2f32:
1441 case MVT::v2i32: OpcodeIndex = 2; break;
1442 // Quad-register operations:
1443 case MVT::v8i16: OpcodeIndex = 0; break;
1444 case MVT::v4f32:
1445 case MVT::v4i32: OpcodeIndex = 1; break;
1446 }
1447
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001448 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001449 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001450
Bob Wilson226036e2010-03-20 22:13:40 +00001451 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001452 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001453 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001454
1455 unsigned Opc = 0;
1456 if (is64BitVector) {
1457 Opc = DOpcodes[OpcodeIndex];
Evan Cheng8f6de382010-05-16 03:27:48 +00001458 if (llvm::ModelWithRegSequence()) {
1459 SDValue RegSeq;
1460 SDValue V0 = N->getOperand(0+3);
1461 SDValue V1 = N->getOperand(1+3);
1462 if (NumVecs == 2) {
1463 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1464 } else {
1465 SDValue V2 = N->getOperand(2+3);
1466 SDValue V3 = (NumVecs == 3)
1467 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1468 : N->getOperand(3+3);
1469 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1470 }
1471
1472 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001473 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001474 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001475 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001476 RegSeq));
1477 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001478 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001479 RegSeq));
1480 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001481 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001482 RegSeq));
1483 } else {
1484 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1485 Ops.push_back(N->getOperand(Vec+3));
1486 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001487 } else {
1488 // Check if this is loading the even or odd subreg of a Q register.
1489 if (Lane < NumElts) {
1490 Opc = QOpcodes0[OpcodeIndex];
1491 } else {
1492 Lane -= NumElts;
1493 Opc = QOpcodes1[OpcodeIndex];
1494 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001495
1496 if (llvm::ModelWithRegSequence()) {
1497 SDValue RegSeq;
1498 SDValue V0 = N->getOperand(0+3);
1499 SDValue V1 = N->getOperand(1+3);
1500 if (NumVecs == 2) {
1501 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1502 } else {
1503 SDValue V2 = N->getOperand(2+3);
1504 SDValue V3 = (NumVecs == 3)
1505 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1506 : N->getOperand(3+3);
1507 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1508 }
1509
1510 // Extract the subregs of the input vector.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001511 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001512 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1513 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1514 RegSeq));
1515 } else {
1516 // Extract the subregs of the input vector.
1517 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1518 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1519 N->getOperand(Vec+3)));
1520 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001521 }
1522 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001523 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001524 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001525 Ops.push_back(Chain);
1526
Bob Wilson96493442009-10-14 16:46:45 +00001527 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001528 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001529
Bob Wilsona7c397c2009-10-14 16:19:03 +00001530 std::vector<EVT> ResTys(NumVecs, RegVT);
1531 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001532 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1533
Evan Cheng7189fd02010-05-15 07:53:37 +00001534 if (llvm::ModelWithRegSequence()) {
Evan Cheng7092c2b2010-05-15 01:36:29 +00001535 // Form a REG_SEQUENCE to force register allocation.
Evan Cheng7189fd02010-05-15 07:53:37 +00001536 SDValue RegSeq;
1537 if (is64BitVector) {
1538 SDValue V0 = SDValue(VLdLn, 0);
1539 SDValue V1 = SDValue(VLdLn, 1);
1540 if (NumVecs == 2) {
1541 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1542 } else {
1543 SDValue V2 = SDValue(VLdLn, 2);
1544 // If it's a vld3, form a quad D-register but discard the last part.
1545 SDValue V3 = (NumVecs == 3)
Evan Cheng7092c2b2010-05-15 01:36:29 +00001546 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1547 : SDValue(VLdLn, 3);
Evan Cheng7189fd02010-05-15 07:53:37 +00001548 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1549 }
1550 } else {
1551 // For 128-bit vectors, take the 64-bit results of the load and insert them
1552 // as subregs into the result.
1553 SDValue V[8];
1554 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Evan Cheng8f6de382010-05-16 03:27:48 +00001555 if (Even) {
Evan Cheng7189fd02010-05-15 07:53:37 +00001556 V[i] = SDValue(VLdLn, Vec);
1557 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1558 dl, RegVT), 0);
1559 } else {
1560 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1561 dl, RegVT), 0);
1562 V[i+1] = SDValue(VLdLn, Vec);
1563 }
1564 }
1565 if (NumVecs == 3)
1566 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1567 dl, RegVT), 0);
1568
1569 if (NumVecs == 2)
1570 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1571 else
1572 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1573 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001574 }
1575
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001576 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1577 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001578 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Evan Cheng7189fd02010-05-15 07:53:37 +00001579 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1580 ReplaceUses(SDValue(N, Vec),
1581 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
Evan Cheng7092c2b2010-05-15 01:36:29 +00001582 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1583 return NULL;
1584 }
1585
Bob Wilsona7c397c2009-10-14 16:19:03 +00001586 // For a 64-bit vector load to D registers, nothing more needs to be done.
1587 if (is64BitVector)
1588 return VLdLn;
1589
1590 // For 128-bit vectors, take the 64-bit results of the load and insert them
1591 // as subregs into the result.
1592 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1593 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1594 N->getOperand(Vec+3),
1595 SDValue(VLdLn, Vec));
1596 ReplaceUses(SDValue(N, Vec), QuadVec);
1597 }
1598
1599 Chain = SDValue(VLdLn, NumVecs);
1600 ReplaceUses(SDValue(N, NumVecs), Chain);
1601 return NULL;
1602}
1603
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001604SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001605 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001606 if (!Subtarget->hasV6T2Ops())
1607 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001608
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001609 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1610 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1611
1612
1613 // For unsigned extracts, check for a shift right and mask
1614 unsigned And_imm = 0;
1615 if (N->getOpcode() == ISD::AND) {
1616 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1617
1618 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1619 if (And_imm & (And_imm + 1))
1620 return NULL;
1621
1622 unsigned Srl_imm = 0;
1623 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1624 Srl_imm)) {
1625 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1626
1627 unsigned Width = CountTrailingOnes_32(And_imm);
1628 unsigned LSB = Srl_imm;
1629 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1630 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1631 CurDAG->getTargetConstant(LSB, MVT::i32),
1632 CurDAG->getTargetConstant(Width, MVT::i32),
1633 getAL(CurDAG), Reg0 };
1634 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1635 }
1636 }
1637 return NULL;
1638 }
1639
1640 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001641 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001642 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001643 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1644 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001645 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001646 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1647 unsigned Width = 32 - Srl_imm;
1648 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001649 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001650 return NULL;
1651 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001652 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001653 CurDAG->getTargetConstant(LSB, MVT::i32),
1654 CurDAG->getTargetConstant(Width, MVT::i32),
1655 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001656 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001657 }
1658 }
1659 return NULL;
1660}
1661
Evan Cheng9ef48352009-11-20 00:54:03 +00001662SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001663SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001664 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1665 SDValue CPTmp0;
1666 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001667 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001668 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1669 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1670 unsigned Opc = 0;
1671 switch (SOShOp) {
1672 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1673 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1674 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1675 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1676 default:
1677 llvm_unreachable("Unknown so_reg opcode!");
1678 break;
1679 }
1680 SDValue SOShImm =
1681 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1682 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1683 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001684 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001685 }
1686 return 0;
1687}
1688
1689SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001690SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001691 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1692 SDValue CPTmp0;
1693 SDValue CPTmp1;
1694 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001695 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001696 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1697 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001698 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001699 }
1700 return 0;
1701}
1702
1703SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001704SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001705 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1706 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1707 if (!T)
1708 return 0;
1709
1710 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1711 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1712 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1713 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001714 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001715 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1716 }
1717 return 0;
1718}
1719
1720SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001721SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001722 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1723 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1724 if (!T)
1725 return 0;
1726
1727 if (Predicate_so_imm(TrueVal.getNode())) {
1728 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1729 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1730 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001731 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001732 ARM::MOVCCi, MVT::i32, Ops, 5);
1733 }
1734 return 0;
1735}
1736
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001737SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1738 EVT VT = N->getValueType(0);
1739 SDValue FalseVal = N->getOperand(0);
1740 SDValue TrueVal = N->getOperand(1);
1741 SDValue CC = N->getOperand(2);
1742 SDValue CCR = N->getOperand(3);
1743 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001744 assert(CC.getOpcode() == ISD::Constant);
1745 assert(CCR.getOpcode() == ISD::Register);
1746 ARMCC::CondCodes CCVal =
1747 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001748
1749 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1750 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1751 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1752 // Pattern complexity = 18 cost = 1 size = 0
1753 SDValue CPTmp0;
1754 SDValue CPTmp1;
1755 SDValue CPTmp2;
1756 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001757 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001758 CCVal, CCR, InFlag);
1759 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001761 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1762 if (Res)
1763 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001764 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001765 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001766 CCVal, CCR, InFlag);
1767 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001768 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001769 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1770 if (Res)
1771 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001772 }
1773
1774 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1775 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1776 // (imm:i32):$cc)
1777 // Emits: (MOVCCi:i32 GPR:i32:$false,
1778 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1779 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001780 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001781 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001782 CCVal, CCR, InFlag);
1783 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001784 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001785 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1786 if (Res)
1787 return Res;
1788 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001789 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001790 CCVal, CCR, InFlag);
1791 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001792 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001793 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1794 if (Res)
1795 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001796 }
1797 }
1798
1799 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1800 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1801 // Pattern complexity = 6 cost = 1 size = 0
1802 //
1803 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1804 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1805 // Pattern complexity = 6 cost = 11 size = 0
1806 //
1807 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001808 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1809 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001810 unsigned Opc = 0;
1811 switch (VT.getSimpleVT().SimpleTy) {
1812 default: assert(false && "Illegal conditional move type!");
1813 break;
1814 case MVT::i32:
1815 Opc = Subtarget->isThumb()
1816 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1817 : ARM::MOVCCr;
1818 break;
1819 case MVT::f32:
1820 Opc = ARM::VMOVScc;
1821 break;
1822 case MVT::f64:
1823 Opc = ARM::VMOVDcc;
1824 break;
1825 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001826 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001827}
1828
Evan Chengde8aa4e2010-05-05 18:28:36 +00001829SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1830 // The only time a CONCAT_VECTORS operation can have legal types is when
1831 // two 64-bit vectors are concatenated to a 128-bit vector.
1832 EVT VT = N->getValueType(0);
1833 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1834 llvm_unreachable("unexpected CONCAT_VECTORS");
1835 DebugLoc dl = N->getDebugLoc();
1836 SDValue V0 = N->getOperand(0);
1837 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001838 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1839 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001840 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1841 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1842}
1843
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001844SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001845 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001846
Dan Gohmane8be6c62008-07-17 19:10:17 +00001847 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001848 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001849
1850 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001851 default: break;
1852 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001853 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001854 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001855 if (Subtarget->hasThumb2())
1856 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1857 // be done with MOV + MOVT, at worst.
1858 UseCP = 0;
1859 else {
1860 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001861 UseCP = (Val > 255 && // MOV
1862 ~Val > 255 && // MOV + MVN
1863 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001864 } else
1865 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1866 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1867 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1868 }
1869
Evan Chenga8e29892007-01-19 07:51:42 +00001870 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001871 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001872 CurDAG->getTargetConstantPool(ConstantInt::get(
1873 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001874 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001875
1876 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001877 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001878 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001879 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001880 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001881 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1882 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001883 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001884 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001885 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001886 CurDAG->getRegister(0, MVT::i32),
1887 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001888 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001889 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001890 CurDAG->getEntryNode()
1891 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001892 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1893 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001894 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001895 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001896 return NULL;
1897 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001898
Evan Chenga8e29892007-01-19 07:51:42 +00001899 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001900 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001901 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001902 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001903 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001904 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001905 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001906 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001907 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1908 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001909 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001910 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1911 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001912 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1913 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1914 CurDAG->getRegister(0, MVT::i32) };
1915 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001916 }
Evan Chenga8e29892007-01-19 07:51:42 +00001917 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001918 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001919 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001920 return I;
1921 break;
1922 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001923 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001924 return I;
1925 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001926 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001927 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001928 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001929 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001930 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001931 if (!RHSV) break;
1932 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001933 unsigned ShImm = Log2_32(RHSV-1);
1934 if (ShImm >= 32)
1935 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001936 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001937 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001938 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1939 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001940 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001941 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001942 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001943 } else {
1944 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001945 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001946 }
Evan Chenga8e29892007-01-19 07:51:42 +00001947 }
1948 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001949 unsigned ShImm = Log2_32(RHSV+1);
1950 if (ShImm >= 32)
1951 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001952 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001953 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001954 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1955 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001956 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001957 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1958 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001959 } else {
1960 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001961 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001962 }
Evan Chenga8e29892007-01-19 07:51:42 +00001963 }
1964 }
1965 break;
Evan Cheng20956592009-10-21 08:15:52 +00001966 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001967 // Check for unsigned bitfield extract
1968 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1969 return I;
1970
Evan Cheng20956592009-10-21 08:15:52 +00001971 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1972 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1973 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1974 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1975 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001977 if (VT != MVT::i32)
1978 break;
1979 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1980 ? ARM::t2MOVTi16
1981 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1982 if (!Opc)
1983 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001985 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1986 if (!N1C)
1987 break;
1988 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1989 SDValue N2 = N0.getOperand(1);
1990 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1991 if (!N2C)
1992 break;
1993 unsigned N1CVal = N1C->getZExtValue();
1994 unsigned N2CVal = N2C->getZExtValue();
1995 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1996 (N1CVal & 0xffffU) == 0xffffU &&
1997 (N2CVal & 0xffffU) == 0x0U) {
1998 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1999 MVT::i32);
2000 SDValue Ops[] = { N0.getOperand(0), Imm16,
2001 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2002 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2003 }
2004 }
2005 break;
2006 }
Jim Grosbache5165492009-11-09 00:11:35 +00002007 case ARMISD::VMOVRRD:
2008 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002010 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002011 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002012 if (Subtarget->isThumb1Only())
2013 break;
2014 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002015 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002016 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2017 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002018 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002019 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002020 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002021 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2022 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002023 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002024 }
Evan Chengee568cf2007-07-05 07:15:27 +00002025 }
Dan Gohman525178c2007-10-08 18:33:35 +00002026 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002027 if (Subtarget->isThumb1Only())
2028 break;
2029 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002030 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002031 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002032 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002033 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002034 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002035 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2036 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002037 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002038 }
Evan Chengee568cf2007-07-05 07:15:27 +00002039 }
Evan Chenga8e29892007-01-19 07:51:42 +00002040 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002041 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002042 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002043 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002044 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002045 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002046 if (ResNode)
2047 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002048
2049 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2050 if (Subtarget->hasVFP2() &&
2051 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2052 SDValue Chain = N->getOperand(0);
2053 SDValue AM5Opc =
2054 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002055 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002056 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2057 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002058 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2059 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2060 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2061 MVT::v2f64, MVT::Other, Ops, 5);
2062 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2063 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002064 }
2065 // Other cases are autogenerated.
2066 break;
2067 }
2068 case ISD::STORE: {
2069 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2070 if (Subtarget->hasVFP2() &&
2071 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2072 SDValue Chain = N->getOperand(0);
2073 SDValue AM5Opc =
2074 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002075 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002076 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2077 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2078 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002079 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2080 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2081 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2082 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2083 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002084 }
Evan Chenga8e29892007-01-19 07:51:42 +00002085 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002086 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002087 }
Evan Chengee568cf2007-07-05 07:15:27 +00002088 case ARMISD::BRCOND: {
2089 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2090 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2091 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002092
Evan Chengee568cf2007-07-05 07:15:27 +00002093 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2094 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2095 // Pattern complexity = 6 cost = 1 size = 0
2096
David Goodwin5e47a9a2009-06-30 18:04:13 +00002097 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2098 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2099 // Pattern complexity = 6 cost = 1 size = 0
2100
Jim Grosbach764ab522009-08-11 15:33:49 +00002101 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002102 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002103 SDValue Chain = N->getOperand(0);
2104 SDValue N1 = N->getOperand(1);
2105 SDValue N2 = N->getOperand(2);
2106 SDValue N3 = N->getOperand(3);
2107 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002108 assert(N1.getOpcode() == ISD::BasicBlock);
2109 assert(N2.getOpcode() == ISD::Constant);
2110 assert(N3.getOpcode() == ISD::Register);
2111
Dan Gohman475871a2008-07-27 21:46:04 +00002112 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002113 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002114 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002115 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002116 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2117 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002118 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002119 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002120 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002121 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002122 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002123 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002124 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002125 return NULL;
2126 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002127 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002128 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002129 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130 EVT VT = N->getValueType(0);
2131 SDValue N0 = N->getOperand(0);
2132 SDValue N1 = N->getOperand(1);
2133 SDValue N2 = N->getOperand(2);
2134 SDValue N3 = N->getOperand(3);
2135 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002136 assert(N2.getOpcode() == ISD::Constant);
2137 assert(N3.getOpcode() == ISD::Register);
2138
Dan Gohman475871a2008-07-27 21:46:04 +00002139 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002140 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002141 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002142 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002143 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002144 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002145 default: assert(false && "Illegal conditional move type!");
2146 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002147 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002148 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002149 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002150 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002151 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002152 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002153 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002154 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002155 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002156
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002157 case ARMISD::VZIP: {
2158 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002159 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002160 switch (VT.getSimpleVT().SimpleTy) {
2161 default: return NULL;
2162 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2163 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2164 case MVT::v2f32:
2165 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2166 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2167 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2168 case MVT::v4f32:
2169 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2170 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002171 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002172 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2173 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2174 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002175 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002176 case ARMISD::VUZP: {
2177 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002178 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002179 switch (VT.getSimpleVT().SimpleTy) {
2180 default: return NULL;
2181 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2182 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2183 case MVT::v2f32:
2184 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2185 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2186 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2187 case MVT::v4f32:
2188 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2189 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002190 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002191 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2192 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2193 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002194 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002195 case ARMISD::VTRN: {
2196 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002197 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002198 switch (VT.getSimpleVT().SimpleTy) {
2199 default: return NULL;
2200 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2201 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2202 case MVT::v2f32:
2203 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2204 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2205 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2206 case MVT::v4f32:
2207 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2208 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002209 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002210 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2211 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2212 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002213 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002214
2215 case ISD::INTRINSIC_VOID:
2216 case ISD::INTRINSIC_W_CHAIN: {
2217 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002218 switch (IntNo) {
2219 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002220 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002221
Bob Wilson621f1952010-03-23 05:25:43 +00002222 case Intrinsic::arm_neon_vld1: {
2223 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2224 ARM::VLD1d32, ARM::VLD1d64 };
2225 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2226 ARM::VLD1q32, ARM::VLD1q64 };
2227 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2228 }
2229
Bob Wilson31fb12f2009-08-26 17:39:53 +00002230 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002231 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002232 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002233 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002234 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002235 }
2236
2237 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002238 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002239 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002240 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2241 ARM::VLD3q16_UPD,
2242 ARM::VLD3q32_UPD };
2243 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2244 ARM::VLD3q16odd_UPD,
2245 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002246 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002247 }
2248
2249 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002250 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002251 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002252 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2253 ARM::VLD4q16_UPD,
2254 ARM::VLD4q32_UPD };
2255 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2256 ARM::VLD4q16odd_UPD,
2257 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002258 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002259 }
2260
Bob Wilson243fcc52009-09-01 04:26:28 +00002261 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002262 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002263 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2264 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002265 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002266 }
2267
2268 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002269 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002270 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2271 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002272 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002273 }
2274
2275 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002276 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002277 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2278 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002279 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002280 }
2281
Bob Wilson11d98992010-03-23 06:20:33 +00002282 case Intrinsic::arm_neon_vst1: {
2283 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2284 ARM::VST1d32, ARM::VST1d64 };
2285 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2286 ARM::VST1q32, ARM::VST1q64 };
2287 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2288 }
2289
Bob Wilson31fb12f2009-08-26 17:39:53 +00002290 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002291 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002292 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002293 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002294 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002295 }
2296
2297 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002298 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002299 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002300 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2301 ARM::VST3q16_UPD,
2302 ARM::VST3q32_UPD };
2303 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2304 ARM::VST3q16odd_UPD,
2305 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002306 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002307 }
2308
2309 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002310 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002311 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002312 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2313 ARM::VST4q16_UPD,
2314 ARM::VST4q32_UPD };
2315 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2316 ARM::VST4q16odd_UPD,
2317 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002319 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002320
2321 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002322 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002323 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2324 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002325 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002326 }
2327
2328 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002329 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002330 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2331 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002332 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002333 }
2334
2335 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002336 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002337 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2338 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002339 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002340 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002341 }
Bob Wilson429009b2010-05-06 16:05:26 +00002342 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002343 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002344
Bob Wilson429009b2010-05-06 16:05:26 +00002345 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002346 return SelectConcatVector(N);
2347 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002348
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002349 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002350}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002351
Bob Wilson224c2442009-05-19 05:53:42 +00002352bool ARMDAGToDAGISel::
2353SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2354 std::vector<SDValue> &OutOps) {
2355 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002356 // Require the address to be in a register. That is safe for all ARM
2357 // variants and it is hard to do anything much smarter without knowing
2358 // how the operand is used.
2359 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002360 return false;
2361}
2362
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002363/// createARMISelDag - This pass converts a legalized DAG into a
2364/// ARM-specific DAG, ready for instruction scheduling.
2365///
Bob Wilson522ce972009-09-28 14:30:20 +00002366FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2367 CodeGenOpt::Level OptLevel) {
2368 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002369}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002370
2371/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2372/// operations involving sub-registers.
2373bool llvm::ModelWithRegSequence() {
2374 return UseRegSeq;
2375}