blob: 51a30c158dd1bb9af0b06a693e77f2c4893e7566 [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
Bob Wilsonf5721912010-09-03 18:16:02 +00001114 EVT ResTy;
1115 if (NumVecs == 1)
1116 ResTy = VT;
1117 else {
1118 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1119 if (!is64BitVector)
1120 ResTyElts *= 2;
1121 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1122 }
1123
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001124 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001125 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001126 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001127 if (is64BitVector) {
1128 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001129 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001130 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001131 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001132 return VLd;
1133
Bob Wilsonf5721912010-09-03 18:16:02 +00001134 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001135 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001136 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001137 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001138 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001139 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001140 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001141 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001142 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001143 }
1144
Bob Wilson621f1952010-03-23 05:25:43 +00001145 if (NumVecs <= 2) {
1146 // Quad registers are directly supported for VLD1 and VLD2,
1147 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001148 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001149 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001150 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001151 if (NumVecs == 1)
1152 return VLd;
1153
Bob Wilsonf5721912010-09-03 18:16:02 +00001154 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001155 Chain = SDValue(VLd, 1);
1156
Bob Wilson3e36f132009-10-14 17:28:52 +00001157 } else {
1158 // Otherwise, quad registers are loaded with two separate instructions,
1159 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001160 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001161
Bob Wilson24f995d2009-10-14 18:32:29 +00001162 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001163 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001164 SDValue ImplDef =
1165 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1166 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1167 SDNode *VLdA =
1168 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1169 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001170
Bob Wilson24f995d2009-10-14 18:32:29 +00001171 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001172 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001173 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1174 Pred, Reg0, Chain };
1175 SDNode *VLdB =
1176 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1177 SuperReg = SDValue(VLdB, 0);
1178 Chain = SDValue(VLdB, 2);
1179 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001180
Bob Wilsonf5721912010-09-03 18:16:02 +00001181 // Extract out the Q registers.
1182 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1183 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1184 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1185 dl, VT, SuperReg);
1186 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001187 }
1188 ReplaceUses(SDValue(N, NumVecs), Chain);
1189 return NULL;
1190}
1191
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001192SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001193 unsigned *DOpcodes, unsigned *QOpcodes0,
1194 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001195 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001196 DebugLoc dl = N->getDebugLoc();
1197
Bob Wilson226036e2010-03-20 22:13:40 +00001198 SDValue MemAddr, Align;
1199 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001200 return NULL;
1201
1202 SDValue Chain = N->getOperand(0);
1203 EVT VT = N->getOperand(3).getValueType();
1204 bool is64BitVector = VT.is64BitVector();
1205
1206 unsigned OpcodeIndex;
1207 switch (VT.getSimpleVT().SimpleTy) {
1208 default: llvm_unreachable("unhandled vst type");
1209 // Double-register operations:
1210 case MVT::v8i8: OpcodeIndex = 0; break;
1211 case MVT::v4i16: OpcodeIndex = 1; break;
1212 case MVT::v2f32:
1213 case MVT::v2i32: OpcodeIndex = 2; break;
1214 case MVT::v1i64: OpcodeIndex = 3; break;
1215 // Quad-register operations:
1216 case MVT::v16i8: OpcodeIndex = 0; break;
1217 case MVT::v8i16: OpcodeIndex = 1; break;
1218 case MVT::v4f32:
1219 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001220 case MVT::v2i64: OpcodeIndex = 3;
1221 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1222 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001223 }
1224
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001225 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001226 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001227
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001228 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001229 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001230 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001231
1232 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001233 if (NumVecs == 1) {
1234 Ops.push_back(N->getOperand(3));
1235 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001236 SDValue RegSeq;
1237 SDValue V0 = N->getOperand(0+3);
1238 SDValue V1 = N->getOperand(1+3);
1239
1240 // Form a REG_SEQUENCE to force register allocation.
1241 if (NumVecs == 2)
1242 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1243 else {
1244 SDValue V2 = N->getOperand(2+3);
1245 // If it's a vld3, form a quad D-register and leave the last part as
1246 // an undef.
1247 SDValue V3 = (NumVecs == 3)
1248 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1249 : N->getOperand(3+3);
1250 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1251 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001252 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001253 }
Evan Chengac0869d2009-11-21 06:21:52 +00001254 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001255 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001256 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001257 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001258 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001259 }
1260
Bob Wilson11d98992010-03-23 06:20:33 +00001261 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001262 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001263 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001264 if (NumVecs == 1) {
1265 Ops.push_back(N->getOperand(3));
1266 } else {
1267 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001268 SDValue Q0 = N->getOperand(3);
1269 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001270 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001271 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001272 Ops.push_back(Pred);
1273 Ops.push_back(Reg0); // predicate register
1274 Ops.push_back(Chain);
1275 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001276 }
1277
1278 // Otherwise, quad registers are stored with two separate instructions,
1279 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001280
Bob Wilson07f6e802010-06-16 21:34:01 +00001281 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001282 SDValue V0 = N->getOperand(0+3);
1283 SDValue V1 = N->getOperand(1+3);
1284 SDValue V2 = N->getOperand(2+3);
1285 SDValue V3 = (NumVecs == 3)
1286 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1287 : N->getOperand(3+3);
1288 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001289
1290 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001291 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001292 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001293 Ops.push_back(Pred);
1294 Ops.push_back(Reg0); // predicate register
1295 Ops.push_back(Chain);
1296 unsigned Opc = QOpcodes0[OpcodeIndex];
1297 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001298 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001299 Chain = SDValue(VStA, 1);
1300
1301 // Store the odd D registers.
1302 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001303 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001304 Opc = QOpcodes1[OpcodeIndex];
1305 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001306 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001307 Chain = SDValue(VStB, 1);
1308 ReplaceUses(SDValue(N, 0), Chain);
1309 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001310}
1311
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001312SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001313 unsigned NumVecs, unsigned *DOpcodes,
1314 unsigned *QOpcodes0,
1315 unsigned *QOpcodes1) {
1316 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001317 DebugLoc dl = N->getDebugLoc();
1318
Bob Wilson226036e2010-03-20 22:13:40 +00001319 SDValue MemAddr, Align;
1320 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001321 return NULL;
1322
1323 SDValue Chain = N->getOperand(0);
1324 unsigned Lane =
1325 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001326 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001327 bool is64BitVector = VT.is64BitVector();
1328
Bob Wilson96493442009-10-14 16:46:45 +00001329 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001330 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001331 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001332 EVT RegVT = VT;
1333 if (!is64BitVector) {
1334 RegVT = GetNEONSubregVT(VT);
1335 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001336 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001337 }
1338
1339 unsigned OpcodeIndex;
1340 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001341 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001342 // Double-register operations:
1343 case MVT::v8i8: OpcodeIndex = 0; break;
1344 case MVT::v4i16: OpcodeIndex = 1; break;
1345 case MVT::v2f32:
1346 case MVT::v2i32: OpcodeIndex = 2; break;
1347 // Quad-register operations:
1348 case MVT::v8i16: OpcodeIndex = 0; break;
1349 case MVT::v4f32:
1350 case MVT::v4i32: OpcodeIndex = 1; break;
1351 }
1352
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001353 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001354 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001355
Bob Wilson226036e2010-03-20 22:13:40 +00001356 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001357 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001358 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001359
1360 unsigned Opc = 0;
1361 if (is64BitVector) {
1362 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001363 SDValue RegSeq;
1364 SDValue V0 = N->getOperand(0+3);
1365 SDValue V1 = N->getOperand(1+3);
1366 if (NumVecs == 2) {
1367 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001368 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001369 SDValue V2 = N->getOperand(2+3);
1370 SDValue V3 = (NumVecs == 3)
1371 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1372 : N->getOperand(3+3);
1373 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001374 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001375
1376 // Now extract the D registers back out.
1377 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1378 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1379 if (NumVecs > 2)
1380 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1381 if (NumVecs > 3)
1382 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001383 } else {
1384 // Check if this is loading the even or odd subreg of a Q register.
1385 if (Lane < NumElts) {
1386 Opc = QOpcodes0[OpcodeIndex];
1387 } else {
1388 Lane -= NumElts;
1389 Opc = QOpcodes1[OpcodeIndex];
1390 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001391
Bob Wilson07f6e802010-06-16 21:34:01 +00001392 SDValue RegSeq;
1393 SDValue V0 = N->getOperand(0+3);
1394 SDValue V1 = N->getOperand(1+3);
1395 if (NumVecs == 2) {
1396 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001397 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001398 SDValue V2 = N->getOperand(2+3);
1399 SDValue V3 = (NumVecs == 3)
1400 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1401 : N->getOperand(3+3);
1402 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001403 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001404
1405 // Extract the subregs of the input vector.
1406 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1407 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1408 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1409 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001410 }
1411 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001412 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001413 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001414 Ops.push_back(Chain);
1415
Bob Wilson96493442009-10-14 16:46:45 +00001416 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001417 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001418
Bob Wilsona7c397c2009-10-14 16:19:03 +00001419 std::vector<EVT> ResTys(NumVecs, RegVT);
1420 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001421 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1422
Bob Wilson07f6e802010-06-16 21:34:01 +00001423 // Form a REG_SEQUENCE to force register allocation.
1424 SDValue RegSeq;
1425 if (is64BitVector) {
1426 SDValue V0 = SDValue(VLdLn, 0);
1427 SDValue V1 = SDValue(VLdLn, 1);
1428 if (NumVecs == 2) {
1429 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001430 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001431 SDValue V2 = SDValue(VLdLn, 2);
1432 // If it's a vld3, form a quad D-register but discard the last part.
1433 SDValue V3 = (NumVecs == 3)
1434 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1435 : SDValue(VLdLn, 3);
1436 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001437 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001438 } else {
1439 // For 128-bit vectors, take the 64-bit results of the load and insert
1440 // them as subregs into the result.
1441 SDValue V[8];
1442 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1443 if (Even) {
1444 V[i] = SDValue(VLdLn, Vec);
1445 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1446 dl, RegVT), 0);
1447 } else {
1448 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1449 dl, RegVT), 0);
1450 V[i+1] = SDValue(VLdLn, Vec);
1451 }
1452 }
1453 if (NumVecs == 3)
1454 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1455 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001456
Bob Wilson07f6e802010-06-16 21:34:01 +00001457 if (NumVecs == 2)
1458 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1459 else
1460 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1461 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001462 }
1463
Bob Wilson07f6e802010-06-16 21:34:01 +00001464 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1465 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1466 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1467 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1468 ReplaceUses(SDValue(N, Vec),
1469 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1470 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001471 return NULL;
1472}
1473
Bob Wilson78dfbc32010-07-07 00:08:54 +00001474SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1475 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001476 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1477 DebugLoc dl = N->getDebugLoc();
1478 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001479 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001480
1481 // Form a REG_SEQUENCE to force register allocation.
1482 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001483 SDValue V0 = N->getOperand(FirstTblReg + 0);
1484 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001485 if (NumVecs == 2)
1486 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1487 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001488 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001489 // If it's a vtbl3, form a quad D-register and leave the last part as
1490 // an undef.
1491 SDValue V3 = (NumVecs == 3)
1492 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001493 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001494 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1495 }
1496
1497 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001498 SmallVector<SDValue, 6> Ops;
1499 if (IsExt)
1500 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001501 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1502 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1503 if (NumVecs > 2)
1504 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1505 if (NumVecs > 3)
1506 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1507
Bob Wilson78dfbc32010-07-07 00:08:54 +00001508 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001509 Ops.push_back(getAL(CurDAG)); // predicate
1510 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001511 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001512}
1513
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001514SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001515 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001516 if (!Subtarget->hasV6T2Ops())
1517 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001518
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001519 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1520 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1521
1522
1523 // For unsigned extracts, check for a shift right and mask
1524 unsigned And_imm = 0;
1525 if (N->getOpcode() == ISD::AND) {
1526 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1527
1528 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1529 if (And_imm & (And_imm + 1))
1530 return NULL;
1531
1532 unsigned Srl_imm = 0;
1533 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1534 Srl_imm)) {
1535 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1536
1537 unsigned Width = CountTrailingOnes_32(And_imm);
1538 unsigned LSB = Srl_imm;
1539 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1540 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1541 CurDAG->getTargetConstant(LSB, MVT::i32),
1542 CurDAG->getTargetConstant(Width, MVT::i32),
1543 getAL(CurDAG), Reg0 };
1544 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1545 }
1546 }
1547 return NULL;
1548 }
1549
1550 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001551 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001552 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001553 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1554 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001555 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001556 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1557 unsigned Width = 32 - Srl_imm;
1558 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001559 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001560 return NULL;
1561 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001562 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001563 CurDAG->getTargetConstant(LSB, MVT::i32),
1564 CurDAG->getTargetConstant(Width, MVT::i32),
1565 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001566 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001567 }
1568 }
1569 return NULL;
1570}
1571
Evan Cheng9ef48352009-11-20 00:54:03 +00001572SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001573SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001574 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1575 SDValue CPTmp0;
1576 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001577 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001578 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1579 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1580 unsigned Opc = 0;
1581 switch (SOShOp) {
1582 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1583 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1584 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1585 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1586 default:
1587 llvm_unreachable("Unknown so_reg opcode!");
1588 break;
1589 }
1590 SDValue SOShImm =
1591 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1592 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1593 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001594 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001595 }
1596 return 0;
1597}
1598
1599SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001600SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001601 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1602 SDValue CPTmp0;
1603 SDValue CPTmp1;
1604 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001605 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001606 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1607 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001608 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001609 }
1610 return 0;
1611}
1612
1613SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001614SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001615 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1616 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1617 if (!T)
1618 return 0;
1619
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001620 if (Pred_t2_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001621 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1622 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1623 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001624 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001625 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1626 }
1627 return 0;
1628}
1629
1630SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001631SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001632 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1633 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1634 if (!T)
1635 return 0;
1636
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001637 if (Pred_so_imm(TrueVal.getNode())) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001638 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1639 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1640 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001641 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001642 ARM::MOVCCi, MVT::i32, Ops, 5);
1643 }
1644 return 0;
1645}
1646
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001647SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1648 EVT VT = N->getValueType(0);
1649 SDValue FalseVal = N->getOperand(0);
1650 SDValue TrueVal = N->getOperand(1);
1651 SDValue CC = N->getOperand(2);
1652 SDValue CCR = N->getOperand(3);
1653 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001654 assert(CC.getOpcode() == ISD::Constant);
1655 assert(CCR.getOpcode() == ISD::Register);
1656 ARMCC::CondCodes CCVal =
1657 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001658
1659 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1660 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1661 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1662 // Pattern complexity = 18 cost = 1 size = 0
1663 SDValue CPTmp0;
1664 SDValue CPTmp1;
1665 SDValue CPTmp2;
1666 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001667 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001668 CCVal, CCR, InFlag);
1669 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001670 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001671 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1672 if (Res)
1673 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001674 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001675 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001676 CCVal, CCR, InFlag);
1677 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001678 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001679 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1680 if (Res)
1681 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001682 }
1683
1684 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001685 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001686 // (imm:i32):$cc)
1687 // Emits: (MOVCCi:i32 GPR:i32:$false,
1688 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1689 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001690 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001691 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001692 CCVal, CCR, InFlag);
1693 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001694 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001695 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1696 if (Res)
1697 return Res;
1698 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001699 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001700 CCVal, CCR, InFlag);
1701 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001702 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001703 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1704 if (Res)
1705 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001706 }
1707 }
1708
1709 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1710 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1711 // Pattern complexity = 6 cost = 1 size = 0
1712 //
1713 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1714 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1715 // Pattern complexity = 6 cost = 11 size = 0
1716 //
1717 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001718 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1719 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001720 unsigned Opc = 0;
1721 switch (VT.getSimpleVT().SimpleTy) {
1722 default: assert(false && "Illegal conditional move type!");
1723 break;
1724 case MVT::i32:
1725 Opc = Subtarget->isThumb()
1726 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1727 : ARM::MOVCCr;
1728 break;
1729 case MVT::f32:
1730 Opc = ARM::VMOVScc;
1731 break;
1732 case MVT::f64:
1733 Opc = ARM::VMOVDcc;
1734 break;
1735 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001736 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001737}
1738
Evan Chengde8aa4e2010-05-05 18:28:36 +00001739SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1740 // The only time a CONCAT_VECTORS operation can have legal types is when
1741 // two 64-bit vectors are concatenated to a 128-bit vector.
1742 EVT VT = N->getValueType(0);
1743 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1744 llvm_unreachable("unexpected CONCAT_VECTORS");
1745 DebugLoc dl = N->getDebugLoc();
1746 SDValue V0 = N->getOperand(0);
1747 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001748 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1749 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001750 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1751 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1752}
1753
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001754SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001755 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001756
Dan Gohmane8be6c62008-07-17 19:10:17 +00001757 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001758 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001759
1760 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001761 default: break;
1762 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001763 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001764 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001765 if (Subtarget->hasThumb2())
1766 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1767 // be done with MOV + MOVT, at worst.
1768 UseCP = 0;
1769 else {
1770 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001771 UseCP = (Val > 255 && // MOV
1772 ~Val > 255 && // MOV + MVN
1773 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001774 } else
1775 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1776 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1777 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1778 }
1779
Evan Chenga8e29892007-01-19 07:51:42 +00001780 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001781 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001782 CurDAG->getTargetConstantPool(ConstantInt::get(
1783 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001784 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001785
1786 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001787 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001788 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001789 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001790 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001791 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1792 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001793 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001794 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001795 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001796 CurDAG->getRegister(0, MVT::i32),
1797 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001798 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001799 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001800 CurDAG->getEntryNode()
1801 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001802 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1803 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001804 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001805 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001806 return NULL;
1807 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001808
Evan Chenga8e29892007-01-19 07:51:42 +00001809 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001810 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001811 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001812 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001813 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001814 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001815 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001816 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001817 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1818 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001819 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001820 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1821 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001822 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1823 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1824 CurDAG->getRegister(0, MVT::i32) };
1825 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001826 }
Evan Chenga8e29892007-01-19 07:51:42 +00001827 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001828 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001829 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001830 return I;
1831 break;
1832 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001833 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001834 return I;
1835 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001836 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001837 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001838 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001839 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001840 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001841 if (!RHSV) break;
1842 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001843 unsigned ShImm = Log2_32(RHSV-1);
1844 if (ShImm >= 32)
1845 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001847 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001848 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1849 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001850 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001851 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001852 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001853 } else {
1854 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001855 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001856 }
Evan Chenga8e29892007-01-19 07:51:42 +00001857 }
1858 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001859 unsigned ShImm = Log2_32(RHSV+1);
1860 if (ShImm >= 32)
1861 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001862 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001863 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001864 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1865 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001866 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001867 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1868 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001869 } else {
1870 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001871 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001872 }
Evan Chenga8e29892007-01-19 07:51:42 +00001873 }
1874 }
1875 break;
Evan Cheng20956592009-10-21 08:15:52 +00001876 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001877 // Check for unsigned bitfield extract
1878 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1879 return I;
1880
Evan Cheng20956592009-10-21 08:15:52 +00001881 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1882 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1883 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1884 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1885 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001886 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001887 if (VT != MVT::i32)
1888 break;
1889 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1890 ? ARM::t2MOVTi16
1891 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1892 if (!Opc)
1893 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001894 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001895 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1896 if (!N1C)
1897 break;
1898 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1899 SDValue N2 = N0.getOperand(1);
1900 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1901 if (!N2C)
1902 break;
1903 unsigned N1CVal = N1C->getZExtValue();
1904 unsigned N2CVal = N2C->getZExtValue();
1905 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1906 (N1CVal & 0xffffU) == 0xffffU &&
1907 (N2CVal & 0xffffU) == 0x0U) {
1908 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1909 MVT::i32);
1910 SDValue Ops[] = { N0.getOperand(0), Imm16,
1911 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1912 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1913 }
1914 }
1915 break;
1916 }
Jim Grosbache5165492009-11-09 00:11:35 +00001917 case ARMISD::VMOVRRD:
1918 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001919 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001920 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001921 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001922 if (Subtarget->isThumb1Only())
1923 break;
1924 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001925 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001926 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1927 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001928 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001929 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001930 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001931 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1932 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001933 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001934 }
Evan Chengee568cf2007-07-05 07:15:27 +00001935 }
Dan Gohman525178c2007-10-08 18:33:35 +00001936 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001937 if (Subtarget->isThumb1Only())
1938 break;
1939 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001940 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001941 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001942 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001943 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001944 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001945 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1946 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001947 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001948 }
Evan Chengee568cf2007-07-05 07:15:27 +00001949 }
Evan Chenga8e29892007-01-19 07:51:42 +00001950 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001951 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001952 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001953 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001954 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001955 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001956 if (ResNode)
1957 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00001958 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001959 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001960 }
Evan Chengee568cf2007-07-05 07:15:27 +00001961 case ARMISD::BRCOND: {
1962 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1963 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1964 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001965
Evan Chengee568cf2007-07-05 07:15:27 +00001966 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1967 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
1968 // Pattern complexity = 6 cost = 1 size = 0
1969
David Goodwin5e47a9a2009-06-30 18:04:13 +00001970 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
1971 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
1972 // Pattern complexity = 6 cost = 1 size = 0
1973
Jim Grosbach764ab522009-08-11 15:33:49 +00001974 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00001975 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 SDValue Chain = N->getOperand(0);
1977 SDValue N1 = N->getOperand(1);
1978 SDValue N2 = N->getOperand(2);
1979 SDValue N3 = N->getOperand(3);
1980 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00001981 assert(N1.getOpcode() == ISD::BasicBlock);
1982 assert(N2.getOpcode() == ISD::Constant);
1983 assert(N3.getOpcode() == ISD::Register);
1984
Dan Gohman475871a2008-07-27 21:46:04 +00001985 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001986 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00001987 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00001988 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00001989 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
1990 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00001991 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001992 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00001993 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001994 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00001995 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001996 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00001997 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00001998 return NULL;
1999 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002000 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002001 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002002 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002003 EVT VT = N->getValueType(0);
2004 SDValue N0 = N->getOperand(0);
2005 SDValue N1 = N->getOperand(1);
2006 SDValue N2 = N->getOperand(2);
2007 SDValue N3 = N->getOperand(3);
2008 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002009 assert(N2.getOpcode() == ISD::Constant);
2010 assert(N3.getOpcode() == ISD::Register);
2011
Dan Gohman475871a2008-07-27 21:46:04 +00002012 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002013 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002014 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002015 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002016 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002017 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002018 default: assert(false && "Illegal conditional move type!");
2019 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002020 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002021 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002022 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002023 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002024 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002025 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002026 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002027 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002028 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002029
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002030 case ARMISD::VZIP: {
2031 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002032 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002033 switch (VT.getSimpleVT().SimpleTy) {
2034 default: return NULL;
2035 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2036 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2037 case MVT::v2f32:
2038 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2039 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2040 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2041 case MVT::v4f32:
2042 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2043 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002044 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002045 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2046 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2047 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002048 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002049 case ARMISD::VUZP: {
2050 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002051 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002052 switch (VT.getSimpleVT().SimpleTy) {
2053 default: return NULL;
2054 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2055 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2056 case MVT::v2f32:
2057 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2058 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2059 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2060 case MVT::v4f32:
2061 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2062 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002063 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002064 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2065 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2066 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002067 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002068 case ARMISD::VTRN: {
2069 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002070 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002071 switch (VT.getSimpleVT().SimpleTy) {
2072 default: return NULL;
2073 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2074 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2075 case MVT::v2f32:
2076 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2077 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2078 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2079 case MVT::v4f32:
2080 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2081 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002082 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002083 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2084 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2085 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002086 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002087 case ARMISD::BUILD_VECTOR: {
2088 EVT VecVT = N->getValueType(0);
2089 EVT EltVT = VecVT.getVectorElementType();
2090 unsigned NumElts = VecVT.getVectorNumElements();
2091 if (EltVT.getSimpleVT() == MVT::f64) {
2092 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2093 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2094 }
2095 assert(EltVT.getSimpleVT() == MVT::f32 &&
2096 "unexpected type for BUILD_VECTOR");
2097 if (NumElts == 2)
2098 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2099 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2100 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2101 N->getOperand(2), N->getOperand(3));
2102 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002103
2104 case ISD::INTRINSIC_VOID:
2105 case ISD::INTRINSIC_W_CHAIN: {
2106 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002107 switch (IntNo) {
2108 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002109 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002110
Bob Wilson621f1952010-03-23 05:25:43 +00002111 case Intrinsic::arm_neon_vld1: {
2112 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2113 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002114 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2115 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002116 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2117 }
2118
Bob Wilson31fb12f2009-08-26 17:39:53 +00002119 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002120 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2121 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2122 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2123 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002124 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002125 }
2126
2127 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002128 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2129 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2130 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2131 ARM::VLD3q16Pseudo_UPD,
2132 ARM::VLD3q32Pseudo_UPD };
2133 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2134 ARM::VLD3q16oddPseudo_UPD,
2135 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002136 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002137 }
2138
2139 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002140 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2141 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2142 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2143 ARM::VLD4q16Pseudo_UPD,
2144 ARM::VLD4q32Pseudo_UPD };
2145 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2146 ARM::VLD4q16oddPseudo_UPD,
2147 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002149 }
2150
Bob Wilson243fcc52009-09-01 04:26:28 +00002151 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002152 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002153 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2154 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002156 }
2157
2158 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002159 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002160 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2161 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002162 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002163 }
2164
2165 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002166 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002167 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2168 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002169 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002170 }
2171
Bob Wilson11d98992010-03-23 06:20:33 +00002172 case Intrinsic::arm_neon_vst1: {
2173 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2174 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002175 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2176 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002177 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2178 }
2179
Bob Wilson31fb12f2009-08-26 17:39:53 +00002180 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002181 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2182 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2183 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2184 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002185 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002186 }
2187
2188 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002189 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2190 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2191 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2192 ARM::VST3q16Pseudo_UPD,
2193 ARM::VST3q32Pseudo_UPD };
2194 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2195 ARM::VST3q16oddPseudo_UPD,
2196 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002197 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002198 }
2199
2200 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002201 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002202 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002203 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2204 ARM::VST4q16Pseudo_UPD,
2205 ARM::VST4q32Pseudo_UPD };
2206 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2207 ARM::VST4q16oddPseudo_UPD,
2208 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002209 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002210 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002211
2212 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002213 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002214 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2215 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002216 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002217 }
2218
2219 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002220 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002221 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2222 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002223 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002224 }
2225
2226 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002227 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002228 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2229 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002230 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002231 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002232 }
Bob Wilson429009b2010-05-06 16:05:26 +00002233 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002234 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002235
Bob Wilsond491d6e2010-07-06 23:36:25 +00002236 case ISD::INTRINSIC_WO_CHAIN: {
2237 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2238 switch (IntNo) {
2239 default:
2240 break;
2241
2242 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002243 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002244 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002245 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002246 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002247 return SelectVTBL(N, false, 4, ARM::VTBL4);
2248
2249 case Intrinsic::arm_neon_vtbx2:
2250 return SelectVTBL(N, true, 2, ARM::VTBX2);
2251 case Intrinsic::arm_neon_vtbx3:
2252 return SelectVTBL(N, true, 3, ARM::VTBX3);
2253 case Intrinsic::arm_neon_vtbx4:
2254 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002255 }
2256 break;
2257 }
2258
Bob Wilson429009b2010-05-06 16:05:26 +00002259 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002260 return SelectConcatVector(N);
2261 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002262
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002263 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002264}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002265
Bob Wilson224c2442009-05-19 05:53:42 +00002266bool ARMDAGToDAGISel::
2267SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2268 std::vector<SDValue> &OutOps) {
2269 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002270 // Require the address to be in a register. That is safe for all ARM
2271 // variants and it is hard to do anything much smarter without knowing
2272 // how the operand is used.
2273 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002274 return false;
2275}
2276
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002277/// createARMISelDag - This pass converts a legalized DAG into a
2278/// ARM-specific DAG, ready for instruction scheduling.
2279///
Bob Wilson522ce972009-09-28 14:30:20 +00002280FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2281 CodeGenOpt::Level OptLevel) {
2282 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002283}