blob: 89c32eae65bd3ea4a02cec3144784f2f24a95ca3 [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
1263 if (is64BitVector) {
Bob Wilson07f6e802010-06-16 21:34:01 +00001264 if (NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001265 SDValue RegSeq;
1266 SDValue V0 = N->getOperand(0+3);
1267 SDValue V1 = N->getOperand(1+3);
1268
1269 // Form a REG_SEQUENCE to force register allocation.
1270 if (NumVecs == 2)
1271 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1272 else {
1273 SDValue V2 = N->getOperand(2+3);
1274 // If it's a vld3, form a quad D-register and leave the last part as
1275 // an undef.
1276 SDValue V3 = (NumVecs == 3)
1277 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1278 : N->getOperand(3+3);
1279 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1280 }
1281
1282 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001283 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001284 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001285 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001286 RegSeq));
1287 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001288 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001289 RegSeq));
1290 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001291 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001292 RegSeq));
1293 } else {
1294 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1295 Ops.push_back(N->getOperand(Vec+3));
1296 }
Evan Chengac0869d2009-11-21 06:21:52 +00001297 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001298 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001299 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001300 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001301 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001302 }
1303
1304 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001305 if (NumVecs <= 2) {
1306 // Quad registers are directly supported for VST1 and VST2,
1307 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001308 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001309 if (NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001310 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001311 SDValue Q0 = N->getOperand(3);
1312 SDValue Q1 = N->getOperand(4);
1313
1314 // Form a QQ register.
1315 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1316
1317 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001318 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001319 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001320 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001321 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001322 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001323 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001324 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001325 QQ));
1326 Ops.push_back(Pred);
1327 Ops.push_back(Reg0); // predicate register
1328 Ops.push_back(Chain);
1329 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1330 } else {
1331 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001332 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001333 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001334 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001335 N->getOperand(Vec+3)));
1336 }
1337 Ops.push_back(Pred);
1338 Ops.push_back(Reg0); // predicate register
1339 Ops.push_back(Chain);
1340 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1341 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001342 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001343 }
1344
1345 // Otherwise, quad registers are stored with two separate instructions,
1346 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001347
Bob Wilson07f6e802010-06-16 21:34:01 +00001348 // Form the QQQQ REG_SEQUENCE.
1349 SDValue V[8];
1350 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1351 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1352 N->getOperand(Vec+3));
1353 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1354 N->getOperand(Vec+3));
Evan Cheng12c24692010-05-14 22:54:52 +00001355 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001356 if (NumVecs == 3)
1357 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1358 dl, RegVT), 0);
1359
1360 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1361 V[4], V[5], V[6], V[7]), 0);
1362
1363 // Store the even D registers.
1364 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1365 Ops.push_back(Reg0); // post-access address offset
1366 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1367 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1368 RegVT, RegSeq));
1369 Ops.push_back(Pred);
1370 Ops.push_back(Reg0); // predicate register
1371 Ops.push_back(Chain);
1372 unsigned Opc = QOpcodes0[OpcodeIndex];
1373 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1374 MVT::Other, Ops.data(), NumVecs+6);
1375 Chain = SDValue(VStA, 1);
1376
1377 // Store the odd D registers.
1378 Ops[0] = SDValue(VStA, 0); // MemAddr
1379 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1380 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1381 RegVT, RegSeq);
1382 Ops[NumVecs+5] = Chain;
1383 Opc = QOpcodes1[OpcodeIndex];
1384 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1385 MVT::Other, Ops.data(), NumVecs+6);
1386 Chain = SDValue(VStB, 1);
1387 ReplaceUses(SDValue(N, 0), Chain);
1388 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001389}
1390
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001391SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001392 unsigned NumVecs, unsigned *DOpcodes,
1393 unsigned *QOpcodes0,
1394 unsigned *QOpcodes1) {
1395 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001396 DebugLoc dl = N->getDebugLoc();
1397
Bob Wilson226036e2010-03-20 22:13:40 +00001398 SDValue MemAddr, Align;
1399 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001400 return NULL;
1401
1402 SDValue Chain = N->getOperand(0);
1403 unsigned Lane =
1404 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001405 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001406 bool is64BitVector = VT.is64BitVector();
1407
Bob Wilson96493442009-10-14 16:46:45 +00001408 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001409 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001410 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001411 EVT RegVT = VT;
1412 if (!is64BitVector) {
1413 RegVT = GetNEONSubregVT(VT);
1414 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001415 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001416 }
1417
1418 unsigned OpcodeIndex;
1419 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001420 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001421 // Double-register operations:
1422 case MVT::v8i8: OpcodeIndex = 0; break;
1423 case MVT::v4i16: OpcodeIndex = 1; break;
1424 case MVT::v2f32:
1425 case MVT::v2i32: OpcodeIndex = 2; break;
1426 // Quad-register operations:
1427 case MVT::v8i16: OpcodeIndex = 0; break;
1428 case MVT::v4f32:
1429 case MVT::v4i32: OpcodeIndex = 1; break;
1430 }
1431
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001432 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001433 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001434
Bob Wilson226036e2010-03-20 22:13:40 +00001435 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001436 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001437 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001438
1439 unsigned Opc = 0;
1440 if (is64BitVector) {
1441 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001442 SDValue RegSeq;
1443 SDValue V0 = N->getOperand(0+3);
1444 SDValue V1 = N->getOperand(1+3);
1445 if (NumVecs == 2) {
1446 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001447 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001448 SDValue V2 = N->getOperand(2+3);
1449 SDValue V3 = (NumVecs == 3)
1450 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1451 : N->getOperand(3+3);
1452 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001453 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001454
1455 // Now extract the D registers back out.
1456 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1457 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1458 if (NumVecs > 2)
1459 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1460 if (NumVecs > 3)
1461 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001462 } else {
1463 // Check if this is loading the even or odd subreg of a Q register.
1464 if (Lane < NumElts) {
1465 Opc = QOpcodes0[OpcodeIndex];
1466 } else {
1467 Lane -= NumElts;
1468 Opc = QOpcodes1[OpcodeIndex];
1469 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001470
Bob Wilson07f6e802010-06-16 21:34:01 +00001471 SDValue RegSeq;
1472 SDValue V0 = N->getOperand(0+3);
1473 SDValue V1 = N->getOperand(1+3);
1474 if (NumVecs == 2) {
1475 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001476 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001477 SDValue V2 = N->getOperand(2+3);
1478 SDValue V3 = (NumVecs == 3)
1479 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1480 : N->getOperand(3+3);
1481 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001482 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001483
1484 // Extract the subregs of the input vector.
1485 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1486 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1487 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1488 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001489 }
1490 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001491 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001492 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001493 Ops.push_back(Chain);
1494
Bob Wilson96493442009-10-14 16:46:45 +00001495 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001496 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001497
Bob Wilsona7c397c2009-10-14 16:19:03 +00001498 std::vector<EVT> ResTys(NumVecs, RegVT);
1499 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001500 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1501
Bob Wilson07f6e802010-06-16 21:34:01 +00001502 // Form a REG_SEQUENCE to force register allocation.
1503 SDValue RegSeq;
1504 if (is64BitVector) {
1505 SDValue V0 = SDValue(VLdLn, 0);
1506 SDValue V1 = SDValue(VLdLn, 1);
1507 if (NumVecs == 2) {
1508 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001509 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001510 SDValue V2 = SDValue(VLdLn, 2);
1511 // If it's a vld3, form a quad D-register but discard the last part.
1512 SDValue V3 = (NumVecs == 3)
1513 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1514 : SDValue(VLdLn, 3);
1515 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001516 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001517 } else {
1518 // For 128-bit vectors, take the 64-bit results of the load and insert
1519 // them as subregs into the result.
1520 SDValue V[8];
1521 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1522 if (Even) {
1523 V[i] = SDValue(VLdLn, Vec);
1524 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1525 dl, RegVT), 0);
1526 } else {
1527 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1528 dl, RegVT), 0);
1529 V[i+1] = SDValue(VLdLn, Vec);
1530 }
1531 }
1532 if (NumVecs == 3)
1533 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1534 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001535
Bob Wilson07f6e802010-06-16 21:34:01 +00001536 if (NumVecs == 2)
1537 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1538 else
1539 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1540 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001541 }
1542
Bob Wilson07f6e802010-06-16 21:34:01 +00001543 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1544 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1545 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1546 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1547 ReplaceUses(SDValue(N, Vec),
1548 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1549 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001550 return NULL;
1551}
1552
Bob Wilson78dfbc32010-07-07 00:08:54 +00001553SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1554 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001555 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1556 DebugLoc dl = N->getDebugLoc();
1557 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001558 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001559
1560 // Form a REG_SEQUENCE to force register allocation.
1561 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001562 SDValue V0 = N->getOperand(FirstTblReg + 0);
1563 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001564 if (NumVecs == 2)
1565 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1566 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001567 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001568 // If it's a vtbl3, form a quad D-register and leave the last part as
1569 // an undef.
1570 SDValue V3 = (NumVecs == 3)
1571 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001572 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001573 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1574 }
1575
1576 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001577 SmallVector<SDValue, 6> Ops;
1578 if (IsExt)
1579 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001580 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1581 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1582 if (NumVecs > 2)
1583 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1584 if (NumVecs > 3)
1585 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1586
Bob Wilson78dfbc32010-07-07 00:08:54 +00001587 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001588 Ops.push_back(getAL(CurDAG)); // predicate
1589 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001590 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001591}
1592
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001594 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001595 if (!Subtarget->hasV6T2Ops())
1596 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001597
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001598 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1599 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1600
1601
1602 // For unsigned extracts, check for a shift right and mask
1603 unsigned And_imm = 0;
1604 if (N->getOpcode() == ISD::AND) {
1605 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1606
1607 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1608 if (And_imm & (And_imm + 1))
1609 return NULL;
1610
1611 unsigned Srl_imm = 0;
1612 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1613 Srl_imm)) {
1614 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1615
1616 unsigned Width = CountTrailingOnes_32(And_imm);
1617 unsigned LSB = Srl_imm;
1618 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1619 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1620 CurDAG->getTargetConstant(LSB, MVT::i32),
1621 CurDAG->getTargetConstant(Width, MVT::i32),
1622 getAL(CurDAG), Reg0 };
1623 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1624 }
1625 }
1626 return NULL;
1627 }
1628
1629 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001630 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001631 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001632 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1633 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001634 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001635 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1636 unsigned Width = 32 - Srl_imm;
1637 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001638 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001639 return NULL;
1640 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001641 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001642 CurDAG->getTargetConstant(LSB, MVT::i32),
1643 CurDAG->getTargetConstant(Width, MVT::i32),
1644 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001645 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001646 }
1647 }
1648 return NULL;
1649}
1650
Evan Cheng9ef48352009-11-20 00:54:03 +00001651SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001652SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001653 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1654 SDValue CPTmp0;
1655 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001656 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001657 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1658 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1659 unsigned Opc = 0;
1660 switch (SOShOp) {
1661 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1662 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1663 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1664 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1665 default:
1666 llvm_unreachable("Unknown so_reg opcode!");
1667 break;
1668 }
1669 SDValue SOShImm =
1670 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1671 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1672 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001673 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001674 }
1675 return 0;
1676}
1677
1678SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001679SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001680 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1681 SDValue CPTmp0;
1682 SDValue CPTmp1;
1683 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001684 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001685 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1686 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001688 }
1689 return 0;
1690}
1691
1692SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001693SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001694 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1695 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1696 if (!T)
1697 return 0;
1698
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001699 if (Pred_t2_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001700 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1701 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1702 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001703 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001704 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1705 }
1706 return 0;
1707}
1708
1709SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001710SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001711 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1712 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1713 if (!T)
1714 return 0;
1715
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001716 if (Pred_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001717 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1718 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1719 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001720 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001721 ARM::MOVCCi, MVT::i32, Ops, 5);
1722 }
1723 return 0;
1724}
1725
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001726SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1727 EVT VT = N->getValueType(0);
1728 SDValue FalseVal = N->getOperand(0);
1729 SDValue TrueVal = N->getOperand(1);
1730 SDValue CC = N->getOperand(2);
1731 SDValue CCR = N->getOperand(3);
1732 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001733 assert(CC.getOpcode() == ISD::Constant);
1734 assert(CCR.getOpcode() == ISD::Register);
1735 ARMCC::CondCodes CCVal =
1736 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001737
1738 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1739 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1740 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1741 // Pattern complexity = 18 cost = 1 size = 0
1742 SDValue CPTmp0;
1743 SDValue CPTmp1;
1744 SDValue CPTmp2;
1745 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001746 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001747 CCVal, CCR, InFlag);
1748 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001749 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001750 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1751 if (Res)
1752 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001753 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001754 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001755 CCVal, CCR, InFlag);
1756 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001757 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001758 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1759 if (Res)
1760 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001761 }
1762
1763 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001764 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001765 // (imm:i32):$cc)
1766 // Emits: (MOVCCi:i32 GPR:i32:$false,
1767 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1768 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001769 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001770 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001771 CCVal, CCR, InFlag);
1772 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001773 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001774 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1775 if (Res)
1776 return Res;
1777 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001778 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001779 CCVal, CCR, InFlag);
1780 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001781 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001782 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1783 if (Res)
1784 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001785 }
1786 }
1787
1788 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1789 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1790 // Pattern complexity = 6 cost = 1 size = 0
1791 //
1792 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1793 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1794 // Pattern complexity = 6 cost = 11 size = 0
1795 //
1796 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001797 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1798 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001799 unsigned Opc = 0;
1800 switch (VT.getSimpleVT().SimpleTy) {
1801 default: assert(false && "Illegal conditional move type!");
1802 break;
1803 case MVT::i32:
1804 Opc = Subtarget->isThumb()
1805 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1806 : ARM::MOVCCr;
1807 break;
1808 case MVT::f32:
1809 Opc = ARM::VMOVScc;
1810 break;
1811 case MVT::f64:
1812 Opc = ARM::VMOVDcc;
1813 break;
1814 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001815 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001816}
1817
Evan Chengde8aa4e2010-05-05 18:28:36 +00001818SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1819 // The only time a CONCAT_VECTORS operation can have legal types is when
1820 // two 64-bit vectors are concatenated to a 128-bit vector.
1821 EVT VT = N->getValueType(0);
1822 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1823 llvm_unreachable("unexpected CONCAT_VECTORS");
1824 DebugLoc dl = N->getDebugLoc();
1825 SDValue V0 = N->getOperand(0);
1826 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001827 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1828 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001829 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1830 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1831}
1832
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001833SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001834 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001835
Dan Gohmane8be6c62008-07-17 19:10:17 +00001836 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001837 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001838
1839 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001840 default: break;
1841 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001842 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001843 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001844 if (Subtarget->hasThumb2())
1845 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1846 // be done with MOV + MOVT, at worst.
1847 UseCP = 0;
1848 else {
1849 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001850 UseCP = (Val > 255 && // MOV
1851 ~Val > 255 && // MOV + MVN
1852 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001853 } else
1854 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1855 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1856 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1857 }
1858
Evan Chenga8e29892007-01-19 07:51:42 +00001859 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001860 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001861 CurDAG->getTargetConstantPool(ConstantInt::get(
1862 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001863 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001864
1865 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001866 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001867 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001868 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001869 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001870 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1871 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001872 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001873 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001874 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001875 CurDAG->getRegister(0, MVT::i32),
1876 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001877 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001878 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001879 CurDAG->getEntryNode()
1880 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001881 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1882 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001883 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001884 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001885 return NULL;
1886 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001887
Evan Chenga8e29892007-01-19 07:51:42 +00001888 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001889 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001890 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001891 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001892 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001893 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001894 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001895 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001896 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1897 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001898 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001899 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1900 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001901 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1902 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1903 CurDAG->getRegister(0, MVT::i32) };
1904 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001905 }
Evan Chenga8e29892007-01-19 07:51:42 +00001906 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001907 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001908 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001909 return I;
1910 break;
1911 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001912 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001913 return I;
1914 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001915 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001916 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001917 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001918 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001919 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001920 if (!RHSV) break;
1921 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001922 unsigned ShImm = Log2_32(RHSV-1);
1923 if (ShImm >= 32)
1924 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001925 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001926 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001927 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1928 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001929 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001930 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001931 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001932 } else {
1933 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001934 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001935 }
Evan Chenga8e29892007-01-19 07:51:42 +00001936 }
1937 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001938 unsigned ShImm = Log2_32(RHSV+1);
1939 if (ShImm >= 32)
1940 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001941 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001942 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001943 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1944 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001945 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001946 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1947 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001948 } else {
1949 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001950 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001951 }
Evan Chenga8e29892007-01-19 07:51:42 +00001952 }
1953 }
1954 break;
Evan Cheng20956592009-10-21 08:15:52 +00001955 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001956 // Check for unsigned bitfield extract
1957 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1958 return I;
1959
Evan Cheng20956592009-10-21 08:15:52 +00001960 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1961 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1962 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1963 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1964 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001965 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001966 if (VT != MVT::i32)
1967 break;
1968 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1969 ? ARM::t2MOVTi16
1970 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1971 if (!Opc)
1972 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001973 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001974 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1975 if (!N1C)
1976 break;
1977 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1978 SDValue N2 = N0.getOperand(1);
1979 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1980 if (!N2C)
1981 break;
1982 unsigned N1CVal = N1C->getZExtValue();
1983 unsigned N2CVal = N2C->getZExtValue();
1984 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1985 (N1CVal & 0xffffU) == 0xffffU &&
1986 (N2CVal & 0xffffU) == 0x0U) {
1987 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1988 MVT::i32);
1989 SDValue Ops[] = { N0.getOperand(0), Imm16,
1990 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1991 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1992 }
1993 }
1994 break;
1995 }
Jim Grosbache5165492009-11-09 00:11:35 +00001996 case ARMISD::VMOVRRD:
1997 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001999 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002000 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002001 if (Subtarget->isThumb1Only())
2002 break;
2003 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002004 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002005 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2006 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002007 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002008 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002010 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2011 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002012 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002013 }
Evan Chengee568cf2007-07-05 07:15:27 +00002014 }
Dan Gohman525178c2007-10-08 18:33:35 +00002015 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002016 if (Subtarget->isThumb1Only())
2017 break;
2018 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002019 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002020 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002021 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002022 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002023 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002024 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2025 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002026 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002027 }
Evan Chengee568cf2007-07-05 07:15:27 +00002028 }
Evan Chenga8e29892007-01-19 07:51:42 +00002029 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002030 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002031 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002033 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002034 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002035 if (ResNode)
2036 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002037
2038 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2039 if (Subtarget->hasVFP2() &&
2040 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2041 SDValue Chain = N->getOperand(0);
2042 SDValue AM5Opc =
2043 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002044 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002045 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2046 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002047 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2048 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2049 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2050 MVT::v2f64, MVT::Other, Ops, 5);
2051 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2052 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002053 }
2054 // Other cases are autogenerated.
2055 break;
2056 }
2057 case ISD::STORE: {
2058 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2059 if (Subtarget->hasVFP2() &&
2060 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2061 SDValue Chain = N->getOperand(0);
2062 SDValue AM5Opc =
2063 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002064 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002065 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2066 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2067 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002068 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2069 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2070 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2071 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2072 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002073 }
Evan Chenga8e29892007-01-19 07:51:42 +00002074 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002075 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002076 }
Evan Chengee568cf2007-07-05 07:15:27 +00002077 case ARMISD::BRCOND: {
2078 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2079 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2080 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002081
Evan Chengee568cf2007-07-05 07:15:27 +00002082 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2083 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2084 // Pattern complexity = 6 cost = 1 size = 0
2085
David Goodwin5e47a9a2009-06-30 18:04:13 +00002086 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2087 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2088 // Pattern complexity = 6 cost = 1 size = 0
2089
Jim Grosbach764ab522009-08-11 15:33:49 +00002090 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002091 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002092 SDValue Chain = N->getOperand(0);
2093 SDValue N1 = N->getOperand(1);
2094 SDValue N2 = N->getOperand(2);
2095 SDValue N3 = N->getOperand(3);
2096 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002097 assert(N1.getOpcode() == ISD::BasicBlock);
2098 assert(N2.getOpcode() == ISD::Constant);
2099 assert(N3.getOpcode() == ISD::Register);
2100
Dan Gohman475871a2008-07-27 21:46:04 +00002101 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002102 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002103 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002104 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002105 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2106 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002107 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002108 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002109 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002110 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002111 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002112 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002113 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002114 return NULL;
2115 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002116 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002117 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002118 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002119 EVT VT = N->getValueType(0);
2120 SDValue N0 = N->getOperand(0);
2121 SDValue N1 = N->getOperand(1);
2122 SDValue N2 = N->getOperand(2);
2123 SDValue N3 = N->getOperand(3);
2124 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002125 assert(N2.getOpcode() == ISD::Constant);
2126 assert(N3.getOpcode() == ISD::Register);
2127
Dan Gohman475871a2008-07-27 21:46:04 +00002128 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002129 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002130 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002131 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002132 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002133 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002134 default: assert(false && "Illegal conditional move type!");
2135 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002136 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002137 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002138 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002139 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002140 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002141 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002142 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002143 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002144 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002145
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002146 case ARMISD::VZIP: {
2147 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002148 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002149 switch (VT.getSimpleVT().SimpleTy) {
2150 default: return NULL;
2151 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2152 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2153 case MVT::v2f32:
2154 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2155 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2156 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2157 case MVT::v4f32:
2158 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2159 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002160 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002161 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2162 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2163 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002164 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002165 case ARMISD::VUZP: {
2166 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002167 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002168 switch (VT.getSimpleVT().SimpleTy) {
2169 default: return NULL;
2170 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2171 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2172 case MVT::v2f32:
2173 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2174 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2175 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2176 case MVT::v4f32:
2177 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2178 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002179 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002180 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2181 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2182 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002183 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002184 case ARMISD::VTRN: {
2185 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002186 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002187 switch (VT.getSimpleVT().SimpleTy) {
2188 default: return NULL;
2189 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2190 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2191 case MVT::v2f32:
2192 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2193 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2194 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2195 case MVT::v4f32:
2196 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2197 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002198 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002199 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2200 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2201 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002202 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002203 case ARMISD::BUILD_VECTOR: {
2204 EVT VecVT = N->getValueType(0);
2205 EVT EltVT = VecVT.getVectorElementType();
2206 unsigned NumElts = VecVT.getVectorNumElements();
2207 if (EltVT.getSimpleVT() == MVT::f64) {
2208 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2209 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2210 }
2211 assert(EltVT.getSimpleVT() == MVT::f32 &&
2212 "unexpected type for BUILD_VECTOR");
2213 if (NumElts == 2)
2214 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2215 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2216 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2217 N->getOperand(2), N->getOperand(3));
2218 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002219
2220 case ISD::INTRINSIC_VOID:
2221 case ISD::INTRINSIC_W_CHAIN: {
2222 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002223 switch (IntNo) {
2224 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002225 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002226
Bob Wilson621f1952010-03-23 05:25:43 +00002227 case Intrinsic::arm_neon_vld1: {
2228 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2229 ARM::VLD1d32, ARM::VLD1d64 };
2230 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2231 ARM::VLD1q32, ARM::VLD1q64 };
2232 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2233 }
2234
Bob Wilson31fb12f2009-08-26 17:39:53 +00002235 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002236 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002237 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002238 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002239 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002240 }
2241
2242 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002243 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002244 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002245 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2246 ARM::VLD3q16_UPD,
2247 ARM::VLD3q32_UPD };
2248 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2249 ARM::VLD3q16odd_UPD,
2250 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002251 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002252 }
2253
2254 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002255 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002256 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002257 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2258 ARM::VLD4q16_UPD,
2259 ARM::VLD4q32_UPD };
2260 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2261 ARM::VLD4q16odd_UPD,
2262 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002263 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002264 }
2265
Bob Wilson243fcc52009-09-01 04:26:28 +00002266 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002267 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002268 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2269 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002270 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002271 }
2272
2273 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002274 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002275 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2276 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002277 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002278 }
2279
2280 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002281 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002282 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2283 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002284 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002285 }
2286
Bob Wilson11d98992010-03-23 06:20:33 +00002287 case Intrinsic::arm_neon_vst1: {
2288 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2289 ARM::VST1d32, ARM::VST1d64 };
2290 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2291 ARM::VST1q32, ARM::VST1q64 };
2292 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2293 }
2294
Bob Wilson31fb12f2009-08-26 17:39:53 +00002295 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002296 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002297 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002298 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002299 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002300 }
2301
2302 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002303 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002304 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002305 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2306 ARM::VST3q16_UPD,
2307 ARM::VST3q32_UPD };
2308 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2309 ARM::VST3q16odd_UPD,
2310 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002311 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002312 }
2313
2314 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002315 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002316 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002317 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2318 ARM::VST4q16_UPD,
2319 ARM::VST4q32_UPD };
2320 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2321 ARM::VST4q16odd_UPD,
2322 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002323 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002324 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002325
2326 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002327 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002328 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2329 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002330 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002331 }
2332
2333 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002334 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002335 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2336 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002337 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002338 }
2339
2340 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002341 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002342 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2343 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002344 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002345 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002346 }
Bob Wilson429009b2010-05-06 16:05:26 +00002347 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002348 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002349
Bob Wilsond491d6e2010-07-06 23:36:25 +00002350 case ISD::INTRINSIC_WO_CHAIN: {
2351 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2352 switch (IntNo) {
2353 default:
2354 break;
2355
2356 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002357 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002358 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002359 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002360 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002361 return SelectVTBL(N, false, 4, ARM::VTBL4);
2362
2363 case Intrinsic::arm_neon_vtbx2:
2364 return SelectVTBL(N, true, 2, ARM::VTBX2);
2365 case Intrinsic::arm_neon_vtbx3:
2366 return SelectVTBL(N, true, 3, ARM::VTBX3);
2367 case Intrinsic::arm_neon_vtbx4:
2368 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002369 }
2370 break;
2371 }
2372
Bob Wilson429009b2010-05-06 16:05:26 +00002373 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002374 return SelectConcatVector(N);
2375 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002376
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002377 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002378}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002379
Bob Wilson224c2442009-05-19 05:53:42 +00002380bool ARMDAGToDAGISel::
2381SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2382 std::vector<SDValue> &OutOps) {
2383 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002384 // Require the address to be in a register. That is safe for all ARM
2385 // variants and it is hard to do anything much smarter without knowing
2386 // how the operand is used.
2387 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002388 return false;
2389}
2390
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002391/// createARMISelDag - This pass converts a legalized DAG into a
2392/// ARM-specific DAG, ready for instruction scheduling.
2393///
Bob Wilson522ce972009-09-28 14:30:20 +00002394FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2395 CodeGenOpt::Level OptLevel) {
2396 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002397}