blob: 4f4f4d08b41a5b0ab679946af6eb1f02c56eeda1 [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;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000484 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), 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 Wilsone5ce4f62010-08-28 05:12:57 +00001259 SmallVector<SDValue, 7> 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 Wilsone5ce4f62010-08-28 05:12:57 +00001264 if (NumVecs == 1) {
1265 Ops.push_back(N->getOperand(3));
1266 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001267 SDValue RegSeq;
1268 SDValue V0 = N->getOperand(0+3);
1269 SDValue V1 = N->getOperand(1+3);
1270
1271 // Form a REG_SEQUENCE to force register allocation.
1272 if (NumVecs == 2)
1273 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1274 else {
1275 SDValue V2 = N->getOperand(2+3);
1276 // If it's a vld3, form a quad D-register and leave the last part as
1277 // an undef.
1278 SDValue V3 = (NumVecs == 3)
1279 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1280 : N->getOperand(3+3);
1281 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1282 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001283 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001284 }
Evan Chengac0869d2009-11-21 06:21:52 +00001285 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001286 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001287 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001288 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001289 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001290 }
1291
Bob Wilson11d98992010-03-23 06:20:33 +00001292 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001293 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001294 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001295 if (NumVecs == 1) {
1296 Ops.push_back(N->getOperand(3));
1297 } else {
1298 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001299 SDValue Q0 = N->getOperand(3);
1300 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001301 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001302 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001303 Ops.push_back(Pred);
1304 Ops.push_back(Reg0); // predicate register
1305 Ops.push_back(Chain);
1306 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001307 }
1308
1309 // Otherwise, quad registers are stored with two separate instructions,
1310 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001311
Bob Wilson07f6e802010-06-16 21:34:01 +00001312 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001313 SDValue V0 = N->getOperand(0+3);
1314 SDValue V1 = N->getOperand(1+3);
1315 SDValue V2 = N->getOperand(2+3);
1316 SDValue V3 = (NumVecs == 3)
1317 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1318 : N->getOperand(3+3);
1319 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001320
1321 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001322 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001323 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001324 Ops.push_back(Pred);
1325 Ops.push_back(Reg0); // predicate register
1326 Ops.push_back(Chain);
1327 unsigned Opc = QOpcodes0[OpcodeIndex];
1328 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001329 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001330 Chain = SDValue(VStA, 1);
1331
1332 // Store the odd D registers.
1333 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001334 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001335 Opc = QOpcodes1[OpcodeIndex];
1336 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001337 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001338 Chain = SDValue(VStB, 1);
1339 ReplaceUses(SDValue(N, 0), Chain);
1340 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001341}
1342
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001343SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001344 unsigned NumVecs, unsigned *DOpcodes,
1345 unsigned *QOpcodes0,
1346 unsigned *QOpcodes1) {
1347 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001348 DebugLoc dl = N->getDebugLoc();
1349
Bob Wilson226036e2010-03-20 22:13:40 +00001350 SDValue MemAddr, Align;
1351 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001352 return NULL;
1353
1354 SDValue Chain = N->getOperand(0);
1355 unsigned Lane =
1356 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001357 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001358 bool is64BitVector = VT.is64BitVector();
1359
Bob Wilson96493442009-10-14 16:46:45 +00001360 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001361 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001362 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001363 EVT RegVT = VT;
1364 if (!is64BitVector) {
1365 RegVT = GetNEONSubregVT(VT);
1366 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001367 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001368 }
1369
1370 unsigned OpcodeIndex;
1371 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001372 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001373 // Double-register operations:
1374 case MVT::v8i8: OpcodeIndex = 0; break;
1375 case MVT::v4i16: OpcodeIndex = 1; break;
1376 case MVT::v2f32:
1377 case MVT::v2i32: OpcodeIndex = 2; break;
1378 // Quad-register operations:
1379 case MVT::v8i16: OpcodeIndex = 0; break;
1380 case MVT::v4f32:
1381 case MVT::v4i32: OpcodeIndex = 1; break;
1382 }
1383
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001384 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001385 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001386
Bob Wilson226036e2010-03-20 22:13:40 +00001387 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001388 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001389 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001390
1391 unsigned Opc = 0;
1392 if (is64BitVector) {
1393 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001394 SDValue RegSeq;
1395 SDValue V0 = N->getOperand(0+3);
1396 SDValue V1 = N->getOperand(1+3);
1397 if (NumVecs == 2) {
1398 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001399 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001400 SDValue V2 = N->getOperand(2+3);
1401 SDValue V3 = (NumVecs == 3)
1402 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1403 : N->getOperand(3+3);
1404 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001405 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001406
1407 // Now extract the D registers back out.
1408 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1409 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1410 if (NumVecs > 2)
1411 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1412 if (NumVecs > 3)
1413 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001414 } else {
1415 // Check if this is loading the even or odd subreg of a Q register.
1416 if (Lane < NumElts) {
1417 Opc = QOpcodes0[OpcodeIndex];
1418 } else {
1419 Lane -= NumElts;
1420 Opc = QOpcodes1[OpcodeIndex];
1421 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001422
Bob Wilson07f6e802010-06-16 21:34:01 +00001423 SDValue RegSeq;
1424 SDValue V0 = N->getOperand(0+3);
1425 SDValue V1 = N->getOperand(1+3);
1426 if (NumVecs == 2) {
1427 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001429 SDValue V2 = N->getOperand(2+3);
1430 SDValue V3 = (NumVecs == 3)
1431 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1432 : N->getOperand(3+3);
1433 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001434 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001435
1436 // Extract the subregs of the input vector.
1437 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1438 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1439 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1440 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001441 }
1442 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001443 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001444 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001445 Ops.push_back(Chain);
1446
Bob Wilson96493442009-10-14 16:46:45 +00001447 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001448 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001449
Bob Wilsona7c397c2009-10-14 16:19:03 +00001450 std::vector<EVT> ResTys(NumVecs, RegVT);
1451 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001452 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1453
Bob Wilson07f6e802010-06-16 21:34:01 +00001454 // Form a REG_SEQUENCE to force register allocation.
1455 SDValue RegSeq;
1456 if (is64BitVector) {
1457 SDValue V0 = SDValue(VLdLn, 0);
1458 SDValue V1 = SDValue(VLdLn, 1);
1459 if (NumVecs == 2) {
1460 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001461 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001462 SDValue V2 = SDValue(VLdLn, 2);
1463 // If it's a vld3, form a quad D-register but discard the last part.
1464 SDValue V3 = (NumVecs == 3)
1465 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1466 : SDValue(VLdLn, 3);
1467 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001468 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001469 } else {
1470 // For 128-bit vectors, take the 64-bit results of the load and insert
1471 // them as subregs into the result.
1472 SDValue V[8];
1473 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1474 if (Even) {
1475 V[i] = SDValue(VLdLn, Vec);
1476 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1477 dl, RegVT), 0);
1478 } else {
1479 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1480 dl, RegVT), 0);
1481 V[i+1] = SDValue(VLdLn, Vec);
1482 }
1483 }
1484 if (NumVecs == 3)
1485 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1486 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001487
Bob Wilson07f6e802010-06-16 21:34:01 +00001488 if (NumVecs == 2)
1489 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1490 else
1491 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1492 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001493 }
1494
Bob Wilson07f6e802010-06-16 21:34:01 +00001495 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1496 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1497 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1498 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1499 ReplaceUses(SDValue(N, Vec),
1500 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1501 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001502 return NULL;
1503}
1504
Bob Wilson78dfbc32010-07-07 00:08:54 +00001505SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1506 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001507 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1508 DebugLoc dl = N->getDebugLoc();
1509 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001510 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001511
1512 // Form a REG_SEQUENCE to force register allocation.
1513 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001514 SDValue V0 = N->getOperand(FirstTblReg + 0);
1515 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001516 if (NumVecs == 2)
1517 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1518 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001519 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001520 // If it's a vtbl3, form a quad D-register and leave the last part as
1521 // an undef.
1522 SDValue V3 = (NumVecs == 3)
1523 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001524 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001525 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1526 }
1527
1528 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001529 SmallVector<SDValue, 6> Ops;
1530 if (IsExt)
1531 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001532 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1533 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1534 if (NumVecs > 2)
1535 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1536 if (NumVecs > 3)
1537 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1538
Bob Wilson78dfbc32010-07-07 00:08:54 +00001539 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001540 Ops.push_back(getAL(CurDAG)); // predicate
1541 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001542 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001543}
1544
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001545SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001546 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001547 if (!Subtarget->hasV6T2Ops())
1548 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001549
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001550 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1551 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1552
1553
1554 // For unsigned extracts, check for a shift right and mask
1555 unsigned And_imm = 0;
1556 if (N->getOpcode() == ISD::AND) {
1557 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1558
1559 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1560 if (And_imm & (And_imm + 1))
1561 return NULL;
1562
1563 unsigned Srl_imm = 0;
1564 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1565 Srl_imm)) {
1566 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1567
1568 unsigned Width = CountTrailingOnes_32(And_imm);
1569 unsigned LSB = Srl_imm;
1570 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1571 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1572 CurDAG->getTargetConstant(LSB, MVT::i32),
1573 CurDAG->getTargetConstant(Width, MVT::i32),
1574 getAL(CurDAG), Reg0 };
1575 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1576 }
1577 }
1578 return NULL;
1579 }
1580
1581 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001582 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001583 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001584 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1585 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001586 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001587 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1588 unsigned Width = 32 - Srl_imm;
1589 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001590 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001591 return NULL;
1592 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001593 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001594 CurDAG->getTargetConstant(LSB, MVT::i32),
1595 CurDAG->getTargetConstant(Width, MVT::i32),
1596 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001597 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001598 }
1599 }
1600 return NULL;
1601}
1602
Evan Cheng9ef48352009-11-20 00:54:03 +00001603SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001604SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001605 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1606 SDValue CPTmp0;
1607 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001608 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001609 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1610 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1611 unsigned Opc = 0;
1612 switch (SOShOp) {
1613 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1614 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1615 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1616 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1617 default:
1618 llvm_unreachable("Unknown so_reg opcode!");
1619 break;
1620 }
1621 SDValue SOShImm =
1622 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1623 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1624 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001625 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001626 }
1627 return 0;
1628}
1629
1630SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001631SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001632 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1633 SDValue CPTmp0;
1634 SDValue CPTmp1;
1635 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001636 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001637 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1638 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001639 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001640 }
1641 return 0;
1642}
1643
1644SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001645SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001646 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1647 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1648 if (!T)
1649 return 0;
1650
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001651 if (Pred_t2_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001652 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1653 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1654 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001655 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001656 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1657 }
1658 return 0;
1659}
1660
1661SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001662SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001663 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1664 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1665 if (!T)
1666 return 0;
1667
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001668 if (Pred_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001669 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1670 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1671 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001672 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001673 ARM::MOVCCi, MVT::i32, Ops, 5);
1674 }
1675 return 0;
1676}
1677
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001678SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1679 EVT VT = N->getValueType(0);
1680 SDValue FalseVal = N->getOperand(0);
1681 SDValue TrueVal = N->getOperand(1);
1682 SDValue CC = N->getOperand(2);
1683 SDValue CCR = N->getOperand(3);
1684 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001685 assert(CC.getOpcode() == ISD::Constant);
1686 assert(CCR.getOpcode() == ISD::Register);
1687 ARMCC::CondCodes CCVal =
1688 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001689
1690 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1691 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1692 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1693 // Pattern complexity = 18 cost = 1 size = 0
1694 SDValue CPTmp0;
1695 SDValue CPTmp1;
1696 SDValue CPTmp2;
1697 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001698 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001699 CCVal, CCR, InFlag);
1700 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001702 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1703 if (Res)
1704 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001705 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001706 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001707 CCVal, CCR, InFlag);
1708 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001709 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001710 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1711 if (Res)
1712 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001713 }
1714
1715 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001716 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001717 // (imm:i32):$cc)
1718 // Emits: (MOVCCi:i32 GPR:i32:$false,
1719 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1720 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001721 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001722 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001723 CCVal, CCR, InFlag);
1724 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001725 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001726 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1727 if (Res)
1728 return Res;
1729 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001730 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001731 CCVal, CCR, InFlag);
1732 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001733 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001734 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1735 if (Res)
1736 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001737 }
1738 }
1739
1740 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1741 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1742 // Pattern complexity = 6 cost = 1 size = 0
1743 //
1744 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1745 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1746 // Pattern complexity = 6 cost = 11 size = 0
1747 //
1748 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001749 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1750 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001751 unsigned Opc = 0;
1752 switch (VT.getSimpleVT().SimpleTy) {
1753 default: assert(false && "Illegal conditional move type!");
1754 break;
1755 case MVT::i32:
1756 Opc = Subtarget->isThumb()
1757 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1758 : ARM::MOVCCr;
1759 break;
1760 case MVT::f32:
1761 Opc = ARM::VMOVScc;
1762 break;
1763 case MVT::f64:
1764 Opc = ARM::VMOVDcc;
1765 break;
1766 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001767 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001768}
1769
Evan Chengde8aa4e2010-05-05 18:28:36 +00001770SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1771 // The only time a CONCAT_VECTORS operation can have legal types is when
1772 // two 64-bit vectors are concatenated to a 128-bit vector.
1773 EVT VT = N->getValueType(0);
1774 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1775 llvm_unreachable("unexpected CONCAT_VECTORS");
1776 DebugLoc dl = N->getDebugLoc();
1777 SDValue V0 = N->getOperand(0);
1778 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001779 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1780 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001781 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1782 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1783}
1784
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001785SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001786 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001787
Dan Gohmane8be6c62008-07-17 19:10:17 +00001788 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001789 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001790
1791 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001792 default: break;
1793 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001794 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001795 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001796 if (Subtarget->hasThumb2())
1797 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1798 // be done with MOV + MOVT, at worst.
1799 UseCP = 0;
1800 else {
1801 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001802 UseCP = (Val > 255 && // MOV
1803 ~Val > 255 && // MOV + MVN
1804 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001805 } else
1806 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1807 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1808 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1809 }
1810
Evan Chenga8e29892007-01-19 07:51:42 +00001811 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001812 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001813 CurDAG->getTargetConstantPool(ConstantInt::get(
1814 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001815 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001816
1817 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001818 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001819 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001820 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001821 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001822 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1823 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001824 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001825 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001826 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001827 CurDAG->getRegister(0, MVT::i32),
1828 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001829 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001830 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001831 CurDAG->getEntryNode()
1832 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001833 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1834 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001835 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001836 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001837 return NULL;
1838 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001839
Evan Chenga8e29892007-01-19 07:51:42 +00001840 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001841 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001842 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001843 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001844 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001845 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001846 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001847 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001848 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1849 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001850 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001851 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1852 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001853 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1854 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1855 CurDAG->getRegister(0, MVT::i32) };
1856 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001857 }
Evan Chenga8e29892007-01-19 07:51:42 +00001858 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001859 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001860 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001861 return I;
1862 break;
1863 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001864 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001865 return I;
1866 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001867 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001868 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001869 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001870 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001871 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001872 if (!RHSV) break;
1873 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001874 unsigned ShImm = Log2_32(RHSV-1);
1875 if (ShImm >= 32)
1876 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001877 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001878 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001879 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1880 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001881 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001882 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001883 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001884 } else {
1885 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001886 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001887 }
Evan Chenga8e29892007-01-19 07:51:42 +00001888 }
1889 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001890 unsigned ShImm = Log2_32(RHSV+1);
1891 if (ShImm >= 32)
1892 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001893 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001894 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001895 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1896 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001897 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001898 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1899 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001900 } else {
1901 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001902 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001903 }
Evan Chenga8e29892007-01-19 07:51:42 +00001904 }
1905 }
1906 break;
Evan Cheng20956592009-10-21 08:15:52 +00001907 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001908 // Check for unsigned bitfield extract
1909 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1910 return I;
1911
Evan Cheng20956592009-10-21 08:15:52 +00001912 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1913 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1914 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1915 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1916 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001917 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001918 if (VT != MVT::i32)
1919 break;
1920 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1921 ? ARM::t2MOVTi16
1922 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1923 if (!Opc)
1924 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001925 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001926 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1927 if (!N1C)
1928 break;
1929 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1930 SDValue N2 = N0.getOperand(1);
1931 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1932 if (!N2C)
1933 break;
1934 unsigned N1CVal = N1C->getZExtValue();
1935 unsigned N2CVal = N2C->getZExtValue();
1936 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1937 (N1CVal & 0xffffU) == 0xffffU &&
1938 (N2CVal & 0xffffU) == 0x0U) {
1939 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1940 MVT::i32);
1941 SDValue Ops[] = { N0.getOperand(0), Imm16,
1942 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1943 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1944 }
1945 }
1946 break;
1947 }
Jim Grosbache5165492009-11-09 00:11:35 +00001948 case ARMISD::VMOVRRD:
1949 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001950 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001951 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001952 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001953 if (Subtarget->isThumb1Only())
1954 break;
1955 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001956 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001957 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1958 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001959 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001960 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001961 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001962 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1963 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001964 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001965 }
Evan Chengee568cf2007-07-05 07:15:27 +00001966 }
Dan Gohman525178c2007-10-08 18:33:35 +00001967 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001968 if (Subtarget->isThumb1Only())
1969 break;
1970 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001972 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001973 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001974 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001975 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001976 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1977 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001978 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001979 }
Evan Chengee568cf2007-07-05 07:15:27 +00001980 }
Evan Chenga8e29892007-01-19 07:51:42 +00001981 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001982 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001983 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001985 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001986 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001987 if (ResNode)
1988 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001989 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001990 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001991 }
Evan Chengee568cf2007-07-05 07:15:27 +00001992 case ARMISD::BRCOND: {
1993 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1994 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1995 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001996
Evan Chengee568cf2007-07-05 07:15:27 +00001997 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1998 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1999 // Pattern complexity = 6 cost = 1 size = 0
2000
David Goodwin5e47a9a2009-06-30 18:04:13 +00002001 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2002 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2003 // Pattern complexity = 6 cost = 1 size = 0
2004
Jim Grosbach764ab522009-08-11 15:33:49 +00002005 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002006 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002007 SDValue Chain = N->getOperand(0);
2008 SDValue N1 = N->getOperand(1);
2009 SDValue N2 = N->getOperand(2);
2010 SDValue N3 = N->getOperand(3);
2011 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002012 assert(N1.getOpcode() == ISD::BasicBlock);
2013 assert(N2.getOpcode() == ISD::Constant);
2014 assert(N3.getOpcode() == ISD::Register);
2015
Dan Gohman475871a2008-07-27 21:46:04 +00002016 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002017 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002018 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002019 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002020 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2021 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002022 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002023 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002024 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002025 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002026 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002027 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002028 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002029 return NULL;
2030 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002031 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002033 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002034 EVT VT = N->getValueType(0);
2035 SDValue N0 = N->getOperand(0);
2036 SDValue N1 = N->getOperand(1);
2037 SDValue N2 = N->getOperand(2);
2038 SDValue N3 = N->getOperand(3);
2039 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002040 assert(N2.getOpcode() == ISD::Constant);
2041 assert(N3.getOpcode() == ISD::Register);
2042
Dan Gohman475871a2008-07-27 21:46:04 +00002043 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002044 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002045 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002046 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002047 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002048 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002049 default: assert(false && "Illegal conditional move type!");
2050 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002051 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002052 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002053 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002054 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002055 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002056 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002057 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002058 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002059 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002060
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002061 case ARMISD::VZIP: {
2062 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002063 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002064 switch (VT.getSimpleVT().SimpleTy) {
2065 default: return NULL;
2066 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2067 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2068 case MVT::v2f32:
2069 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2070 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2071 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2072 case MVT::v4f32:
2073 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2074 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002075 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002076 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2077 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2078 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002079 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002080 case ARMISD::VUZP: {
2081 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002082 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002083 switch (VT.getSimpleVT().SimpleTy) {
2084 default: return NULL;
2085 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2086 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2087 case MVT::v2f32:
2088 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2089 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2090 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2091 case MVT::v4f32:
2092 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2093 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002094 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002095 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2096 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2097 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002098 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002099 case ARMISD::VTRN: {
2100 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002101 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002102 switch (VT.getSimpleVT().SimpleTy) {
2103 default: return NULL;
2104 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2105 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2106 case MVT::v2f32:
2107 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2108 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2109 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2110 case MVT::v4f32:
2111 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2112 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002113 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002114 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2115 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2116 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002117 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002118 case ARMISD::BUILD_VECTOR: {
2119 EVT VecVT = N->getValueType(0);
2120 EVT EltVT = VecVT.getVectorElementType();
2121 unsigned NumElts = VecVT.getVectorNumElements();
2122 if (EltVT.getSimpleVT() == MVT::f64) {
2123 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2124 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2125 }
2126 assert(EltVT.getSimpleVT() == MVT::f32 &&
2127 "unexpected type for BUILD_VECTOR");
2128 if (NumElts == 2)
2129 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2130 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2131 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2132 N->getOperand(2), N->getOperand(3));
2133 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002134
2135 case ISD::INTRINSIC_VOID:
2136 case ISD::INTRINSIC_W_CHAIN: {
2137 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002138 switch (IntNo) {
2139 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002140 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002141
Bob Wilson621f1952010-03-23 05:25:43 +00002142 case Intrinsic::arm_neon_vld1: {
2143 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2144 ARM::VLD1d32, ARM::VLD1d64 };
2145 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2146 ARM::VLD1q32, ARM::VLD1q64 };
2147 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2148 }
2149
Bob Wilson31fb12f2009-08-26 17:39:53 +00002150 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002151 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002152 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002153 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002154 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002155 }
2156
2157 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002158 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002159 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002160 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2161 ARM::VLD3q16_UPD,
2162 ARM::VLD3q32_UPD };
2163 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2164 ARM::VLD3q16odd_UPD,
2165 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002166 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002167 }
2168
2169 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002170 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002171 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002172 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2173 ARM::VLD4q16_UPD,
2174 ARM::VLD4q32_UPD };
2175 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2176 ARM::VLD4q16odd_UPD,
2177 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002178 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002179 }
2180
Bob Wilson243fcc52009-09-01 04:26:28 +00002181 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002182 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002183 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2184 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002185 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002186 }
2187
2188 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002189 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002190 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2191 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002192 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002193 }
2194
2195 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002196 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002197 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2198 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002199 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002200 }
2201
Bob Wilson11d98992010-03-23 06:20:33 +00002202 case Intrinsic::arm_neon_vst1: {
2203 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2204 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002205 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2206 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002207 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2208 }
2209
Bob Wilson31fb12f2009-08-26 17:39:53 +00002210 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002211 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2212 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2213 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2214 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002215 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002216 }
2217
2218 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002219 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2220 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2221 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2222 ARM::VST3q16Pseudo_UPD,
2223 ARM::VST3q32Pseudo_UPD };
2224 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2225 ARM::VST3q16oddPseudo_UPD,
2226 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002227 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002228 }
2229
2230 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002231 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002232 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002233 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2234 ARM::VST4q16Pseudo_UPD,
2235 ARM::VST4q32Pseudo_UPD };
2236 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2237 ARM::VST4q16oddPseudo_UPD,
2238 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002239 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002240 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002241
2242 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002243 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002244 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2245 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002246 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002247 }
2248
2249 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002250 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002251 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2252 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002253 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002254 }
2255
2256 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002257 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002258 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2259 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002260 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002261 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002262 }
Bob Wilson429009b2010-05-06 16:05:26 +00002263 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002264 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002265
Bob Wilsond491d6e2010-07-06 23:36:25 +00002266 case ISD::INTRINSIC_WO_CHAIN: {
2267 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2268 switch (IntNo) {
2269 default:
2270 break;
2271
2272 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002273 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002274 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002275 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002276 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002277 return SelectVTBL(N, false, 4, ARM::VTBL4);
2278
2279 case Intrinsic::arm_neon_vtbx2:
2280 return SelectVTBL(N, true, 2, ARM::VTBX2);
2281 case Intrinsic::arm_neon_vtbx3:
2282 return SelectVTBL(N, true, 3, ARM::VTBX3);
2283 case Intrinsic::arm_neon_vtbx4:
2284 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002285 }
2286 break;
2287 }
2288
Bob Wilson429009b2010-05-06 16:05:26 +00002289 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002290 return SelectConcatVector(N);
2291 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002292
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002293 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002294}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002295
Bob Wilson224c2442009-05-19 05:53:42 +00002296bool ARMDAGToDAGISel::
2297SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2298 std::vector<SDValue> &OutOps) {
2299 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002300 // Require the address to be in a register. That is safe for all ARM
2301 // variants and it is hard to do anything much smarter without knowing
2302 // how the operand is used.
2303 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002304 return false;
2305}
2306
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002307/// createARMISelDag - This pass converts a legalized DAG into a
2308/// ARM-specific DAG, ready for instruction scheduling.
2309///
Bob Wilson522ce972009-09-28 14:30:20 +00002310FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2311 CodeGenOpt::Level OptLevel) {
2312 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002313}