blob: 616942c00343cbf0f933e760e076f681f6b41055 [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,
40 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"));
41
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000042//===--------------------------------------------------------------------===//
43/// ARMDAGToDAGISel - ARM specific code to select ARM machine
44/// instructions for SelectionDAG operations.
45///
46namespace {
47class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000048 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000049
Evan Chenga8e29892007-01-19 07:51:42 +000050 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
51 /// make the right decision when generating code for different targets.
52 const ARMSubtarget *Subtarget;
53
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000054public:
Bob Wilson522ce972009-09-28 14:30:20 +000055 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
56 CodeGenOpt::Level OptLevel)
57 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000058 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000059 }
60
Evan Chenga8e29892007-01-19 07:51:42 +000061 virtual const char *getPassName() const {
62 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000063 }
64
Bob Wilsonaf4a8912009-10-08 18:51:31 +000065 /// getI32Imm - Return a target constant of type i32 with the specified
66 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000067 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000068 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000069 }
70
Dan Gohmaneeb3a002010-01-05 01:24:18 +000071 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000072
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000074 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000076 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000084 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000086 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000087 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000088
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000090 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000091
Dan Gohmaneeb3a002010-01-05 01:24:18 +000092 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000093 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &Base, SDValue &OffImm,
96 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000097 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000098 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000099 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000100 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000101 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000102 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000104 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000105
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000106 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000107 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000108 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000109 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000111 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000112 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000113 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000115 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000116 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000117 SDValue &OffReg, SDValue &ShImm);
118
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000119 // Include the pieces autogenerated from the target description.
120#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000121
122private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000123 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
124 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 SDNode *SelectARMIndexedLoad(SDNode *N);
126 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000127
Bob Wilson621f1952010-03-23 05:25:43 +0000128 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
129 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000130 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000131 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000133 unsigned *QOpcodes0, unsigned *QOpcodes1);
134
Bob Wilson24f995d2009-10-14 18:32:29 +0000135 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000136 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000137 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000138 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000140 unsigned *QOpcodes0, unsigned *QOpcodes1);
141
Bob Wilson96493442009-10-14 16:46:45 +0000142 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000143 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000145 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000146 unsigned *DOpcodes, unsigned *QOpcodes0,
147 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000148
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000149 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000150 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000151
Evan Cheng07ba9062009-11-19 21:45:22 +0000152 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000153 SDNode *SelectCMOVOp(SDNode *N);
154 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000155 ARMCC::CondCodes CCVal, SDValue CCR,
156 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000158 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000161 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000163 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000164 ARMCC::CondCodes CCVal, SDValue CCR,
165 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000166
Evan Chengaf4550f2009-07-02 01:23:32 +0000167 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
168 /// inline asm expressions.
169 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
170 char ConstraintCode,
171 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000172
173 /// PairDRegs - Insert a pair of double registers into an implicit def to
174 /// form a quad register.
175 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000176};
Evan Chenga8e29892007-01-19 07:51:42 +0000177}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000178
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000179/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
180/// operand. If so Imm will receive the 32-bit value.
181static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
182 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
183 Imm = cast<ConstantSDNode>(N)->getZExtValue();
184 return true;
185 }
186 return false;
187}
188
189// isInt32Immediate - This method tests to see if a constant operand.
190// If so Imm will receive the 32 bit value.
191static bool isInt32Immediate(SDValue N, unsigned &Imm) {
192 return isInt32Immediate(N.getNode(), Imm);
193}
194
195// isOpcWithIntImmediate - This method tests to see if the node is a specific
196// opcode and that it has a immediate integer right operand.
197// If so Imm will receive the 32 bit value.
198static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
199 return N->getOpcode() == Opc &&
200 isInt32Immediate(N->getOperand(1).getNode(), Imm);
201}
202
203
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000204bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000205 SDValue N,
206 SDValue &BaseReg,
207 SDValue &ShReg,
208 SDValue &Opc) {
209 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
210
211 // Don't match base register only case. That is matched to a separate
212 // lower complexity pattern with explicit register operand.
213 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000214
Evan Cheng055b0312009-06-29 07:51:04 +0000215 BaseReg = N.getOperand(0);
216 unsigned ShImmVal = 0;
217 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000218 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000219 ShImmVal = RHS->getZExtValue() & 31;
220 } else {
221 ShReg = N.getOperand(1);
222 }
223 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000224 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000225 return true;
226}
227
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000228bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000229 SDValue &Base, SDValue &Offset,
230 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000231 if (N.getOpcode() == ISD::MUL) {
232 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
233 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000234 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000235 if (RHSC & 1) {
236 RHSC = RHSC & ~1;
237 ARM_AM::AddrOpc AddSub = ARM_AM::add;
238 if (RHSC < 0) {
239 AddSub = ARM_AM::sub;
240 RHSC = - RHSC;
241 }
242 if (isPowerOf2_32(RHSC)) {
243 unsigned ShAmt = Log2_32(RHSC);
244 Base = Offset = N.getOperand(0);
245 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
246 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000247 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000248 return true;
249 }
250 }
251 }
252 }
253
Evan Chenga8e29892007-01-19 07:51:42 +0000254 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
255 Base = N;
256 if (N.getOpcode() == ISD::FrameIndex) {
257 int FI = cast<FrameIndexSDNode>(N)->getIndex();
258 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000259 } else if (N.getOpcode() == ARMISD::Wrapper &&
260 !(Subtarget->useMovt() &&
261 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000262 Base = N.getOperand(0);
263 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000264 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
266 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000268 return true;
269 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000270
Evan Chenga8e29892007-01-19 07:51:42 +0000271 // Match simple R +/- imm12 operands.
272 if (N.getOpcode() == ISD::ADD)
273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000274 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000275 if ((RHSC >= 0 && RHSC < 0x1000) ||
276 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000277 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000278 if (Base.getOpcode() == ISD::FrameIndex) {
279 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
280 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
281 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000282 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000283
284 ARM_AM::AddrOpc AddSub = ARM_AM::add;
285 if (RHSC < 0) {
286 AddSub = ARM_AM::sub;
287 RHSC = - RHSC;
288 }
289 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000290 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000291 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000292 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000293 }
Evan Chenga8e29892007-01-19 07:51:42 +0000294 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000295
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000296 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000297 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
298 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
299 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000300
Evan Chenga8e29892007-01-19 07:51:42 +0000301 Base = N.getOperand(0);
302 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000303
Evan Chenga8e29892007-01-19 07:51:42 +0000304 if (ShOpcVal != ARM_AM::no_shift) {
305 // Check to see if the RHS of the shift is a constant, if not, we can't fold
306 // it.
307 if (ConstantSDNode *Sh =
308 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000309 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000310 Offset = N.getOperand(1).getOperand(0);
311 } else {
312 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
314 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Evan Chenga8e29892007-01-19 07:51:42 +0000316 // Try matching (R shl C) + (R).
317 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
318 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
319 if (ShOpcVal != ARM_AM::no_shift) {
320 // Check to see if the RHS of the shift is a constant, if not, we can't
321 // fold it.
322 if (ConstantSDNode *Sh =
323 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000324 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000325 Offset = N.getOperand(0).getOperand(0);
326 Base = N.getOperand(1);
327 } else {
328 ShOpcVal = ARM_AM::no_shift;
329 }
330 }
331 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000332
Evan Chenga8e29892007-01-19 07:51:42 +0000333 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000334 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000335 return true;
336}
337
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000338bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000339 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000340 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000341 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
342 ? cast<LoadSDNode>(Op)->getAddressingMode()
343 : cast<StoreSDNode>(Op)->getAddressingMode();
344 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
345 ? ARM_AM::add : ARM_AM::sub;
346 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000347 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000348 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000349 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000350 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
351 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000352 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000353 return true;
354 }
355 }
356
357 Offset = N;
358 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
359 unsigned ShAmt = 0;
360 if (ShOpcVal != ARM_AM::no_shift) {
361 // Check to see if the RHS of the shift is a constant, if not, we can't fold
362 // it.
363 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000364 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000365 Offset = N.getOperand(0);
366 } else {
367 ShOpcVal = ARM_AM::no_shift;
368 }
369 }
370
371 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000372 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000373 return true;
374}
375
Evan Chenga8e29892007-01-19 07:51:42 +0000376
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000377bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000378 SDValue &Base, SDValue &Offset,
379 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000380 if (N.getOpcode() == ISD::SUB) {
381 // X - C is canonicalize to X + -C, no need to handle it here.
382 Base = N.getOperand(0);
383 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000384 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000385 return true;
386 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000387
Evan Chenga8e29892007-01-19 07:51:42 +0000388 if (N.getOpcode() != ISD::ADD) {
389 Base = N;
390 if (N.getOpcode() == ISD::FrameIndex) {
391 int FI = cast<FrameIndexSDNode>(N)->getIndex();
392 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
393 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 Offset = CurDAG->getRegister(0, MVT::i32);
395 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000396 return true;
397 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000398
Evan Chenga8e29892007-01-19 07:51:42 +0000399 // If the RHS is +/- imm8, fold into addr mode.
400 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000401 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000402 if ((RHSC >= 0 && RHSC < 256) ||
403 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000404 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000405 if (Base.getOpcode() == ISD::FrameIndex) {
406 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
407 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
408 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000409 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000410
411 ARM_AM::AddrOpc AddSub = ARM_AM::add;
412 if (RHSC < 0) {
413 AddSub = ARM_AM::sub;
414 RHSC = - RHSC;
415 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000417 return true;
418 }
419 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000420
Evan Chenga8e29892007-01-19 07:51:42 +0000421 Base = N.getOperand(0);
422 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000423 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000424 return true;
425}
426
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000427bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000428 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000429 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000430 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
431 ? cast<LoadSDNode>(Op)->getAddressingMode()
432 : cast<StoreSDNode>(Op)->getAddressingMode();
433 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
434 ? ARM_AM::add : ARM_AM::sub;
435 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000436 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000437 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000438 Offset = CurDAG->getRegister(0, MVT::i32);
439 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000440 return true;
441 }
442 }
443
444 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000445 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000446 return true;
447}
448
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000450 SDValue &Addr, SDValue &Mode) {
451 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000452 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000453 return true;
454}
Evan Chenga8e29892007-01-19 07:51:42 +0000455
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000456bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000457 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000458 if (N.getOpcode() != ISD::ADD) {
459 Base = N;
460 if (N.getOpcode() == ISD::FrameIndex) {
461 int FI = cast<FrameIndexSDNode>(N)->getIndex();
462 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000463 } else if (N.getOpcode() == ARMISD::Wrapper &&
464 !(Subtarget->useMovt() &&
465 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000466 Base = N.getOperand(0);
467 }
468 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000469 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000470 return true;
471 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000472
Evan Chenga8e29892007-01-19 07:51:42 +0000473 // If the RHS is +/- imm8, fold into addr mode.
474 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000475 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000476 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
477 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000478 if ((RHSC >= 0 && RHSC < 256) ||
479 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000480 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000481 if (Base.getOpcode() == ISD::FrameIndex) {
482 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
483 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
484 }
485
486 ARM_AM::AddrOpc AddSub = ARM_AM::add;
487 if (RHSC < 0) {
488 AddSub = ARM_AM::sub;
489 RHSC = - RHSC;
490 }
491 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000492 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000493 return true;
494 }
495 }
496 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000497
Evan Chenga8e29892007-01-19 07:51:42 +0000498 Base = N;
499 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000500 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000501 return true;
502}
503
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000504bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000505 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000506 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000507 // Default to no alignment.
508 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000509 return true;
510}
511
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000512bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000513 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000514 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
515 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000516 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000517 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000518 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000519 return true;
520 }
521 return false;
522}
523
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000524bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000525 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000526 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000527 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000528 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000529 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
530 if (!NC || NC->getZExtValue() != 0)
531 return false;
532
533 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000534 return true;
535 }
536
Evan Chenga8e29892007-01-19 07:51:42 +0000537 Base = N.getOperand(0);
538 Offset = N.getOperand(1);
539 return true;
540}
541
Evan Cheng79d43262007-01-24 02:21:22 +0000542bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000543ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000544 unsigned Scale, SDValue &Base,
545 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000546 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000547 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000548 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
549 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000550 if (N.getOpcode() == ARMISD::Wrapper &&
551 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
552 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000553 }
554
Evan Chenga8e29892007-01-19 07:51:42 +0000555 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000556 if (N.getOpcode() == ARMISD::Wrapper &&
557 !(Subtarget->useMovt() &&
558 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
559 Base = N.getOperand(0);
560 } else
561 Base = N;
562
Owen Anderson825b72b2009-08-11 20:47:22 +0000563 Offset = CurDAG->getRegister(0, MVT::i32);
564 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000565 return true;
566 }
567
Evan Chengad0e4652007-02-06 00:22:06 +0000568 // Thumb does not have [sp, r] address mode.
569 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
570 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
571 if ((LHSR && LHSR->getReg() == ARM::SP) ||
572 (RHSR && RHSR->getReg() == ARM::SP)) {
573 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000574 Offset = CurDAG->getRegister(0, MVT::i32);
575 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000576 return true;
577 }
578
Evan Chenga8e29892007-01-19 07:51:42 +0000579 // If the RHS is + imm5 * scale, fold into addr mode.
580 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000581 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000582 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
583 RHSC /= Scale;
584 if (RHSC >= 0 && RHSC < 32) {
585 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000586 Offset = CurDAG->getRegister(0, MVT::i32);
587 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000588 return true;
589 }
590 }
591 }
592
Evan Chengc38f2bc2007-01-23 22:59:13 +0000593 Base = N.getOperand(0);
594 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000596 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000597}
598
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000599bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000600 SDValue &Base, SDValue &OffImm,
601 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000602 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000603}
604
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000605bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000606 SDValue &Base, SDValue &OffImm,
607 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000608 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000609}
610
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000611bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000612 SDValue &Base, SDValue &OffImm,
613 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000614 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000615}
616
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000617bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000618 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000619 if (N.getOpcode() == ISD::FrameIndex) {
620 int FI = cast<FrameIndexSDNode>(N)->getIndex();
621 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000622 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000623 return true;
624 }
Evan Cheng79d43262007-01-24 02:21:22 +0000625
Evan Chengad0e4652007-02-06 00:22:06 +0000626 if (N.getOpcode() != ISD::ADD)
627 return false;
628
629 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000630 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
631 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000632 // If the RHS is + imm8 * scale, fold into addr mode.
633 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000634 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000635 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
636 RHSC >>= 2;
637 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000638 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000639 if (Base.getOpcode() == ISD::FrameIndex) {
640 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
641 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
642 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000643 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000644 return true;
645 }
646 }
647 }
648 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000649
Evan Chenga8e29892007-01-19 07:51:42 +0000650 return false;
651}
652
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000653bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000654 SDValue &BaseReg,
655 SDValue &Opc) {
656 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
657
658 // Don't match base register only case. That is matched to a separate
659 // lower complexity pattern with explicit register operand.
660 if (ShOpcVal == ARM_AM::no_shift) return false;
661
662 BaseReg = N.getOperand(0);
663 unsigned ShImmVal = 0;
664 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
665 ShImmVal = RHS->getZExtValue() & 31;
666 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
667 return true;
668 }
669
670 return false;
671}
672
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000673bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000674 SDValue &Base, SDValue &OffImm) {
675 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000676
Evan Cheng3a214252009-08-11 08:52:18 +0000677 // Base only.
678 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000679 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000680 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000681 int FI = cast<FrameIndexSDNode>(N)->getIndex();
682 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000683 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000684 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000685 } else if (N.getOpcode() == ARMISD::Wrapper &&
686 !(Subtarget->useMovt() &&
687 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000688 Base = N.getOperand(0);
689 if (Base.getOpcode() == ISD::TargetConstantPool)
690 return false; // We want to select t2LDRpci instead.
691 } else
692 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000693 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000694 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000695 }
Evan Cheng055b0312009-06-29 07:51:04 +0000696
697 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000698 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
699 // Let t2LDRi8 handle (R - imm8).
700 return false;
701
Evan Cheng055b0312009-06-29 07:51:04 +0000702 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000703 if (N.getOpcode() == ISD::SUB)
704 RHSC = -RHSC;
705
706 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000707 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000708 if (Base.getOpcode() == ISD::FrameIndex) {
709 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
710 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
711 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000712 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000713 return true;
714 }
715 }
716
Evan Cheng3a214252009-08-11 08:52:18 +0000717 // Base only.
718 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000719 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000720 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000721}
722
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000723bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000724 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000725 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000726 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000727 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
728 int RHSC = (int)RHS->getSExtValue();
729 if (N.getOpcode() == ISD::SUB)
730 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000731
Evan Cheng3a214252009-08-11 08:52:18 +0000732 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
733 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000734 if (Base.getOpcode() == ISD::FrameIndex) {
735 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
736 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
737 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000738 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000739 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000740 }
Evan Cheng055b0312009-06-29 07:51:04 +0000741 }
742 }
743
744 return false;
745}
746
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000747bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000748 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000749 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000750 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
751 ? cast<LoadSDNode>(Op)->getAddressingMode()
752 : cast<StoreSDNode>(Op)->getAddressingMode();
753 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
754 int RHSC = (int)RHS->getZExtValue();
755 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000756 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000757 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
758 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000759 return true;
760 }
761 }
762
763 return false;
764}
765
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000766bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000767 SDValue &Base, SDValue &OffImm) {
768 if (N.getOpcode() == ISD::ADD) {
769 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
770 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000771 if (((RHSC & 0x3) == 0) &&
772 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000773 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000774 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000775 return true;
776 }
777 }
778 } else if (N.getOpcode() == ISD::SUB) {
779 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
780 int RHSC = (int)RHS->getZExtValue();
781 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
782 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000783 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000784 return true;
785 }
786 }
787 }
788
789 return false;
790}
791
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000792bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000793 SDValue &Base,
794 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000795 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
796 if (N.getOpcode() != ISD::ADD)
797 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000798
Evan Cheng3a214252009-08-11 08:52:18 +0000799 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
800 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
801 int RHSC = (int)RHS->getZExtValue();
802 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
803 return false;
804 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000805 return false;
806 }
807
Evan Cheng055b0312009-06-29 07:51:04 +0000808 // Look for (R + R) or (R + (R << [1,2,3])).
809 unsigned ShAmt = 0;
810 Base = N.getOperand(0);
811 OffReg = N.getOperand(1);
812
813 // Swap if it is ((R << c) + R).
814 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
815 if (ShOpcVal != ARM_AM::lsl) {
816 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
817 if (ShOpcVal == ARM_AM::lsl)
818 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000819 }
820
Evan Cheng055b0312009-06-29 07:51:04 +0000821 if (ShOpcVal == ARM_AM::lsl) {
822 // Check to see if the RHS of the shift is a constant, if not, we can't fold
823 // it.
824 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
825 ShAmt = Sh->getZExtValue();
826 if (ShAmt >= 4) {
827 ShAmt = 0;
828 ShOpcVal = ARM_AM::no_shift;
829 } else
830 OffReg = OffReg.getOperand(0);
831 } else {
832 ShOpcVal = ARM_AM::no_shift;
833 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000834 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000835
Owen Anderson825b72b2009-08-11 20:47:22 +0000836 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000837
838 return true;
839}
840
841//===--------------------------------------------------------------------===//
842
Evan Chengee568cf2007-07-05 07:15:27 +0000843/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000844static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000846}
847
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000848SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
849 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000850 ISD::MemIndexedMode AM = LD->getAddressingMode();
851 if (AM == ISD::UNINDEXED)
852 return NULL;
853
Owen Andersone50ed302009-08-10 22:56:29 +0000854 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000855 SDValue Offset, AMOpc;
856 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
857 unsigned Opcode = 0;
858 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000859 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000860 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000861 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
862 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000864 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 Match = true;
866 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
867 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
868 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000869 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000871 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000872 Match = true;
873 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
874 }
875 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000876 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000877 Match = true;
878 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
879 }
880 }
881 }
882
883 if (Match) {
884 SDValue Chain = LD->getChain();
885 SDValue Base = LD->getBasePtr();
886 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000887 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000888 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000889 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000890 }
891
892 return NULL;
893}
894
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000895SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
896 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000897 ISD::MemIndexedMode AM = LD->getAddressingMode();
898 if (AM == ISD::UNINDEXED)
899 return NULL;
900
Owen Andersone50ed302009-08-10 22:56:29 +0000901 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000902 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000903 SDValue Offset;
904 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
905 unsigned Opcode = 0;
906 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000907 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000908 switch (LoadedVT.getSimpleVT().SimpleTy) {
909 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000910 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
911 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000912 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000913 if (isSExtLd)
914 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
915 else
916 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000917 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000918 case MVT::i8:
919 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000920 if (isSExtLd)
921 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
922 else
923 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000924 break;
925 default:
926 return NULL;
927 }
928 Match = true;
929 }
930
931 if (Match) {
932 SDValue Chain = LD->getChain();
933 SDValue Base = LD->getBasePtr();
934 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000935 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000936 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000937 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000938 }
939
940 return NULL;
941}
942
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000943/// PairDRegs - Insert a pair of double registers into an implicit def to
944/// form a quad register.
945SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
946 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000947 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
948 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Cheng94cc6d32010-05-04 20:39:49 +0000949 if (UseRegSeq) {
950 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
951 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
952 }
953 SDValue Undef =
954 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000955 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000956 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000957 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000958 VT, SDValue(Pair, 0), V1, SubReg1);
959}
960
Bob Wilsona7c397c2009-10-14 16:19:03 +0000961/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
962/// for a 64-bit subregister of the vector.
963static EVT GetNEONSubregVT(EVT VT) {
964 switch (VT.getSimpleVT().SimpleTy) {
965 default: llvm_unreachable("unhandled NEON type");
966 case MVT::v16i8: return MVT::v8i8;
967 case MVT::v8i16: return MVT::v4i16;
968 case MVT::v4f32: return MVT::v2f32;
969 case MVT::v4i32: return MVT::v2i32;
970 case MVT::v2i64: return MVT::v1i64;
971 }
972}
973
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000974SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +0000975 unsigned *DOpcodes, unsigned *QOpcodes0,
976 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +0000977 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +0000978 DebugLoc dl = N->getDebugLoc();
979
Bob Wilson226036e2010-03-20 22:13:40 +0000980 SDValue MemAddr, Align;
981 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +0000982 return NULL;
983
984 SDValue Chain = N->getOperand(0);
985 EVT VT = N->getValueType(0);
986 bool is64BitVector = VT.is64BitVector();
987
988 unsigned OpcodeIndex;
989 switch (VT.getSimpleVT().SimpleTy) {
990 default: llvm_unreachable("unhandled vld type");
991 // Double-register operations:
992 case MVT::v8i8: OpcodeIndex = 0; break;
993 case MVT::v4i16: OpcodeIndex = 1; break;
994 case MVT::v2f32:
995 case MVT::v2i32: OpcodeIndex = 2; break;
996 case MVT::v1i64: OpcodeIndex = 3; break;
997 // Quad-register operations:
998 case MVT::v16i8: OpcodeIndex = 0; break;
999 case MVT::v8i16: OpcodeIndex = 1; break;
1000 case MVT::v4f32:
1001 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001002 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001003 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001004 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001005 }
1006
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001007 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001008 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001009 if (is64BitVector) {
1010 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001011 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001012 std::vector<EVT> ResTys(NumVecs, VT);
1013 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001014 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson3e36f132009-10-14 17:28:52 +00001015 }
1016
1017 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001018 if (NumVecs <= 2) {
1019 // Quad registers are directly supported for VLD1 and VLD2,
1020 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001021 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001022 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001023 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001024 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001025 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001026 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001027
1028 // Combine the even and odd subregs to produce the result.
1029 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1030 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1031 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1032 }
1033 } else {
1034 // Otherwise, quad registers are loaded with two separate instructions,
1035 // where one loads the even registers and the other loads the odd registers.
1036
Bob Wilson3e36f132009-10-14 17:28:52 +00001037 std::vector<EVT> ResTys(NumVecs, RegVT);
1038 ResTys.push_back(MemAddr.getValueType());
1039 ResTys.push_back(MVT::Other);
1040
Bob Wilson24f995d2009-10-14 18:32:29 +00001041 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001042 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001043 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1044 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001045 Chain = SDValue(VLdA, NumVecs+1);
1046
Bob Wilson24f995d2009-10-14 18:32:29 +00001047 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001048 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001049 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1050 Align, Reg0, Pred, Reg0, Chain };
1051 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001052 Chain = SDValue(VLdB, NumVecs+1);
1053
1054 // Combine the even and odd subregs to produce the result.
1055 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1056 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1057 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1058 }
1059 }
1060 ReplaceUses(SDValue(N, NumVecs), Chain);
1061 return NULL;
1062}
1063
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001064SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001065 unsigned *DOpcodes, unsigned *QOpcodes0,
1066 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001067 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001068 DebugLoc dl = N->getDebugLoc();
1069
Bob Wilson226036e2010-03-20 22:13:40 +00001070 SDValue MemAddr, Align;
1071 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001072 return NULL;
1073
1074 SDValue Chain = N->getOperand(0);
1075 EVT VT = N->getOperand(3).getValueType();
1076 bool is64BitVector = VT.is64BitVector();
1077
1078 unsigned OpcodeIndex;
1079 switch (VT.getSimpleVT().SimpleTy) {
1080 default: llvm_unreachable("unhandled vst type");
1081 // Double-register operations:
1082 case MVT::v8i8: OpcodeIndex = 0; break;
1083 case MVT::v4i16: OpcodeIndex = 1; break;
1084 case MVT::v2f32:
1085 case MVT::v2i32: OpcodeIndex = 2; break;
1086 case MVT::v1i64: OpcodeIndex = 3; break;
1087 // Quad-register operations:
1088 case MVT::v16i8: OpcodeIndex = 0; break;
1089 case MVT::v8i16: OpcodeIndex = 1; break;
1090 case MVT::v4f32:
1091 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001092 case MVT::v2i64: OpcodeIndex = 3;
1093 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1094 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001095 }
1096
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001097 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001098 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001099
Bob Wilson226036e2010-03-20 22:13:40 +00001100 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001101 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001102 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001103
1104 if (is64BitVector) {
1105 unsigned Opc = DOpcodes[OpcodeIndex];
1106 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1107 Ops.push_back(N->getOperand(Vec+3));
Evan Chengac0869d2009-11-21 06:21:52 +00001108 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001109 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001110 Ops.push_back(Chain);
Bob Wilson226036e2010-03-20 22:13:40 +00001111 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001112 }
1113
1114 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001115 if (NumVecs <= 2) {
1116 // Quad registers are directly supported for VST1 and VST2,
1117 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001118 unsigned Opc = QOpcodes0[OpcodeIndex];
1119 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1120 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1121 N->getOperand(Vec+3)));
1122 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1123 N->getOperand(Vec+3)));
1124 }
Evan Chengac0869d2009-11-21 06:21:52 +00001125 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001126 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001127 Ops.push_back(Chain);
Bob Wilson11d98992010-03-23 06:20:33 +00001128 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1129 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001130 }
1131
1132 // Otherwise, quad registers are stored with two separate instructions,
1133 // where one stores the even registers and the other stores the odd registers.
1134
Bob Wilson226036e2010-03-20 22:13:40 +00001135 Ops.push_back(Reg0); // post-access address offset
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001136
Bob Wilson24f995d2009-10-14 18:32:29 +00001137 // Store the even subregs.
1138 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1139 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1140 N->getOperand(Vec+3)));
Evan Chengac0869d2009-11-21 06:21:52 +00001141 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001142 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001143 Ops.push_back(Chain);
1144 unsigned Opc = QOpcodes0[OpcodeIndex];
1145 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001146 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001147 Chain = SDValue(VStA, 1);
1148
1149 // Store the odd subregs.
1150 Ops[0] = SDValue(VStA, 0); // MemAddr
1151 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Bob Wilson226036e2010-03-20 22:13:40 +00001152 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Bob Wilson24f995d2009-10-14 18:32:29 +00001153 N->getOperand(Vec+3));
Bob Wilson226036e2010-03-20 22:13:40 +00001154 Ops[NumVecs+5] = Chain;
Bob Wilson24f995d2009-10-14 18:32:29 +00001155 Opc = QOpcodes1[OpcodeIndex];
1156 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson226036e2010-03-20 22:13:40 +00001157 MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001158 Chain = SDValue(VStB, 1);
1159 ReplaceUses(SDValue(N, 0), Chain);
1160 return NULL;
1161}
1162
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001163SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001164 unsigned NumVecs, unsigned *DOpcodes,
1165 unsigned *QOpcodes0,
1166 unsigned *QOpcodes1) {
1167 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001168 DebugLoc dl = N->getDebugLoc();
1169
Bob Wilson226036e2010-03-20 22:13:40 +00001170 SDValue MemAddr, Align;
1171 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001172 return NULL;
1173
1174 SDValue Chain = N->getOperand(0);
1175 unsigned Lane =
1176 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001177 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001178 bool is64BitVector = VT.is64BitVector();
1179
Bob Wilson96493442009-10-14 16:46:45 +00001180 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001181 unsigned NumElts = 0;
1182 int SubregIdx = 0;
1183 EVT RegVT = VT;
1184 if (!is64BitVector) {
1185 RegVT = GetNEONSubregVT(VT);
1186 NumElts = RegVT.getVectorNumElements();
1187 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1188 }
1189
1190 unsigned OpcodeIndex;
1191 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001192 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001193 // Double-register operations:
1194 case MVT::v8i8: OpcodeIndex = 0; break;
1195 case MVT::v4i16: OpcodeIndex = 1; break;
1196 case MVT::v2f32:
1197 case MVT::v2i32: OpcodeIndex = 2; break;
1198 // Quad-register operations:
1199 case MVT::v8i16: OpcodeIndex = 0; break;
1200 case MVT::v4f32:
1201 case MVT::v4i32: OpcodeIndex = 1; break;
1202 }
1203
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001204 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001205 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001206
Bob Wilson226036e2010-03-20 22:13:40 +00001207 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001208 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001209 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001210
1211 unsigned Opc = 0;
1212 if (is64BitVector) {
1213 Opc = DOpcodes[OpcodeIndex];
1214 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1215 Ops.push_back(N->getOperand(Vec+3));
1216 } else {
1217 // Check if this is loading the even or odd subreg of a Q register.
1218 if (Lane < NumElts) {
1219 Opc = QOpcodes0[OpcodeIndex];
1220 } else {
1221 Lane -= NumElts;
1222 Opc = QOpcodes1[OpcodeIndex];
1223 }
1224 // Extract the subregs of the input vector.
1225 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1226 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1227 N->getOperand(Vec+3)));
1228 }
1229 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001230 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001231 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001232 Ops.push_back(Chain);
1233
Bob Wilson96493442009-10-14 16:46:45 +00001234 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001235 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001236
Bob Wilsona7c397c2009-10-14 16:19:03 +00001237 std::vector<EVT> ResTys(NumVecs, RegVT);
1238 ResTys.push_back(MVT::Other);
1239 SDNode *VLdLn =
Bob Wilson226036e2010-03-20 22:13:40 +00001240 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), NumVecs+6);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001241 // For a 64-bit vector load to D registers, nothing more needs to be done.
1242 if (is64BitVector)
1243 return VLdLn;
1244
1245 // For 128-bit vectors, take the 64-bit results of the load and insert them
1246 // as subregs into the result.
1247 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1248 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1249 N->getOperand(Vec+3),
1250 SDValue(VLdLn, Vec));
1251 ReplaceUses(SDValue(N, Vec), QuadVec);
1252 }
1253
1254 Chain = SDValue(VLdLn, NumVecs);
1255 ReplaceUses(SDValue(N, NumVecs), Chain);
1256 return NULL;
1257}
1258
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001259SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001260 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001261 if (!Subtarget->hasV6T2Ops())
1262 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001263
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001264 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1265 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1266
1267
1268 // For unsigned extracts, check for a shift right and mask
1269 unsigned And_imm = 0;
1270 if (N->getOpcode() == ISD::AND) {
1271 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1272
1273 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1274 if (And_imm & (And_imm + 1))
1275 return NULL;
1276
1277 unsigned Srl_imm = 0;
1278 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1279 Srl_imm)) {
1280 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1281
1282 unsigned Width = CountTrailingOnes_32(And_imm);
1283 unsigned LSB = Srl_imm;
1284 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1285 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1286 CurDAG->getTargetConstant(LSB, MVT::i32),
1287 CurDAG->getTargetConstant(Width, MVT::i32),
1288 getAL(CurDAG), Reg0 };
1289 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1290 }
1291 }
1292 return NULL;
1293 }
1294
1295 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001296 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001297 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001298 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1299 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001300 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001301 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1302 unsigned Width = 32 - Srl_imm;
1303 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001304 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001305 return NULL;
1306 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001307 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001308 CurDAG->getTargetConstant(LSB, MVT::i32),
1309 CurDAG->getTargetConstant(Width, MVT::i32),
1310 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001311 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001312 }
1313 }
1314 return NULL;
1315}
1316
Evan Cheng9ef48352009-11-20 00:54:03 +00001317SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001318SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001319 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1320 SDValue CPTmp0;
1321 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001322 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001323 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1324 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1325 unsigned Opc = 0;
1326 switch (SOShOp) {
1327 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1328 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1329 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1330 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1331 default:
1332 llvm_unreachable("Unknown so_reg opcode!");
1333 break;
1334 }
1335 SDValue SOShImm =
1336 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1337 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1338 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001339 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001340 }
1341 return 0;
1342}
1343
1344SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001345SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001346 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1347 SDValue CPTmp0;
1348 SDValue CPTmp1;
1349 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001350 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001351 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1352 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001353 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001354 }
1355 return 0;
1356}
1357
1358SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001359SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001360 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1361 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1362 if (!T)
1363 return 0;
1364
1365 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1366 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1367 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1368 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001369 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001370 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1371 }
1372 return 0;
1373}
1374
1375SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001376SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001377 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1378 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1379 if (!T)
1380 return 0;
1381
1382 if (Predicate_so_imm(TrueVal.getNode())) {
1383 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1384 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1385 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001386 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001387 ARM::MOVCCi, MVT::i32, Ops, 5);
1388 }
1389 return 0;
1390}
1391
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001392SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1393 EVT VT = N->getValueType(0);
1394 SDValue FalseVal = N->getOperand(0);
1395 SDValue TrueVal = N->getOperand(1);
1396 SDValue CC = N->getOperand(2);
1397 SDValue CCR = N->getOperand(3);
1398 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001399 assert(CC.getOpcode() == ISD::Constant);
1400 assert(CCR.getOpcode() == ISD::Register);
1401 ARMCC::CondCodes CCVal =
1402 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001403
1404 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1405 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1406 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1407 // Pattern complexity = 18 cost = 1 size = 0
1408 SDValue CPTmp0;
1409 SDValue CPTmp1;
1410 SDValue CPTmp2;
1411 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001412 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001413 CCVal, CCR, InFlag);
1414 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001415 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001416 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1417 if (Res)
1418 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001419 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001420 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001421 CCVal, CCR, InFlag);
1422 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001423 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001424 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1425 if (Res)
1426 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001427 }
1428
1429 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1430 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1431 // (imm:i32):$cc)
1432 // Emits: (MOVCCi:i32 GPR:i32:$false,
1433 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1434 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001435 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001436 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001437 CCVal, CCR, InFlag);
1438 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001439 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001440 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1441 if (Res)
1442 return Res;
1443 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001444 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001445 CCVal, CCR, InFlag);
1446 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001447 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001448 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1449 if (Res)
1450 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001451 }
1452 }
1453
1454 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1455 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1456 // Pattern complexity = 6 cost = 1 size = 0
1457 //
1458 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1459 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1460 // Pattern complexity = 6 cost = 11 size = 0
1461 //
1462 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001463 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1464 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001465 unsigned Opc = 0;
1466 switch (VT.getSimpleVT().SimpleTy) {
1467 default: assert(false && "Illegal conditional move type!");
1468 break;
1469 case MVT::i32:
1470 Opc = Subtarget->isThumb()
1471 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1472 : ARM::MOVCCr;
1473 break;
1474 case MVT::f32:
1475 Opc = ARM::VMOVScc;
1476 break;
1477 case MVT::f64:
1478 Opc = ARM::VMOVDcc;
1479 break;
1480 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001481 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001482}
1483
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001484SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001485 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001486
Dan Gohmane8be6c62008-07-17 19:10:17 +00001487 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001488 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001489
1490 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001491 default: break;
1492 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001493 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001494 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001495 if (Subtarget->hasThumb2())
1496 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1497 // be done with MOV + MOVT, at worst.
1498 UseCP = 0;
1499 else {
1500 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001501 UseCP = (Val > 255 && // MOV
1502 ~Val > 255 && // MOV + MVN
1503 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001504 } else
1505 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1506 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1507 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1508 }
1509
Evan Chenga8e29892007-01-19 07:51:42 +00001510 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001511 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001512 CurDAG->getTargetConstantPool(ConstantInt::get(
1513 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001514 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001515
1516 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001517 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001518 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001519 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001520 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001521 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1522 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001523 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001524 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001525 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001526 CurDAG->getRegister(0, MVT::i32),
1527 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001528 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001529 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001530 CurDAG->getEntryNode()
1531 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001532 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1533 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001534 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001535 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001536 return NULL;
1537 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001538
Evan Chenga8e29892007-01-19 07:51:42 +00001539 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001540 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001541 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001542 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001543 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001544 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001545 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001546 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001547 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1548 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001549 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001550 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1551 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001552 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1553 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1554 CurDAG->getRegister(0, MVT::i32) };
1555 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001556 }
Evan Chenga8e29892007-01-19 07:51:42 +00001557 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001558 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001559 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001560 return I;
1561 break;
1562 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001563 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001564 return I;
1565 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001566 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001567 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001568 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001569 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001570 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001571 if (!RHSV) break;
1572 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001573 unsigned ShImm = Log2_32(RHSV-1);
1574 if (ShImm >= 32)
1575 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001576 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001577 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001578 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1579 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001580 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001581 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001582 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001583 } else {
1584 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001585 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001586 }
Evan Chenga8e29892007-01-19 07:51:42 +00001587 }
1588 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001589 unsigned ShImm = Log2_32(RHSV+1);
1590 if (ShImm >= 32)
1591 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001592 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001593 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001594 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1595 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001596 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001597 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001598 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001599 } else {
1600 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001601 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001602 }
Evan Chenga8e29892007-01-19 07:51:42 +00001603 }
1604 }
1605 break;
Evan Cheng20956592009-10-21 08:15:52 +00001606 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001607 // Check for unsigned bitfield extract
1608 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1609 return I;
1610
Evan Cheng20956592009-10-21 08:15:52 +00001611 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1612 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1613 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1614 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1615 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001616 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001617 if (VT != MVT::i32)
1618 break;
1619 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1620 ? ARM::t2MOVTi16
1621 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1622 if (!Opc)
1623 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001624 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001625 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1626 if (!N1C)
1627 break;
1628 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1629 SDValue N2 = N0.getOperand(1);
1630 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1631 if (!N2C)
1632 break;
1633 unsigned N1CVal = N1C->getZExtValue();
1634 unsigned N2CVal = N2C->getZExtValue();
1635 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1636 (N1CVal & 0xffffU) == 0xffffU &&
1637 (N2CVal & 0xffffU) == 0x0U) {
1638 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1639 MVT::i32);
1640 SDValue Ops[] = { N0.getOperand(0), Imm16,
1641 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1642 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1643 }
1644 }
1645 break;
1646 }
Jim Grosbache5165492009-11-09 00:11:35 +00001647 case ARMISD::VMOVRRD:
1648 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001649 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001650 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001651 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001652 if (Subtarget->isThumb1Only())
1653 break;
1654 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001655 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001656 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1657 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001658 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001659 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001660 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001661 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1662 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001663 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001664 }
Evan Chengee568cf2007-07-05 07:15:27 +00001665 }
Dan Gohman525178c2007-10-08 18:33:35 +00001666 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001667 if (Subtarget->isThumb1Only())
1668 break;
1669 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001670 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001671 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001672 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001673 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001674 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001675 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1676 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001677 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001678 }
Evan Chengee568cf2007-07-05 07:15:27 +00001679 }
Evan Chenga8e29892007-01-19 07:51:42 +00001680 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001681 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001682 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001683 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001684 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001685 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001686 if (ResNode)
1687 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001688
1689 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1690 if (Subtarget->hasVFP2() &&
1691 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1692 SDValue Chain = N->getOperand(0);
1693 SDValue AM5Opc =
1694 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001695 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001696 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1697 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
1698 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
1699 Ops, 5);
1700 }
1701 // Other cases are autogenerated.
1702 break;
1703 }
1704 case ISD::STORE: {
1705 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1706 if (Subtarget->hasVFP2() &&
1707 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1708 SDValue Chain = N->getOperand(0);
1709 SDValue AM5Opc =
1710 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001711 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001712 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1713 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
1714 AM5Opc, Pred, PredReg, Chain };
1715 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
1716 }
Evan Chenga8e29892007-01-19 07:51:42 +00001717 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001718 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001719 }
Evan Chengee568cf2007-07-05 07:15:27 +00001720 case ARMISD::BRCOND: {
1721 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1722 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1723 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001724
Evan Chengee568cf2007-07-05 07:15:27 +00001725 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1726 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1727 // Pattern complexity = 6 cost = 1 size = 0
1728
David Goodwin5e47a9a2009-06-30 18:04:13 +00001729 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1730 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1731 // Pattern complexity = 6 cost = 1 size = 0
1732
Jim Grosbach764ab522009-08-11 15:33:49 +00001733 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001734 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001735 SDValue Chain = N->getOperand(0);
1736 SDValue N1 = N->getOperand(1);
1737 SDValue N2 = N->getOperand(2);
1738 SDValue N3 = N->getOperand(3);
1739 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001740 assert(N1.getOpcode() == ISD::BasicBlock);
1741 assert(N2.getOpcode() == ISD::Constant);
1742 assert(N3.getOpcode() == ISD::Register);
1743
Dan Gohman475871a2008-07-27 21:46:04 +00001744 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001745 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001746 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001747 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001748 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1749 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001750 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001751 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001752 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001753 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001754 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001755 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001756 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001757 return NULL;
1758 }
Evan Cheng07ba9062009-11-19 21:45:22 +00001759 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00001761 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001762 EVT VT = N->getValueType(0);
1763 SDValue N0 = N->getOperand(0);
1764 SDValue N1 = N->getOperand(1);
1765 SDValue N2 = N->getOperand(2);
1766 SDValue N3 = N->getOperand(3);
1767 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001768 assert(N2.getOpcode() == ISD::Constant);
1769 assert(N3.getOpcode() == ISD::Register);
1770
Dan Gohman475871a2008-07-27 21:46:04 +00001771 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001772 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001773 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001774 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00001775 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00001776 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00001777 default: assert(false && "Illegal conditional move type!");
1778 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001779 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00001780 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00001781 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001782 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00001783 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00001784 break;
Evan Chengee568cf2007-07-05 07:15:27 +00001785 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001786 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001787 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001788
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001789 case ARMISD::VZIP: {
1790 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001791 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001792 switch (VT.getSimpleVT().SimpleTy) {
1793 default: return NULL;
1794 case MVT::v8i8: Opc = ARM::VZIPd8; break;
1795 case MVT::v4i16: Opc = ARM::VZIPd16; break;
1796 case MVT::v2f32:
1797 case MVT::v2i32: Opc = ARM::VZIPd32; break;
1798 case MVT::v16i8: Opc = ARM::VZIPq8; break;
1799 case MVT::v8i16: Opc = ARM::VZIPq16; break;
1800 case MVT::v4f32:
1801 case MVT::v4i32: Opc = ARM::VZIPq32; break;
1802 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001803 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001804 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1805 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1806 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001807 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001808 case ARMISD::VUZP: {
1809 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001810 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001811 switch (VT.getSimpleVT().SimpleTy) {
1812 default: return NULL;
1813 case MVT::v8i8: Opc = ARM::VUZPd8; break;
1814 case MVT::v4i16: Opc = ARM::VUZPd16; break;
1815 case MVT::v2f32:
1816 case MVT::v2i32: Opc = ARM::VUZPd32; break;
1817 case MVT::v16i8: Opc = ARM::VUZPq8; break;
1818 case MVT::v8i16: Opc = ARM::VUZPq16; break;
1819 case MVT::v4f32:
1820 case MVT::v4i32: Opc = ARM::VUZPq32; break;
1821 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001822 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001823 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1824 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1825 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001826 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001827 case ARMISD::VTRN: {
1828 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001829 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00001830 switch (VT.getSimpleVT().SimpleTy) {
1831 default: return NULL;
1832 case MVT::v8i8: Opc = ARM::VTRNd8; break;
1833 case MVT::v4i16: Opc = ARM::VTRNd16; break;
1834 case MVT::v2f32:
1835 case MVT::v2i32: Opc = ARM::VTRNd32; break;
1836 case MVT::v16i8: Opc = ARM::VTRNq8; break;
1837 case MVT::v8i16: Opc = ARM::VTRNq16; break;
1838 case MVT::v4f32:
1839 case MVT::v4i32: Opc = ARM::VTRNq32; break;
1840 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001841 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00001842 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1843 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
1844 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00001845 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001846
1847 case ISD::INTRINSIC_VOID:
1848 case ISD::INTRINSIC_W_CHAIN: {
1849 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00001850 switch (IntNo) {
1851 default:
1852 break;
1853
Bob Wilson621f1952010-03-23 05:25:43 +00001854 case Intrinsic::arm_neon_vld1: {
1855 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
1856 ARM::VLD1d32, ARM::VLD1d64 };
1857 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
1858 ARM::VLD1q32, ARM::VLD1q64 };
1859 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
1860 }
1861
Bob Wilson31fb12f2009-08-26 17:39:53 +00001862 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001863 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00001864 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00001865 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001866 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001867 }
1868
1869 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001870 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001871 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001872 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
1873 ARM::VLD3q16_UPD,
1874 ARM::VLD3q32_UPD };
1875 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
1876 ARM::VLD3q16odd_UPD,
1877 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001878 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001879 }
1880
1881 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00001882 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001883 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001884 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
1885 ARM::VLD4q16_UPD,
1886 ARM::VLD4q32_UPD };
1887 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
1888 ARM::VLD4q16odd_UPD,
1889 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001890 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001891 }
1892
Bob Wilson243fcc52009-09-01 04:26:28 +00001893 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001894 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001895 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
1896 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001897 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001898 }
1899
1900 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001901 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001902 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
1903 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001904 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001905 }
1906
1907 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00001908 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001909 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
1910 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001911 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00001912 }
1913
Bob Wilson11d98992010-03-23 06:20:33 +00001914 case Intrinsic::arm_neon_vst1: {
1915 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
1916 ARM::VST1d32, ARM::VST1d64 };
1917 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
1918 ARM::VST1q32, ARM::VST1q64 };
1919 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
1920 }
1921
Bob Wilson31fb12f2009-08-26 17:39:53 +00001922 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001923 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00001924 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00001925 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001926 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001927 }
1928
1929 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001930 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001931 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001932 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
1933 ARM::VST3q16_UPD,
1934 ARM::VST3q32_UPD };
1935 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
1936 ARM::VST3q16odd_UPD,
1937 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001938 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001939 }
1940
1941 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00001942 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00001943 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001944 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
1945 ARM::VST4q16_UPD,
1946 ARM::VST4q32_UPD };
1947 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
1948 ARM::VST4q16odd_UPD,
1949 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001950 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00001951 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00001952
1953 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001954 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001955 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
1956 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001957 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001958 }
1959
1960 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001961 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001962 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
1963 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001965 }
1966
1967 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00001968 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00001969 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
1970 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00001972 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00001973 }
1974 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00001975 }
1976
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001977 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00001978}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001979
Bob Wilson224c2442009-05-19 05:53:42 +00001980bool ARMDAGToDAGISel::
1981SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1982 std::vector<SDValue> &OutOps) {
1983 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00001984 // Require the address to be in a register. That is safe for all ARM
1985 // variants and it is hard to do anything much smarter without knowing
1986 // how the operand is used.
1987 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00001988 return false;
1989}
1990
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001991/// createARMISelDag - This pass converts a legalized DAG into a
1992/// ARM-specific DAG, ready for instruction scheduling.
1993///
Bob Wilson522ce972009-09-28 14:30:20 +00001994FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
1995 CodeGenOpt::Level OptLevel) {
1996 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001997}