blob: 21474bdb4159be7b7350bc28b5ef85fe24f08a77 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000017#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000022#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000029#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
35
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036using namespace llvm;
37
Evan Cheng94cc6d32010-05-04 20:39:49 +000038static cl::opt<bool>
39UseRegSeq("neon-reg-sequence", cl::Hidden,
Evan Cheng62061242010-05-17 19:51:20 +000040 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"),
41 cl::init(true));
Evan Cheng94cc6d32010-05-04 20:39:49 +000042
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000043//===--------------------------------------------------------------------===//
44/// ARMDAGToDAGISel - ARM specific code to select ARM machine
45/// instructions for SelectionDAG operations.
46///
47namespace {
48class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000049 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000050
Evan Chenga8e29892007-01-19 07:51:42 +000051 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
52 /// make the right decision when generating code for different targets.
53 const ARMSubtarget *Subtarget;
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055public:
Bob Wilson522ce972009-09-28 14:30:20 +000056 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
57 CodeGenOpt::Level OptLevel)
58 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000059 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000060 }
61
Evan Chenga8e29892007-01-19 07:51:42 +000062 virtual const char *getPassName() const {
63 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000064 }
65
Bob Wilsonaf4a8912009-10-08 18:51:31 +000066 /// getI32Imm - Return a target constant of type i32 with the specified
67 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000068 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000069 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000070 }
71
Dan Gohmaneeb3a002010-01-05 01:24:18 +000072 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000073
Dan Gohmaneeb3a002010-01-05 01:24:18 +000074 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000075 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000076 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000078 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000079 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000080 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000081 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000082 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000083 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000084 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000085 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000087 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000088 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000089
Dan Gohmaneeb3a002010-01-05 01:24:18 +000090 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000091 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000092
Dan Gohmaneeb3a002010-01-05 01:24:18 +000093 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000094 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000095 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000096 SDValue &Base, SDValue &OffImm,
97 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000103 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000104 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000105 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000106
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000108 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000114 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000115 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000116 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000117 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000118 SDValue &OffReg, SDValue &ShImm);
119
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000120 // Include the pieces autogenerated from the target description.
121#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000122
123private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
125 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000126 SDNode *SelectARMIndexedLoad(SDNode *N);
127 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000128
Bob Wilson621f1952010-03-23 05:25:43 +0000129 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
130 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000131 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000132 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000133 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000134 unsigned *QOpcodes0, unsigned *QOpcodes1);
135
Bob Wilson24f995d2009-10-14 18:32:29 +0000136 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000137 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000138 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000139 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000141 unsigned *QOpcodes0, unsigned *QOpcodes1);
142
Bob Wilson96493442009-10-14 16:46:45 +0000143 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000144 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000145 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000146 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000147 unsigned *DOpcodes, unsigned *QOpcodes0,
148 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000149
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000150 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000151 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000152
Evan Cheng07ba9062009-11-19 21:45:22 +0000153 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000154 SDNode *SelectCMOVOp(SDNode *N);
155 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000156 ARMCC::CondCodes CCVal, SDValue CCR,
157 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000158 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000159 ARMCC::CondCodes CCVal, SDValue CCR,
160 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000162 ARMCC::CondCodes CCVal, SDValue CCR,
163 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000164 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000165 ARMCC::CondCodes CCVal, SDValue CCR,
166 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000167
Evan Chengde8aa4e2010-05-05 18:28:36 +0000168 SDNode *SelectConcatVector(SDNode *N);
169
Evan Chengaf4550f2009-07-02 01:23:32 +0000170 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
171 /// inline asm expressions.
172 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
173 char ConstraintCode,
174 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000175
Evan Cheng603afbf2010-05-10 17:34:18 +0000176 /// PairDRegs - Form a quad register from a pair of D registers.
177 ///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000178 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000179
180 /// PairDRegs - Form a quad register pair from a pair of Q registers.
181 ///
182 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
183
184 /// QuadDRegs - Form a quad register pair from a quad of D registers.
185 ///
186 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng5c6aba22010-05-14 18:54:59 +0000187
Evan Cheng8f6de382010-05-16 03:27:48 +0000188 /// QuadQRegs - Form 4 consecutive Q registers.
189 ///
190 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
191
Evan Cheng5c6aba22010-05-14 18:54:59 +0000192 /// OctoDRegs - Form 8 consecutive D registers.
193 ///
194 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
195 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000196};
Evan Chenga8e29892007-01-19 07:51:42 +0000197}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000198
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000199/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
200/// operand. If so Imm will receive the 32-bit value.
201static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
202 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
203 Imm = cast<ConstantSDNode>(N)->getZExtValue();
204 return true;
205 }
206 return false;
207}
208
209// isInt32Immediate - This method tests to see if a constant operand.
210// If so Imm will receive the 32 bit value.
211static bool isInt32Immediate(SDValue N, unsigned &Imm) {
212 return isInt32Immediate(N.getNode(), Imm);
213}
214
215// isOpcWithIntImmediate - This method tests to see if the node is a specific
216// opcode and that it has a immediate integer right operand.
217// If so Imm will receive the 32 bit value.
218static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
219 return N->getOpcode() == Opc &&
220 isInt32Immediate(N->getOperand(1).getNode(), Imm);
221}
222
223
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000224bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000225 SDValue N,
226 SDValue &BaseReg,
227 SDValue &ShReg,
228 SDValue &Opc) {
229 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
230
231 // Don't match base register only case. That is matched to a separate
232 // lower complexity pattern with explicit register operand.
233 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000234
Evan Cheng055b0312009-06-29 07:51:04 +0000235 BaseReg = N.getOperand(0);
236 unsigned ShImmVal = 0;
237 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000238 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000239 ShImmVal = RHS->getZExtValue() & 31;
240 } else {
241 ShReg = N.getOperand(1);
242 }
243 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000244 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000245 return true;
246}
247
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000248bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000249 SDValue &Base, SDValue &Offset,
250 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000251 if (N.getOpcode() == ISD::MUL) {
252 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
253 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000254 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000255 if (RHSC & 1) {
256 RHSC = RHSC & ~1;
257 ARM_AM::AddrOpc AddSub = ARM_AM::add;
258 if (RHSC < 0) {
259 AddSub = ARM_AM::sub;
260 RHSC = - RHSC;
261 }
262 if (isPowerOf2_32(RHSC)) {
263 unsigned ShAmt = Log2_32(RHSC);
264 Base = Offset = N.getOperand(0);
265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
266 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000268 return true;
269 }
270 }
271 }
272 }
273
Evan Chenga8e29892007-01-19 07:51:42 +0000274 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
275 Base = N;
276 if (N.getOpcode() == ISD::FrameIndex) {
277 int FI = cast<FrameIndexSDNode>(N)->getIndex();
278 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000279 } else if (N.getOpcode() == ARMISD::Wrapper &&
280 !(Subtarget->useMovt() &&
281 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000282 Base = N.getOperand(0);
283 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000284 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000285 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
286 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000287 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000288 return true;
289 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000290
Evan Chenga8e29892007-01-19 07:51:42 +0000291 // Match simple R +/- imm12 operands.
292 if (N.getOpcode() == ISD::ADD)
293 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000294 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000295 if ((RHSC >= 0 && RHSC < 0x1000) ||
296 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000297 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000298 if (Base.getOpcode() == ISD::FrameIndex) {
299 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
300 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
301 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000302 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000303
304 ARM_AM::AddrOpc AddSub = ARM_AM::add;
305 if (RHSC < 0) {
306 AddSub = ARM_AM::sub;
307 RHSC = - RHSC;
308 }
309 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000310 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000311 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000312 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
Evan Chenga8e29892007-01-19 07:51:42 +0000314 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000316 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000317 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
318 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
319 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000320
Evan Chenga8e29892007-01-19 07:51:42 +0000321 Base = N.getOperand(0);
322 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000323
Evan Chenga8e29892007-01-19 07:51:42 +0000324 if (ShOpcVal != ARM_AM::no_shift) {
325 // Check to see if the RHS of the shift is a constant, if not, we can't fold
326 // it.
327 if (ConstantSDNode *Sh =
328 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000329 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000330 Offset = N.getOperand(1).getOperand(0);
331 } else {
332 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000333 }
334 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000335
Evan Chenga8e29892007-01-19 07:51:42 +0000336 // Try matching (R shl C) + (R).
337 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
338 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
339 if (ShOpcVal != ARM_AM::no_shift) {
340 // Check to see if the RHS of the shift is a constant, if not, we can't
341 // fold it.
342 if (ConstantSDNode *Sh =
343 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000344 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000345 Offset = N.getOperand(0).getOperand(0);
346 Base = N.getOperand(1);
347 } else {
348 ShOpcVal = ARM_AM::no_shift;
349 }
350 }
351 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000352
Evan Chenga8e29892007-01-19 07:51:42 +0000353 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000354 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000355 return true;
356}
357
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000358bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000359 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000360 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000361 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
362 ? cast<LoadSDNode>(Op)->getAddressingMode()
363 : cast<StoreSDNode>(Op)->getAddressingMode();
364 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
365 ? ARM_AM::add : ARM_AM::sub;
366 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000367 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000368 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000369 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000370 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
371 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000372 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000373 return true;
374 }
375 }
376
377 Offset = N;
378 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
379 unsigned ShAmt = 0;
380 if (ShOpcVal != ARM_AM::no_shift) {
381 // Check to see if the RHS of the shift is a constant, if not, we can't fold
382 // it.
383 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000384 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000385 Offset = N.getOperand(0);
386 } else {
387 ShOpcVal = ARM_AM::no_shift;
388 }
389 }
390
391 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000392 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000393 return true;
394}
395
Evan Chenga8e29892007-01-19 07:51:42 +0000396
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000397bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000398 SDValue &Base, SDValue &Offset,
399 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000400 if (N.getOpcode() == ISD::SUB) {
401 // X - C is canonicalize to X + -C, no need to handle it here.
402 Base = N.getOperand(0);
403 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000405 return true;
406 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000407
Evan Chenga8e29892007-01-19 07:51:42 +0000408 if (N.getOpcode() != ISD::ADD) {
409 Base = N;
410 if (N.getOpcode() == ISD::FrameIndex) {
411 int FI = cast<FrameIndexSDNode>(N)->getIndex();
412 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
413 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000414 Offset = CurDAG->getRegister(0, MVT::i32);
415 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000416 return true;
417 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000418
Evan Chenga8e29892007-01-19 07:51:42 +0000419 // If the RHS is +/- imm8, fold into addr mode.
420 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000421 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000422 if ((RHSC >= 0 && RHSC < 256) ||
423 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000424 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000425 if (Base.getOpcode() == ISD::FrameIndex) {
426 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
427 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
428 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000429 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000430
431 ARM_AM::AddrOpc AddSub = ARM_AM::add;
432 if (RHSC < 0) {
433 AddSub = ARM_AM::sub;
434 RHSC = - RHSC;
435 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000436 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000437 return true;
438 }
439 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000440
Evan Chenga8e29892007-01-19 07:51:42 +0000441 Base = N.getOperand(0);
442 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000443 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000444 return true;
445}
446
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000447bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000448 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000450 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
451 ? cast<LoadSDNode>(Op)->getAddressingMode()
452 : cast<StoreSDNode>(Op)->getAddressingMode();
453 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
454 ? ARM_AM::add : ARM_AM::sub;
455 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000456 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000457 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000458 Offset = CurDAG->getRegister(0, MVT::i32);
459 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000460 return true;
461 }
462 }
463
464 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000465 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000466 return true;
467}
468
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000469bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000470 SDValue &Addr, SDValue &Mode) {
471 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000472 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000473 return true;
474}
Evan Chenga8e29892007-01-19 07:51:42 +0000475
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000476bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000477 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000478 if (N.getOpcode() != ISD::ADD) {
479 Base = N;
480 if (N.getOpcode() == ISD::FrameIndex) {
481 int FI = cast<FrameIndexSDNode>(N)->getIndex();
482 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000483 } else if (N.getOpcode() == ARMISD::Wrapper &&
484 !(Subtarget->useMovt() &&
485 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000486 Base = N.getOperand(0);
487 }
488 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000489 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000490 return true;
491 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000492
Evan Chenga8e29892007-01-19 07:51:42 +0000493 // If the RHS is +/- imm8, fold into addr mode.
494 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000495 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000496 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
497 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000498 if ((RHSC >= 0 && RHSC < 256) ||
499 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000500 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000501 if (Base.getOpcode() == ISD::FrameIndex) {
502 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
503 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
504 }
505
506 ARM_AM::AddrOpc AddSub = ARM_AM::add;
507 if (RHSC < 0) {
508 AddSub = ARM_AM::sub;
509 RHSC = - RHSC;
510 }
511 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000512 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000513 return true;
514 }
515 }
516 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000517
Evan Chenga8e29892007-01-19 07:51:42 +0000518 Base = N;
519 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000520 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000521 return true;
522}
523
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000524bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000525 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000526 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000527 // Default to no alignment.
528 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000529 return true;
530}
531
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000532bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000533 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000534 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
535 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000536 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000537 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000538 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000539 return true;
540 }
541 return false;
542}
543
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000544bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000545 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000546 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000547 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000548 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000549 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
550 if (!NC || NC->getZExtValue() != 0)
551 return false;
552
553 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000554 return true;
555 }
556
Evan Chenga8e29892007-01-19 07:51:42 +0000557 Base = N.getOperand(0);
558 Offset = N.getOperand(1);
559 return true;
560}
561
Evan Cheng79d43262007-01-24 02:21:22 +0000562bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000563ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000564 unsigned Scale, SDValue &Base,
565 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000566 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000567 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000568 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
569 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000570 if (N.getOpcode() == ARMISD::Wrapper &&
571 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
572 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000573 }
574
Evan Chenga8e29892007-01-19 07:51:42 +0000575 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000576 if (N.getOpcode() == ARMISD::Wrapper &&
577 !(Subtarget->useMovt() &&
578 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
579 Base = N.getOperand(0);
580 } else
581 Base = N;
582
Owen Anderson825b72b2009-08-11 20:47:22 +0000583 Offset = CurDAG->getRegister(0, MVT::i32);
584 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000585 return true;
586 }
587
Evan Chengad0e4652007-02-06 00:22:06 +0000588 // Thumb does not have [sp, r] address mode.
589 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
590 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
591 if ((LHSR && LHSR->getReg() == ARM::SP) ||
592 (RHSR && RHSR->getReg() == ARM::SP)) {
593 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 Offset = CurDAG->getRegister(0, MVT::i32);
595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000596 return true;
597 }
598
Evan Chenga8e29892007-01-19 07:51:42 +0000599 // If the RHS is + imm5 * scale, fold into addr mode.
600 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000601 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000602 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
603 RHSC /= Scale;
604 if (RHSC >= 0 && RHSC < 32) {
605 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 Offset = CurDAG->getRegister(0, MVT::i32);
607 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000608 return true;
609 }
610 }
611 }
612
Evan Chengc38f2bc2007-01-23 22:59:13 +0000613 Base = N.getOperand(0);
614 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000616 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000617}
618
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000619bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000620 SDValue &Base, SDValue &OffImm,
621 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000622 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000623}
624
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000625bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000626 SDValue &Base, SDValue &OffImm,
627 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000628 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000629}
630
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000631bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000632 SDValue &Base, SDValue &OffImm,
633 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000634 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000635}
636
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000637bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000638 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000639 if (N.getOpcode() == ISD::FrameIndex) {
640 int FI = cast<FrameIndexSDNode>(N)->getIndex();
641 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000642 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000643 return true;
644 }
Evan Cheng79d43262007-01-24 02:21:22 +0000645
Evan Chengad0e4652007-02-06 00:22:06 +0000646 if (N.getOpcode() != ISD::ADD)
647 return false;
648
649 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000650 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
651 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000652 // If the RHS is + imm8 * scale, fold into addr mode.
653 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000654 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000655 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
656 RHSC >>= 2;
657 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000658 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000659 if (Base.getOpcode() == ISD::FrameIndex) {
660 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
661 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
662 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000663 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000664 return true;
665 }
666 }
667 }
668 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 return false;
671}
672
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000673bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000674 SDValue &BaseReg,
675 SDValue &Opc) {
676 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
677
678 // Don't match base register only case. That is matched to a separate
679 // lower complexity pattern with explicit register operand.
680 if (ShOpcVal == ARM_AM::no_shift) return false;
681
682 BaseReg = N.getOperand(0);
683 unsigned ShImmVal = 0;
684 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
685 ShImmVal = RHS->getZExtValue() & 31;
686 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
687 return true;
688 }
689
690 return false;
691}
692
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000693bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000694 SDValue &Base, SDValue &OffImm) {
695 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000696
Evan Cheng3a214252009-08-11 08:52:18 +0000697 // Base only.
698 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000699 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000700 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000701 int FI = cast<FrameIndexSDNode>(N)->getIndex();
702 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000703 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000704 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000705 } else if (N.getOpcode() == ARMISD::Wrapper &&
706 !(Subtarget->useMovt() &&
707 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000708 Base = N.getOperand(0);
709 if (Base.getOpcode() == ISD::TargetConstantPool)
710 return false; // We want to select t2LDRpci instead.
711 } else
712 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000713 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000714 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000715 }
Evan Cheng055b0312009-06-29 07:51:04 +0000716
717 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000718 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
719 // Let t2LDRi8 handle (R - imm8).
720 return false;
721
Evan Cheng055b0312009-06-29 07:51:04 +0000722 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000723 if (N.getOpcode() == ISD::SUB)
724 RHSC = -RHSC;
725
726 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000727 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000728 if (Base.getOpcode() == ISD::FrameIndex) {
729 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
730 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
731 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000732 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000733 return true;
734 }
735 }
736
Evan Cheng3a214252009-08-11 08:52:18 +0000737 // Base only.
738 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000739 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000740 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000741}
742
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000743bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000744 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000745 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000746 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000747 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
748 int RHSC = (int)RHS->getSExtValue();
749 if (N.getOpcode() == ISD::SUB)
750 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000751
Evan Cheng3a214252009-08-11 08:52:18 +0000752 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
753 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000754 if (Base.getOpcode() == ISD::FrameIndex) {
755 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
756 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
757 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000758 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000759 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000760 }
Evan Cheng055b0312009-06-29 07:51:04 +0000761 }
762 }
763
764 return false;
765}
766
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000767bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000768 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000769 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000770 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
771 ? cast<LoadSDNode>(Op)->getAddressingMode()
772 : cast<StoreSDNode>(Op)->getAddressingMode();
773 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
774 int RHSC = (int)RHS->getZExtValue();
775 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000776 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000777 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
778 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000779 return true;
780 }
781 }
782
783 return false;
784}
785
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000786bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000787 SDValue &Base, SDValue &OffImm) {
788 if (N.getOpcode() == ISD::ADD) {
789 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
790 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000791 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000792 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000793 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000794 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000795 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000796 return true;
797 }
798 }
799 } else if (N.getOpcode() == ISD::SUB) {
800 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
801 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000802 // 8 bits.
803 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
David Goodwin6647cea2009-06-30 22:50:01 +0000804 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000805 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000806 return true;
807 }
808 }
809 }
810
811 return false;
812}
813
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000814bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000815 SDValue &Base,
816 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000817 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
818 if (N.getOpcode() != ISD::ADD)
819 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000820
Evan Cheng3a214252009-08-11 08:52:18 +0000821 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
822 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
823 int RHSC = (int)RHS->getZExtValue();
824 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
825 return false;
826 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000827 return false;
828 }
829
Evan Cheng055b0312009-06-29 07:51:04 +0000830 // Look for (R + R) or (R + (R << [1,2,3])).
831 unsigned ShAmt = 0;
832 Base = N.getOperand(0);
833 OffReg = N.getOperand(1);
834
835 // Swap if it is ((R << c) + R).
836 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
837 if (ShOpcVal != ARM_AM::lsl) {
838 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
839 if (ShOpcVal == ARM_AM::lsl)
840 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000841 }
842
Evan Cheng055b0312009-06-29 07:51:04 +0000843 if (ShOpcVal == ARM_AM::lsl) {
844 // Check to see if the RHS of the shift is a constant, if not, we can't fold
845 // it.
846 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
847 ShAmt = Sh->getZExtValue();
848 if (ShAmt >= 4) {
849 ShAmt = 0;
850 ShOpcVal = ARM_AM::no_shift;
851 } else
852 OffReg = OffReg.getOperand(0);
853 } else {
854 ShOpcVal = ARM_AM::no_shift;
855 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000856 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000857
Owen Anderson825b72b2009-08-11 20:47:22 +0000858 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000859
860 return true;
861}
862
863//===--------------------------------------------------------------------===//
864
Evan Chengee568cf2007-07-05 07:15:27 +0000865/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000866static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000867 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000868}
869
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000870SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
871 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000872 ISD::MemIndexedMode AM = LD->getAddressingMode();
873 if (AM == ISD::UNINDEXED)
874 return NULL;
875
Owen Andersone50ed302009-08-10 22:56:29 +0000876 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000877 SDValue Offset, AMOpc;
878 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
879 unsigned Opcode = 0;
880 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000881 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000882 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000883 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
884 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000885 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Match = true;
888 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
889 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
890 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000891 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000893 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000894 Match = true;
895 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
896 }
897 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000898 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000899 Match = true;
900 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
901 }
902 }
903 }
904
905 if (Match) {
906 SDValue Chain = LD->getChain();
907 SDValue Base = LD->getBasePtr();
908 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000909 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000910 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000911 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000912 }
913
914 return NULL;
915}
916
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000917SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
918 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000919 ISD::MemIndexedMode AM = LD->getAddressingMode();
920 if (AM == ISD::UNINDEXED)
921 return NULL;
922
Owen Andersone50ed302009-08-10 22:56:29 +0000923 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000924 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000925 SDValue Offset;
926 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
927 unsigned Opcode = 0;
928 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000929 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000930 switch (LoadedVT.getSimpleVT().SimpleTy) {
931 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000932 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
933 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000934 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000935 if (isSExtLd)
936 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
937 else
938 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000939 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000940 case MVT::i8:
941 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000942 if (isSExtLd)
943 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
944 else
945 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000946 break;
947 default:
948 return NULL;
949 }
950 Match = true;
951 }
952
953 if (Match) {
954 SDValue Chain = LD->getChain();
955 SDValue Base = LD->getBasePtr();
956 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000957 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000958 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000959 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000960 }
961
962 return NULL;
963}
964
Evan Cheng603afbf2010-05-10 17:34:18 +0000965/// PairDRegs - Form a quad register from a pair of D registers.
966///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000967SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
968 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000969 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
970 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000971 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000972 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
973 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
974 }
975 SDValue Undef =
976 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000977 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000978 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000979 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000980 VT, SDValue(Pair, 0), V1, SubReg1);
981}
982
Evan Cheng7f687192010-05-14 00:21:45 +0000983/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000984///
985SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
986 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000987 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
988 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000989 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
990 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
991}
992
Evan Cheng7f687192010-05-14 00:21:45 +0000993/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000994///
995SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
996 SDValue V2, SDValue V3) {
997 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000998 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
999 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1000 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1001 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001002 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1003 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1004}
1005
Evan Cheng8f6de382010-05-16 03:27:48 +00001006/// QuadQRegs - Form 4 consecutive Q registers.
1007///
1008SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1009 SDValue V2, SDValue V3) {
1010 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001011 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1012 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1013 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1014 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001015 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1016 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1017}
1018
Evan Cheng5c6aba22010-05-14 18:54:59 +00001019/// OctoDRegs - Form 8 consecutive D registers.
1020///
1021SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1022 SDValue V2, SDValue V3,
1023 SDValue V4, SDValue V5,
1024 SDValue V6, SDValue V7) {
1025 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001026 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1027 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1028 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1029 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1030 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1031 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1032 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1033 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001034 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1035 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1036 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1037}
1038
Bob Wilsona7c397c2009-10-14 16:19:03 +00001039/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1040/// for a 64-bit subregister of the vector.
1041static EVT GetNEONSubregVT(EVT VT) {
1042 switch (VT.getSimpleVT().SimpleTy) {
1043 default: llvm_unreachable("unhandled NEON type");
1044 case MVT::v16i8: return MVT::v8i8;
1045 case MVT::v8i16: return MVT::v4i16;
1046 case MVT::v4f32: return MVT::v2f32;
1047 case MVT::v4i32: return MVT::v2i32;
1048 case MVT::v2i64: return MVT::v1i64;
1049 }
1050}
1051
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001052SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001053 unsigned *DOpcodes, unsigned *QOpcodes0,
1054 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001055 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001056 DebugLoc dl = N->getDebugLoc();
1057
Bob Wilson226036e2010-03-20 22:13:40 +00001058 SDValue MemAddr, Align;
1059 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001060 return NULL;
1061
1062 SDValue Chain = N->getOperand(0);
1063 EVT VT = N->getValueType(0);
1064 bool is64BitVector = VT.is64BitVector();
1065
1066 unsigned OpcodeIndex;
1067 switch (VT.getSimpleVT().SimpleTy) {
1068 default: llvm_unreachable("unhandled vld type");
1069 // Double-register operations:
1070 case MVT::v8i8: OpcodeIndex = 0; break;
1071 case MVT::v4i16: OpcodeIndex = 1; break;
1072 case MVT::v2f32:
1073 case MVT::v2i32: OpcodeIndex = 2; break;
1074 case MVT::v1i64: OpcodeIndex = 3; break;
1075 // Quad-register operations:
1076 case MVT::v16i8: OpcodeIndex = 0; break;
1077 case MVT::v8i16: OpcodeIndex = 1; break;
1078 case MVT::v4f32:
1079 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001080 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001081 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001082 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001083 }
1084
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001085 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001086 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001087 if (is64BitVector) {
1088 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001089 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001090 std::vector<EVT> ResTys(NumVecs, VT);
1091 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001092 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1093 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1094 return VLd;
1095
Evan Cheng0ce537a2010-05-11 01:19:40 +00001096 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001097 SDValue V0 = SDValue(VLd, 0);
1098 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001099
Evan Cheng0ce537a2010-05-11 01:19:40 +00001100 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001101 if (NumVecs == 2)
1102 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1103 else {
1104 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001105 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001106 SDValue V3 = (NumVecs == 3)
1107 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1108 : SDValue(VLd, 3);
1109 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1110 }
1111
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001112 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001113 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001114 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001115 dl, VT, RegSeq);
1116 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001117 }
1118 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1119 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001120 }
1121
1122 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001123 if (NumVecs <= 2) {
1124 // Quad registers are directly supported for VLD1 and VLD2,
1125 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001126 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001127 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001128 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001129 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001130 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001131 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001132
1133 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001134 if (llvm::ModelWithRegSequence()) {
1135 if (NumVecs == 1) {
1136 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1137 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1138 } else {
1139 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1140 SDValue(VLd, 0), SDValue(VLd, 1),
1141 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001142 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1143 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
Evan Cheng603afbf2010-05-10 17:34:18 +00001144 ReplaceUses(SDValue(N, 0), Q0);
1145 ReplaceUses(SDValue(N, 1), Q1);
1146 }
1147 } else {
1148 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1149 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1150 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1151 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001152 }
1153 } else {
1154 // Otherwise, quad registers are loaded with two separate instructions,
1155 // where one loads the even registers and the other loads the odd registers.
1156
Bob Wilson3e36f132009-10-14 17:28:52 +00001157 std::vector<EVT> ResTys(NumVecs, RegVT);
1158 ResTys.push_back(MemAddr.getValueType());
1159 ResTys.push_back(MVT::Other);
1160
Bob Wilson24f995d2009-10-14 18:32:29 +00001161 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001162 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001163 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1164 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001165 Chain = SDValue(VLdA, NumVecs+1);
1166
Bob Wilson24f995d2009-10-14 18:32:29 +00001167 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001168 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001169 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1170 Align, Reg0, Pred, Reg0, Chain };
1171 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001172 Chain = SDValue(VLdB, NumVecs+1);
1173
Evan Cheng5c6aba22010-05-14 18:54:59 +00001174 if (llvm::ModelWithRegSequence()) {
1175 SDValue V0 = SDValue(VLdA, 0);
1176 SDValue V1 = SDValue(VLdB, 0);
1177 SDValue V2 = SDValue(VLdA, 1);
1178 SDValue V3 = SDValue(VLdB, 1);
1179 SDValue V4 = SDValue(VLdA, 2);
1180 SDValue V5 = SDValue(VLdB, 2);
1181 SDValue V6 = (NumVecs == 3)
1182 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1183 0)
1184 : SDValue(VLdA, 3);
1185 SDValue V7 = (NumVecs == 3)
1186 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1187 0)
1188 : SDValue(VLdB, 3);
1189 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1190 V4, V5, V6, V7), 0);
1191
1192 // Extract out the 3 / 4 Q registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001193 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001194 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001195 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001196 dl, VT, RegSeq);
1197 ReplaceUses(SDValue(N, Vec), Q);
1198 }
1199 } else {
1200 // Combine the even and odd subregs to produce the result.
1201 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1202 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1203 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1204 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001205 }
1206 }
1207 ReplaceUses(SDValue(N, NumVecs), Chain);
1208 return NULL;
1209}
1210
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001211SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001212 unsigned *DOpcodes, unsigned *QOpcodes0,
1213 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001214 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001215 DebugLoc dl = N->getDebugLoc();
1216
Bob Wilson226036e2010-03-20 22:13:40 +00001217 SDValue MemAddr, Align;
1218 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001219 return NULL;
1220
1221 SDValue Chain = N->getOperand(0);
1222 EVT VT = N->getOperand(3).getValueType();
1223 bool is64BitVector = VT.is64BitVector();
1224
1225 unsigned OpcodeIndex;
1226 switch (VT.getSimpleVT().SimpleTy) {
1227 default: llvm_unreachable("unhandled vst type");
1228 // Double-register operations:
1229 case MVT::v8i8: OpcodeIndex = 0; break;
1230 case MVT::v4i16: OpcodeIndex = 1; break;
1231 case MVT::v2f32:
1232 case MVT::v2i32: OpcodeIndex = 2; break;
1233 case MVT::v1i64: OpcodeIndex = 3; break;
1234 // Quad-register operations:
1235 case MVT::v16i8: OpcodeIndex = 0; break;
1236 case MVT::v8i16: OpcodeIndex = 1; break;
1237 case MVT::v4f32:
1238 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001239 case MVT::v2i64: OpcodeIndex = 3;
1240 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1241 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001242 }
1243
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001244 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001245 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001246
Bob Wilson226036e2010-03-20 22:13:40 +00001247 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001248 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001249 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001250
1251 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001252 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001253 SDValue RegSeq;
1254 SDValue V0 = N->getOperand(0+3);
1255 SDValue V1 = N->getOperand(1+3);
1256
1257 // Form a REG_SEQUENCE to force register allocation.
1258 if (NumVecs == 2)
1259 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1260 else {
1261 SDValue V2 = N->getOperand(2+3);
1262 // If it's a vld3, form a quad D-register and leave the last part as
1263 // an undef.
1264 SDValue V3 = (NumVecs == 3)
1265 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1266 : N->getOperand(3+3);
1267 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1268 }
1269
1270 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001271 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001272 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001273 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001274 RegSeq));
1275 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001276 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001277 RegSeq));
1278 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001279 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001280 RegSeq));
1281 } else {
1282 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1283 Ops.push_back(N->getOperand(Vec+3));
1284 }
Evan Chengac0869d2009-11-21 06:21:52 +00001285 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001286 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001287 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001288 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001289 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001290 }
1291
1292 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001293 if (NumVecs <= 2) {
1294 // Quad registers are directly supported for VST1 and VST2,
1295 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001296 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001297 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001298 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001299 SDValue Q0 = N->getOperand(3);
1300 SDValue Q1 = N->getOperand(4);
1301
1302 // Form a QQ register.
1303 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1304
1305 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001306 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001307 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001308 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001309 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001310 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001311 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001312 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001313 QQ));
1314 Ops.push_back(Pred);
1315 Ops.push_back(Reg0); // predicate register
1316 Ops.push_back(Chain);
1317 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1318 } else {
1319 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001320 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001321 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001322 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001323 N->getOperand(Vec+3)));
1324 }
1325 Ops.push_back(Pred);
1326 Ops.push_back(Reg0); // predicate register
1327 Ops.push_back(Chain);
1328 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1329 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001330 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001331 }
1332
1333 // Otherwise, quad registers are stored with two separate instructions,
1334 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001335 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001336 // Form the QQQQ REG_SEQUENCE.
1337 SDValue V[8];
1338 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001339 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001340 N->getOperand(Vec+3));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001341 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001342 N->getOperand(Vec+3));
1343 }
1344 if (NumVecs == 3)
Evan Cheng7189fd02010-05-15 07:53:37 +00001345 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1346 dl, RegVT), 0);
1347
Evan Cheng12c24692010-05-14 22:54:52 +00001348 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1349 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001350
Evan Cheng12c24692010-05-14 22:54:52 +00001351 // Store the even D registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001352 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng12c24692010-05-14 22:54:52 +00001353 Ops.push_back(Reg0); // post-access address offset
1354 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001355 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001356 RegVT, RegSeq));
1357 Ops.push_back(Pred);
1358 Ops.push_back(Reg0); // predicate register
1359 Ops.push_back(Chain);
1360 unsigned Opc = QOpcodes0[OpcodeIndex];
1361 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1362 MVT::Other, Ops.data(), NumVecs+6);
1363 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001364
Evan Cheng12c24692010-05-14 22:54:52 +00001365 // Store the odd D registers.
1366 Ops[0] = SDValue(VStA, 0); // MemAddr
1367 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001368 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001369 RegVT, RegSeq);
1370 Ops[NumVecs+5] = Chain;
1371 Opc = QOpcodes1[OpcodeIndex];
1372 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1373 MVT::Other, Ops.data(), NumVecs+6);
1374 Chain = SDValue(VStB, 1);
1375 ReplaceUses(SDValue(N, 0), Chain);
1376 return NULL;
1377 } else {
1378 Ops.push_back(Reg0); // post-access address offset
1379
1380 // Store the even subregs.
1381 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001382 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001383 N->getOperand(Vec+3)));
1384 Ops.push_back(Pred);
1385 Ops.push_back(Reg0); // predicate register
1386 Ops.push_back(Chain);
1387 unsigned Opc = QOpcodes0[OpcodeIndex];
1388 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1389 MVT::Other, Ops.data(), NumVecs+6);
1390 Chain = SDValue(VStA, 1);
1391
1392 // Store the odd subregs.
1393 Ops[0] = SDValue(VStA, 0); // MemAddr
1394 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001395 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001396 N->getOperand(Vec+3));
1397 Ops[NumVecs+5] = Chain;
1398 Opc = QOpcodes1[OpcodeIndex];
1399 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1400 MVT::Other, Ops.data(), NumVecs+6);
1401 Chain = SDValue(VStB, 1);
1402 ReplaceUses(SDValue(N, 0), Chain);
1403 return NULL;
1404 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001405}
1406
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001407SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001408 unsigned NumVecs, unsigned *DOpcodes,
1409 unsigned *QOpcodes0,
1410 unsigned *QOpcodes1) {
1411 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001412 DebugLoc dl = N->getDebugLoc();
1413
Bob Wilson226036e2010-03-20 22:13:40 +00001414 SDValue MemAddr, Align;
1415 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001416 return NULL;
1417
1418 SDValue Chain = N->getOperand(0);
1419 unsigned Lane =
1420 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001421 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001422 bool is64BitVector = VT.is64BitVector();
1423
Bob Wilson96493442009-10-14 16:46:45 +00001424 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001425 unsigned NumElts = 0;
1426 int SubregIdx = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001427 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001428 EVT RegVT = VT;
1429 if (!is64BitVector) {
1430 RegVT = GetNEONSubregVT(VT);
1431 NumElts = RegVT.getVectorNumElements();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001432 SubregIdx = (Lane < NumElts) ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001433 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001434 }
1435
1436 unsigned OpcodeIndex;
1437 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001438 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001439 // Double-register operations:
1440 case MVT::v8i8: OpcodeIndex = 0; break;
1441 case MVT::v4i16: OpcodeIndex = 1; break;
1442 case MVT::v2f32:
1443 case MVT::v2i32: OpcodeIndex = 2; break;
1444 // Quad-register operations:
1445 case MVT::v8i16: OpcodeIndex = 0; break;
1446 case MVT::v4f32:
1447 case MVT::v4i32: OpcodeIndex = 1; break;
1448 }
1449
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001450 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001451 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001452
Bob Wilson226036e2010-03-20 22:13:40 +00001453 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001454 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001455 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001456
1457 unsigned Opc = 0;
1458 if (is64BitVector) {
1459 Opc = DOpcodes[OpcodeIndex];
Evan Cheng8f6de382010-05-16 03:27:48 +00001460 if (llvm::ModelWithRegSequence()) {
1461 SDValue RegSeq;
1462 SDValue V0 = N->getOperand(0+3);
1463 SDValue V1 = N->getOperand(1+3);
1464 if (NumVecs == 2) {
1465 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1466 } else {
1467 SDValue V2 = N->getOperand(2+3);
1468 SDValue V3 = (NumVecs == 3)
1469 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1470 : N->getOperand(3+3);
1471 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1472 }
1473
1474 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001475 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001476 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001477 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001478 RegSeq));
1479 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001480 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001481 RegSeq));
1482 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001483 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001484 RegSeq));
1485 } else {
1486 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1487 Ops.push_back(N->getOperand(Vec+3));
1488 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001489 } else {
1490 // Check if this is loading the even or odd subreg of a Q register.
1491 if (Lane < NumElts) {
1492 Opc = QOpcodes0[OpcodeIndex];
1493 } else {
1494 Lane -= NumElts;
1495 Opc = QOpcodes1[OpcodeIndex];
1496 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001497
1498 if (llvm::ModelWithRegSequence()) {
1499 SDValue RegSeq;
1500 SDValue V0 = N->getOperand(0+3);
1501 SDValue V1 = N->getOperand(1+3);
1502 if (NumVecs == 2) {
1503 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1504 } else {
1505 SDValue V2 = N->getOperand(2+3);
1506 SDValue V3 = (NumVecs == 3)
1507 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1508 : N->getOperand(3+3);
1509 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1510 }
1511
1512 // Extract the subregs of the input vector.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001513 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001514 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1515 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1516 RegSeq));
1517 } else {
1518 // Extract the subregs of the input vector.
1519 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1520 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1521 N->getOperand(Vec+3)));
1522 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001523 }
1524 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001525 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001526 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001527 Ops.push_back(Chain);
1528
Bob Wilson96493442009-10-14 16:46:45 +00001529 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001530 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001531
Bob Wilsona7c397c2009-10-14 16:19:03 +00001532 std::vector<EVT> ResTys(NumVecs, RegVT);
1533 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001534 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1535
Evan Cheng7189fd02010-05-15 07:53:37 +00001536 if (llvm::ModelWithRegSequence()) {
Evan Cheng7092c2b2010-05-15 01:36:29 +00001537 // Form a REG_SEQUENCE to force register allocation.
Evan Cheng7189fd02010-05-15 07:53:37 +00001538 SDValue RegSeq;
1539 if (is64BitVector) {
1540 SDValue V0 = SDValue(VLdLn, 0);
1541 SDValue V1 = SDValue(VLdLn, 1);
1542 if (NumVecs == 2) {
1543 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1544 } else {
1545 SDValue V2 = SDValue(VLdLn, 2);
1546 // If it's a vld3, form a quad D-register but discard the last part.
1547 SDValue V3 = (NumVecs == 3)
Evan Cheng7092c2b2010-05-15 01:36:29 +00001548 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1549 : SDValue(VLdLn, 3);
Evan Cheng7189fd02010-05-15 07:53:37 +00001550 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1551 }
1552 } else {
Jim Grosbach18f30e62010-06-02 21:53:11 +00001553 // For 128-bit vectors, take the 64-bit results of the load and insert
1554 // them as subregs into the result.
Evan Cheng7189fd02010-05-15 07:53:37 +00001555 SDValue V[8];
1556 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Evan Cheng8f6de382010-05-16 03:27:48 +00001557 if (Even) {
Evan Cheng7189fd02010-05-15 07:53:37 +00001558 V[i] = SDValue(VLdLn, Vec);
1559 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1560 dl, RegVT), 0);
1561 } else {
1562 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1563 dl, RegVT), 0);
1564 V[i+1] = SDValue(VLdLn, Vec);
1565 }
1566 }
1567 if (NumVecs == 3)
1568 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1569 dl, RegVT), 0);
1570
1571 if (NumVecs == 2)
1572 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1573 else
1574 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1575 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001576 }
1577
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001578 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1579 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001580 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Evan Cheng7189fd02010-05-15 07:53:37 +00001581 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1582 ReplaceUses(SDValue(N, Vec),
1583 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
Evan Cheng7092c2b2010-05-15 01:36:29 +00001584 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1585 return NULL;
1586 }
1587
Bob Wilsona7c397c2009-10-14 16:19:03 +00001588 // For a 64-bit vector load to D registers, nothing more needs to be done.
1589 if (is64BitVector)
1590 return VLdLn;
1591
1592 // For 128-bit vectors, take the 64-bit results of the load and insert them
1593 // as subregs into the result.
1594 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1595 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1596 N->getOperand(Vec+3),
1597 SDValue(VLdLn, Vec));
1598 ReplaceUses(SDValue(N, Vec), QuadVec);
1599 }
1600
1601 Chain = SDValue(VLdLn, NumVecs);
1602 ReplaceUses(SDValue(N, NumVecs), Chain);
1603 return NULL;
1604}
1605
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001606SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001607 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001608 if (!Subtarget->hasV6T2Ops())
1609 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001610
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001611 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1612 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1613
1614
1615 // For unsigned extracts, check for a shift right and mask
1616 unsigned And_imm = 0;
1617 if (N->getOpcode() == ISD::AND) {
1618 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1619
1620 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1621 if (And_imm & (And_imm + 1))
1622 return NULL;
1623
1624 unsigned Srl_imm = 0;
1625 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1626 Srl_imm)) {
1627 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1628
1629 unsigned Width = CountTrailingOnes_32(And_imm);
1630 unsigned LSB = Srl_imm;
1631 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1632 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1633 CurDAG->getTargetConstant(LSB, MVT::i32),
1634 CurDAG->getTargetConstant(Width, MVT::i32),
1635 getAL(CurDAG), Reg0 };
1636 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1637 }
1638 }
1639 return NULL;
1640 }
1641
1642 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001643 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001644 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001645 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1646 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001647 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001648 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1649 unsigned Width = 32 - Srl_imm;
1650 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001651 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001652 return NULL;
1653 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001654 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001655 CurDAG->getTargetConstant(LSB, MVT::i32),
1656 CurDAG->getTargetConstant(Width, MVT::i32),
1657 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001658 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001659 }
1660 }
1661 return NULL;
1662}
1663
Evan Cheng9ef48352009-11-20 00:54:03 +00001664SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001665SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001666 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1667 SDValue CPTmp0;
1668 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001669 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001670 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1671 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1672 unsigned Opc = 0;
1673 switch (SOShOp) {
1674 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1675 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1676 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1677 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1678 default:
1679 llvm_unreachable("Unknown so_reg opcode!");
1680 break;
1681 }
1682 SDValue SOShImm =
1683 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1684 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1685 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001686 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001687 }
1688 return 0;
1689}
1690
1691SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001692SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001693 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1694 SDValue CPTmp0;
1695 SDValue CPTmp1;
1696 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001697 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001698 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1699 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001700 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001701 }
1702 return 0;
1703}
1704
1705SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001706SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001707 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1708 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1709 if (!T)
1710 return 0;
1711
1712 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1713 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1714 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1715 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001716 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001717 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1718 }
1719 return 0;
1720}
1721
1722SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001723SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001724 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1725 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1726 if (!T)
1727 return 0;
1728
1729 if (Predicate_so_imm(TrueVal.getNode())) {
1730 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1731 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1732 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001733 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001734 ARM::MOVCCi, MVT::i32, Ops, 5);
1735 }
1736 return 0;
1737}
1738
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001739SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1740 EVT VT = N->getValueType(0);
1741 SDValue FalseVal = N->getOperand(0);
1742 SDValue TrueVal = N->getOperand(1);
1743 SDValue CC = N->getOperand(2);
1744 SDValue CCR = N->getOperand(3);
1745 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001746 assert(CC.getOpcode() == ISD::Constant);
1747 assert(CCR.getOpcode() == ISD::Register);
1748 ARMCC::CondCodes CCVal =
1749 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001750
1751 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1752 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1753 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1754 // Pattern complexity = 18 cost = 1 size = 0
1755 SDValue CPTmp0;
1756 SDValue CPTmp1;
1757 SDValue CPTmp2;
1758 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001759 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001760 CCVal, CCR, InFlag);
1761 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001762 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001763 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1764 if (Res)
1765 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001766 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001767 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001768 CCVal, CCR, InFlag);
1769 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001770 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001771 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1772 if (Res)
1773 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001774 }
1775
1776 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1777 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1778 // (imm:i32):$cc)
1779 // Emits: (MOVCCi:i32 GPR:i32:$false,
1780 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1781 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001782 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001783 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001784 CCVal, CCR, InFlag);
1785 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001786 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001787 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1788 if (Res)
1789 return Res;
1790 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001791 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001792 CCVal, CCR, InFlag);
1793 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001794 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001795 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1796 if (Res)
1797 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001798 }
1799 }
1800
1801 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1802 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1803 // Pattern complexity = 6 cost = 1 size = 0
1804 //
1805 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1806 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1807 // Pattern complexity = 6 cost = 11 size = 0
1808 //
1809 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001810 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1811 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001812 unsigned Opc = 0;
1813 switch (VT.getSimpleVT().SimpleTy) {
1814 default: assert(false && "Illegal conditional move type!");
1815 break;
1816 case MVT::i32:
1817 Opc = Subtarget->isThumb()
1818 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1819 : ARM::MOVCCr;
1820 break;
1821 case MVT::f32:
1822 Opc = ARM::VMOVScc;
1823 break;
1824 case MVT::f64:
1825 Opc = ARM::VMOVDcc;
1826 break;
1827 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001828 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001829}
1830
Evan Chengde8aa4e2010-05-05 18:28:36 +00001831SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1832 // The only time a CONCAT_VECTORS operation can have legal types is when
1833 // two 64-bit vectors are concatenated to a 128-bit vector.
1834 EVT VT = N->getValueType(0);
1835 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1836 llvm_unreachable("unexpected CONCAT_VECTORS");
1837 DebugLoc dl = N->getDebugLoc();
1838 SDValue V0 = N->getOperand(0);
1839 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001840 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1841 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001842 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1843 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1844}
1845
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001847 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001848
Dan Gohmane8be6c62008-07-17 19:10:17 +00001849 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001850 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001851
1852 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001853 default: break;
1854 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001855 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001856 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001857 if (Subtarget->hasThumb2())
1858 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1859 // be done with MOV + MOVT, at worst.
1860 UseCP = 0;
1861 else {
1862 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001863 UseCP = (Val > 255 && // MOV
1864 ~Val > 255 && // MOV + MVN
1865 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001866 } else
1867 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1868 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1869 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1870 }
1871
Evan Chenga8e29892007-01-19 07:51:42 +00001872 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001873 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001874 CurDAG->getTargetConstantPool(ConstantInt::get(
1875 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001876 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001877
1878 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001879 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001880 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001881 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001882 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001883 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1884 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001885 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001886 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001887 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001888 CurDAG->getRegister(0, MVT::i32),
1889 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001890 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001891 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001892 CurDAG->getEntryNode()
1893 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001894 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1895 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001896 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001897 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001898 return NULL;
1899 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001900
Evan Chenga8e29892007-01-19 07:51:42 +00001901 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001902 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001903 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001904 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001905 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001906 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001907 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001908 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001909 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1910 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001911 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001912 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1913 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001914 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1915 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1916 CurDAG->getRegister(0, MVT::i32) };
1917 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001918 }
Evan Chenga8e29892007-01-19 07:51:42 +00001919 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001920 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001921 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001922 return I;
1923 break;
1924 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001925 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001926 return I;
1927 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001928 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001929 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001930 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001931 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001932 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001933 if (!RHSV) break;
1934 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001935 unsigned ShImm = Log2_32(RHSV-1);
1936 if (ShImm >= 32)
1937 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001938 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001939 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001940 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1941 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001942 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001943 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001944 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001945 } else {
1946 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001947 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001948 }
Evan Chenga8e29892007-01-19 07:51:42 +00001949 }
1950 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001951 unsigned ShImm = Log2_32(RHSV+1);
1952 if (ShImm >= 32)
1953 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001954 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001955 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001956 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1957 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001958 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001959 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1960 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001961 } else {
1962 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001963 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001964 }
Evan Chenga8e29892007-01-19 07:51:42 +00001965 }
1966 }
1967 break;
Evan Cheng20956592009-10-21 08:15:52 +00001968 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001969 // Check for unsigned bitfield extract
1970 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1971 return I;
1972
Evan Cheng20956592009-10-21 08:15:52 +00001973 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1974 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1975 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1976 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1977 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001978 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001979 if (VT != MVT::i32)
1980 break;
1981 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1982 ? ARM::t2MOVTi16
1983 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1984 if (!Opc)
1985 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001986 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001987 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1988 if (!N1C)
1989 break;
1990 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1991 SDValue N2 = N0.getOperand(1);
1992 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1993 if (!N2C)
1994 break;
1995 unsigned N1CVal = N1C->getZExtValue();
1996 unsigned N2CVal = N2C->getZExtValue();
1997 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1998 (N1CVal & 0xffffU) == 0xffffU &&
1999 (N2CVal & 0xffffU) == 0x0U) {
2000 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2001 MVT::i32);
2002 SDValue Ops[] = { N0.getOperand(0), Imm16,
2003 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2004 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2005 }
2006 }
2007 break;
2008 }
Jim Grosbache5165492009-11-09 00:11:35 +00002009 case ARMISD::VMOVRRD:
2010 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002011 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002012 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002013 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002014 if (Subtarget->isThumb1Only())
2015 break;
2016 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002017 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002018 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2019 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002020 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002021 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002022 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002023 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2024 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002025 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002026 }
Evan Chengee568cf2007-07-05 07:15:27 +00002027 }
Dan Gohman525178c2007-10-08 18:33:35 +00002028 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002029 if (Subtarget->isThumb1Only())
2030 break;
2031 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002033 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002034 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002035 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002036 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002037 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2038 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002039 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002040 }
Evan Chengee568cf2007-07-05 07:15:27 +00002041 }
Evan Chenga8e29892007-01-19 07:51:42 +00002042 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002043 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002044 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002045 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002046 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002047 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002048 if (ResNode)
2049 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002050
2051 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2052 if (Subtarget->hasVFP2() &&
2053 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2054 SDValue Chain = N->getOperand(0);
2055 SDValue AM5Opc =
2056 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002057 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002058 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2059 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002060 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2061 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2062 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2063 MVT::v2f64, MVT::Other, Ops, 5);
2064 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2065 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002066 }
2067 // Other cases are autogenerated.
2068 break;
2069 }
2070 case ISD::STORE: {
2071 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2072 if (Subtarget->hasVFP2() &&
2073 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2074 SDValue Chain = N->getOperand(0);
2075 SDValue AM5Opc =
2076 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002077 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002078 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2079 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2080 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002081 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2082 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2083 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2084 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2085 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002086 }
Evan Chenga8e29892007-01-19 07:51:42 +00002087 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002088 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002089 }
Evan Chengee568cf2007-07-05 07:15:27 +00002090 case ARMISD::BRCOND: {
2091 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2092 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2093 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002094
Evan Chengee568cf2007-07-05 07:15:27 +00002095 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2096 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2097 // Pattern complexity = 6 cost = 1 size = 0
2098
David Goodwin5e47a9a2009-06-30 18:04:13 +00002099 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2100 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2101 // Pattern complexity = 6 cost = 1 size = 0
2102
Jim Grosbach764ab522009-08-11 15:33:49 +00002103 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002104 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002105 SDValue Chain = N->getOperand(0);
2106 SDValue N1 = N->getOperand(1);
2107 SDValue N2 = N->getOperand(2);
2108 SDValue N3 = N->getOperand(3);
2109 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002110 assert(N1.getOpcode() == ISD::BasicBlock);
2111 assert(N2.getOpcode() == ISD::Constant);
2112 assert(N3.getOpcode() == ISD::Register);
2113
Dan Gohman475871a2008-07-27 21:46:04 +00002114 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002115 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002116 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002117 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002118 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2119 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002120 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002121 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002122 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002123 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002124 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002125 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002126 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002127 return NULL;
2128 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002129 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002131 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002132 EVT VT = N->getValueType(0);
2133 SDValue N0 = N->getOperand(0);
2134 SDValue N1 = N->getOperand(1);
2135 SDValue N2 = N->getOperand(2);
2136 SDValue N3 = N->getOperand(3);
2137 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002138 assert(N2.getOpcode() == ISD::Constant);
2139 assert(N3.getOpcode() == ISD::Register);
2140
Dan Gohman475871a2008-07-27 21:46:04 +00002141 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002142 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002143 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002144 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002145 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002146 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002147 default: assert(false && "Illegal conditional move type!");
2148 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002149 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002150 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002151 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002152 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002153 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002154 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002155 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002156 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002157 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002158
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002159 case ARMISD::VZIP: {
2160 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002161 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002162 switch (VT.getSimpleVT().SimpleTy) {
2163 default: return NULL;
2164 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2165 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2166 case MVT::v2f32:
2167 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2168 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2169 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2170 case MVT::v4f32:
2171 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2172 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002173 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002174 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2175 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2176 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002177 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002178 case ARMISD::VUZP: {
2179 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002180 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002181 switch (VT.getSimpleVT().SimpleTy) {
2182 default: return NULL;
2183 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2184 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2185 case MVT::v2f32:
2186 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2187 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2188 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2189 case MVT::v4f32:
2190 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2191 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002192 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002193 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2194 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2195 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002196 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002197 case ARMISD::VTRN: {
2198 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002199 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002200 switch (VT.getSimpleVT().SimpleTy) {
2201 default: return NULL;
2202 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2203 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2204 case MVT::v2f32:
2205 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2206 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2207 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2208 case MVT::v4f32:
2209 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2210 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002211 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002212 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2213 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2214 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002215 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002216
2217 case ISD::INTRINSIC_VOID:
2218 case ISD::INTRINSIC_W_CHAIN: {
2219 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002220 switch (IntNo) {
2221 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002222 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002223
Bob Wilson621f1952010-03-23 05:25:43 +00002224 case Intrinsic::arm_neon_vld1: {
2225 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2226 ARM::VLD1d32, ARM::VLD1d64 };
2227 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2228 ARM::VLD1q32, ARM::VLD1q64 };
2229 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2230 }
2231
Bob Wilson31fb12f2009-08-26 17:39:53 +00002232 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002233 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002234 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002235 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002236 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002237 }
2238
2239 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002240 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002241 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002242 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2243 ARM::VLD3q16_UPD,
2244 ARM::VLD3q32_UPD };
2245 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2246 ARM::VLD3q16odd_UPD,
2247 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002248 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002249 }
2250
2251 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002252 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002253 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002254 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2255 ARM::VLD4q16_UPD,
2256 ARM::VLD4q32_UPD };
2257 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2258 ARM::VLD4q16odd_UPD,
2259 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002260 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002261 }
2262
Bob Wilson243fcc52009-09-01 04:26:28 +00002263 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002264 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002265 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2266 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002267 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002268 }
2269
2270 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002271 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002272 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2273 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002274 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002275 }
2276
2277 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002278 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002279 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2280 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002281 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002282 }
2283
Bob Wilson11d98992010-03-23 06:20:33 +00002284 case Intrinsic::arm_neon_vst1: {
2285 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2286 ARM::VST1d32, ARM::VST1d64 };
2287 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2288 ARM::VST1q32, ARM::VST1q64 };
2289 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2290 }
2291
Bob Wilson31fb12f2009-08-26 17:39:53 +00002292 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002293 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002294 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002295 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002296 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002297 }
2298
2299 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002300 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002301 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002302 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2303 ARM::VST3q16_UPD,
2304 ARM::VST3q32_UPD };
2305 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2306 ARM::VST3q16odd_UPD,
2307 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002308 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002309 }
2310
2311 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002312 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002313 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002314 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2315 ARM::VST4q16_UPD,
2316 ARM::VST4q32_UPD };
2317 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2318 ARM::VST4q16odd_UPD,
2319 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002320 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002321 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002322
2323 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002324 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002325 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2326 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002327 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002328 }
2329
2330 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002331 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002332 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2333 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002334 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002335 }
2336
2337 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002338 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002339 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2340 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002341 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002342 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002343 }
Bob Wilson429009b2010-05-06 16:05:26 +00002344 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002345 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002346
Bob Wilson429009b2010-05-06 16:05:26 +00002347 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002348 return SelectConcatVector(N);
2349 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002350
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002351 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002352}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002353
Bob Wilson224c2442009-05-19 05:53:42 +00002354bool ARMDAGToDAGISel::
2355SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2356 std::vector<SDValue> &OutOps) {
2357 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002358 // Require the address to be in a register. That is safe for all ARM
2359 // variants and it is hard to do anything much smarter without knowing
2360 // how the operand is used.
2361 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002362 return false;
2363}
2364
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002365/// createARMISelDag - This pass converts a legalized DAG into a
2366/// ARM-specific DAG, ready for instruction scheduling.
2367///
Bob Wilson522ce972009-09-28 14:30:20 +00002368FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2369 CodeGenOpt::Level OptLevel) {
2370 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002371}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002372
2373/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2374/// operations involving sub-registers.
2375bool llvm::ModelWithRegSequence() {
2376 return UseRegSeq;
2377}