blob: 86f64bc48a04a874728487e217aa545f7350a753 [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
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000016#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037using namespace llvm;
38
Evan Chenga2c519b2010-07-30 23:33:54 +000039static cl::opt<bool>
40DisableShifterOp("disable-shifter-op", cl::Hidden,
41 cl::desc("Disable isel of shifter-op"),
42 cl::init(false));
43
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000044//===--------------------------------------------------------------------===//
45/// ARMDAGToDAGISel - ARM specific code to select ARM machine
46/// instructions for SelectionDAG operations.
47///
48namespace {
49class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000050 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000051
Evan Chenga8e29892007-01-19 07:51:42 +000052 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
53 /// make the right decision when generating code for different targets.
54 const ARMSubtarget *Subtarget;
55
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000056public:
Bob Wilson522ce972009-09-28 14:30:20 +000057 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
58 CodeGenOpt::Level OptLevel)
59 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000060 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061 }
62
Evan Chenga8e29892007-01-19 07:51:42 +000063 virtual const char *getPassName() const {
64 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000065 }
66
Bob Wilsonaf4a8912009-10-08 18:51:31 +000067 /// getI32Imm - Return a target constant of type i32 with the specified
68 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000069 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000070 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Dan Gohmaneeb3a002010-01-05 01:24:18 +000073 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000074
Dan Gohmaneeb3a002010-01-05 01:24:18 +000075 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000076 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000077 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000078 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000081 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000082 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000083 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000084 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000085 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000086 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000088 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000089 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000090
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000092 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000093
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000097 SDValue &Base, SDValue &OffImm,
98 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000099 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000100 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000101 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000102 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000104 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000106 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000107
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000108 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000109 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000111 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000112 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000113 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000115 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000116 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000117 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000118 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000119 SDValue &OffReg, SDValue &ShImm);
120
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000121 inline bool Pred_so_imm(SDNode *inN) const {
122 ConstantSDNode *N = cast<ConstantSDNode>(inN);
123 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
124 }
125
126 inline bool Pred_t2_so_imm(SDNode *inN) const {
127 ConstantSDNode *N = cast<ConstantSDNode>(inN);
128 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
129 }
130
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000131 // Include the pieces autogenerated from the target description.
132#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000133
134private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000135 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
136 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000137 SDNode *SelectARMIndexedLoad(SDNode *N);
138 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000139
Bob Wilson621f1952010-03-23 05:25:43 +0000140 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
141 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000142 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000143 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000144 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000145 unsigned *QOpcodes0, unsigned *QOpcodes1);
146
Bob Wilson24f995d2009-10-14 18:32:29 +0000147 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000148 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000149 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000150 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000151 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000152 unsigned *QOpcodes0, unsigned *QOpcodes1);
153
Bob Wilson96493442009-10-14 16:46:45 +0000154 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000155 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000156 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000158 unsigned *DOpcodes, unsigned *QOpcodes0,
159 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000160
Bob Wilson78dfbc32010-07-07 00:08:54 +0000161 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
162 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
163 /// generated to force the table registers to be consecutive.
164 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000165
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000166 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000167 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000168
Evan Cheng07ba9062009-11-19 21:45:22 +0000169 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000170 SDNode *SelectCMOVOp(SDNode *N);
171 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000172 ARMCC::CondCodes CCVal, SDValue CCR,
173 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000174 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000175 ARMCC::CondCodes CCVal, SDValue CCR,
176 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000177 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000178 ARMCC::CondCodes CCVal, SDValue CCR,
179 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000180 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000181 ARMCC::CondCodes CCVal, SDValue CCR,
182 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000183
Evan Chengde8aa4e2010-05-05 18:28:36 +0000184 SDNode *SelectConcatVector(SDNode *N);
185
Evan Chengaf4550f2009-07-02 01:23:32 +0000186 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
187 /// inline asm expressions.
188 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
189 char ConstraintCode,
190 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000191
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000192 // Form pairs of consecutive S, D, or Q registers.
193 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000194 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000195 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
196
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000197 // Form sequences of 4 consecutive S, D, or Q registers.
198 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000199 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000200 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
201
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000202 // Form sequences of 8 consecutive D registers.
Evan Cheng5c6aba22010-05-14 18:54:59 +0000203 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
204 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000205};
Evan Chenga8e29892007-01-19 07:51:42 +0000206}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000207
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000208/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
209/// operand. If so Imm will receive the 32-bit value.
210static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
211 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
212 Imm = cast<ConstantSDNode>(N)->getZExtValue();
213 return true;
214 }
215 return false;
216}
217
218// isInt32Immediate - This method tests to see if a constant operand.
219// If so Imm will receive the 32 bit value.
220static bool isInt32Immediate(SDValue N, unsigned &Imm) {
221 return isInt32Immediate(N.getNode(), Imm);
222}
223
224// isOpcWithIntImmediate - This method tests to see if the node is a specific
225// opcode and that it has a immediate integer right operand.
226// If so Imm will receive the 32 bit value.
227static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
228 return N->getOpcode() == Opc &&
229 isInt32Immediate(N->getOperand(1).getNode(), Imm);
230}
231
232
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000234 SDValue N,
235 SDValue &BaseReg,
236 SDValue &ShReg,
237 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000238 if (DisableShifterOp)
239 return false;
240
Evan Cheng055b0312009-06-29 07:51:04 +0000241 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
242
243 // Don't match base register only case. That is matched to a separate
244 // lower complexity pattern with explicit register operand.
245 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000246
Evan Cheng055b0312009-06-29 07:51:04 +0000247 BaseReg = N.getOperand(0);
248 unsigned ShImmVal = 0;
249 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000250 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000251 ShImmVal = RHS->getZExtValue() & 31;
252 } else {
253 ShReg = N.getOperand(1);
254 }
255 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000256 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000257 return true;
258}
259
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000260bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000261 SDValue &Base, SDValue &Offset,
262 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000263 if (N.getOpcode() == ISD::MUL) {
264 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
265 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000266 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000267 if (RHSC & 1) {
268 RHSC = RHSC & ~1;
269 ARM_AM::AddrOpc AddSub = ARM_AM::add;
270 if (RHSC < 0) {
271 AddSub = ARM_AM::sub;
272 RHSC = - RHSC;
273 }
274 if (isPowerOf2_32(RHSC)) {
275 unsigned ShAmt = Log2_32(RHSC);
276 Base = Offset = N.getOperand(0);
277 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
278 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000279 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000280 return true;
281 }
282 }
283 }
284 }
285
Evan Chenga8e29892007-01-19 07:51:42 +0000286 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
287 Base = N;
288 if (N.getOpcode() == ISD::FrameIndex) {
289 int FI = cast<FrameIndexSDNode>(N)->getIndex();
290 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000291 } else if (N.getOpcode() == ARMISD::Wrapper &&
292 !(Subtarget->useMovt() &&
293 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000294 Base = N.getOperand(0);
295 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000296 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000297 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
298 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000299 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000300 return true;
301 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000302
Evan Chenga8e29892007-01-19 07:51:42 +0000303 // Match simple R +/- imm12 operands.
304 if (N.getOpcode() == ISD::ADD)
305 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000306 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000307 if ((RHSC >= 0 && RHSC < 0x1000) ||
308 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000309 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000310 if (Base.getOpcode() == ISD::FrameIndex) {
311 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
312 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
313 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000314 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000315
316 ARM_AM::AddrOpc AddSub = ARM_AM::add;
317 if (RHSC < 0) {
318 AddSub = ARM_AM::sub;
319 RHSC = - RHSC;
320 }
321 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000322 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000323 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000324 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000325 }
Evan Chenga8e29892007-01-19 07:51:42 +0000326 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000327
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000328 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000329 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
330 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
331 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000332
Evan Chenga8e29892007-01-19 07:51:42 +0000333 Base = N.getOperand(0);
334 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000335
Evan Chenga8e29892007-01-19 07:51:42 +0000336 if (ShOpcVal != ARM_AM::no_shift) {
337 // Check to see if the RHS of the shift is a constant, if not, we can't fold
338 // it.
339 if (ConstantSDNode *Sh =
340 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000341 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000342 Offset = N.getOperand(1).getOperand(0);
343 } else {
344 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000345 }
346 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000347
Evan Chenga8e29892007-01-19 07:51:42 +0000348 // Try matching (R shl C) + (R).
349 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
350 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
351 if (ShOpcVal != ARM_AM::no_shift) {
352 // Check to see if the RHS of the shift is a constant, if not, we can't
353 // fold it.
354 if (ConstantSDNode *Sh =
355 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000356 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000357 Offset = N.getOperand(0).getOperand(0);
358 Base = N.getOperand(1);
359 } else {
360 ShOpcVal = ARM_AM::no_shift;
361 }
362 }
363 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000364
Evan Chenga8e29892007-01-19 07:51:42 +0000365 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000366 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000367 return true;
368}
369
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000370bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000371 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000372 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000373 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
374 ? cast<LoadSDNode>(Op)->getAddressingMode()
375 : cast<StoreSDNode>(Op)->getAddressingMode();
376 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
377 ? ARM_AM::add : ARM_AM::sub;
378 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000379 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000380 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000381 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000382 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
383 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000384 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000385 return true;
386 }
387 }
388
389 Offset = N;
390 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
391 unsigned ShAmt = 0;
392 if (ShOpcVal != ARM_AM::no_shift) {
393 // Check to see if the RHS of the shift is a constant, if not, we can't fold
394 // it.
395 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000396 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000397 Offset = N.getOperand(0);
398 } else {
399 ShOpcVal = ARM_AM::no_shift;
400 }
401 }
402
403 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000404 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000405 return true;
406}
407
Evan Chenga8e29892007-01-19 07:51:42 +0000408
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000409bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000410 SDValue &Base, SDValue &Offset,
411 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000412 if (N.getOpcode() == ISD::SUB) {
413 // X - C is canonicalize to X + -C, no need to handle it here.
414 Base = N.getOperand(0);
415 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000417 return true;
418 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000419
Evan Chenga8e29892007-01-19 07:51:42 +0000420 if (N.getOpcode() != ISD::ADD) {
421 Base = N;
422 if (N.getOpcode() == ISD::FrameIndex) {
423 int FI = cast<FrameIndexSDNode>(N)->getIndex();
424 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
425 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000426 Offset = CurDAG->getRegister(0, MVT::i32);
427 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000428 return true;
429 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000430
Evan Chenga8e29892007-01-19 07:51:42 +0000431 // If the RHS is +/- imm8, fold into addr mode.
432 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000433 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000434 if ((RHSC >= 0 && RHSC < 256) ||
435 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000436 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000437 if (Base.getOpcode() == ISD::FrameIndex) {
438 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
439 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
440 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000441 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000442
443 ARM_AM::AddrOpc AddSub = ARM_AM::add;
444 if (RHSC < 0) {
445 AddSub = ARM_AM::sub;
446 RHSC = - RHSC;
447 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000448 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000449 return true;
450 }
451 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000452
Evan Chenga8e29892007-01-19 07:51:42 +0000453 Base = N.getOperand(0);
454 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000455 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000456 return true;
457}
458
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000459bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000460 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000461 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000462 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
463 ? cast<LoadSDNode>(Op)->getAddressingMode()
464 : cast<StoreSDNode>(Op)->getAddressingMode();
465 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
466 ? ARM_AM::add : ARM_AM::sub;
467 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000468 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000469 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000470 Offset = CurDAG->getRegister(0, MVT::i32);
471 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000472 return true;
473 }
474 }
475
476 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000477 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000478 return true;
479}
480
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000481bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000482 SDValue &Addr, SDValue &Mode) {
483 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000484 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000485 return true;
486}
Evan Chenga8e29892007-01-19 07:51:42 +0000487
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000488bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000489 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000490 if (N.getOpcode() != ISD::ADD) {
491 Base = N;
492 if (N.getOpcode() == ISD::FrameIndex) {
493 int FI = cast<FrameIndexSDNode>(N)->getIndex();
494 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000495 } else if (N.getOpcode() == ARMISD::Wrapper &&
496 !(Subtarget->useMovt() &&
497 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000498 Base = N.getOperand(0);
499 }
500 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000501 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000502 return true;
503 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000504
Evan Chenga8e29892007-01-19 07:51:42 +0000505 // If the RHS is +/- imm8, fold into addr mode.
506 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000507 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000508 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
509 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000510 if ((RHSC >= 0 && RHSC < 256) ||
511 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000512 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000513 if (Base.getOpcode() == ISD::FrameIndex) {
514 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
515 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
516 }
517
518 ARM_AM::AddrOpc AddSub = ARM_AM::add;
519 if (RHSC < 0) {
520 AddSub = ARM_AM::sub;
521 RHSC = - RHSC;
522 }
523 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000524 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000525 return true;
526 }
527 }
528 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000529
Evan Chenga8e29892007-01-19 07:51:42 +0000530 Base = N;
531 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000532 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000533 return true;
534}
535
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000536bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000537 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000538 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000539 // Default to no alignment.
540 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000541 return true;
542}
543
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000544bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000545 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000546 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
547 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000548 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000549 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000550 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000551 return true;
552 }
553 return false;
554}
555
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000556bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000557 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000558 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000559 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000560 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000561 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000562 return false;
563
564 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000565 return true;
566 }
567
Evan Chenga8e29892007-01-19 07:51:42 +0000568 Base = N.getOperand(0);
569 Offset = N.getOperand(1);
570 return true;
571}
572
Evan Cheng79d43262007-01-24 02:21:22 +0000573bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000574ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000575 unsigned Scale, SDValue &Base,
576 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000577 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000578 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000579 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
580 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000581 if (N.getOpcode() == ARMISD::Wrapper &&
582 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
583 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000584 }
585
Evan Chenga8e29892007-01-19 07:51:42 +0000586 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000587 if (N.getOpcode() == ARMISD::Wrapper &&
588 !(Subtarget->useMovt() &&
589 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
590 Base = N.getOperand(0);
591 } else
592 Base = N;
593
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 Offset = CurDAG->getRegister(0, MVT::i32);
595 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000596 return true;
597 }
598
Evan Chengad0e4652007-02-06 00:22:06 +0000599 // Thumb does not have [sp, r] address mode.
600 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
601 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
602 if ((LHSR && LHSR->getReg() == ARM::SP) ||
603 (RHSR && RHSR->getReg() == ARM::SP)) {
604 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000605 Offset = CurDAG->getRegister(0, MVT::i32);
606 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000607 return true;
608 }
609
Evan Chenga8e29892007-01-19 07:51:42 +0000610 // If the RHS is + imm5 * scale, fold into addr mode.
611 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000612 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000613 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
614 RHSC /= Scale;
615 if (RHSC >= 0 && RHSC < 32) {
616 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000617 Offset = CurDAG->getRegister(0, MVT::i32);
618 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000619 return true;
620 }
621 }
622 }
623
Evan Chengc38f2bc2007-01-23 22:59:13 +0000624 Base = N.getOperand(0);
625 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000627 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000628}
629
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000630bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000631 SDValue &Base, SDValue &OffImm,
632 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000633 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000634}
635
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000636bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000637 SDValue &Base, SDValue &OffImm,
638 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000639 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000640}
641
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000642bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000643 SDValue &Base, SDValue &OffImm,
644 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000645 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000646}
647
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000648bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000649 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000650 if (N.getOpcode() == ISD::FrameIndex) {
651 int FI = cast<FrameIndexSDNode>(N)->getIndex();
652 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000653 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000654 return true;
655 }
Evan Cheng79d43262007-01-24 02:21:22 +0000656
Evan Chengad0e4652007-02-06 00:22:06 +0000657 if (N.getOpcode() != ISD::ADD)
658 return false;
659
660 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000661 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
662 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000663 // If the RHS is + imm8 * scale, fold into addr mode.
664 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000665 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000666 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
667 RHSC >>= 2;
668 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000669 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000670 if (Base.getOpcode() == ISD::FrameIndex) {
671 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
672 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
673 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000674 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000675 return true;
676 }
677 }
678 }
679 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000680
Evan Chenga8e29892007-01-19 07:51:42 +0000681 return false;
682}
683
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000684bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000685 SDValue &BaseReg,
686 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000687 if (DisableShifterOp)
688 return false;
689
Evan Cheng9cb9e672009-06-27 02:26:13 +0000690 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
691
692 // Don't match base register only case. That is matched to a separate
693 // lower complexity pattern with explicit register operand.
694 if (ShOpcVal == ARM_AM::no_shift) return false;
695
696 BaseReg = N.getOperand(0);
697 unsigned ShImmVal = 0;
698 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
699 ShImmVal = RHS->getZExtValue() & 31;
700 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
701 return true;
702 }
703
704 return false;
705}
706
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000707bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000708 SDValue &Base, SDValue &OffImm) {
709 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000710
Evan Cheng3a214252009-08-11 08:52:18 +0000711 // Base only.
712 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000713 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000714 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000715 int FI = cast<FrameIndexSDNode>(N)->getIndex();
716 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000717 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000718 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000719 } else if (N.getOpcode() == ARMISD::Wrapper &&
720 !(Subtarget->useMovt() &&
721 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000722 Base = N.getOperand(0);
723 if (Base.getOpcode() == ISD::TargetConstantPool)
724 return false; // We want to select t2LDRpci instead.
725 } else
726 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000727 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000728 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000729 }
Evan Cheng055b0312009-06-29 07:51:04 +0000730
731 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000732 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
733 // Let t2LDRi8 handle (R - imm8).
734 return false;
735
Evan Cheng055b0312009-06-29 07:51:04 +0000736 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000737 if (N.getOpcode() == ISD::SUB)
738 RHSC = -RHSC;
739
740 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000741 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000742 if (Base.getOpcode() == ISD::FrameIndex) {
743 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
744 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
745 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000746 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000747 return true;
748 }
749 }
750
Evan Cheng3a214252009-08-11 08:52:18 +0000751 // Base only.
752 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000753 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000754 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000755}
756
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000757bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000758 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000759 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000760 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000761 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
762 int RHSC = (int)RHS->getSExtValue();
763 if (N.getOpcode() == ISD::SUB)
764 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000765
Evan Cheng3a214252009-08-11 08:52:18 +0000766 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
767 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000768 if (Base.getOpcode() == ISD::FrameIndex) {
769 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
770 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
771 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000773 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000774 }
Evan Cheng055b0312009-06-29 07:51:04 +0000775 }
776 }
777
778 return false;
779}
780
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000781bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000782 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000783 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000784 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
785 ? cast<LoadSDNode>(Op)->getAddressingMode()
786 : cast<StoreSDNode>(Op)->getAddressingMode();
787 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
788 int RHSC = (int)RHS->getZExtValue();
789 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000790 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000791 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
792 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000793 return true;
794 }
795 }
796
797 return false;
798}
799
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000800bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000801 SDValue &Base, SDValue &OffImm) {
802 if (N.getOpcode() == ISD::ADD) {
803 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
804 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000805 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000806 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000807 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000808 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000809 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000810 return true;
811 }
812 }
813 } else if (N.getOpcode() == ISD::SUB) {
814 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
815 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000816 // 8 bits.
817 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
David Goodwin6647cea2009-06-30 22:50:01 +0000818 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000819 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000820 return true;
821 }
822 }
823 }
824
825 return false;
826}
827
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000828bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000829 SDValue &Base,
830 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000831 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
832 if (N.getOpcode() != ISD::ADD)
833 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000834
Evan Cheng3a214252009-08-11 08:52:18 +0000835 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
836 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
837 int RHSC = (int)RHS->getZExtValue();
838 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
839 return false;
840 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000841 return false;
842 }
843
Evan Cheng055b0312009-06-29 07:51:04 +0000844 // Look for (R + R) or (R + (R << [1,2,3])).
845 unsigned ShAmt = 0;
846 Base = N.getOperand(0);
847 OffReg = N.getOperand(1);
848
849 // Swap if it is ((R << c) + R).
850 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
851 if (ShOpcVal != ARM_AM::lsl) {
852 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
853 if (ShOpcVal == ARM_AM::lsl)
854 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000855 }
856
Evan Cheng055b0312009-06-29 07:51:04 +0000857 if (ShOpcVal == ARM_AM::lsl) {
858 // Check to see if the RHS of the shift is a constant, if not, we can't fold
859 // it.
860 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
861 ShAmt = Sh->getZExtValue();
862 if (ShAmt >= 4) {
863 ShAmt = 0;
864 ShOpcVal = ARM_AM::no_shift;
865 } else
866 OffReg = OffReg.getOperand(0);
867 } else {
868 ShOpcVal = ARM_AM::no_shift;
869 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000870 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000871
Owen Anderson825b72b2009-08-11 20:47:22 +0000872 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000873
874 return true;
875}
876
877//===--------------------------------------------------------------------===//
878
Evan Chengee568cf2007-07-05 07:15:27 +0000879/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000880static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000881 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000882}
883
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000884SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
885 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000886 ISD::MemIndexedMode AM = LD->getAddressingMode();
887 if (AM == ISD::UNINDEXED)
888 return NULL;
889
Owen Andersone50ed302009-08-10 22:56:29 +0000890 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000891 SDValue Offset, AMOpc;
892 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
893 unsigned Opcode = 0;
894 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000895 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000896 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000897 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
898 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000899 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000900 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000901 Match = true;
902 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
903 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
904 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000905 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000906 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000907 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000908 Match = true;
909 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
910 }
911 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000912 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000913 Match = true;
914 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
915 }
916 }
917 }
918
919 if (Match) {
920 SDValue Chain = LD->getChain();
921 SDValue Base = LD->getBasePtr();
922 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000923 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000924 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000925 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000926 }
927
928 return NULL;
929}
930
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000931SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
932 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000933 ISD::MemIndexedMode AM = LD->getAddressingMode();
934 if (AM == ISD::UNINDEXED)
935 return NULL;
936
Owen Andersone50ed302009-08-10 22:56:29 +0000937 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000938 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000939 SDValue Offset;
940 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
941 unsigned Opcode = 0;
942 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000943 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000944 switch (LoadedVT.getSimpleVT().SimpleTy) {
945 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000946 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
947 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000948 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000949 if (isSExtLd)
950 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
951 else
952 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000953 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000954 case MVT::i8:
955 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000956 if (isSExtLd)
957 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
958 else
959 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000960 break;
961 default:
962 return NULL;
963 }
964 Match = true;
965 }
966
967 if (Match) {
968 SDValue Chain = LD->getChain();
969 SDValue Base = LD->getBasePtr();
970 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000971 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000972 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000973 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000974 }
975
976 return NULL;
977}
978
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000979/// PairSRegs - Form a D register from a pair of S registers.
980///
981SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
982 DebugLoc dl = V0.getNode()->getDebugLoc();
983 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
984 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000985 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
986 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000987}
988
Evan Cheng603afbf2010-05-10 17:34:18 +0000989/// PairDRegs - Form a quad register from a pair of D registers.
990///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000991SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
992 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000993 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
994 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000995 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
996 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000997}
998
Evan Cheng7f687192010-05-14 00:21:45 +0000999/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001000///
1001SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1002 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001003 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1004 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001005 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1006 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1007}
1008
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001009/// QuadSRegs - Form 4 consecutive S registers.
1010///
1011SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1012 SDValue V2, SDValue V3) {
1013 DebugLoc dl = V0.getNode()->getDebugLoc();
1014 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1015 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1016 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1017 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1018 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1019 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1020}
1021
Evan Cheng7f687192010-05-14 00:21:45 +00001022/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001023///
1024SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1025 SDValue V2, SDValue V3) {
1026 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001027 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1028 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1029 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1030 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001031 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1032 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1033}
1034
Evan Cheng8f6de382010-05-16 03:27:48 +00001035/// QuadQRegs - Form 4 consecutive Q registers.
1036///
1037SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1038 SDValue V2, SDValue V3) {
1039 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001040 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1041 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1042 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1043 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001044 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1045 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1046}
1047
Evan Cheng5c6aba22010-05-14 18:54:59 +00001048/// OctoDRegs - Form 8 consecutive D registers.
1049///
1050SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1051 SDValue V2, SDValue V3,
1052 SDValue V4, SDValue V5,
1053 SDValue V6, SDValue V7) {
1054 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001055 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1056 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1057 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1058 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1059 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1060 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1061 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1062 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001063 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1064 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1065 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1066}
1067
Bob Wilsona7c397c2009-10-14 16:19:03 +00001068/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1069/// for a 64-bit subregister of the vector.
1070static EVT GetNEONSubregVT(EVT VT) {
1071 switch (VT.getSimpleVT().SimpleTy) {
1072 default: llvm_unreachable("unhandled NEON type");
1073 case MVT::v16i8: return MVT::v8i8;
1074 case MVT::v8i16: return MVT::v4i16;
1075 case MVT::v4f32: return MVT::v2f32;
1076 case MVT::v4i32: return MVT::v2i32;
1077 case MVT::v2i64: return MVT::v1i64;
1078 }
1079}
1080
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001081SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001082 unsigned *DOpcodes, unsigned *QOpcodes0,
1083 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001084 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001085 DebugLoc dl = N->getDebugLoc();
1086
Bob Wilson226036e2010-03-20 22:13:40 +00001087 SDValue MemAddr, Align;
1088 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001089 return NULL;
1090
1091 SDValue Chain = N->getOperand(0);
1092 EVT VT = N->getValueType(0);
1093 bool is64BitVector = VT.is64BitVector();
1094
1095 unsigned OpcodeIndex;
1096 switch (VT.getSimpleVT().SimpleTy) {
1097 default: llvm_unreachable("unhandled vld type");
1098 // Double-register operations:
1099 case MVT::v8i8: OpcodeIndex = 0; break;
1100 case MVT::v4i16: OpcodeIndex = 1; break;
1101 case MVT::v2f32:
1102 case MVT::v2i32: OpcodeIndex = 2; break;
1103 case MVT::v1i64: OpcodeIndex = 3; break;
1104 // Quad-register operations:
1105 case MVT::v16i8: OpcodeIndex = 0; break;
1106 case MVT::v8i16: OpcodeIndex = 1; break;
1107 case MVT::v4f32:
1108 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001109 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001110 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001111 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001112 }
1113
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001114 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001115 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001116 if (is64BitVector) {
1117 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001118 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001119 std::vector<EVT> ResTys(NumVecs, VT);
1120 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001121 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson07f6e802010-06-16 21:34:01 +00001122 if (NumVecs < 2)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001123 return VLd;
1124
Evan Cheng0ce537a2010-05-11 01:19:40 +00001125 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001126 SDValue V0 = SDValue(VLd, 0);
1127 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001128
Evan Cheng0ce537a2010-05-11 01:19:40 +00001129 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001130 if (NumVecs == 2)
1131 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1132 else {
1133 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001134 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001135 SDValue V3 = (NumVecs == 3)
1136 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1137 : SDValue(VLd, 3);
1138 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1139 }
1140
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001141 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001142 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001143 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001144 dl, VT, RegSeq);
1145 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001146 }
1147 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1148 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001149 }
1150
1151 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001152 if (NumVecs <= 2) {
1153 // Quad registers are directly supported for VLD1 and VLD2,
1154 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001155 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001156 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001157 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001158 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001159 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001160 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001161
1162 // Combine the even and odd subregs to produce the result.
Bob Wilson07f6e802010-06-16 21:34:01 +00001163 if (NumVecs == 1) {
1164 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1165 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
Evan Cheng603afbf2010-05-10 17:34:18 +00001166 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001167 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1168 SDValue(VLd, 0), SDValue(VLd, 1),
1169 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1170 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1171 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
1172 ReplaceUses(SDValue(N, 0), Q0);
1173 ReplaceUses(SDValue(N, 1), Q1);
Bob Wilson3e36f132009-10-14 17:28:52 +00001174 }
1175 } else {
1176 // Otherwise, quad registers are loaded with two separate instructions,
1177 // where one loads the even registers and the other loads the odd registers.
1178
Bob Wilson3e36f132009-10-14 17:28:52 +00001179 std::vector<EVT> ResTys(NumVecs, RegVT);
1180 ResTys.push_back(MemAddr.getValueType());
1181 ResTys.push_back(MVT::Other);
1182
Bob Wilson24f995d2009-10-14 18:32:29 +00001183 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001184 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001185 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1186 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001187 Chain = SDValue(VLdA, NumVecs+1);
1188
Bob Wilson24f995d2009-10-14 18:32:29 +00001189 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001190 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001191 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1192 Align, Reg0, Pred, Reg0, Chain };
1193 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001194 Chain = SDValue(VLdB, NumVecs+1);
1195
Bob Wilson07f6e802010-06-16 21:34:01 +00001196 SDValue V0 = SDValue(VLdA, 0);
1197 SDValue V1 = SDValue(VLdB, 0);
1198 SDValue V2 = SDValue(VLdA, 1);
1199 SDValue V3 = SDValue(VLdB, 1);
1200 SDValue V4 = SDValue(VLdA, 2);
1201 SDValue V5 = SDValue(VLdB, 2);
1202 SDValue V6 = (NumVecs == 3)
1203 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1204 : SDValue(VLdA, 3);
1205 SDValue V7 = (NumVecs == 3)
1206 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1207 : SDValue(VLdB, 3);
1208 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1209 V4, V5, V6, V7), 0);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001210
Bob Wilson07f6e802010-06-16 21:34:01 +00001211 // Extract out the 3 / 4 Q registers.
1212 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1213 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1214 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1215 dl, VT, RegSeq);
1216 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001217 }
1218 }
1219 ReplaceUses(SDValue(N, NumVecs), Chain);
1220 return NULL;
1221}
1222
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001223SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001224 unsigned *DOpcodes, unsigned *QOpcodes0,
1225 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001226 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001227 DebugLoc dl = N->getDebugLoc();
1228
Bob Wilson226036e2010-03-20 22:13:40 +00001229 SDValue MemAddr, Align;
1230 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001231 return NULL;
1232
1233 SDValue Chain = N->getOperand(0);
1234 EVT VT = N->getOperand(3).getValueType();
1235 bool is64BitVector = VT.is64BitVector();
1236
1237 unsigned OpcodeIndex;
1238 switch (VT.getSimpleVT().SimpleTy) {
1239 default: llvm_unreachable("unhandled vst type");
1240 // Double-register operations:
1241 case MVT::v8i8: OpcodeIndex = 0; break;
1242 case MVT::v4i16: OpcodeIndex = 1; break;
1243 case MVT::v2f32:
1244 case MVT::v2i32: OpcodeIndex = 2; break;
1245 case MVT::v1i64: OpcodeIndex = 3; break;
1246 // Quad-register operations:
1247 case MVT::v16i8: OpcodeIndex = 0; break;
1248 case MVT::v8i16: OpcodeIndex = 1; break;
1249 case MVT::v4f32:
1250 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001251 case MVT::v2i64: OpcodeIndex = 3;
1252 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1253 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001254 }
1255
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001256 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001257 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001258
Bob Wilson226036e2010-03-20 22:13:40 +00001259 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001260 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001261 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001262
Bob Wilson709d5922010-08-25 23:27:42 +00001263 // FIXME: This is a temporary flag to distinguish VSTs that have been
1264 // converted to pseudo instructions.
1265 bool usePseudoInstrs = (NumVecs == 4 &&
1266 VT.getSimpleVT().SimpleTy != MVT::v1i64);
1267
Bob Wilson24f995d2009-10-14 18:32:29 +00001268 if (is64BitVector) {
Bob Wilson07f6e802010-06-16 21:34:01 +00001269 if (NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001270 SDValue RegSeq;
1271 SDValue V0 = N->getOperand(0+3);
1272 SDValue V1 = N->getOperand(1+3);
1273
1274 // Form a REG_SEQUENCE to force register allocation.
1275 if (NumVecs == 2)
1276 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1277 else {
1278 SDValue V2 = N->getOperand(2+3);
1279 // If it's a vld3, form a quad D-register and leave the last part as
1280 // an undef.
1281 SDValue V3 = (NumVecs == 3)
1282 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1283 : N->getOperand(3+3);
1284 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1285 }
Bob Wilson709d5922010-08-25 23:27:42 +00001286 if (usePseudoInstrs)
1287 Ops.push_back(RegSeq);
1288 else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001289
1290 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001291 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001292 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001293 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001294 RegSeq));
1295 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001296 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001297 RegSeq));
1298 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001299 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001300 RegSeq));
Bob Wilson709d5922010-08-25 23:27:42 +00001301 }
Evan Cheng0ce537a2010-05-11 01:19:40 +00001302 } else {
Bob Wilson709d5922010-08-25 23:27:42 +00001303 Ops.push_back(N->getOperand(3));
Evan Cheng0ce537a2010-05-11 01:19:40 +00001304 }
Evan Chengac0869d2009-11-21 06:21:52 +00001305 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001306 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001307 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001308 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson709d5922010-08-25 23:27:42 +00001309 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1310 usePseudoInstrs ? 6 : NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001311 }
1312
1313 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001314 if (NumVecs <= 2) {
1315 // Quad registers are directly supported for VST1 and VST2,
1316 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001317 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001318 if (NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001319 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001320 SDValue Q0 = N->getOperand(3);
1321 SDValue Q1 = N->getOperand(4);
1322
1323 // Form a QQ register.
1324 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1325
1326 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001327 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001328 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001329 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001330 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001331 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001332 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001333 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001334 QQ));
1335 Ops.push_back(Pred);
1336 Ops.push_back(Reg0); // predicate register
1337 Ops.push_back(Chain);
1338 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1339 } else {
1340 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001341 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001342 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001343 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001344 N->getOperand(Vec+3)));
1345 }
1346 Ops.push_back(Pred);
1347 Ops.push_back(Reg0); // predicate register
1348 Ops.push_back(Chain);
1349 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1350 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001351 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001352 }
1353
1354 // Otherwise, quad registers are stored with two separate instructions,
1355 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001356
Bob Wilson07f6e802010-06-16 21:34:01 +00001357 // Form the QQQQ REG_SEQUENCE.
1358 SDValue V[8];
1359 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1360 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1361 N->getOperand(Vec+3));
1362 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1363 N->getOperand(Vec+3));
Evan Cheng12c24692010-05-14 22:54:52 +00001364 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001365 if (NumVecs == 3)
1366 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1367 dl, RegVT), 0);
1368
1369 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1370 V[4], V[5], V[6], V[7]), 0);
1371
1372 // Store the even D registers.
1373 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1374 Ops.push_back(Reg0); // post-access address offset
Bob Wilson709d5922010-08-25 23:27:42 +00001375 if (usePseudoInstrs)
1376 Ops.push_back(RegSeq);
1377 else
Bob Wilson07f6e802010-06-16 21:34:01 +00001378 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1379 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1380 RegVT, RegSeq));
1381 Ops.push_back(Pred);
1382 Ops.push_back(Reg0); // predicate register
1383 Ops.push_back(Chain);
1384 unsigned Opc = QOpcodes0[OpcodeIndex];
1385 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson709d5922010-08-25 23:27:42 +00001386 MVT::Other, Ops.data(),
1387 usePseudoInstrs ? 7 : NumVecs+6);
Bob Wilson07f6e802010-06-16 21:34:01 +00001388 Chain = SDValue(VStA, 1);
1389
1390 // Store the odd D registers.
1391 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilson709d5922010-08-25 23:27:42 +00001392 if (usePseudoInstrs)
1393 Ops[6] = Chain;
1394 else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001395 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1396 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1397 RegVT, RegSeq);
1398 Ops[NumVecs+5] = Chain;
Bob Wilson709d5922010-08-25 23:27:42 +00001399 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001400 Opc = QOpcodes1[OpcodeIndex];
1401 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilson709d5922010-08-25 23:27:42 +00001402 MVT::Other, Ops.data(),
1403 usePseudoInstrs ? 7 : NumVecs+6);
Bob Wilson07f6e802010-06-16 21:34:01 +00001404 Chain = SDValue(VStB, 1);
1405 ReplaceUses(SDValue(N, 0), Chain);
1406 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001407}
1408
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001409SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001410 unsigned NumVecs, unsigned *DOpcodes,
1411 unsigned *QOpcodes0,
1412 unsigned *QOpcodes1) {
1413 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001414 DebugLoc dl = N->getDebugLoc();
1415
Bob Wilson226036e2010-03-20 22:13:40 +00001416 SDValue MemAddr, Align;
1417 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001418 return NULL;
1419
1420 SDValue Chain = N->getOperand(0);
1421 unsigned Lane =
1422 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001423 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001424 bool is64BitVector = VT.is64BitVector();
1425
Bob Wilson96493442009-10-14 16:46:45 +00001426 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001427 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001429 EVT RegVT = VT;
1430 if (!is64BitVector) {
1431 RegVT = GetNEONSubregVT(VT);
1432 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001433 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001434 }
1435
1436 unsigned OpcodeIndex;
1437 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001438 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001439 // Double-register operations:
1440 case MVT::v8i8: OpcodeIndex = 0; break;
1441 case MVT::v4i16: OpcodeIndex = 1; break;
1442 case MVT::v2f32:
1443 case MVT::v2i32: OpcodeIndex = 2; break;
1444 // Quad-register operations:
1445 case MVT::v8i16: OpcodeIndex = 0; break;
1446 case MVT::v4f32:
1447 case MVT::v4i32: OpcodeIndex = 1; break;
1448 }
1449
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001450 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001451 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001452
Bob Wilson226036e2010-03-20 22:13:40 +00001453 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001454 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001455 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001456
1457 unsigned Opc = 0;
1458 if (is64BitVector) {
1459 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001460 SDValue RegSeq;
1461 SDValue V0 = N->getOperand(0+3);
1462 SDValue V1 = N->getOperand(1+3);
1463 if (NumVecs == 2) {
1464 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001465 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001466 SDValue V2 = N->getOperand(2+3);
1467 SDValue V3 = (NumVecs == 3)
1468 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1469 : N->getOperand(3+3);
1470 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001471 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001472
1473 // Now extract the D registers back out.
1474 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1475 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1476 if (NumVecs > 2)
1477 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1478 if (NumVecs > 3)
1479 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001480 } else {
1481 // Check if this is loading the even or odd subreg of a Q register.
1482 if (Lane < NumElts) {
1483 Opc = QOpcodes0[OpcodeIndex];
1484 } else {
1485 Lane -= NumElts;
1486 Opc = QOpcodes1[OpcodeIndex];
1487 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001488
Bob Wilson07f6e802010-06-16 21:34:01 +00001489 SDValue RegSeq;
1490 SDValue V0 = N->getOperand(0+3);
1491 SDValue V1 = N->getOperand(1+3);
1492 if (NumVecs == 2) {
1493 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001494 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001495 SDValue V2 = N->getOperand(2+3);
1496 SDValue V3 = (NumVecs == 3)
1497 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1498 : N->getOperand(3+3);
1499 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001500 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001501
1502 // Extract the subregs of the input vector.
1503 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1504 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1505 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1506 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001507 }
1508 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001509 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001510 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001511 Ops.push_back(Chain);
1512
Bob Wilson96493442009-10-14 16:46:45 +00001513 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001514 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001515
Bob Wilsona7c397c2009-10-14 16:19:03 +00001516 std::vector<EVT> ResTys(NumVecs, RegVT);
1517 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001518 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1519
Bob Wilson07f6e802010-06-16 21:34:01 +00001520 // Form a REG_SEQUENCE to force register allocation.
1521 SDValue RegSeq;
1522 if (is64BitVector) {
1523 SDValue V0 = SDValue(VLdLn, 0);
1524 SDValue V1 = SDValue(VLdLn, 1);
1525 if (NumVecs == 2) {
1526 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001527 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001528 SDValue V2 = SDValue(VLdLn, 2);
1529 // If it's a vld3, form a quad D-register but discard the last part.
1530 SDValue V3 = (NumVecs == 3)
1531 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1532 : SDValue(VLdLn, 3);
1533 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001534 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001535 } else {
1536 // For 128-bit vectors, take the 64-bit results of the load and insert
1537 // them as subregs into the result.
1538 SDValue V[8];
1539 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1540 if (Even) {
1541 V[i] = SDValue(VLdLn, Vec);
1542 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1543 dl, RegVT), 0);
1544 } else {
1545 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1546 dl, RegVT), 0);
1547 V[i+1] = SDValue(VLdLn, Vec);
1548 }
1549 }
1550 if (NumVecs == 3)
1551 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1552 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001553
Bob Wilson07f6e802010-06-16 21:34:01 +00001554 if (NumVecs == 2)
1555 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1556 else
1557 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1558 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001559 }
1560
Bob Wilson07f6e802010-06-16 21:34:01 +00001561 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1562 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1563 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1564 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1565 ReplaceUses(SDValue(N, Vec),
1566 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1567 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001568 return NULL;
1569}
1570
Bob Wilson78dfbc32010-07-07 00:08:54 +00001571SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1572 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001573 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1574 DebugLoc dl = N->getDebugLoc();
1575 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001576 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001577
1578 // Form a REG_SEQUENCE to force register allocation.
1579 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001580 SDValue V0 = N->getOperand(FirstTblReg + 0);
1581 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001582 if (NumVecs == 2)
1583 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1584 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001585 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001586 // If it's a vtbl3, form a quad D-register and leave the last part as
1587 // an undef.
1588 SDValue V3 = (NumVecs == 3)
1589 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001590 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001591 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1592 }
1593
1594 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001595 SmallVector<SDValue, 6> Ops;
1596 if (IsExt)
1597 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001598 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1599 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1600 if (NumVecs > 2)
1601 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1602 if (NumVecs > 3)
1603 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1604
Bob Wilson78dfbc32010-07-07 00:08:54 +00001605 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001606 Ops.push_back(getAL(CurDAG)); // predicate
1607 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001608 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001609}
1610
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001611SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001612 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001613 if (!Subtarget->hasV6T2Ops())
1614 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001615
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001616 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1617 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1618
1619
1620 // For unsigned extracts, check for a shift right and mask
1621 unsigned And_imm = 0;
1622 if (N->getOpcode() == ISD::AND) {
1623 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1624
1625 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1626 if (And_imm & (And_imm + 1))
1627 return NULL;
1628
1629 unsigned Srl_imm = 0;
1630 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1631 Srl_imm)) {
1632 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1633
1634 unsigned Width = CountTrailingOnes_32(And_imm);
1635 unsigned LSB = Srl_imm;
1636 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1637 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1638 CurDAG->getTargetConstant(LSB, MVT::i32),
1639 CurDAG->getTargetConstant(Width, MVT::i32),
1640 getAL(CurDAG), Reg0 };
1641 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1642 }
1643 }
1644 return NULL;
1645 }
1646
1647 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001648 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001649 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001650 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1651 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001652 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001653 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1654 unsigned Width = 32 - Srl_imm;
1655 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001656 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001657 return NULL;
1658 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001659 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001660 CurDAG->getTargetConstant(LSB, MVT::i32),
1661 CurDAG->getTargetConstant(Width, MVT::i32),
1662 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001663 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001664 }
1665 }
1666 return NULL;
1667}
1668
Evan Cheng9ef48352009-11-20 00:54:03 +00001669SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001670SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001671 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1672 SDValue CPTmp0;
1673 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001674 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001675 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1676 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1677 unsigned Opc = 0;
1678 switch (SOShOp) {
1679 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1680 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1681 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1682 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1683 default:
1684 llvm_unreachable("Unknown so_reg opcode!");
1685 break;
1686 }
1687 SDValue SOShImm =
1688 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1689 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1690 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001691 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001692 }
1693 return 0;
1694}
1695
1696SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001697SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001698 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1699 SDValue CPTmp0;
1700 SDValue CPTmp1;
1701 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001702 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001703 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1704 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001705 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001706 }
1707 return 0;
1708}
1709
1710SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001711SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001712 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1713 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1714 if (!T)
1715 return 0;
1716
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001717 if (Pred_t2_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001718 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1719 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1720 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001721 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001722 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1723 }
1724 return 0;
1725}
1726
1727SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001728SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001729 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1730 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1731 if (!T)
1732 return 0;
1733
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001734 if (Pred_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001735 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1736 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1737 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001738 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001739 ARM::MOVCCi, MVT::i32, Ops, 5);
1740 }
1741 return 0;
1742}
1743
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001744SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1745 EVT VT = N->getValueType(0);
1746 SDValue FalseVal = N->getOperand(0);
1747 SDValue TrueVal = N->getOperand(1);
1748 SDValue CC = N->getOperand(2);
1749 SDValue CCR = N->getOperand(3);
1750 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001751 assert(CC.getOpcode() == ISD::Constant);
1752 assert(CCR.getOpcode() == ISD::Register);
1753 ARMCC::CondCodes CCVal =
1754 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001755
1756 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1757 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1758 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1759 // Pattern complexity = 18 cost = 1 size = 0
1760 SDValue CPTmp0;
1761 SDValue CPTmp1;
1762 SDValue CPTmp2;
1763 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001764 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001765 CCVal, CCR, InFlag);
1766 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001767 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001768 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1769 if (Res)
1770 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001771 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001772 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001773 CCVal, CCR, InFlag);
1774 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001775 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001776 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1777 if (Res)
1778 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001779 }
1780
1781 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001782 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001783 // (imm:i32):$cc)
1784 // Emits: (MOVCCi:i32 GPR:i32:$false,
1785 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1786 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001787 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001788 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001789 CCVal, CCR, InFlag);
1790 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001791 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001792 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1793 if (Res)
1794 return Res;
1795 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001796 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001797 CCVal, CCR, InFlag);
1798 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001799 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001800 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1801 if (Res)
1802 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001803 }
1804 }
1805
1806 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1807 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1808 // Pattern complexity = 6 cost = 1 size = 0
1809 //
1810 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1811 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1812 // Pattern complexity = 6 cost = 11 size = 0
1813 //
1814 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001815 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1816 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001817 unsigned Opc = 0;
1818 switch (VT.getSimpleVT().SimpleTy) {
1819 default: assert(false && "Illegal conditional move type!");
1820 break;
1821 case MVT::i32:
1822 Opc = Subtarget->isThumb()
1823 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1824 : ARM::MOVCCr;
1825 break;
1826 case MVT::f32:
1827 Opc = ARM::VMOVScc;
1828 break;
1829 case MVT::f64:
1830 Opc = ARM::VMOVDcc;
1831 break;
1832 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001833 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001834}
1835
Evan Chengde8aa4e2010-05-05 18:28:36 +00001836SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1837 // The only time a CONCAT_VECTORS operation can have legal types is when
1838 // two 64-bit vectors are concatenated to a 128-bit vector.
1839 EVT VT = N->getValueType(0);
1840 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1841 llvm_unreachable("unexpected CONCAT_VECTORS");
1842 DebugLoc dl = N->getDebugLoc();
1843 SDValue V0 = N->getOperand(0);
1844 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001845 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1846 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001847 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1848 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1849}
1850
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001851SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001852 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001853
Dan Gohmane8be6c62008-07-17 19:10:17 +00001854 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001855 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001856
1857 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001858 default: break;
1859 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001860 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001861 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001862 if (Subtarget->hasThumb2())
1863 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1864 // be done with MOV + MOVT, at worst.
1865 UseCP = 0;
1866 else {
1867 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001868 UseCP = (Val > 255 && // MOV
1869 ~Val > 255 && // MOV + MVN
1870 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001871 } else
1872 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1873 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1874 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1875 }
1876
Evan Chenga8e29892007-01-19 07:51:42 +00001877 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001878 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001879 CurDAG->getTargetConstantPool(ConstantInt::get(
1880 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001881 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001882
1883 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001884 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001885 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001886 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001887 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001888 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1889 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001890 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001891 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001892 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001893 CurDAG->getRegister(0, MVT::i32),
1894 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001895 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001896 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001897 CurDAG->getEntryNode()
1898 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001899 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1900 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001901 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001902 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001903 return NULL;
1904 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001905
Evan Chenga8e29892007-01-19 07:51:42 +00001906 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001907 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001908 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001909 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001910 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001911 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001912 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001913 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001914 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1915 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001916 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001917 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1918 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001919 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1920 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1921 CurDAG->getRegister(0, MVT::i32) };
1922 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001923 }
Evan Chenga8e29892007-01-19 07:51:42 +00001924 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001925 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001926 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001927 return I;
1928 break;
1929 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001930 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001931 return I;
1932 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001933 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001934 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001935 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001936 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001937 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001938 if (!RHSV) break;
1939 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001940 unsigned ShImm = Log2_32(RHSV-1);
1941 if (ShImm >= 32)
1942 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001943 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001944 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001945 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1946 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001947 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001948 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001949 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001950 } else {
1951 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001952 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001953 }
Evan Chenga8e29892007-01-19 07:51:42 +00001954 }
1955 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001956 unsigned ShImm = Log2_32(RHSV+1);
1957 if (ShImm >= 32)
1958 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001959 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001960 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001961 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1962 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001963 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001964 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1965 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001966 } else {
1967 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001968 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001969 }
Evan Chenga8e29892007-01-19 07:51:42 +00001970 }
1971 }
1972 break;
Evan Cheng20956592009-10-21 08:15:52 +00001973 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001974 // Check for unsigned bitfield extract
1975 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1976 return I;
1977
Evan Cheng20956592009-10-21 08:15:52 +00001978 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1979 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1980 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1981 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1982 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001984 if (VT != MVT::i32)
1985 break;
1986 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1987 ? ARM::t2MOVTi16
1988 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1989 if (!Opc)
1990 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001991 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001992 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1993 if (!N1C)
1994 break;
1995 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1996 SDValue N2 = N0.getOperand(1);
1997 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1998 if (!N2C)
1999 break;
2000 unsigned N1CVal = N1C->getZExtValue();
2001 unsigned N2CVal = N2C->getZExtValue();
2002 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2003 (N1CVal & 0xffffU) == 0xffffU &&
2004 (N2CVal & 0xffffU) == 0x0U) {
2005 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2006 MVT::i32);
2007 SDValue Ops[] = { N0.getOperand(0), Imm16,
2008 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2009 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2010 }
2011 }
2012 break;
2013 }
Jim Grosbache5165492009-11-09 00:11:35 +00002014 case ARMISD::VMOVRRD:
2015 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002016 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002017 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002018 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002019 if (Subtarget->isThumb1Only())
2020 break;
2021 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002022 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002023 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2024 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002025 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002026 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002027 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002028 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2029 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002030 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002031 }
Evan Chengee568cf2007-07-05 07:15:27 +00002032 }
Dan Gohman525178c2007-10-08 18:33:35 +00002033 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002034 if (Subtarget->isThumb1Only())
2035 break;
2036 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002037 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002038 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002039 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002040 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002041 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002042 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2043 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002044 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002045 }
Evan Chengee568cf2007-07-05 07:15:27 +00002046 }
Evan Chenga8e29892007-01-19 07:51:42 +00002047 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002048 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002049 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002050 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002051 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002052 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002053 if (ResNode)
2054 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002055
2056 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2057 if (Subtarget->hasVFP2() &&
2058 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2059 SDValue Chain = N->getOperand(0);
2060 SDValue AM5Opc =
2061 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002062 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002063 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2064 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002065 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2066 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2067 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2068 MVT::v2f64, MVT::Other, Ops, 5);
2069 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2070 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002071 }
2072 // Other cases are autogenerated.
2073 break;
2074 }
2075 case ISD::STORE: {
2076 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2077 if (Subtarget->hasVFP2() &&
2078 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2079 SDValue Chain = N->getOperand(0);
2080 SDValue AM5Opc =
2081 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002082 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002083 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2084 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2085 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002086 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2087 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2088 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2089 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2090 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002091 }
Evan Chenga8e29892007-01-19 07:51:42 +00002092 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002093 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002094 }
Evan Chengee568cf2007-07-05 07:15:27 +00002095 case ARMISD::BRCOND: {
2096 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2097 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2098 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002099
Evan Chengee568cf2007-07-05 07:15:27 +00002100 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2101 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2102 // Pattern complexity = 6 cost = 1 size = 0
2103
David Goodwin5e47a9a2009-06-30 18:04:13 +00002104 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2105 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2106 // Pattern complexity = 6 cost = 1 size = 0
2107
Jim Grosbach764ab522009-08-11 15:33:49 +00002108 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002109 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002110 SDValue Chain = N->getOperand(0);
2111 SDValue N1 = N->getOperand(1);
2112 SDValue N2 = N->getOperand(2);
2113 SDValue N3 = N->getOperand(3);
2114 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002115 assert(N1.getOpcode() == ISD::BasicBlock);
2116 assert(N2.getOpcode() == ISD::Constant);
2117 assert(N3.getOpcode() == ISD::Register);
2118
Dan Gohman475871a2008-07-27 21:46:04 +00002119 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002120 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002121 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002122 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002123 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2124 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002125 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002126 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002127 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002128 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002129 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002131 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002132 return NULL;
2133 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002134 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002135 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002136 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002137 EVT VT = N->getValueType(0);
2138 SDValue N0 = N->getOperand(0);
2139 SDValue N1 = N->getOperand(1);
2140 SDValue N2 = N->getOperand(2);
2141 SDValue N3 = N->getOperand(3);
2142 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002143 assert(N2.getOpcode() == ISD::Constant);
2144 assert(N3.getOpcode() == ISD::Register);
2145
Dan Gohman475871a2008-07-27 21:46:04 +00002146 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002147 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002148 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002149 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002150 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002151 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002152 default: assert(false && "Illegal conditional move type!");
2153 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002154 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002155 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002156 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002157 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002158 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002159 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002160 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002161 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002162 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002163
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002164 case ARMISD::VZIP: {
2165 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002166 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002167 switch (VT.getSimpleVT().SimpleTy) {
2168 default: return NULL;
2169 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2170 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2171 case MVT::v2f32:
2172 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2173 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2174 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2175 case MVT::v4f32:
2176 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2177 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002178 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002179 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2180 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2181 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002182 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002183 case ARMISD::VUZP: {
2184 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002185 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002186 switch (VT.getSimpleVT().SimpleTy) {
2187 default: return NULL;
2188 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2189 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2190 case MVT::v2f32:
2191 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2192 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2193 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2194 case MVT::v4f32:
2195 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2196 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002197 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002198 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2199 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2200 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002201 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002202 case ARMISD::VTRN: {
2203 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002204 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002205 switch (VT.getSimpleVT().SimpleTy) {
2206 default: return NULL;
2207 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2208 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2209 case MVT::v2f32:
2210 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2211 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2212 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2213 case MVT::v4f32:
2214 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2215 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002216 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002217 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2218 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2219 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002220 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002221 case ARMISD::BUILD_VECTOR: {
2222 EVT VecVT = N->getValueType(0);
2223 EVT EltVT = VecVT.getVectorElementType();
2224 unsigned NumElts = VecVT.getVectorNumElements();
2225 if (EltVT.getSimpleVT() == MVT::f64) {
2226 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2227 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2228 }
2229 assert(EltVT.getSimpleVT() == MVT::f32 &&
2230 "unexpected type for BUILD_VECTOR");
2231 if (NumElts == 2)
2232 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2233 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2234 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2235 N->getOperand(2), N->getOperand(3));
2236 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002237
2238 case ISD::INTRINSIC_VOID:
2239 case ISD::INTRINSIC_W_CHAIN: {
2240 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002241 switch (IntNo) {
2242 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002243 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002244
Bob Wilson621f1952010-03-23 05:25:43 +00002245 case Intrinsic::arm_neon_vld1: {
2246 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2247 ARM::VLD1d32, ARM::VLD1d64 };
2248 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2249 ARM::VLD1q32, ARM::VLD1q64 };
2250 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2251 }
2252
Bob Wilson31fb12f2009-08-26 17:39:53 +00002253 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002254 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002255 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002256 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002257 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002258 }
2259
2260 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002261 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002262 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002263 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2264 ARM::VLD3q16_UPD,
2265 ARM::VLD3q32_UPD };
2266 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2267 ARM::VLD3q16odd_UPD,
2268 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002269 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002270 }
2271
2272 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002273 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002274 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002275 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2276 ARM::VLD4q16_UPD,
2277 ARM::VLD4q32_UPD };
2278 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2279 ARM::VLD4q16odd_UPD,
2280 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002281 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002282 }
2283
Bob Wilson243fcc52009-09-01 04:26:28 +00002284 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002285 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002286 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2287 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002288 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002289 }
2290
2291 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002292 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002293 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2294 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002295 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002296 }
2297
2298 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002299 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002300 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2301 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002302 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002303 }
2304
Bob Wilson11d98992010-03-23 06:20:33 +00002305 case Intrinsic::arm_neon_vst1: {
2306 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2307 ARM::VST1d32, ARM::VST1d64 };
2308 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2309 ARM::VST1q32, ARM::VST1q64 };
2310 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2311 }
2312
Bob Wilson31fb12f2009-08-26 17:39:53 +00002313 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002314 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002315 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002316 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002317 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002318 }
2319
2320 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002321 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002322 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002323 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2324 ARM::VST3q16_UPD,
2325 ARM::VST3q32_UPD };
2326 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2327 ARM::VST3q16odd_UPD,
2328 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002329 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002330 }
2331
2332 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002333 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
2334 ARM::VST4d32Pseudo, ARM::VST1d64Q };
2335 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2336 ARM::VST4q16Pseudo_UPD,
2337 ARM::VST4q32Pseudo_UPD };
2338 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2339 ARM::VST4q16oddPseudo_UPD,
2340 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002341 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002342 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002343
2344 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002345 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002346 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2347 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002349 }
2350
2351 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002352 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002353 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2354 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002355 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002356 }
2357
2358 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002359 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002360 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2361 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002362 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002363 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002364 }
Bob Wilson429009b2010-05-06 16:05:26 +00002365 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002366 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002367
Bob Wilsond491d6e2010-07-06 23:36:25 +00002368 case ISD::INTRINSIC_WO_CHAIN: {
2369 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2370 switch (IntNo) {
2371 default:
2372 break;
2373
2374 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002375 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002376 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002377 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002378 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002379 return SelectVTBL(N, false, 4, ARM::VTBL4);
2380
2381 case Intrinsic::arm_neon_vtbx2:
2382 return SelectVTBL(N, true, 2, ARM::VTBX2);
2383 case Intrinsic::arm_neon_vtbx3:
2384 return SelectVTBL(N, true, 3, ARM::VTBX3);
2385 case Intrinsic::arm_neon_vtbx4:
2386 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002387 }
2388 break;
2389 }
2390
Bob Wilson429009b2010-05-06 16:05:26 +00002391 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002392 return SelectConcatVector(N);
2393 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002394
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002395 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002396}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002397
Bob Wilson224c2442009-05-19 05:53:42 +00002398bool ARMDAGToDAGISel::
2399SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2400 std::vector<SDValue> &OutOps) {
2401 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002402 // Require the address to be in a register. That is safe for all ARM
2403 // variants and it is hard to do anything much smarter without knowing
2404 // how the operand is used.
2405 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002406 return false;
2407}
2408
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002409/// createARMISelDag - This pass converts a legalized DAG into a
2410/// ARM-specific DAG, ready for instruction scheduling.
2411///
Bob Wilson522ce972009-09-28 14:30:20 +00002412FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2413 CodeGenOpt::Level OptLevel) {
2414 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002415}