blob: 193b246b865c9b1ceaa3dcfd8b25b8fe314ea17f [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000015#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000017#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000019#include "llvm/DerivedTypes.h"
20#include "llvm/Function.h"
21#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000022#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineFunction.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000029#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
34#include "llvm/Support/raw_ostream.h"
35
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036using namespace llvm;
37
Evan Cheng94cc6d32010-05-04 20:39:49 +000038static cl::opt<bool>
39UseRegSeq("neon-reg-sequence", cl::Hidden,
Evan Cheng62061242010-05-17 19:51:20 +000040 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"),
41 cl::init(true));
Evan Cheng94cc6d32010-05-04 20:39:49 +000042
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000043//===--------------------------------------------------------------------===//
44/// ARMDAGToDAGISel - ARM specific code to select ARM machine
45/// instructions for SelectionDAG operations.
46///
47namespace {
48class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000049 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000050
Evan Chenga8e29892007-01-19 07:51:42 +000051 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
52 /// make the right decision when generating code for different targets.
53 const ARMSubtarget *Subtarget;
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055public:
Bob Wilson522ce972009-09-28 14:30:20 +000056 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
57 CodeGenOpt::Level OptLevel)
58 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000059 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000060 }
61
Evan Chenga8e29892007-01-19 07:51:42 +000062 virtual const char *getPassName() const {
63 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000064 }
65
Bob Wilsonaf4a8912009-10-08 18:51:31 +000066 /// getI32Imm - Return a target constant of type i32 with the specified
67 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000068 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000069 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000070 }
71
Dan Gohmaneeb3a002010-01-05 01:24:18 +000072 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000073
Dan Gohmaneeb3a002010-01-05 01:24:18 +000074 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000075 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000076 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000078 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000079 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000080 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000081 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000082 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000083 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000084 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000085 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000087 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000088 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000089
Dan Gohmaneeb3a002010-01-05 01:24:18 +000090 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000091 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000092
Dan Gohmaneeb3a002010-01-05 01:24:18 +000093 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000094 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000095 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000096 SDValue &Base, SDValue &OffImm,
97 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000102 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000103 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000104 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000105 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000106
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000108 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000114 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000115 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000116 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000117 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000118 SDValue &OffReg, SDValue &ShImm);
119
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000120 // Include the pieces autogenerated from the target description.
121#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000122
123private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
125 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000126 SDNode *SelectARMIndexedLoad(SDNode *N);
127 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000128
Bob Wilson621f1952010-03-23 05:25:43 +0000129 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
130 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000131 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000132 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000133 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000134 unsigned *QOpcodes0, unsigned *QOpcodes1);
135
Bob Wilson24f995d2009-10-14 18:32:29 +0000136 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000137 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000138 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000139 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000141 unsigned *QOpcodes0, unsigned *QOpcodes1);
142
Bob Wilson96493442009-10-14 16:46:45 +0000143 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000144 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000145 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000146 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000147 unsigned *DOpcodes, unsigned *QOpcodes0,
148 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000149
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000150 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000151 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000152
Evan Cheng07ba9062009-11-19 21:45:22 +0000153 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000154 SDNode *SelectCMOVOp(SDNode *N);
155 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000156 ARMCC::CondCodes CCVal, SDValue CCR,
157 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000158 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000159 ARMCC::CondCodes CCVal, SDValue CCR,
160 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000162 ARMCC::CondCodes CCVal, SDValue CCR,
163 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000164 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000165 ARMCC::CondCodes CCVal, SDValue CCR,
166 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000167
Evan Chengde8aa4e2010-05-05 18:28:36 +0000168 SDNode *SelectConcatVector(SDNode *N);
169
Evan Chengaf4550f2009-07-02 01:23:32 +0000170 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
171 /// inline asm expressions.
172 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
173 char ConstraintCode,
174 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000175
Evan Cheng603afbf2010-05-10 17:34:18 +0000176 /// PairDRegs - Form a quad register from a pair of D registers.
177 ///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000178 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000179
180 /// PairDRegs - Form a quad register pair from a pair of Q registers.
181 ///
182 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
183
184 /// QuadDRegs - Form a quad register pair from a quad of D registers.
185 ///
186 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng5c6aba22010-05-14 18:54:59 +0000187
Evan Cheng8f6de382010-05-16 03:27:48 +0000188 /// QuadQRegs - Form 4 consecutive Q registers.
189 ///
190 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
191
Evan Cheng5c6aba22010-05-14 18:54:59 +0000192 /// OctoDRegs - Form 8 consecutive D registers.
193 ///
194 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
195 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000196};
Evan Chenga8e29892007-01-19 07:51:42 +0000197}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000198
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000199/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
200/// operand. If so Imm will receive the 32-bit value.
201static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
202 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
203 Imm = cast<ConstantSDNode>(N)->getZExtValue();
204 return true;
205 }
206 return false;
207}
208
209// isInt32Immediate - This method tests to see if a constant operand.
210// If so Imm will receive the 32 bit value.
211static bool isInt32Immediate(SDValue N, unsigned &Imm) {
212 return isInt32Immediate(N.getNode(), Imm);
213}
214
215// isOpcWithIntImmediate - This method tests to see if the node is a specific
216// opcode and that it has a immediate integer right operand.
217// If so Imm will receive the 32 bit value.
218static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
219 return N->getOpcode() == Opc &&
220 isInt32Immediate(N->getOperand(1).getNode(), Imm);
221}
222
223
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000224bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000225 SDValue N,
226 SDValue &BaseReg,
227 SDValue &ShReg,
228 SDValue &Opc) {
229 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
230
231 // Don't match base register only case. That is matched to a separate
232 // lower complexity pattern with explicit register operand.
233 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000234
Evan Cheng055b0312009-06-29 07:51:04 +0000235 BaseReg = N.getOperand(0);
236 unsigned ShImmVal = 0;
237 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000238 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000239 ShImmVal = RHS->getZExtValue() & 31;
240 } else {
241 ShReg = N.getOperand(1);
242 }
243 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000244 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000245 return true;
246}
247
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000248bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000249 SDValue &Base, SDValue &Offset,
250 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000251 if (N.getOpcode() == ISD::MUL) {
252 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
253 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000254 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000255 if (RHSC & 1) {
256 RHSC = RHSC & ~1;
257 ARM_AM::AddrOpc AddSub = ARM_AM::add;
258 if (RHSC < 0) {
259 AddSub = ARM_AM::sub;
260 RHSC = - RHSC;
261 }
262 if (isPowerOf2_32(RHSC)) {
263 unsigned ShAmt = Log2_32(RHSC);
264 Base = Offset = N.getOperand(0);
265 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
266 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000267 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000268 return true;
269 }
270 }
271 }
272 }
273
Evan Chenga8e29892007-01-19 07:51:42 +0000274 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
275 Base = N;
276 if (N.getOpcode() == ISD::FrameIndex) {
277 int FI = cast<FrameIndexSDNode>(N)->getIndex();
278 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000279 } else if (N.getOpcode() == ARMISD::Wrapper &&
280 !(Subtarget->useMovt() &&
281 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000282 Base = N.getOperand(0);
283 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000284 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000285 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
286 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000287 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000288 return true;
289 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000290
Evan Chenga8e29892007-01-19 07:51:42 +0000291 // Match simple R +/- imm12 operands.
292 if (N.getOpcode() == ISD::ADD)
293 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000294 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000295 if ((RHSC >= 0 && RHSC < 0x1000) ||
296 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000297 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000298 if (Base.getOpcode() == ISD::FrameIndex) {
299 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
300 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
301 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000302 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000303
304 ARM_AM::AddrOpc AddSub = ARM_AM::add;
305 if (RHSC < 0) {
306 AddSub = ARM_AM::sub;
307 RHSC = - RHSC;
308 }
309 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000310 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000311 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000312 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000313 }
Evan Chenga8e29892007-01-19 07:51:42 +0000314 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000315
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000316 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000317 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
318 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
319 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000320
Evan Chenga8e29892007-01-19 07:51:42 +0000321 Base = N.getOperand(0);
322 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000323
Evan Chenga8e29892007-01-19 07:51:42 +0000324 if (ShOpcVal != ARM_AM::no_shift) {
325 // Check to see if the RHS of the shift is a constant, if not, we can't fold
326 // it.
327 if (ConstantSDNode *Sh =
328 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000329 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000330 Offset = N.getOperand(1).getOperand(0);
331 } else {
332 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000333 }
334 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000335
Evan Chenga8e29892007-01-19 07:51:42 +0000336 // Try matching (R shl C) + (R).
337 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
338 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
339 if (ShOpcVal != ARM_AM::no_shift) {
340 // Check to see if the RHS of the shift is a constant, if not, we can't
341 // fold it.
342 if (ConstantSDNode *Sh =
343 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000344 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000345 Offset = N.getOperand(0).getOperand(0);
346 Base = N.getOperand(1);
347 } else {
348 ShOpcVal = ARM_AM::no_shift;
349 }
350 }
351 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000352
Evan Chenga8e29892007-01-19 07:51:42 +0000353 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000354 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000355 return true;
356}
357
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000358bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000359 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000360 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000361 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
362 ? cast<LoadSDNode>(Op)->getAddressingMode()
363 : cast<StoreSDNode>(Op)->getAddressingMode();
364 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
365 ? ARM_AM::add : ARM_AM::sub;
366 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000367 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000368 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000369 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000370 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
371 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000372 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000373 return true;
374 }
375 }
376
377 Offset = N;
378 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
379 unsigned ShAmt = 0;
380 if (ShOpcVal != ARM_AM::no_shift) {
381 // Check to see if the RHS of the shift is a constant, if not, we can't fold
382 // it.
383 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000384 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000385 Offset = N.getOperand(0);
386 } else {
387 ShOpcVal = ARM_AM::no_shift;
388 }
389 }
390
391 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000392 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000393 return true;
394}
395
Evan Chenga8e29892007-01-19 07:51:42 +0000396
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000397bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000398 SDValue &Base, SDValue &Offset,
399 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000400 if (N.getOpcode() == ISD::SUB) {
401 // X - C is canonicalize to X + -C, no need to handle it here.
402 Base = N.getOperand(0);
403 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000405 return true;
406 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000407
Evan Chenga8e29892007-01-19 07:51:42 +0000408 if (N.getOpcode() != ISD::ADD) {
409 Base = N;
410 if (N.getOpcode() == ISD::FrameIndex) {
411 int FI = cast<FrameIndexSDNode>(N)->getIndex();
412 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
413 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000414 Offset = CurDAG->getRegister(0, MVT::i32);
415 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000416 return true;
417 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000418
Evan Chenga8e29892007-01-19 07:51:42 +0000419 // If the RHS is +/- imm8, fold into addr mode.
420 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000421 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000422 if ((RHSC >= 0 && RHSC < 256) ||
423 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000424 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000425 if (Base.getOpcode() == ISD::FrameIndex) {
426 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
427 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
428 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000429 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000430
431 ARM_AM::AddrOpc AddSub = ARM_AM::add;
432 if (RHSC < 0) {
433 AddSub = ARM_AM::sub;
434 RHSC = - RHSC;
435 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000436 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000437 return true;
438 }
439 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000440
Evan Chenga8e29892007-01-19 07:51:42 +0000441 Base = N.getOperand(0);
442 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000443 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000444 return true;
445}
446
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000447bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000448 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000450 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
451 ? cast<LoadSDNode>(Op)->getAddressingMode()
452 : cast<StoreSDNode>(Op)->getAddressingMode();
453 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
454 ? ARM_AM::add : ARM_AM::sub;
455 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000456 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000457 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000458 Offset = CurDAG->getRegister(0, MVT::i32);
459 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000460 return true;
461 }
462 }
463
464 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000465 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000466 return true;
467}
468
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000469bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000470 SDValue &Addr, SDValue &Mode) {
471 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000472 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000473 return true;
474}
Evan Chenga8e29892007-01-19 07:51:42 +0000475
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000476bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000477 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000478 if (N.getOpcode() != ISD::ADD) {
479 Base = N;
480 if (N.getOpcode() == ISD::FrameIndex) {
481 int FI = cast<FrameIndexSDNode>(N)->getIndex();
482 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000483 } else if (N.getOpcode() == ARMISD::Wrapper &&
484 !(Subtarget->useMovt() &&
485 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000486 Base = N.getOperand(0);
487 }
488 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000489 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000490 return true;
491 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000492
Evan Chenga8e29892007-01-19 07:51:42 +0000493 // If the RHS is +/- imm8, fold into addr mode.
494 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000495 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000496 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
497 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000498 if ((RHSC >= 0 && RHSC < 256) ||
499 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000500 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000501 if (Base.getOpcode() == ISD::FrameIndex) {
502 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
503 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
504 }
505
506 ARM_AM::AddrOpc AddSub = ARM_AM::add;
507 if (RHSC < 0) {
508 AddSub = ARM_AM::sub;
509 RHSC = - RHSC;
510 }
511 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000512 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000513 return true;
514 }
515 }
516 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000517
Evan Chenga8e29892007-01-19 07:51:42 +0000518 Base = N;
519 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000520 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000521 return true;
522}
523
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000524bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000525 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000526 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000527 // Default to no alignment.
528 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000529 return true;
530}
531
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000532bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000533 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000534 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
535 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000536 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000537 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000538 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000539 return true;
540 }
541 return false;
542}
543
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000544bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000545 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000546 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000547 DebugLoc dl = Op->getDebugLoc();
Evan Chengc38f2bc2007-01-23 22:59:13 +0000548 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000549 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
550 if (!NC || NC->getZExtValue() != 0)
551 return false;
552
553 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000554 return true;
555 }
556
Evan Chenga8e29892007-01-19 07:51:42 +0000557 Base = N.getOperand(0);
558 Offset = N.getOperand(1);
559 return true;
560}
561
Evan Cheng79d43262007-01-24 02:21:22 +0000562bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000563ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000564 unsigned Scale, SDValue &Base,
565 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000566 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000567 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000568 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
569 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000570 if (N.getOpcode() == ARMISD::Wrapper &&
571 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
572 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000573 }
574
Evan Chenga8e29892007-01-19 07:51:42 +0000575 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000576 if (N.getOpcode() == ARMISD::Wrapper &&
577 !(Subtarget->useMovt() &&
578 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
579 Base = N.getOperand(0);
580 } else
581 Base = N;
582
Owen Anderson825b72b2009-08-11 20:47:22 +0000583 Offset = CurDAG->getRegister(0, MVT::i32);
584 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000585 return true;
586 }
587
Evan Chengad0e4652007-02-06 00:22:06 +0000588 // Thumb does not have [sp, r] address mode.
589 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
590 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
591 if ((LHSR && LHSR->getReg() == ARM::SP) ||
592 (RHSR && RHSR->getReg() == ARM::SP)) {
593 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 Offset = CurDAG->getRegister(0, MVT::i32);
595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000596 return true;
597 }
598
Evan Chenga8e29892007-01-19 07:51:42 +0000599 // If the RHS is + imm5 * scale, fold into addr mode.
600 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000601 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000602 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
603 RHSC /= Scale;
604 if (RHSC >= 0 && RHSC < 32) {
605 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 Offset = CurDAG->getRegister(0, MVT::i32);
607 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000608 return true;
609 }
610 }
611 }
612
Evan Chengc38f2bc2007-01-23 22:59:13 +0000613 Base = N.getOperand(0);
614 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000616 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000617}
618
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000619bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000620 SDValue &Base, SDValue &OffImm,
621 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000622 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000623}
624
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000625bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000626 SDValue &Base, SDValue &OffImm,
627 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000628 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000629}
630
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000631bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000632 SDValue &Base, SDValue &OffImm,
633 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000634 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000635}
636
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000637bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000638 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000639 if (N.getOpcode() == ISD::FrameIndex) {
640 int FI = cast<FrameIndexSDNode>(N)->getIndex();
641 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000642 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000643 return true;
644 }
Evan Cheng79d43262007-01-24 02:21:22 +0000645
Evan Chengad0e4652007-02-06 00:22:06 +0000646 if (N.getOpcode() != ISD::ADD)
647 return false;
648
649 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000650 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
651 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000652 // If the RHS is + imm8 * scale, fold into addr mode.
653 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000654 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000655 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
656 RHSC >>= 2;
657 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000658 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000659 if (Base.getOpcode() == ISD::FrameIndex) {
660 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
661 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
662 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000663 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000664 return true;
665 }
666 }
667 }
668 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 return false;
671}
672
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000673bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000674 SDValue &BaseReg,
675 SDValue &Opc) {
676 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
677
678 // Don't match base register only case. That is matched to a separate
679 // lower complexity pattern with explicit register operand.
680 if (ShOpcVal == ARM_AM::no_shift) return false;
681
682 BaseReg = N.getOperand(0);
683 unsigned ShImmVal = 0;
684 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
685 ShImmVal = RHS->getZExtValue() & 31;
686 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
687 return true;
688 }
689
690 return false;
691}
692
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000693bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000694 SDValue &Base, SDValue &OffImm) {
695 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000696
Evan Cheng3a214252009-08-11 08:52:18 +0000697 // Base only.
698 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000699 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000700 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000701 int FI = cast<FrameIndexSDNode>(N)->getIndex();
702 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000703 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000704 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000705 } else if (N.getOpcode() == ARMISD::Wrapper &&
706 !(Subtarget->useMovt() &&
707 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000708 Base = N.getOperand(0);
709 if (Base.getOpcode() == ISD::TargetConstantPool)
710 return false; // We want to select t2LDRpci instead.
711 } else
712 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000713 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000714 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000715 }
Evan Cheng055b0312009-06-29 07:51:04 +0000716
717 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000718 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
719 // Let t2LDRi8 handle (R - imm8).
720 return false;
721
Evan Cheng055b0312009-06-29 07:51:04 +0000722 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000723 if (N.getOpcode() == ISD::SUB)
724 RHSC = -RHSC;
725
726 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000727 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000728 if (Base.getOpcode() == ISD::FrameIndex) {
729 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
730 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
731 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000732 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000733 return true;
734 }
735 }
736
Evan Cheng3a214252009-08-11 08:52:18 +0000737 // Base only.
738 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000739 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000740 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000741}
742
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000743bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000744 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000745 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000746 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000747 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
748 int RHSC = (int)RHS->getSExtValue();
749 if (N.getOpcode() == ISD::SUB)
750 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000751
Evan Cheng3a214252009-08-11 08:52:18 +0000752 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
753 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000754 if (Base.getOpcode() == ISD::FrameIndex) {
755 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
756 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
757 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000758 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000759 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000760 }
Evan Cheng055b0312009-06-29 07:51:04 +0000761 }
762 }
763
764 return false;
765}
766
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000767bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000768 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000769 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000770 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
771 ? cast<LoadSDNode>(Op)->getAddressingMode()
772 : cast<StoreSDNode>(Op)->getAddressingMode();
773 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
774 int RHSC = (int)RHS->getZExtValue();
775 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000776 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000777 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
778 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000779 return true;
780 }
781 }
782
783 return false;
784}
785
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000786bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000787 SDValue &Base, SDValue &OffImm) {
788 if (N.getOpcode() == ISD::ADD) {
789 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
790 int RHSC = (int)RHS->getZExtValue();
Evan Cheng5c874172009-07-09 22:21:59 +0000791 if (((RHSC & 0x3) == 0) &&
792 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) { // 8 bits.
David Goodwin6647cea2009-06-30 22:50:01 +0000793 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000794 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000795 return true;
796 }
797 }
798 } else if (N.getOpcode() == ISD::SUB) {
799 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
800 int RHSC = (int)RHS->getZExtValue();
801 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) { // 8 bits.
802 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000803 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000804 return true;
805 }
806 }
807 }
808
809 return false;
810}
811
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000812bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000813 SDValue &Base,
814 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000815 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
816 if (N.getOpcode() != ISD::ADD)
817 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000818
Evan Cheng3a214252009-08-11 08:52:18 +0000819 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
820 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
821 int RHSC = (int)RHS->getZExtValue();
822 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
823 return false;
824 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000825 return false;
826 }
827
Evan Cheng055b0312009-06-29 07:51:04 +0000828 // Look for (R + R) or (R + (R << [1,2,3])).
829 unsigned ShAmt = 0;
830 Base = N.getOperand(0);
831 OffReg = N.getOperand(1);
832
833 // Swap if it is ((R << c) + R).
834 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
835 if (ShOpcVal != ARM_AM::lsl) {
836 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
837 if (ShOpcVal == ARM_AM::lsl)
838 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000839 }
840
Evan Cheng055b0312009-06-29 07:51:04 +0000841 if (ShOpcVal == ARM_AM::lsl) {
842 // Check to see if the RHS of the shift is a constant, if not, we can't fold
843 // it.
844 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
845 ShAmt = Sh->getZExtValue();
846 if (ShAmt >= 4) {
847 ShAmt = 0;
848 ShOpcVal = ARM_AM::no_shift;
849 } else
850 OffReg = OffReg.getOperand(0);
851 } else {
852 ShOpcVal = ARM_AM::no_shift;
853 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000854 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000855
Owen Anderson825b72b2009-08-11 20:47:22 +0000856 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000857
858 return true;
859}
860
861//===--------------------------------------------------------------------===//
862
Evan Chengee568cf2007-07-05 07:15:27 +0000863/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000864static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000865 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000866}
867
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000868SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
869 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 ISD::MemIndexedMode AM = LD->getAddressingMode();
871 if (AM == ISD::UNINDEXED)
872 return NULL;
873
Owen Andersone50ed302009-08-10 22:56:29 +0000874 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000875 SDValue Offset, AMOpc;
876 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
877 unsigned Opcode = 0;
878 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000880 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
882 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000883 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000884 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000885 Match = true;
886 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
887 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
888 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000889 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000890 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000891 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 Match = true;
893 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
894 }
895 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000896 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000897 Match = true;
898 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
899 }
900 }
901 }
902
903 if (Match) {
904 SDValue Chain = LD->getChain();
905 SDValue Base = LD->getBasePtr();
906 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000907 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000908 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000909 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000910 }
911
912 return NULL;
913}
914
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000915SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
916 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000917 ISD::MemIndexedMode AM = LD->getAddressingMode();
918 if (AM == ISD::UNINDEXED)
919 return NULL;
920
Owen Andersone50ed302009-08-10 22:56:29 +0000921 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000922 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000923 SDValue Offset;
924 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
925 unsigned Opcode = 0;
926 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000927 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000928 switch (LoadedVT.getSimpleVT().SimpleTy) {
929 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000930 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
931 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000932 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000933 if (isSExtLd)
934 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
935 else
936 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000937 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000938 case MVT::i8:
939 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000940 if (isSExtLd)
941 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
942 else
943 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000944 break;
945 default:
946 return NULL;
947 }
948 Match = true;
949 }
950
951 if (Match) {
952 SDValue Chain = LD->getChain();
953 SDValue Base = LD->getBasePtr();
954 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000955 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000956 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000957 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000958 }
959
960 return NULL;
961}
962
Evan Cheng603afbf2010-05-10 17:34:18 +0000963/// PairDRegs - Form a quad register from a pair of D registers.
964///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000965SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
966 DebugLoc dl = V0.getNode()->getDebugLoc();
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000967 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
968 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000969 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000970 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
971 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
972 }
973 SDValue Undef =
974 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000975 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000976 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000977 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000978 VT, SDValue(Pair, 0), V1, SubReg1);
979}
980
Evan Cheng7f687192010-05-14 00:21:45 +0000981/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000982///
983SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
984 DebugLoc dl = V0.getNode()->getDebugLoc();
985 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
986 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
987 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
988 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
989}
990
Evan Cheng7f687192010-05-14 00:21:45 +0000991/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000992///
993SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
994 SDValue V2, SDValue V3) {
995 DebugLoc dl = V0.getNode()->getDebugLoc();
996 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
997 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
998 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
999 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
1000 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1001 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1002}
1003
Evan Cheng8f6de382010-05-16 03:27:48 +00001004/// QuadQRegs - Form 4 consecutive Q registers.
1005///
1006SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1007 SDValue V2, SDValue V3) {
1008 DebugLoc dl = V0.getNode()->getDebugLoc();
1009 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::QSUBREG_0, MVT::i32);
1010 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::QSUBREG_1, MVT::i32);
1011 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::QSUBREG_2, MVT::i32);
1012 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::QSUBREG_3, MVT::i32);
1013 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1014 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1015}
1016
Evan Cheng5c6aba22010-05-14 18:54:59 +00001017/// OctoDRegs - Form 8 consecutive D registers.
1018///
1019SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1020 SDValue V2, SDValue V3,
1021 SDValue V4, SDValue V5,
1022 SDValue V6, SDValue V7) {
1023 DebugLoc dl = V0.getNode()->getDebugLoc();
1024 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1025 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1026 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::DSUBREG_2, MVT::i32);
1027 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::DSUBREG_3, MVT::i32);
1028 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::DSUBREG_4, MVT::i32);
1029 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::DSUBREG_5, MVT::i32);
1030 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::DSUBREG_6, MVT::i32);
1031 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::DSUBREG_7, MVT::i32);
1032 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1033 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1034 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1035}
1036
Bob Wilsona7c397c2009-10-14 16:19:03 +00001037/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1038/// for a 64-bit subregister of the vector.
1039static EVT GetNEONSubregVT(EVT VT) {
1040 switch (VT.getSimpleVT().SimpleTy) {
1041 default: llvm_unreachable("unhandled NEON type");
1042 case MVT::v16i8: return MVT::v8i8;
1043 case MVT::v8i16: return MVT::v4i16;
1044 case MVT::v4f32: return MVT::v2f32;
1045 case MVT::v4i32: return MVT::v2i32;
1046 case MVT::v2i64: return MVT::v1i64;
1047 }
1048}
1049
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001050SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001051 unsigned *DOpcodes, unsigned *QOpcodes0,
1052 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001053 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001054 DebugLoc dl = N->getDebugLoc();
1055
Bob Wilson226036e2010-03-20 22:13:40 +00001056 SDValue MemAddr, Align;
1057 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001058 return NULL;
1059
1060 SDValue Chain = N->getOperand(0);
1061 EVT VT = N->getValueType(0);
1062 bool is64BitVector = VT.is64BitVector();
1063
1064 unsigned OpcodeIndex;
1065 switch (VT.getSimpleVT().SimpleTy) {
1066 default: llvm_unreachable("unhandled vld type");
1067 // Double-register operations:
1068 case MVT::v8i8: OpcodeIndex = 0; break;
1069 case MVT::v4i16: OpcodeIndex = 1; break;
1070 case MVT::v2f32:
1071 case MVT::v2i32: OpcodeIndex = 2; break;
1072 case MVT::v1i64: OpcodeIndex = 3; break;
1073 // Quad-register operations:
1074 case MVT::v16i8: OpcodeIndex = 0; break;
1075 case MVT::v8i16: OpcodeIndex = 1; break;
1076 case MVT::v4f32:
1077 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001078 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001079 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001080 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001081 }
1082
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001083 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001084 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 if (is64BitVector) {
1086 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001087 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001088 std::vector<EVT> ResTys(NumVecs, VT);
1089 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001090 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1091 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1092 return VLd;
1093
Evan Cheng0ce537a2010-05-11 01:19:40 +00001094 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001095 SDValue V0 = SDValue(VLd, 0);
1096 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001097
Evan Cheng0ce537a2010-05-11 01:19:40 +00001098 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001099 if (NumVecs == 2)
1100 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1101 else {
1102 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001103 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001104 SDValue V3 = (NumVecs == 3)
1105 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1106 : SDValue(VLd, 3);
1107 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1108 }
1109
Evan Cheng5c6aba22010-05-14 18:54:59 +00001110 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1111 SDValue D = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec,
1112 dl, VT, RegSeq);
1113 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001114 }
1115 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1116 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001117 }
1118
1119 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001120 if (NumVecs <= 2) {
1121 // Quad registers are directly supported for VLD1 and VLD2,
1122 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001123 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001124 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001125 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001126 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001127 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001128 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001129
1130 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001131 if (llvm::ModelWithRegSequence()) {
1132 if (NumVecs == 1) {
1133 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1134 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1135 } else {
1136 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1137 SDValue(VLd, 0), SDValue(VLd, 1),
1138 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1139 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0, dl, VT, QQ);
1140 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_1, dl, VT, QQ);
1141 ReplaceUses(SDValue(N, 0), Q0);
1142 ReplaceUses(SDValue(N, 1), Q1);
1143 }
1144 } else {
1145 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1146 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1147 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1148 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001149 }
1150 } else {
1151 // Otherwise, quad registers are loaded with two separate instructions,
1152 // where one loads the even registers and the other loads the odd registers.
1153
Bob Wilson3e36f132009-10-14 17:28:52 +00001154 std::vector<EVT> ResTys(NumVecs, RegVT);
1155 ResTys.push_back(MemAddr.getValueType());
1156 ResTys.push_back(MVT::Other);
1157
Bob Wilson24f995d2009-10-14 18:32:29 +00001158 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001159 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001160 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1161 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001162 Chain = SDValue(VLdA, NumVecs+1);
1163
Bob Wilson24f995d2009-10-14 18:32:29 +00001164 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001165 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001166 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1167 Align, Reg0, Pred, Reg0, Chain };
1168 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001169 Chain = SDValue(VLdB, NumVecs+1);
1170
Evan Cheng5c6aba22010-05-14 18:54:59 +00001171 if (llvm::ModelWithRegSequence()) {
1172 SDValue V0 = SDValue(VLdA, 0);
1173 SDValue V1 = SDValue(VLdB, 0);
1174 SDValue V2 = SDValue(VLdA, 1);
1175 SDValue V3 = SDValue(VLdB, 1);
1176 SDValue V4 = SDValue(VLdA, 2);
1177 SDValue V5 = SDValue(VLdB, 2);
1178 SDValue V6 = (NumVecs == 3)
1179 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1180 0)
1181 : SDValue(VLdA, 3);
1182 SDValue V7 = (NumVecs == 3)
1183 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1184 0)
1185 : SDValue(VLdB, 3);
1186 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1187 V4, V5, V6, V7), 0);
1188
1189 // Extract out the 3 / 4 Q registers.
1190 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1191 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::QSUBREG_0+Vec,
1192 dl, VT, RegSeq);
1193 ReplaceUses(SDValue(N, Vec), Q);
1194 }
1195 } else {
1196 // Combine the even and odd subregs to produce the result.
1197 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1198 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1199 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1200 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001201 }
1202 }
1203 ReplaceUses(SDValue(N, NumVecs), Chain);
1204 return NULL;
1205}
1206
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001207SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001208 unsigned *DOpcodes, unsigned *QOpcodes0,
1209 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001210 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001211 DebugLoc dl = N->getDebugLoc();
1212
Bob Wilson226036e2010-03-20 22:13:40 +00001213 SDValue MemAddr, Align;
1214 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001215 return NULL;
1216
1217 SDValue Chain = N->getOperand(0);
1218 EVT VT = N->getOperand(3).getValueType();
1219 bool is64BitVector = VT.is64BitVector();
1220
1221 unsigned OpcodeIndex;
1222 switch (VT.getSimpleVT().SimpleTy) {
1223 default: llvm_unreachable("unhandled vst type");
1224 // Double-register operations:
1225 case MVT::v8i8: OpcodeIndex = 0; break;
1226 case MVT::v4i16: OpcodeIndex = 1; break;
1227 case MVT::v2f32:
1228 case MVT::v2i32: OpcodeIndex = 2; break;
1229 case MVT::v1i64: OpcodeIndex = 3; break;
1230 // Quad-register operations:
1231 case MVT::v16i8: OpcodeIndex = 0; break;
1232 case MVT::v8i16: OpcodeIndex = 1; break;
1233 case MVT::v4f32:
1234 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001235 case MVT::v2i64: OpcodeIndex = 3;
1236 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1237 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001238 }
1239
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001240 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001241 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001242
Bob Wilson226036e2010-03-20 22:13:40 +00001243 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001244 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001245 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001246
1247 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001248 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001249 SDValue RegSeq;
1250 SDValue V0 = N->getOperand(0+3);
1251 SDValue V1 = N->getOperand(1+3);
1252
1253 // Form a REG_SEQUENCE to force register allocation.
1254 if (NumVecs == 2)
1255 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1256 else {
1257 SDValue V2 = N->getOperand(2+3);
1258 // If it's a vld3, form a quad D-register and leave the last part as
1259 // an undef.
1260 SDValue V3 = (NumVecs == 3)
1261 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1262 : N->getOperand(3+3);
1263 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1264 }
1265
1266 // Now extract the D registers back out.
1267 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT,
1268 RegSeq));
1269 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT,
1270 RegSeq));
1271 if (NumVecs > 2)
1272 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT,
1273 RegSeq));
1274 if (NumVecs > 3)
1275 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT,
1276 RegSeq));
1277 } else {
1278 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1279 Ops.push_back(N->getOperand(Vec+3));
1280 }
Evan Chengac0869d2009-11-21 06:21:52 +00001281 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001282 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001283 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001284 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001285 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001286 }
1287
1288 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001289 if (NumVecs <= 2) {
1290 // Quad registers are directly supported for VST1 and VST2,
1291 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001292 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001293 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001294 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001295 SDValue Q0 = N->getOperand(3);
1296 SDValue Q1 = N->getOperand(4);
1297
1298 // Form a QQ register.
1299 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1300
1301 // Now extract the D registers back out.
Bob Wilson24f995d2009-10-14 18:32:29 +00001302 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001303 QQ));
Bob Wilson24f995d2009-10-14 18:32:29 +00001304 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001305 QQ));
1306 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, RegVT,
1307 QQ));
1308 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, RegVT,
1309 QQ));
1310 Ops.push_back(Pred);
1311 Ops.push_back(Reg0); // predicate register
1312 Ops.push_back(Chain);
1313 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1314 } else {
1315 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1316 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1317 N->getOperand(Vec+3)));
1318 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1319 N->getOperand(Vec+3)));
1320 }
1321 Ops.push_back(Pred);
1322 Ops.push_back(Reg0); // predicate register
1323 Ops.push_back(Chain);
1324 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1325 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001326 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001327 }
1328
1329 // Otherwise, quad registers are stored with two separate instructions,
1330 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001331 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001332 // Form the QQQQ REG_SEQUENCE.
1333 SDValue V[8];
1334 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1335 V[i] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1336 N->getOperand(Vec+3));
1337 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1338 N->getOperand(Vec+3));
1339 }
1340 if (NumVecs == 3)
Evan Cheng7189fd02010-05-15 07:53:37 +00001341 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1342 dl, RegVT), 0);
1343
Evan Cheng12c24692010-05-14 22:54:52 +00001344 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1345 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001346
Evan Cheng12c24692010-05-14 22:54:52 +00001347 // Store the even D registers.
1348 Ops.push_back(Reg0); // post-access address offset
1349 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1350 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0+Vec*2, dl,
1351 RegVT, RegSeq));
1352 Ops.push_back(Pred);
1353 Ops.push_back(Reg0); // predicate register
1354 Ops.push_back(Chain);
1355 unsigned Opc = QOpcodes0[OpcodeIndex];
1356 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1357 MVT::Other, Ops.data(), NumVecs+6);
1358 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001359
Evan Cheng12c24692010-05-14 22:54:52 +00001360 // Store the odd D registers.
1361 Ops[0] = SDValue(VStA, 0); // MemAddr
1362 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1363 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1+Vec*2, dl,
1364 RegVT, RegSeq);
1365 Ops[NumVecs+5] = Chain;
1366 Opc = QOpcodes1[OpcodeIndex];
1367 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1368 MVT::Other, Ops.data(), NumVecs+6);
1369 Chain = SDValue(VStB, 1);
1370 ReplaceUses(SDValue(N, 0), Chain);
1371 return NULL;
1372 } else {
1373 Ops.push_back(Reg0); // post-access address offset
1374
1375 // Store the even subregs.
1376 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1377 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, RegVT,
1378 N->getOperand(Vec+3)));
1379 Ops.push_back(Pred);
1380 Ops.push_back(Reg0); // predicate register
1381 Ops.push_back(Chain);
1382 unsigned Opc = QOpcodes0[OpcodeIndex];
1383 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1384 MVT::Other, Ops.data(), NumVecs+6);
1385 Chain = SDValue(VStA, 1);
1386
1387 // Store the odd subregs.
1388 Ops[0] = SDValue(VStA, 0); // MemAddr
1389 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1390 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, RegVT,
1391 N->getOperand(Vec+3));
1392 Ops[NumVecs+5] = Chain;
1393 Opc = QOpcodes1[OpcodeIndex];
1394 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1395 MVT::Other, Ops.data(), NumVecs+6);
1396 Chain = SDValue(VStB, 1);
1397 ReplaceUses(SDValue(N, 0), Chain);
1398 return NULL;
1399 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001400}
1401
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001402SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001403 unsigned NumVecs, unsigned *DOpcodes,
1404 unsigned *QOpcodes0,
1405 unsigned *QOpcodes1) {
1406 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001407 DebugLoc dl = N->getDebugLoc();
1408
Bob Wilson226036e2010-03-20 22:13:40 +00001409 SDValue MemAddr, Align;
1410 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001411 return NULL;
1412
1413 SDValue Chain = N->getOperand(0);
1414 unsigned Lane =
1415 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001416 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001417 bool is64BitVector = VT.is64BitVector();
1418
Bob Wilson96493442009-10-14 16:46:45 +00001419 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001420 unsigned NumElts = 0;
1421 int SubregIdx = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001422 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001423 EVT RegVT = VT;
1424 if (!is64BitVector) {
1425 RegVT = GetNEONSubregVT(VT);
1426 NumElts = RegVT.getVectorNumElements();
1427 SubregIdx = (Lane < NumElts) ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001429 }
1430
1431 unsigned OpcodeIndex;
1432 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001433 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001434 // Double-register operations:
1435 case MVT::v8i8: OpcodeIndex = 0; break;
1436 case MVT::v4i16: OpcodeIndex = 1; break;
1437 case MVT::v2f32:
1438 case MVT::v2i32: OpcodeIndex = 2; break;
1439 // Quad-register operations:
1440 case MVT::v8i16: OpcodeIndex = 0; break;
1441 case MVT::v4f32:
1442 case MVT::v4i32: OpcodeIndex = 1; break;
1443 }
1444
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001445 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001446 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001447
Bob Wilson226036e2010-03-20 22:13:40 +00001448 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001449 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001450 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001451
1452 unsigned Opc = 0;
1453 if (is64BitVector) {
1454 Opc = DOpcodes[OpcodeIndex];
Evan Cheng8f6de382010-05-16 03:27:48 +00001455 if (llvm::ModelWithRegSequence()) {
1456 SDValue RegSeq;
1457 SDValue V0 = N->getOperand(0+3);
1458 SDValue V1 = N->getOperand(1+3);
1459 if (NumVecs == 2) {
1460 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1461 } else {
1462 SDValue V2 = N->getOperand(2+3);
1463 SDValue V3 = (NumVecs == 3)
1464 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1465 : N->getOperand(3+3);
1466 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1467 }
1468
1469 // Now extract the D registers back out.
1470 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_0, dl, VT,
1471 RegSeq));
1472 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_1, dl, VT,
1473 RegSeq));
1474 if (NumVecs > 2)
1475 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_2, dl, VT,
1476 RegSeq));
1477 if (NumVecs > 3)
1478 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::DSUBREG_3, dl, VT,
1479 RegSeq));
1480 } else {
1481 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1482 Ops.push_back(N->getOperand(Vec+3));
1483 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001484 } else {
1485 // Check if this is loading the even or odd subreg of a Q register.
1486 if (Lane < NumElts) {
1487 Opc = QOpcodes0[OpcodeIndex];
1488 } else {
1489 Lane -= NumElts;
1490 Opc = QOpcodes1[OpcodeIndex];
1491 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001492
1493 if (llvm::ModelWithRegSequence()) {
1494 SDValue RegSeq;
1495 SDValue V0 = N->getOperand(0+3);
1496 SDValue V1 = N->getOperand(1+3);
1497 if (NumVecs == 2) {
1498 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1499 } else {
1500 SDValue V2 = N->getOperand(2+3);
1501 SDValue V3 = (NumVecs == 3)
1502 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1503 : N->getOperand(3+3);
1504 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1505 }
1506
1507 // Extract the subregs of the input vector.
1508 unsigned SubIdx = Even ? ARM::DSUBREG_0 : ARM::DSUBREG_1;
1509 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1510 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1511 RegSeq));
1512 } else {
1513 // Extract the subregs of the input vector.
1514 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1515 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1516 N->getOperand(Vec+3)));
1517 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001518 }
1519 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001520 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001521 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001522 Ops.push_back(Chain);
1523
Bob Wilson96493442009-10-14 16:46:45 +00001524 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001525 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001526
Bob Wilsona7c397c2009-10-14 16:19:03 +00001527 std::vector<EVT> ResTys(NumVecs, RegVT);
1528 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001529 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1530
Evan Cheng7189fd02010-05-15 07:53:37 +00001531 if (llvm::ModelWithRegSequence()) {
Evan Cheng7092c2b2010-05-15 01:36:29 +00001532 // Form a REG_SEQUENCE to force register allocation.
Evan Cheng7189fd02010-05-15 07:53:37 +00001533 SDValue RegSeq;
1534 if (is64BitVector) {
1535 SDValue V0 = SDValue(VLdLn, 0);
1536 SDValue V1 = SDValue(VLdLn, 1);
1537 if (NumVecs == 2) {
1538 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1539 } else {
1540 SDValue V2 = SDValue(VLdLn, 2);
1541 // If it's a vld3, form a quad D-register but discard the last part.
1542 SDValue V3 = (NumVecs == 3)
Evan Cheng7092c2b2010-05-15 01:36:29 +00001543 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1544 : SDValue(VLdLn, 3);
Evan Cheng7189fd02010-05-15 07:53:37 +00001545 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1546 }
1547 } else {
1548 // For 128-bit vectors, take the 64-bit results of the load and insert them
1549 // as subregs into the result.
1550 SDValue V[8];
1551 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Evan Cheng8f6de382010-05-16 03:27:48 +00001552 if (Even) {
Evan Cheng7189fd02010-05-15 07:53:37 +00001553 V[i] = SDValue(VLdLn, Vec);
1554 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1555 dl, RegVT), 0);
1556 } else {
1557 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1558 dl, RegVT), 0);
1559 V[i+1] = SDValue(VLdLn, Vec);
1560 }
1561 }
1562 if (NumVecs == 3)
1563 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1564 dl, RegVT), 0);
1565
1566 if (NumVecs == 2)
1567 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1568 else
1569 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1570 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001571 }
1572
Evan Cheng7189fd02010-05-15 07:53:37 +00001573 unsigned SubIdx = is64BitVector ? ARM::DSUBREG_0 : ARM::QSUBREG_0;
1574 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1575 ReplaceUses(SDValue(N, Vec),
1576 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
Evan Cheng7092c2b2010-05-15 01:36:29 +00001577 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1578 return NULL;
1579 }
1580
Bob Wilsona7c397c2009-10-14 16:19:03 +00001581 // For a 64-bit vector load to D registers, nothing more needs to be done.
1582 if (is64BitVector)
1583 return VLdLn;
1584
1585 // For 128-bit vectors, take the 64-bit results of the load and insert them
1586 // as subregs into the result.
1587 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1588 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1589 N->getOperand(Vec+3),
1590 SDValue(VLdLn, Vec));
1591 ReplaceUses(SDValue(N, Vec), QuadVec);
1592 }
1593
1594 Chain = SDValue(VLdLn, NumVecs);
1595 ReplaceUses(SDValue(N, NumVecs), Chain);
1596 return NULL;
1597}
1598
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001599SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001600 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001601 if (!Subtarget->hasV6T2Ops())
1602 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001603
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001604 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1605 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1606
1607
1608 // For unsigned extracts, check for a shift right and mask
1609 unsigned And_imm = 0;
1610 if (N->getOpcode() == ISD::AND) {
1611 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1612
1613 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1614 if (And_imm & (And_imm + 1))
1615 return NULL;
1616
1617 unsigned Srl_imm = 0;
1618 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1619 Srl_imm)) {
1620 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1621
1622 unsigned Width = CountTrailingOnes_32(And_imm);
1623 unsigned LSB = Srl_imm;
1624 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1625 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1626 CurDAG->getTargetConstant(LSB, MVT::i32),
1627 CurDAG->getTargetConstant(Width, MVT::i32),
1628 getAL(CurDAG), Reg0 };
1629 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1630 }
1631 }
1632 return NULL;
1633 }
1634
1635 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001636 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001637 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001638 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1639 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001640 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001641 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1642 unsigned Width = 32 - Srl_imm;
1643 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001644 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001645 return NULL;
1646 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001647 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001648 CurDAG->getTargetConstant(LSB, MVT::i32),
1649 CurDAG->getTargetConstant(Width, MVT::i32),
1650 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001651 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001652 }
1653 }
1654 return NULL;
1655}
1656
Evan Cheng9ef48352009-11-20 00:54:03 +00001657SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001658SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001659 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1660 SDValue CPTmp0;
1661 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001662 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001663 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1664 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1665 unsigned Opc = 0;
1666 switch (SOShOp) {
1667 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1668 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1669 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1670 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1671 default:
1672 llvm_unreachable("Unknown so_reg opcode!");
1673 break;
1674 }
1675 SDValue SOShImm =
1676 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1677 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1678 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001679 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001680 }
1681 return 0;
1682}
1683
1684SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001685SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001686 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1687 SDValue CPTmp0;
1688 SDValue CPTmp1;
1689 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001690 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001691 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1692 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001693 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001694 }
1695 return 0;
1696}
1697
1698SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001699SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001700 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1701 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1702 if (!T)
1703 return 0;
1704
1705 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1706 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1707 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1708 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001709 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001710 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1711 }
1712 return 0;
1713}
1714
1715SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001716SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001717 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1718 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1719 if (!T)
1720 return 0;
1721
1722 if (Predicate_so_imm(TrueVal.getNode())) {
1723 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1724 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1725 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001726 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001727 ARM::MOVCCi, MVT::i32, Ops, 5);
1728 }
1729 return 0;
1730}
1731
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001732SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1733 EVT VT = N->getValueType(0);
1734 SDValue FalseVal = N->getOperand(0);
1735 SDValue TrueVal = N->getOperand(1);
1736 SDValue CC = N->getOperand(2);
1737 SDValue CCR = N->getOperand(3);
1738 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001739 assert(CC.getOpcode() == ISD::Constant);
1740 assert(CCR.getOpcode() == ISD::Register);
1741 ARMCC::CondCodes CCVal =
1742 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001743
1744 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1745 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1746 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1747 // Pattern complexity = 18 cost = 1 size = 0
1748 SDValue CPTmp0;
1749 SDValue CPTmp1;
1750 SDValue CPTmp2;
1751 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001752 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001753 CCVal, CCR, InFlag);
1754 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001755 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001756 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1757 if (Res)
1758 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001759 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001761 CCVal, CCR, InFlag);
1762 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001763 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001764 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1765 if (Res)
1766 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001767 }
1768
1769 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1770 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1771 // (imm:i32):$cc)
1772 // Emits: (MOVCCi:i32 GPR:i32:$false,
1773 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1774 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001775 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001776 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001777 CCVal, CCR, InFlag);
1778 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001779 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001780 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1781 if (Res)
1782 return Res;
1783 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001784 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001785 CCVal, CCR, InFlag);
1786 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001787 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001788 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1789 if (Res)
1790 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001791 }
1792 }
1793
1794 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1795 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1796 // Pattern complexity = 6 cost = 1 size = 0
1797 //
1798 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1799 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1800 // Pattern complexity = 6 cost = 11 size = 0
1801 //
1802 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001803 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1804 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001805 unsigned Opc = 0;
1806 switch (VT.getSimpleVT().SimpleTy) {
1807 default: assert(false && "Illegal conditional move type!");
1808 break;
1809 case MVT::i32:
1810 Opc = Subtarget->isThumb()
1811 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1812 : ARM::MOVCCr;
1813 break;
1814 case MVT::f32:
1815 Opc = ARM::VMOVScc;
1816 break;
1817 case MVT::f64:
1818 Opc = ARM::VMOVDcc;
1819 break;
1820 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001821 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001822}
1823
Evan Chengde8aa4e2010-05-05 18:28:36 +00001824SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1825 // The only time a CONCAT_VECTORS operation can have legal types is when
1826 // two 64-bit vectors are concatenated to a 128-bit vector.
1827 EVT VT = N->getValueType(0);
1828 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1829 llvm_unreachable("unexpected CONCAT_VECTORS");
1830 DebugLoc dl = N->getDebugLoc();
1831 SDValue V0 = N->getOperand(0);
1832 SDValue V1 = N->getOperand(1);
1833 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::DSUBREG_0, MVT::i32);
1834 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::DSUBREG_1, MVT::i32);
1835 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1836 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1837}
1838
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001839SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001840 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001841
Dan Gohmane8be6c62008-07-17 19:10:17 +00001842 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001843 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001844
1845 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001846 default: break;
1847 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001848 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001849 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001850 if (Subtarget->hasThumb2())
1851 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1852 // be done with MOV + MOVT, at worst.
1853 UseCP = 0;
1854 else {
1855 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001856 UseCP = (Val > 255 && // MOV
1857 ~Val > 255 && // MOV + MVN
1858 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001859 } else
1860 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1861 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1862 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1863 }
1864
Evan Chenga8e29892007-01-19 07:51:42 +00001865 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001866 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001867 CurDAG->getTargetConstantPool(ConstantInt::get(
1868 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001869 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001870
1871 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001872 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001873 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001874 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001875 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001876 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1877 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001878 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001879 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001880 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001881 CurDAG->getRegister(0, MVT::i32),
1882 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001883 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001884 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001885 CurDAG->getEntryNode()
1886 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001887 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1888 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001889 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001890 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001891 return NULL;
1892 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001893
Evan Chenga8e29892007-01-19 07:51:42 +00001894 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001895 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001896 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001897 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001898 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001899 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001900 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001901 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001902 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1903 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001904 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001905 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1906 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001907 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1908 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1909 CurDAG->getRegister(0, MVT::i32) };
1910 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001911 }
Evan Chenga8e29892007-01-19 07:51:42 +00001912 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001913 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001914 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001915 return I;
1916 break;
1917 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001918 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001919 return I;
1920 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001921 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001922 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001923 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001924 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001925 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001926 if (!RHSV) break;
1927 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001928 unsigned ShImm = Log2_32(RHSV-1);
1929 if (ShImm >= 32)
1930 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001931 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001932 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001933 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1934 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001935 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001936 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001937 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001938 } else {
1939 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001940 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001941 }
Evan Chenga8e29892007-01-19 07:51:42 +00001942 }
1943 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001944 unsigned ShImm = Log2_32(RHSV+1);
1945 if (ShImm >= 32)
1946 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001947 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001948 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001949 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1950 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001951 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001952 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001953 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 5);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001954 } else {
1955 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001956 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001957 }
Evan Chenga8e29892007-01-19 07:51:42 +00001958 }
1959 }
1960 break;
Evan Cheng20956592009-10-21 08:15:52 +00001961 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001962 // Check for unsigned bitfield extract
1963 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1964 return I;
1965
Evan Cheng20956592009-10-21 08:15:52 +00001966 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1967 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1968 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1969 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1970 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001972 if (VT != MVT::i32)
1973 break;
1974 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1975 ? ARM::t2MOVTi16
1976 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1977 if (!Opc)
1978 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001980 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1981 if (!N1C)
1982 break;
1983 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1984 SDValue N2 = N0.getOperand(1);
1985 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1986 if (!N2C)
1987 break;
1988 unsigned N1CVal = N1C->getZExtValue();
1989 unsigned N2CVal = N2C->getZExtValue();
1990 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1991 (N1CVal & 0xffffU) == 0xffffU &&
1992 (N2CVal & 0xffffU) == 0x0U) {
1993 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1994 MVT::i32);
1995 SDValue Ops[] = { N0.getOperand(0), Imm16,
1996 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1997 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1998 }
1999 }
2000 break;
2001 }
Jim Grosbache5165492009-11-09 00:11:35 +00002002 case ARMISD::VMOVRRD:
2003 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002004 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002005 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002006 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002007 if (Subtarget->isThumb1Only())
2008 break;
2009 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002010 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002011 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2012 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002013 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002014 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002015 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002016 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2017 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002018 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002019 }
Evan Chengee568cf2007-07-05 07:15:27 +00002020 }
Dan Gohman525178c2007-10-08 18:33:35 +00002021 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002022 if (Subtarget->isThumb1Only())
2023 break;
2024 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002025 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002026 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002027 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002028 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002029 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002030 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2031 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002032 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002033 }
Evan Chengee568cf2007-07-05 07:15:27 +00002034 }
Evan Chenga8e29892007-01-19 07:51:42 +00002035 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002036 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002037 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002038 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002039 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002040 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002041 if (ResNode)
2042 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002043
2044 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2045 if (Subtarget->hasVFP2() &&
2046 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2047 SDValue Chain = N->getOperand(0);
2048 SDValue AM5Opc =
2049 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002050 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002051 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2052 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
2053 return CurDAG->getMachineNode(ARM::VLDMQ, dl, MVT::v2f64, MVT::Other,
2054 Ops, 5);
2055 }
2056 // Other cases are autogenerated.
2057 break;
2058 }
2059 case ISD::STORE: {
2060 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2061 if (Subtarget->hasVFP2() &&
2062 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2063 SDValue Chain = N->getOperand(0);
2064 SDValue AM5Opc =
2065 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002066 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002067 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2068 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2069 AM5Opc, Pred, PredReg, Chain };
2070 return CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2071 }
Evan Chenga8e29892007-01-19 07:51:42 +00002072 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002073 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002074 }
Evan Chengee568cf2007-07-05 07:15:27 +00002075 case ARMISD::BRCOND: {
2076 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2077 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2078 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002079
Evan Chengee568cf2007-07-05 07:15:27 +00002080 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2081 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2082 // Pattern complexity = 6 cost = 1 size = 0
2083
David Goodwin5e47a9a2009-06-30 18:04:13 +00002084 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2085 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2086 // Pattern complexity = 6 cost = 1 size = 0
2087
Jim Grosbach764ab522009-08-11 15:33:49 +00002088 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002089 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002090 SDValue Chain = N->getOperand(0);
2091 SDValue N1 = N->getOperand(1);
2092 SDValue N2 = N->getOperand(2);
2093 SDValue N3 = N->getOperand(3);
2094 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002095 assert(N1.getOpcode() == ISD::BasicBlock);
2096 assert(N2.getOpcode() == ISD::Constant);
2097 assert(N3.getOpcode() == ISD::Register);
2098
Dan Gohman475871a2008-07-27 21:46:04 +00002099 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002100 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002101 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002102 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002103 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2104 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002105 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002107 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002108 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002109 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002110 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002111 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002112 return NULL;
2113 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002114 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002115 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002116 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002117 EVT VT = N->getValueType(0);
2118 SDValue N0 = N->getOperand(0);
2119 SDValue N1 = N->getOperand(1);
2120 SDValue N2 = N->getOperand(2);
2121 SDValue N3 = N->getOperand(3);
2122 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002123 assert(N2.getOpcode() == ISD::Constant);
2124 assert(N3.getOpcode() == ISD::Register);
2125
Dan Gohman475871a2008-07-27 21:46:04 +00002126 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002127 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002128 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002129 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002130 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002131 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002132 default: assert(false && "Illegal conditional move type!");
2133 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002134 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002135 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002136 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002137 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002138 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002139 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002140 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002141 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002142 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002143
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002144 case ARMISD::VZIP: {
2145 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002146 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002147 switch (VT.getSimpleVT().SimpleTy) {
2148 default: return NULL;
2149 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2150 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2151 case MVT::v2f32:
2152 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2153 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2154 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2155 case MVT::v4f32:
2156 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2157 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002158 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002159 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2160 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2161 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002162 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002163 case ARMISD::VUZP: {
2164 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002165 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002166 switch (VT.getSimpleVT().SimpleTy) {
2167 default: return NULL;
2168 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2169 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2170 case MVT::v2f32:
2171 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2172 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2173 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2174 case MVT::v4f32:
2175 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2176 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002177 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002178 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2179 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2180 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002181 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002182 case ARMISD::VTRN: {
2183 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002184 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002185 switch (VT.getSimpleVT().SimpleTy) {
2186 default: return NULL;
2187 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2188 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2189 case MVT::v2f32:
2190 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2191 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2192 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2193 case MVT::v4f32:
2194 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2195 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002196 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002197 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2198 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2199 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002200 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002201
2202 case ISD::INTRINSIC_VOID:
2203 case ISD::INTRINSIC_W_CHAIN: {
2204 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002205 switch (IntNo) {
2206 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002207 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002208
Bob Wilson621f1952010-03-23 05:25:43 +00002209 case Intrinsic::arm_neon_vld1: {
2210 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2211 ARM::VLD1d32, ARM::VLD1d64 };
2212 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2213 ARM::VLD1q32, ARM::VLD1q64 };
2214 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2215 }
2216
Bob Wilson31fb12f2009-08-26 17:39:53 +00002217 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002218 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002219 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002220 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002221 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002222 }
2223
2224 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002225 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002226 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002227 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2228 ARM::VLD3q16_UPD,
2229 ARM::VLD3q32_UPD };
2230 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2231 ARM::VLD3q16odd_UPD,
2232 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002233 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002234 }
2235
2236 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002237 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002238 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002239 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2240 ARM::VLD4q16_UPD,
2241 ARM::VLD4q32_UPD };
2242 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2243 ARM::VLD4q16odd_UPD,
2244 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002245 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002246 }
2247
Bob Wilson243fcc52009-09-01 04:26:28 +00002248 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002249 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002250 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2251 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002252 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002253 }
2254
2255 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002256 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002257 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2258 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002259 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002260 }
2261
2262 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002263 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002264 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2265 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002266 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002267 }
2268
Bob Wilson11d98992010-03-23 06:20:33 +00002269 case Intrinsic::arm_neon_vst1: {
2270 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2271 ARM::VST1d32, ARM::VST1d64 };
2272 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2273 ARM::VST1q32, ARM::VST1q64 };
2274 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2275 }
2276
Bob Wilson31fb12f2009-08-26 17:39:53 +00002277 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002278 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002279 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002280 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002281 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002282 }
2283
2284 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002285 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002286 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002287 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2288 ARM::VST3q16_UPD,
2289 ARM::VST3q32_UPD };
2290 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2291 ARM::VST3q16odd_UPD,
2292 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002293 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002294 }
2295
2296 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002297 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002298 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002299 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2300 ARM::VST4q16_UPD,
2301 ARM::VST4q32_UPD };
2302 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2303 ARM::VST4q16odd_UPD,
2304 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002305 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002306 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002307
2308 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002309 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002310 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2311 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002312 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002313 }
2314
2315 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002316 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002317 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2318 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002319 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002320 }
2321
2322 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002323 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002324 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2325 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002326 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002327 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002328 }
Bob Wilson429009b2010-05-06 16:05:26 +00002329 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002330 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002331
Bob Wilson429009b2010-05-06 16:05:26 +00002332 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002333 return SelectConcatVector(N);
2334 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002335
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002336 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002337}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002338
Bob Wilson224c2442009-05-19 05:53:42 +00002339bool ARMDAGToDAGISel::
2340SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2341 std::vector<SDValue> &OutOps) {
2342 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002343 // Require the address to be in a register. That is safe for all ARM
2344 // variants and it is hard to do anything much smarter without knowing
2345 // how the operand is used.
2346 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002347 return false;
2348}
2349
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002350/// createARMISelDag - This pass converts a legalized DAG into a
2351/// ARM-specific DAG, ready for instruction scheduling.
2352///
Bob Wilson522ce972009-09-28 14:30:20 +00002353FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2354 CodeGenOpt::Level OptLevel) {
2355 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002356}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002357
2358/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2359/// operations involving sub-registers.
2360bool llvm::ModelWithRegSequence() {
2361 return UseRegSeq;
2362}