blob: f4012c71d7e9392f9f3988fcdff15dd95cbebf15 [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
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000121 // Include the pieces autogenerated from the target description.
122#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000123
124private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000125 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
126 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000127 SDNode *SelectARMIndexedLoad(SDNode *N);
128 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000129
Bob Wilson621f1952010-03-23 05:25:43 +0000130 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
131 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000132 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000133 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000135 unsigned *QOpcodes0, unsigned *QOpcodes1);
136
Bob Wilson24f995d2009-10-14 18:32:29 +0000137 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000138 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000139 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000140 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000142 unsigned *QOpcodes0, unsigned *QOpcodes1);
143
Bob Wilson96493442009-10-14 16:46:45 +0000144 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000145 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000146 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000147 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000148 unsigned *DOpcodes, unsigned *QOpcodes0,
149 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000150
Bob Wilson78dfbc32010-07-07 00:08:54 +0000151 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
152 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
153 /// generated to force the table registers to be consecutive.
154 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000155
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000156 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000157 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000158
Evan Cheng07ba9062009-11-19 21:45:22 +0000159 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectCMOVOp(SDNode *N);
161 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000162 ARMCC::CondCodes CCVal, SDValue CCR,
163 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000164 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000165 ARMCC::CondCodes CCVal, SDValue CCR,
166 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000167 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000168 ARMCC::CondCodes CCVal, SDValue CCR,
169 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000170 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000171 ARMCC::CondCodes CCVal, SDValue CCR,
172 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000173
Evan Chengde8aa4e2010-05-05 18:28:36 +0000174 SDNode *SelectConcatVector(SDNode *N);
175
Evan Chengaf4550f2009-07-02 01:23:32 +0000176 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
177 /// inline asm expressions.
178 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
179 char ConstraintCode,
180 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000181
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000182 // Form pairs of consecutive S, D, or Q registers.
183 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000184 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000185 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
186
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000187 // Form sequences of 4 consecutive S, D, or Q registers.
188 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000189 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000190 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
191
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000192 // Form sequences of 8 consecutive D registers.
Evan Cheng5c6aba22010-05-14 18:54:59 +0000193 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
194 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000195};
Evan Chenga8e29892007-01-19 07:51:42 +0000196}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000197
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000198/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
199/// operand. If so Imm will receive the 32-bit value.
200static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
201 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
202 Imm = cast<ConstantSDNode>(N)->getZExtValue();
203 return true;
204 }
205 return false;
206}
207
208// isInt32Immediate - This method tests to see if a constant operand.
209// If so Imm will receive the 32 bit value.
210static bool isInt32Immediate(SDValue N, unsigned &Imm) {
211 return isInt32Immediate(N.getNode(), Imm);
212}
213
214// isOpcWithIntImmediate - This method tests to see if the node is a specific
215// opcode and that it has a immediate integer right operand.
216// If so Imm will receive the 32 bit value.
217static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
218 return N->getOpcode() == Opc &&
219 isInt32Immediate(N->getOperand(1).getNode(), Imm);
220}
221
222
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000223bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000224 SDValue N,
225 SDValue &BaseReg,
226 SDValue &ShReg,
227 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000228 if (DisableShifterOp)
229 return false;
230
Evan Cheng055b0312009-06-29 07:51:04 +0000231 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
232
233 // Don't match base register only case. That is matched to a separate
234 // lower complexity pattern with explicit register operand.
235 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000236
Evan Cheng055b0312009-06-29 07:51:04 +0000237 BaseReg = N.getOperand(0);
238 unsigned ShImmVal = 0;
239 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000240 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000241 ShImmVal = RHS->getZExtValue() & 31;
242 } else {
243 ShReg = N.getOperand(1);
244 }
245 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000246 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000247 return true;
248}
249
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000250bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000251 SDValue &Base, SDValue &Offset,
252 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000253 if (N.getOpcode() == ISD::MUL) {
254 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
255 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000256 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000257 if (RHSC & 1) {
258 RHSC = RHSC & ~1;
259 ARM_AM::AddrOpc AddSub = ARM_AM::add;
260 if (RHSC < 0) {
261 AddSub = ARM_AM::sub;
262 RHSC = - RHSC;
263 }
264 if (isPowerOf2_32(RHSC)) {
265 unsigned ShAmt = Log2_32(RHSC);
266 Base = Offset = N.getOperand(0);
267 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
268 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000269 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000270 return true;
271 }
272 }
273 }
274 }
275
Evan Chenga8e29892007-01-19 07:51:42 +0000276 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
277 Base = N;
278 if (N.getOpcode() == ISD::FrameIndex) {
279 int FI = cast<FrameIndexSDNode>(N)->getIndex();
280 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000281 } else if (N.getOpcode() == ARMISD::Wrapper &&
282 !(Subtarget->useMovt() &&
283 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000284 Base = N.getOperand(0);
285 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000286 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000287 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
288 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000289 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000290 return true;
291 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000292
Evan Chenga8e29892007-01-19 07:51:42 +0000293 // Match simple R +/- imm12 operands.
294 if (N.getOpcode() == ISD::ADD)
295 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000296 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000297 if ((RHSC >= 0 && RHSC < 0x1000) ||
298 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000299 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000300 if (Base.getOpcode() == ISD::FrameIndex) {
301 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
302 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
303 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000304 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000305
306 ARM_AM::AddrOpc AddSub = ARM_AM::add;
307 if (RHSC < 0) {
308 AddSub = ARM_AM::sub;
309 RHSC = - RHSC;
310 }
311 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000312 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000313 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000314 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000315 }
Evan Chenga8e29892007-01-19 07:51:42 +0000316 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000317
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000318 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000319 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
320 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
321 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000322
Evan Chenga8e29892007-01-19 07:51:42 +0000323 Base = N.getOperand(0);
324 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000325
Evan Chenga8e29892007-01-19 07:51:42 +0000326 if (ShOpcVal != ARM_AM::no_shift) {
327 // Check to see if the RHS of the shift is a constant, if not, we can't fold
328 // it.
329 if (ConstantSDNode *Sh =
330 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000331 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000332 Offset = N.getOperand(1).getOperand(0);
333 } else {
334 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000335 }
336 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000337
Evan Chenga8e29892007-01-19 07:51:42 +0000338 // Try matching (R shl C) + (R).
339 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
340 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
341 if (ShOpcVal != ARM_AM::no_shift) {
342 // Check to see if the RHS of the shift is a constant, if not, we can't
343 // fold it.
344 if (ConstantSDNode *Sh =
345 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000346 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000347 Offset = N.getOperand(0).getOperand(0);
348 Base = N.getOperand(1);
349 } else {
350 ShOpcVal = ARM_AM::no_shift;
351 }
352 }
353 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000354
Evan Chenga8e29892007-01-19 07:51:42 +0000355 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000356 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000357 return true;
358}
359
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000360bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000361 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000362 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000363 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
364 ? cast<LoadSDNode>(Op)->getAddressingMode()
365 : cast<StoreSDNode>(Op)->getAddressingMode();
366 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
367 ? ARM_AM::add : ARM_AM::sub;
368 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000369 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000370 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000371 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000372 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
373 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000374 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000375 return true;
376 }
377 }
378
379 Offset = N;
380 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
381 unsigned ShAmt = 0;
382 if (ShOpcVal != ARM_AM::no_shift) {
383 // Check to see if the RHS of the shift is a constant, if not, we can't fold
384 // it.
385 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000386 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000387 Offset = N.getOperand(0);
388 } else {
389 ShOpcVal = ARM_AM::no_shift;
390 }
391 }
392
393 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000395 return true;
396}
397
Evan Chenga8e29892007-01-19 07:51:42 +0000398
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000399bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000400 SDValue &Base, SDValue &Offset,
401 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000402 if (N.getOpcode() == ISD::SUB) {
403 // X - C is canonicalize to X + -C, no need to handle it here.
404 Base = N.getOperand(0);
405 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000406 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000407 return true;
408 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000409
Evan Chenga8e29892007-01-19 07:51:42 +0000410 if (N.getOpcode() != ISD::ADD) {
411 Base = N;
412 if (N.getOpcode() == ISD::FrameIndex) {
413 int FI = cast<FrameIndexSDNode>(N)->getIndex();
414 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
415 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000416 Offset = CurDAG->getRegister(0, MVT::i32);
417 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000418 return true;
419 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000420
Evan Chenga8e29892007-01-19 07:51:42 +0000421 // If the RHS is +/- imm8, fold into addr mode.
422 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000423 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000424 if ((RHSC >= 0 && RHSC < 256) ||
425 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000426 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000427 if (Base.getOpcode() == ISD::FrameIndex) {
428 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
429 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
430 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000431 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000432
433 ARM_AM::AddrOpc AddSub = ARM_AM::add;
434 if (RHSC < 0) {
435 AddSub = ARM_AM::sub;
436 RHSC = - RHSC;
437 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000438 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000439 return true;
440 }
441 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000442
Evan Chenga8e29892007-01-19 07:51:42 +0000443 Base = N.getOperand(0);
444 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000445 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000446 return true;
447}
448
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000449bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000450 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000451 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000452 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
453 ? cast<LoadSDNode>(Op)->getAddressingMode()
454 : cast<StoreSDNode>(Op)->getAddressingMode();
455 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
456 ? ARM_AM::add : ARM_AM::sub;
457 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000458 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000459 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000460 Offset = CurDAG->getRegister(0, MVT::i32);
461 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000462 return true;
463 }
464 }
465
466 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000467 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000468 return true;
469}
470
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000471bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000472 SDValue &Addr, SDValue &Mode) {
473 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000474 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000475 return true;
476}
Evan Chenga8e29892007-01-19 07:51:42 +0000477
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000478bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000479 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000480 if (N.getOpcode() != ISD::ADD) {
481 Base = N;
482 if (N.getOpcode() == ISD::FrameIndex) {
483 int FI = cast<FrameIndexSDNode>(N)->getIndex();
484 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000485 } else if (N.getOpcode() == ARMISD::Wrapper &&
486 !(Subtarget->useMovt() &&
487 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000488 Base = N.getOperand(0);
489 }
490 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000491 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000492 return true;
493 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000494
Evan Chenga8e29892007-01-19 07:51:42 +0000495 // If the RHS is +/- imm8, fold into addr mode.
496 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000497 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000498 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
499 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000500 if ((RHSC >= 0 && RHSC < 256) ||
501 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000502 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000503 if (Base.getOpcode() == ISD::FrameIndex) {
504 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
505 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
506 }
507
508 ARM_AM::AddrOpc AddSub = ARM_AM::add;
509 if (RHSC < 0) {
510 AddSub = ARM_AM::sub;
511 RHSC = - RHSC;
512 }
513 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000514 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000515 return true;
516 }
517 }
518 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000519
Evan Chenga8e29892007-01-19 07:51:42 +0000520 Base = N;
521 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000522 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000523 return true;
524}
525
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000526bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000527 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000528 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000529 // Default to no alignment.
530 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000531 return true;
532}
533
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000534bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000535 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000536 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
537 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000538 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000539 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000540 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000541 return true;
542 }
543 return false;
544}
545
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000546bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000547 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000548 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000549 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000550 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000551 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000552 return false;
553
554 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000555 return true;
556 }
557
Evan Chenga8e29892007-01-19 07:51:42 +0000558 Base = N.getOperand(0);
559 Offset = N.getOperand(1);
560 return true;
561}
562
Evan Cheng79d43262007-01-24 02:21:22 +0000563bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000564ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000565 unsigned Scale, SDValue &Base,
566 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000567 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000568 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000569 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
570 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000571 if (N.getOpcode() == ARMISD::Wrapper &&
572 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
573 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000574 }
575
Evan Chenga8e29892007-01-19 07:51:42 +0000576 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000577 if (N.getOpcode() == ARMISD::Wrapper &&
578 !(Subtarget->useMovt() &&
579 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
580 Base = N.getOperand(0);
581 } else
582 Base = N;
583
Owen Anderson825b72b2009-08-11 20:47:22 +0000584 Offset = CurDAG->getRegister(0, MVT::i32);
585 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000586 return true;
587 }
588
Evan Chengad0e4652007-02-06 00:22:06 +0000589 // Thumb does not have [sp, r] address mode.
590 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
591 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
592 if ((LHSR && LHSR->getReg() == ARM::SP) ||
593 (RHSR && RHSR->getReg() == ARM::SP)) {
594 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000595 Offset = CurDAG->getRegister(0, MVT::i32);
596 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000597 return true;
598 }
599
Evan Chenga8e29892007-01-19 07:51:42 +0000600 // If the RHS is + imm5 * scale, fold into addr mode.
601 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000602 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000603 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
604 RHSC /= Scale;
605 if (RHSC >= 0 && RHSC < 32) {
606 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000607 Offset = CurDAG->getRegister(0, MVT::i32);
608 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000609 return true;
610 }
611 }
612 }
613
Evan Chengc38f2bc2007-01-23 22:59:13 +0000614 Base = N.getOperand(0);
615 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000617 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000618}
619
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000620bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue &Base, SDValue &OffImm,
622 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000623 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000624}
625
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000626bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000627 SDValue &Base, SDValue &OffImm,
628 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000629 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000630}
631
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000632bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000633 SDValue &Base, SDValue &OffImm,
634 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000635 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000636}
637
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000638bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000639 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000640 if (N.getOpcode() == ISD::FrameIndex) {
641 int FI = cast<FrameIndexSDNode>(N)->getIndex();
642 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000643 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000644 return true;
645 }
Evan Cheng79d43262007-01-24 02:21:22 +0000646
Evan Chengad0e4652007-02-06 00:22:06 +0000647 if (N.getOpcode() != ISD::ADD)
648 return false;
649
650 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000651 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
652 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000653 // If the RHS is + imm8 * scale, fold into addr mode.
654 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000655 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000656 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
657 RHSC >>= 2;
658 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000659 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000660 if (Base.getOpcode() == ISD::FrameIndex) {
661 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
662 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
663 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000664 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000665 return true;
666 }
667 }
668 }
669 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000670
Evan Chenga8e29892007-01-19 07:51:42 +0000671 return false;
672}
673
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000674bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000675 SDValue &BaseReg,
676 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000677 if (DisableShifterOp)
678 return false;
679
Evan Cheng9cb9e672009-06-27 02:26:13 +0000680 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
681
682 // Don't match base register only case. That is matched to a separate
683 // lower complexity pattern with explicit register operand.
684 if (ShOpcVal == ARM_AM::no_shift) return false;
685
686 BaseReg = N.getOperand(0);
687 unsigned ShImmVal = 0;
688 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
689 ShImmVal = RHS->getZExtValue() & 31;
690 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
691 return true;
692 }
693
694 return false;
695}
696
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000697bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000698 SDValue &Base, SDValue &OffImm) {
699 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000700
Evan Cheng3a214252009-08-11 08:52:18 +0000701 // Base only.
702 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000703 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000704 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000705 int FI = cast<FrameIndexSDNode>(N)->getIndex();
706 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000707 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000708 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000709 } else if (N.getOpcode() == ARMISD::Wrapper &&
710 !(Subtarget->useMovt() &&
711 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000712 Base = N.getOperand(0);
713 if (Base.getOpcode() == ISD::TargetConstantPool)
714 return false; // We want to select t2LDRpci instead.
715 } else
716 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000717 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000718 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000719 }
Evan Cheng055b0312009-06-29 07:51:04 +0000720
721 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000722 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
723 // Let t2LDRi8 handle (R - imm8).
724 return false;
725
Evan Cheng055b0312009-06-29 07:51:04 +0000726 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000727 if (N.getOpcode() == ISD::SUB)
728 RHSC = -RHSC;
729
730 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000731 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000732 if (Base.getOpcode() == ISD::FrameIndex) {
733 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
734 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
735 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000736 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000737 return true;
738 }
739 }
740
Evan Cheng3a214252009-08-11 08:52:18 +0000741 // Base only.
742 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000743 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000744 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000745}
746
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000747bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000748 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000749 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000750 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000751 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
752 int RHSC = (int)RHS->getSExtValue();
753 if (N.getOpcode() == ISD::SUB)
754 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000755
Evan Cheng3a214252009-08-11 08:52:18 +0000756 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
757 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000758 if (Base.getOpcode() == ISD::FrameIndex) {
759 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
760 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
761 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000762 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000763 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000764 }
Evan Cheng055b0312009-06-29 07:51:04 +0000765 }
766 }
767
768 return false;
769}
770
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000771bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000772 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000773 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000774 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
775 ? cast<LoadSDNode>(Op)->getAddressingMode()
776 : cast<StoreSDNode>(Op)->getAddressingMode();
777 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
778 int RHSC = (int)RHS->getZExtValue();
779 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000780 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000781 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
782 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000783 return true;
784 }
785 }
786
787 return false;
788}
789
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000790bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000791 SDValue &Base, SDValue &OffImm) {
792 if (N.getOpcode() == ISD::ADD) {
793 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
794 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000795 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000796 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000797 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000798 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000799 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000800 return true;
801 }
802 }
803 } else if (N.getOpcode() == ISD::SUB) {
804 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
805 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000806 // 8 bits.
807 if (((RHSC & 0x3) == 0) && (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 }
814
815 return false;
816}
817
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000818bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000819 SDValue &Base,
820 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000821 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
822 if (N.getOpcode() != ISD::ADD)
823 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000824
Evan Cheng3a214252009-08-11 08:52:18 +0000825 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
826 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
827 int RHSC = (int)RHS->getZExtValue();
828 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
829 return false;
830 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000831 return false;
832 }
833
Evan Cheng055b0312009-06-29 07:51:04 +0000834 // Look for (R + R) or (R + (R << [1,2,3])).
835 unsigned ShAmt = 0;
836 Base = N.getOperand(0);
837 OffReg = N.getOperand(1);
838
839 // Swap if it is ((R << c) + R).
840 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
841 if (ShOpcVal != ARM_AM::lsl) {
842 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
843 if (ShOpcVal == ARM_AM::lsl)
844 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000845 }
846
Evan Cheng055b0312009-06-29 07:51:04 +0000847 if (ShOpcVal == ARM_AM::lsl) {
848 // Check to see if the RHS of the shift is a constant, if not, we can't fold
849 // it.
850 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
851 ShAmt = Sh->getZExtValue();
852 if (ShAmt >= 4) {
853 ShAmt = 0;
854 ShOpcVal = ARM_AM::no_shift;
855 } else
856 OffReg = OffReg.getOperand(0);
857 } else {
858 ShOpcVal = ARM_AM::no_shift;
859 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000860 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000861
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000863
864 return true;
865}
866
867//===--------------------------------------------------------------------===//
868
Evan Chengee568cf2007-07-05 07:15:27 +0000869/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000870static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000871 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000872}
873
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000874SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
875 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 ISD::MemIndexedMode AM = LD->getAddressingMode();
877 if (AM == ISD::UNINDEXED)
878 return NULL;
879
Owen Andersone50ed302009-08-10 22:56:29 +0000880 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000881 SDValue Offset, AMOpc;
882 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
883 unsigned Opcode = 0;
884 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000885 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
888 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000889 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000890 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000891 Match = true;
892 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
893 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
894 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000895 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000896 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000897 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000898 Match = true;
899 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
900 }
901 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000902 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000903 Match = true;
904 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
905 }
906 }
907 }
908
909 if (Match) {
910 SDValue Chain = LD->getChain();
911 SDValue Base = LD->getBasePtr();
912 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000913 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000914 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000915 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000916 }
917
918 return NULL;
919}
920
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000921SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
922 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000923 ISD::MemIndexedMode AM = LD->getAddressingMode();
924 if (AM == ISD::UNINDEXED)
925 return NULL;
926
Owen Andersone50ed302009-08-10 22:56:29 +0000927 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000928 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000929 SDValue Offset;
930 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
931 unsigned Opcode = 0;
932 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000933 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000934 switch (LoadedVT.getSimpleVT().SimpleTy) {
935 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000936 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
937 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000938 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000939 if (isSExtLd)
940 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
941 else
942 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000943 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000944 case MVT::i8:
945 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000946 if (isSExtLd)
947 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
948 else
949 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000950 break;
951 default:
952 return NULL;
953 }
954 Match = true;
955 }
956
957 if (Match) {
958 SDValue Chain = LD->getChain();
959 SDValue Base = LD->getBasePtr();
960 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000961 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000962 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000963 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000964 }
965
966 return NULL;
967}
968
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000969/// PairSRegs - Form a D register from a pair of S registers.
970///
971SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
972 DebugLoc dl = V0.getNode()->getDebugLoc();
973 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
974 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000975 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
976 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000977}
978
Evan Cheng603afbf2010-05-10 17:34:18 +0000979/// PairDRegs - Form a quad register from a pair of D registers.
980///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000981SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
982 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000983 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
984 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_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 Wilson3bf12ab2009-10-06 22:01:59 +0000987}
988
Evan Cheng7f687192010-05-14 00:21:45 +0000989/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000990///
991SDNode *ARMDAGToDAGISel::PairQRegs(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::qsub_0, MVT::i32);
994 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000995 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
996 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
997}
998
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000999/// QuadSRegs - Form 4 consecutive S registers.
1000///
1001SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1002 SDValue V2, SDValue V3) {
1003 DebugLoc dl = V0.getNode()->getDebugLoc();
1004 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1005 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1006 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1007 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1008 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1009 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1010}
1011
Evan Cheng7f687192010-05-14 00:21:45 +00001012/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001013///
1014SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1015 SDValue V2, SDValue V3) {
1016 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001017 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1018 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1019 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1020 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001021 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1022 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1023}
1024
Evan Cheng8f6de382010-05-16 03:27:48 +00001025/// QuadQRegs - Form 4 consecutive Q registers.
1026///
1027SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1028 SDValue V2, SDValue V3) {
1029 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001030 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1031 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1032 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1033 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001034 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1035 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1036}
1037
Evan Cheng5c6aba22010-05-14 18:54:59 +00001038/// OctoDRegs - Form 8 consecutive D registers.
1039///
1040SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1041 SDValue V2, SDValue V3,
1042 SDValue V4, SDValue V5,
1043 SDValue V6, SDValue V7) {
1044 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001045 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1046 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1047 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1048 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1049 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1050 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1051 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1052 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001053 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1054 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1055 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1056}
1057
Bob Wilsona7c397c2009-10-14 16:19:03 +00001058/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1059/// for a 64-bit subregister of the vector.
1060static EVT GetNEONSubregVT(EVT VT) {
1061 switch (VT.getSimpleVT().SimpleTy) {
1062 default: llvm_unreachable("unhandled NEON type");
1063 case MVT::v16i8: return MVT::v8i8;
1064 case MVT::v8i16: return MVT::v4i16;
1065 case MVT::v4f32: return MVT::v2f32;
1066 case MVT::v4i32: return MVT::v2i32;
1067 case MVT::v2i64: return MVT::v1i64;
1068 }
1069}
1070
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001071SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001072 unsigned *DOpcodes, unsigned *QOpcodes0,
1073 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001074 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001075 DebugLoc dl = N->getDebugLoc();
1076
Bob Wilson226036e2010-03-20 22:13:40 +00001077 SDValue MemAddr, Align;
1078 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001079 return NULL;
1080
1081 SDValue Chain = N->getOperand(0);
1082 EVT VT = N->getValueType(0);
1083 bool is64BitVector = VT.is64BitVector();
1084
1085 unsigned OpcodeIndex;
1086 switch (VT.getSimpleVT().SimpleTy) {
1087 default: llvm_unreachable("unhandled vld type");
1088 // Double-register operations:
1089 case MVT::v8i8: OpcodeIndex = 0; break;
1090 case MVT::v4i16: OpcodeIndex = 1; break;
1091 case MVT::v2f32:
1092 case MVT::v2i32: OpcodeIndex = 2; break;
1093 case MVT::v1i64: OpcodeIndex = 3; break;
1094 // Quad-register operations:
1095 case MVT::v16i8: OpcodeIndex = 0; break;
1096 case MVT::v8i16: OpcodeIndex = 1; break;
1097 case MVT::v4f32:
1098 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001099 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001100 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001101 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001102 }
1103
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001104 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001105 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001106 if (is64BitVector) {
1107 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001108 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001109 std::vector<EVT> ResTys(NumVecs, VT);
1110 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001111 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson07f6e802010-06-16 21:34:01 +00001112 if (NumVecs < 2)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001113 return VLd;
1114
Evan Cheng0ce537a2010-05-11 01:19:40 +00001115 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001116 SDValue V0 = SDValue(VLd, 0);
1117 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001118
Evan Cheng0ce537a2010-05-11 01:19:40 +00001119 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001120 if (NumVecs == 2)
1121 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1122 else {
1123 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001124 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001125 SDValue V3 = (NumVecs == 3)
1126 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1127 : SDValue(VLd, 3);
1128 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1129 }
1130
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001131 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001132 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001133 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001134 dl, VT, RegSeq);
1135 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001136 }
1137 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1138 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001139 }
1140
1141 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001142 if (NumVecs <= 2) {
1143 // Quad registers are directly supported for VLD1 and VLD2,
1144 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001145 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001146 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001147 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001148 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001149 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001150 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001151
1152 // Combine the even and odd subregs to produce the result.
Bob Wilson07f6e802010-06-16 21:34:01 +00001153 if (NumVecs == 1) {
1154 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1155 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
Evan Cheng603afbf2010-05-10 17:34:18 +00001156 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001157 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1158 SDValue(VLd, 0), SDValue(VLd, 1),
1159 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1160 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1161 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
1162 ReplaceUses(SDValue(N, 0), Q0);
1163 ReplaceUses(SDValue(N, 1), Q1);
Bob Wilson3e36f132009-10-14 17:28:52 +00001164 }
1165 } else {
1166 // Otherwise, quad registers are loaded with two separate instructions,
1167 // where one loads the even registers and the other loads the odd registers.
1168
Bob Wilson3e36f132009-10-14 17:28:52 +00001169 std::vector<EVT> ResTys(NumVecs, RegVT);
1170 ResTys.push_back(MemAddr.getValueType());
1171 ResTys.push_back(MVT::Other);
1172
Bob Wilson24f995d2009-10-14 18:32:29 +00001173 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001174 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001175 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1176 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001177 Chain = SDValue(VLdA, NumVecs+1);
1178
Bob Wilson24f995d2009-10-14 18:32:29 +00001179 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001180 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001181 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1182 Align, Reg0, Pred, Reg0, Chain };
1183 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001184 Chain = SDValue(VLdB, NumVecs+1);
1185
Bob Wilson07f6e802010-06-16 21:34:01 +00001186 SDValue V0 = SDValue(VLdA, 0);
1187 SDValue V1 = SDValue(VLdB, 0);
1188 SDValue V2 = SDValue(VLdA, 1);
1189 SDValue V3 = SDValue(VLdB, 1);
1190 SDValue V4 = SDValue(VLdA, 2);
1191 SDValue V5 = SDValue(VLdB, 2);
1192 SDValue V6 = (NumVecs == 3)
1193 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1194 : SDValue(VLdA, 3);
1195 SDValue V7 = (NumVecs == 3)
1196 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1197 : SDValue(VLdB, 3);
1198 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1199 V4, V5, V6, V7), 0);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001200
Bob Wilson07f6e802010-06-16 21:34:01 +00001201 // Extract out the 3 / 4 Q registers.
1202 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1203 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1204 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1205 dl, VT, RegSeq);
1206 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001207 }
1208 }
1209 ReplaceUses(SDValue(N, NumVecs), Chain);
1210 return NULL;
1211}
1212
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001213SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001214 unsigned *DOpcodes, unsigned *QOpcodes0,
1215 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001216 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001217 DebugLoc dl = N->getDebugLoc();
1218
Bob Wilson226036e2010-03-20 22:13:40 +00001219 SDValue MemAddr, Align;
1220 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001221 return NULL;
1222
1223 SDValue Chain = N->getOperand(0);
1224 EVT VT = N->getOperand(3).getValueType();
1225 bool is64BitVector = VT.is64BitVector();
1226
1227 unsigned OpcodeIndex;
1228 switch (VT.getSimpleVT().SimpleTy) {
1229 default: llvm_unreachable("unhandled vst type");
1230 // Double-register operations:
1231 case MVT::v8i8: OpcodeIndex = 0; break;
1232 case MVT::v4i16: OpcodeIndex = 1; break;
1233 case MVT::v2f32:
1234 case MVT::v2i32: OpcodeIndex = 2; break;
1235 case MVT::v1i64: OpcodeIndex = 3; break;
1236 // Quad-register operations:
1237 case MVT::v16i8: OpcodeIndex = 0; break;
1238 case MVT::v8i16: OpcodeIndex = 1; break;
1239 case MVT::v4f32:
1240 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001241 case MVT::v2i64: OpcodeIndex = 3;
1242 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1243 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001244 }
1245
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001246 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001247 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001248
Bob Wilson226036e2010-03-20 22:13:40 +00001249 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001250 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001251 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001252
1253 if (is64BitVector) {
Bob Wilson07f6e802010-06-16 21:34:01 +00001254 if (NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001255 SDValue RegSeq;
1256 SDValue V0 = N->getOperand(0+3);
1257 SDValue V1 = N->getOperand(1+3);
1258
1259 // Form a REG_SEQUENCE to force register allocation.
1260 if (NumVecs == 2)
1261 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1262 else {
1263 SDValue V2 = N->getOperand(2+3);
1264 // If it's a vld3, form a quad D-register and leave the last part as
1265 // an undef.
1266 SDValue V3 = (NumVecs == 3)
1267 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1268 : N->getOperand(3+3);
1269 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1270 }
1271
1272 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001273 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001274 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001275 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001276 RegSeq));
1277 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001278 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001279 RegSeq));
1280 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001281 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001282 RegSeq));
1283 } else {
1284 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1285 Ops.push_back(N->getOperand(Vec+3));
1286 }
Evan Chengac0869d2009-11-21 06:21:52 +00001287 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001288 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001289 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001290 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001291 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001292 }
1293
1294 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001295 if (NumVecs <= 2) {
1296 // Quad registers are directly supported for VST1 and VST2,
1297 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001298 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001299 if (NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001300 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001301 SDValue Q0 = N->getOperand(3);
1302 SDValue Q1 = N->getOperand(4);
1303
1304 // Form a QQ register.
1305 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1306
1307 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001308 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001309 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001310 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001311 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001312 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001313 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001314 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001315 QQ));
1316 Ops.push_back(Pred);
1317 Ops.push_back(Reg0); // predicate register
1318 Ops.push_back(Chain);
1319 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1320 } else {
1321 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001322 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001323 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001324 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001325 N->getOperand(Vec+3)));
1326 }
1327 Ops.push_back(Pred);
1328 Ops.push_back(Reg0); // predicate register
1329 Ops.push_back(Chain);
1330 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1331 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001332 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001333 }
1334
1335 // Otherwise, quad registers are stored with two separate instructions,
1336 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001337
Bob Wilson07f6e802010-06-16 21:34:01 +00001338 // Form the QQQQ REG_SEQUENCE.
1339 SDValue V[8];
1340 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1341 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1342 N->getOperand(Vec+3));
1343 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1344 N->getOperand(Vec+3));
Evan Cheng12c24692010-05-14 22:54:52 +00001345 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001346 if (NumVecs == 3)
1347 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1348 dl, RegVT), 0);
1349
1350 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1351 V[4], V[5], V[6], V[7]), 0);
1352
1353 // Store the even D registers.
1354 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1355 Ops.push_back(Reg0); // post-access address offset
1356 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1357 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1358 RegVT, RegSeq));
1359 Ops.push_back(Pred);
1360 Ops.push_back(Reg0); // predicate register
1361 Ops.push_back(Chain);
1362 unsigned Opc = QOpcodes0[OpcodeIndex];
1363 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1364 MVT::Other, Ops.data(), NumVecs+6);
1365 Chain = SDValue(VStA, 1);
1366
1367 // Store the odd D registers.
1368 Ops[0] = SDValue(VStA, 0); // MemAddr
1369 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1370 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1371 RegVT, RegSeq);
1372 Ops[NumVecs+5] = Chain;
1373 Opc = QOpcodes1[OpcodeIndex];
1374 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1375 MVT::Other, Ops.data(), NumVecs+6);
1376 Chain = SDValue(VStB, 1);
1377 ReplaceUses(SDValue(N, 0), Chain);
1378 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001379}
1380
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001381SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001382 unsigned NumVecs, unsigned *DOpcodes,
1383 unsigned *QOpcodes0,
1384 unsigned *QOpcodes1) {
1385 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001386 DebugLoc dl = N->getDebugLoc();
1387
Bob Wilson226036e2010-03-20 22:13:40 +00001388 SDValue MemAddr, Align;
1389 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001390 return NULL;
1391
1392 SDValue Chain = N->getOperand(0);
1393 unsigned Lane =
1394 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001395 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001396 bool is64BitVector = VT.is64BitVector();
1397
Bob Wilson96493442009-10-14 16:46:45 +00001398 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001399 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001400 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001401 EVT RegVT = VT;
1402 if (!is64BitVector) {
1403 RegVT = GetNEONSubregVT(VT);
1404 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001405 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001406 }
1407
1408 unsigned OpcodeIndex;
1409 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001410 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001411 // Double-register operations:
1412 case MVT::v8i8: OpcodeIndex = 0; break;
1413 case MVT::v4i16: OpcodeIndex = 1; break;
1414 case MVT::v2f32:
1415 case MVT::v2i32: OpcodeIndex = 2; break;
1416 // Quad-register operations:
1417 case MVT::v8i16: OpcodeIndex = 0; break;
1418 case MVT::v4f32:
1419 case MVT::v4i32: OpcodeIndex = 1; break;
1420 }
1421
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001422 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001423 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001424
Bob Wilson226036e2010-03-20 22:13:40 +00001425 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001426 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001427 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001428
1429 unsigned Opc = 0;
1430 if (is64BitVector) {
1431 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001432 SDValue RegSeq;
1433 SDValue V0 = N->getOperand(0+3);
1434 SDValue V1 = N->getOperand(1+3);
1435 if (NumVecs == 2) {
1436 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001437 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001438 SDValue V2 = N->getOperand(2+3);
1439 SDValue V3 = (NumVecs == 3)
1440 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1441 : N->getOperand(3+3);
1442 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001443 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001444
1445 // Now extract the D registers back out.
1446 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1447 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1448 if (NumVecs > 2)
1449 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1450 if (NumVecs > 3)
1451 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001452 } else {
1453 // Check if this is loading the even or odd subreg of a Q register.
1454 if (Lane < NumElts) {
1455 Opc = QOpcodes0[OpcodeIndex];
1456 } else {
1457 Lane -= NumElts;
1458 Opc = QOpcodes1[OpcodeIndex];
1459 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001460
Bob Wilson07f6e802010-06-16 21:34:01 +00001461 SDValue RegSeq;
1462 SDValue V0 = N->getOperand(0+3);
1463 SDValue V1 = N->getOperand(1+3);
1464 if (NumVecs == 2) {
1465 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001466 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001467 SDValue V2 = N->getOperand(2+3);
1468 SDValue V3 = (NumVecs == 3)
1469 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1470 : N->getOperand(3+3);
1471 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001472 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001473
1474 // Extract the subregs of the input vector.
1475 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1476 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1477 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1478 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001479 }
1480 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001481 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001482 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001483 Ops.push_back(Chain);
1484
Bob Wilson96493442009-10-14 16:46:45 +00001485 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001486 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001487
Bob Wilsona7c397c2009-10-14 16:19:03 +00001488 std::vector<EVT> ResTys(NumVecs, RegVT);
1489 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001490 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1491
Bob Wilson07f6e802010-06-16 21:34:01 +00001492 // Form a REG_SEQUENCE to force register allocation.
1493 SDValue RegSeq;
1494 if (is64BitVector) {
1495 SDValue V0 = SDValue(VLdLn, 0);
1496 SDValue V1 = SDValue(VLdLn, 1);
1497 if (NumVecs == 2) {
1498 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001499 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001500 SDValue V2 = SDValue(VLdLn, 2);
1501 // If it's a vld3, form a quad D-register but discard the last part.
1502 SDValue V3 = (NumVecs == 3)
1503 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1504 : SDValue(VLdLn, 3);
1505 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001506 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001507 } else {
1508 // For 128-bit vectors, take the 64-bit results of the load and insert
1509 // them as subregs into the result.
1510 SDValue V[8];
1511 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1512 if (Even) {
1513 V[i] = SDValue(VLdLn, Vec);
1514 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1515 dl, RegVT), 0);
1516 } else {
1517 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1518 dl, RegVT), 0);
1519 V[i+1] = SDValue(VLdLn, Vec);
1520 }
1521 }
1522 if (NumVecs == 3)
1523 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1524 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001525
Bob Wilson07f6e802010-06-16 21:34:01 +00001526 if (NumVecs == 2)
1527 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1528 else
1529 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1530 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001531 }
1532
Bob Wilson07f6e802010-06-16 21:34:01 +00001533 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1534 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1535 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1536 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1537 ReplaceUses(SDValue(N, Vec),
1538 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1539 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001540 return NULL;
1541}
1542
Bob Wilson78dfbc32010-07-07 00:08:54 +00001543SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1544 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001545 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1546 DebugLoc dl = N->getDebugLoc();
1547 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001548 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001549
1550 // Form a REG_SEQUENCE to force register allocation.
1551 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001552 SDValue V0 = N->getOperand(FirstTblReg + 0);
1553 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001554 if (NumVecs == 2)
1555 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1556 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001557 SDValue V2 = N->getOperand(FirstTblReg + 2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001558 // If it's a vtbl3, form a quad D-register and leave the last part as
1559 // an undef.
1560 SDValue V3 = (NumVecs == 3)
1561 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001562 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001563 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1564 }
1565
1566 // Now extract the D registers back out.
Bob Wilson78dfbc32010-07-07 00:08:54 +00001567 SmallVector<SDValue, 6> Ops;
1568 if (IsExt)
1569 Ops.push_back(N->getOperand(1));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001570 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1571 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1572 if (NumVecs > 2)
1573 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1574 if (NumVecs > 3)
1575 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1576
Bob Wilson78dfbc32010-07-07 00:08:54 +00001577 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001578 Ops.push_back(getAL(CurDAG)); // predicate
1579 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001580 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001581}
1582
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001583SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001584 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001585 if (!Subtarget->hasV6T2Ops())
1586 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001587
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001588 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1589 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1590
1591
1592 // For unsigned extracts, check for a shift right and mask
1593 unsigned And_imm = 0;
1594 if (N->getOpcode() == ISD::AND) {
1595 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1596
1597 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1598 if (And_imm & (And_imm + 1))
1599 return NULL;
1600
1601 unsigned Srl_imm = 0;
1602 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1603 Srl_imm)) {
1604 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1605
1606 unsigned Width = CountTrailingOnes_32(And_imm);
1607 unsigned LSB = Srl_imm;
1608 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1609 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1610 CurDAG->getTargetConstant(LSB, MVT::i32),
1611 CurDAG->getTargetConstant(Width, MVT::i32),
1612 getAL(CurDAG), Reg0 };
1613 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1614 }
1615 }
1616 return NULL;
1617 }
1618
1619 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001620 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001621 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001622 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1623 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001624 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001625 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1626 unsigned Width = 32 - Srl_imm;
1627 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001628 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001629 return NULL;
1630 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001631 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001632 CurDAG->getTargetConstant(LSB, MVT::i32),
1633 CurDAG->getTargetConstant(Width, MVT::i32),
1634 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001635 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001636 }
1637 }
1638 return NULL;
1639}
1640
Evan Cheng9ef48352009-11-20 00:54:03 +00001641SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001642SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001643 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1644 SDValue CPTmp0;
1645 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001646 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001647 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1648 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1649 unsigned Opc = 0;
1650 switch (SOShOp) {
1651 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1652 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1653 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1654 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1655 default:
1656 llvm_unreachable("Unknown so_reg opcode!");
1657 break;
1658 }
1659 SDValue SOShImm =
1660 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1661 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1662 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001663 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001664 }
1665 return 0;
1666}
1667
1668SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001669SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001670 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1671 SDValue CPTmp0;
1672 SDValue CPTmp1;
1673 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001674 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001675 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1676 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001677 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001678 }
1679 return 0;
1680}
1681
1682SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001683SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001684 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1685 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1686 if (!T)
1687 return 0;
1688
1689 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1690 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1691 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1692 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001693 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001694 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1695 }
1696 return 0;
1697}
1698
1699SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001700SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001701 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1702 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1703 if (!T)
1704 return 0;
1705
1706 if (Predicate_so_imm(TrueVal.getNode())) {
1707 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1708 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1709 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001710 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001711 ARM::MOVCCi, MVT::i32, Ops, 5);
1712 }
1713 return 0;
1714}
1715
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001716SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1717 EVT VT = N->getValueType(0);
1718 SDValue FalseVal = N->getOperand(0);
1719 SDValue TrueVal = N->getOperand(1);
1720 SDValue CC = N->getOperand(2);
1721 SDValue CCR = N->getOperand(3);
1722 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001723 assert(CC.getOpcode() == ISD::Constant);
1724 assert(CCR.getOpcode() == ISD::Register);
1725 ARMCC::CondCodes CCVal =
1726 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001727
1728 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1729 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1730 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1731 // Pattern complexity = 18 cost = 1 size = 0
1732 SDValue CPTmp0;
1733 SDValue CPTmp1;
1734 SDValue CPTmp2;
1735 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001736 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001737 CCVal, CCR, InFlag);
1738 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001739 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001740 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1741 if (Res)
1742 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001743 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001744 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001745 CCVal, CCR, InFlag);
1746 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001747 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001748 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1749 if (Res)
1750 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001751 }
1752
1753 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1754 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1755 // (imm:i32):$cc)
1756 // Emits: (MOVCCi:i32 GPR:i32:$false,
1757 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1758 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001759 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001761 CCVal, CCR, InFlag);
1762 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001763 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001764 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1765 if (Res)
1766 return Res;
1767 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001768 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001769 CCVal, CCR, InFlag);
1770 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001771 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001772 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1773 if (Res)
1774 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001775 }
1776 }
1777
1778 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1779 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1780 // Pattern complexity = 6 cost = 1 size = 0
1781 //
1782 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1783 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1784 // Pattern complexity = 6 cost = 11 size = 0
1785 //
1786 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001787 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1788 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001789 unsigned Opc = 0;
1790 switch (VT.getSimpleVT().SimpleTy) {
1791 default: assert(false && "Illegal conditional move type!");
1792 break;
1793 case MVT::i32:
1794 Opc = Subtarget->isThumb()
1795 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1796 : ARM::MOVCCr;
1797 break;
1798 case MVT::f32:
1799 Opc = ARM::VMOVScc;
1800 break;
1801 case MVT::f64:
1802 Opc = ARM::VMOVDcc;
1803 break;
1804 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001805 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001806}
1807
Evan Chengde8aa4e2010-05-05 18:28:36 +00001808SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1809 // The only time a CONCAT_VECTORS operation can have legal types is when
1810 // two 64-bit vectors are concatenated to a 128-bit vector.
1811 EVT VT = N->getValueType(0);
1812 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1813 llvm_unreachable("unexpected CONCAT_VECTORS");
1814 DebugLoc dl = N->getDebugLoc();
1815 SDValue V0 = N->getOperand(0);
1816 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001817 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1818 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001819 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1820 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1821}
1822
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001823SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001824 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001825
Dan Gohmane8be6c62008-07-17 19:10:17 +00001826 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001827 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001828
1829 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001830 default: break;
1831 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001832 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001833 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001834 if (Subtarget->hasThumb2())
1835 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1836 // be done with MOV + MOVT, at worst.
1837 UseCP = 0;
1838 else {
1839 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001840 UseCP = (Val > 255 && // MOV
1841 ~Val > 255 && // MOV + MVN
1842 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001843 } else
1844 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1845 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1846 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1847 }
1848
Evan Chenga8e29892007-01-19 07:51:42 +00001849 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001850 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001851 CurDAG->getTargetConstantPool(ConstantInt::get(
1852 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001853 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001854
1855 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001856 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001857 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001858 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001859 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001860 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1861 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001862 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001863 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001864 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001865 CurDAG->getRegister(0, MVT::i32),
1866 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001867 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001868 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001869 CurDAG->getEntryNode()
1870 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001871 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1872 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001873 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001874 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001875 return NULL;
1876 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001877
Evan Chenga8e29892007-01-19 07:51:42 +00001878 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001879 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001880 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001881 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001882 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001883 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001884 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001885 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001886 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1887 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001888 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001889 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1890 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001891 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1892 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1893 CurDAG->getRegister(0, MVT::i32) };
1894 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001895 }
Evan Chenga8e29892007-01-19 07:51:42 +00001896 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001897 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001898 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001899 return I;
1900 break;
1901 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001902 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001903 return I;
1904 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001905 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001906 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001907 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001908 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001909 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001910 if (!RHSV) break;
1911 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001912 unsigned ShImm = Log2_32(RHSV-1);
1913 if (ShImm >= 32)
1914 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001915 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001916 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001917 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1918 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001919 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001920 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001921 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001922 } else {
1923 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001924 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001925 }
Evan Chenga8e29892007-01-19 07:51:42 +00001926 }
1927 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001928 unsigned ShImm = Log2_32(RHSV+1);
1929 if (ShImm >= 32)
1930 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001931 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001932 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001933 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1934 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001935 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001936 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1937 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001938 } else {
1939 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001940 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001941 }
Evan Chenga8e29892007-01-19 07:51:42 +00001942 }
1943 }
1944 break;
Evan Cheng20956592009-10-21 08:15:52 +00001945 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001946 // Check for unsigned bitfield extract
1947 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1948 return I;
1949
Evan Cheng20956592009-10-21 08:15:52 +00001950 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1951 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1952 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1953 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1954 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001955 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001956 if (VT != MVT::i32)
1957 break;
1958 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1959 ? ARM::t2MOVTi16
1960 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1961 if (!Opc)
1962 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001963 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001964 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1965 if (!N1C)
1966 break;
1967 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1968 SDValue N2 = N0.getOperand(1);
1969 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1970 if (!N2C)
1971 break;
1972 unsigned N1CVal = N1C->getZExtValue();
1973 unsigned N2CVal = N2C->getZExtValue();
1974 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1975 (N1CVal & 0xffffU) == 0xffffU &&
1976 (N2CVal & 0xffffU) == 0x0U) {
1977 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1978 MVT::i32);
1979 SDValue Ops[] = { N0.getOperand(0), Imm16,
1980 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1981 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1982 }
1983 }
1984 break;
1985 }
Jim Grosbache5165492009-11-09 00:11:35 +00001986 case ARMISD::VMOVRRD:
1987 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001988 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001989 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001990 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001991 if (Subtarget->isThumb1Only())
1992 break;
1993 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001994 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001995 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1996 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001997 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001998 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001999 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002000 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2001 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002002 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002003 }
Evan Chengee568cf2007-07-05 07:15:27 +00002004 }
Dan Gohman525178c2007-10-08 18:33:35 +00002005 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002006 if (Subtarget->isThumb1Only())
2007 break;
2008 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002010 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002011 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002012 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002013 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002014 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2015 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002016 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002017 }
Evan Chengee568cf2007-07-05 07:15:27 +00002018 }
Evan Chenga8e29892007-01-19 07:51:42 +00002019 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002020 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002021 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002022 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002023 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002025 if (ResNode)
2026 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002027
2028 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2029 if (Subtarget->hasVFP2() &&
2030 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2031 SDValue Chain = N->getOperand(0);
2032 SDValue AM5Opc =
2033 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002034 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002035 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2036 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002037 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2038 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2039 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2040 MVT::v2f64, MVT::Other, Ops, 5);
2041 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2042 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002043 }
2044 // Other cases are autogenerated.
2045 break;
2046 }
2047 case ISD::STORE: {
2048 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2049 if (Subtarget->hasVFP2() &&
2050 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2051 SDValue Chain = N->getOperand(0);
2052 SDValue AM5Opc =
2053 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002054 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002055 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2056 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2057 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002058 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2059 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2060 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2061 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2062 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002063 }
Evan Chenga8e29892007-01-19 07:51:42 +00002064 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002065 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002066 }
Evan Chengee568cf2007-07-05 07:15:27 +00002067 case ARMISD::BRCOND: {
2068 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2069 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2070 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002071
Evan Chengee568cf2007-07-05 07:15:27 +00002072 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2073 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2074 // Pattern complexity = 6 cost = 1 size = 0
2075
David Goodwin5e47a9a2009-06-30 18:04:13 +00002076 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2077 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2078 // Pattern complexity = 6 cost = 1 size = 0
2079
Jim Grosbach764ab522009-08-11 15:33:49 +00002080 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002081 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002082 SDValue Chain = N->getOperand(0);
2083 SDValue N1 = N->getOperand(1);
2084 SDValue N2 = N->getOperand(2);
2085 SDValue N3 = N->getOperand(3);
2086 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002087 assert(N1.getOpcode() == ISD::BasicBlock);
2088 assert(N2.getOpcode() == ISD::Constant);
2089 assert(N3.getOpcode() == ISD::Register);
2090
Dan Gohman475871a2008-07-27 21:46:04 +00002091 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002092 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002093 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002094 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002095 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2096 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002097 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002098 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002099 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002100 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002101 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002102 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002103 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002104 return NULL;
2105 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002106 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002107 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002108 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002109 EVT VT = N->getValueType(0);
2110 SDValue N0 = N->getOperand(0);
2111 SDValue N1 = N->getOperand(1);
2112 SDValue N2 = N->getOperand(2);
2113 SDValue N3 = N->getOperand(3);
2114 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002115 assert(N2.getOpcode() == ISD::Constant);
2116 assert(N3.getOpcode() == ISD::Register);
2117
Dan Gohman475871a2008-07-27 21:46:04 +00002118 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002119 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002120 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002121 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002122 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002123 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002124 default: assert(false && "Illegal conditional move type!");
2125 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002126 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002127 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002128 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002129 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002130 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002131 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002132 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002133 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002134 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002135
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002136 case ARMISD::VZIP: {
2137 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002138 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002139 switch (VT.getSimpleVT().SimpleTy) {
2140 default: return NULL;
2141 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2142 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2143 case MVT::v2f32:
2144 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2145 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2146 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2147 case MVT::v4f32:
2148 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2149 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002150 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002151 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2152 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2153 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002154 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002155 case ARMISD::VUZP: {
2156 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002157 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002158 switch (VT.getSimpleVT().SimpleTy) {
2159 default: return NULL;
2160 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2161 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2162 case MVT::v2f32:
2163 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2164 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2165 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2166 case MVT::v4f32:
2167 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2168 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002169 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002170 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2171 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2172 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002173 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002174 case ARMISD::VTRN: {
2175 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002176 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002177 switch (VT.getSimpleVT().SimpleTy) {
2178 default: return NULL;
2179 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2180 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2181 case MVT::v2f32:
2182 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2183 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2184 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2185 case MVT::v4f32:
2186 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2187 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002188 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002189 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2190 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2191 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002192 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002193 case ARMISD::BUILD_VECTOR: {
2194 EVT VecVT = N->getValueType(0);
2195 EVT EltVT = VecVT.getVectorElementType();
2196 unsigned NumElts = VecVT.getVectorNumElements();
2197 if (EltVT.getSimpleVT() == MVT::f64) {
2198 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2199 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2200 }
2201 assert(EltVT.getSimpleVT() == MVT::f32 &&
2202 "unexpected type for BUILD_VECTOR");
2203 if (NumElts == 2)
2204 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2205 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2206 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2207 N->getOperand(2), N->getOperand(3));
2208 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002209
2210 case ISD::INTRINSIC_VOID:
2211 case ISD::INTRINSIC_W_CHAIN: {
2212 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002213 switch (IntNo) {
2214 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002215 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002216
Bob Wilson621f1952010-03-23 05:25:43 +00002217 case Intrinsic::arm_neon_vld1: {
2218 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2219 ARM::VLD1d32, ARM::VLD1d64 };
2220 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2221 ARM::VLD1q32, ARM::VLD1q64 };
2222 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2223 }
2224
Bob Wilson31fb12f2009-08-26 17:39:53 +00002225 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002226 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002227 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002228 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002229 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002230 }
2231
2232 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002233 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002234 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002235 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2236 ARM::VLD3q16_UPD,
2237 ARM::VLD3q32_UPD };
2238 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2239 ARM::VLD3q16odd_UPD,
2240 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002241 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002242 }
2243
2244 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002245 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002246 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002247 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2248 ARM::VLD4q16_UPD,
2249 ARM::VLD4q32_UPD };
2250 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2251 ARM::VLD4q16odd_UPD,
2252 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002253 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002254 }
2255
Bob Wilson243fcc52009-09-01 04:26:28 +00002256 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002257 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002258 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2259 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002260 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002261 }
2262
2263 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002264 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002265 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2266 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002267 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002268 }
2269
2270 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002271 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002272 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2273 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002274 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002275 }
2276
Bob Wilson11d98992010-03-23 06:20:33 +00002277 case Intrinsic::arm_neon_vst1: {
2278 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2279 ARM::VST1d32, ARM::VST1d64 };
2280 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2281 ARM::VST1q32, ARM::VST1q64 };
2282 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2283 }
2284
Bob Wilson31fb12f2009-08-26 17:39:53 +00002285 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002286 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002287 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002288 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002289 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002290 }
2291
2292 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002293 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002294 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002295 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2296 ARM::VST3q16_UPD,
2297 ARM::VST3q32_UPD };
2298 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2299 ARM::VST3q16odd_UPD,
2300 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002302 }
2303
2304 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002305 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002306 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002307 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2308 ARM::VST4q16_UPD,
2309 ARM::VST4q32_UPD };
2310 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2311 ARM::VST4q16odd_UPD,
2312 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002313 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002314 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002315
2316 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002317 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002318 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2319 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002320 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002321 }
2322
2323 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002324 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002325 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2326 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002327 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002328 }
2329
2330 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002331 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002332 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2333 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002334 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002335 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002336 }
Bob Wilson429009b2010-05-06 16:05:26 +00002337 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002338 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002339
Bob Wilsond491d6e2010-07-06 23:36:25 +00002340 case ISD::INTRINSIC_WO_CHAIN: {
2341 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2342 switch (IntNo) {
2343 default:
2344 break;
2345
2346 case Intrinsic::arm_neon_vtbl2:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002347 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002348 case Intrinsic::arm_neon_vtbl3:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002349 return SelectVTBL(N, false, 3, ARM::VTBL3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002350 case Intrinsic::arm_neon_vtbl4:
Bob Wilson78dfbc32010-07-07 00:08:54 +00002351 return SelectVTBL(N, false, 4, ARM::VTBL4);
2352
2353 case Intrinsic::arm_neon_vtbx2:
2354 return SelectVTBL(N, true, 2, ARM::VTBX2);
2355 case Intrinsic::arm_neon_vtbx3:
2356 return SelectVTBL(N, true, 3, ARM::VTBX3);
2357 case Intrinsic::arm_neon_vtbx4:
2358 return SelectVTBL(N, true, 4, ARM::VTBX4);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002359 }
2360 break;
2361 }
2362
Bob Wilson429009b2010-05-06 16:05:26 +00002363 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002364 return SelectConcatVector(N);
2365 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002366
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002367 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002368}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002369
Bob Wilson224c2442009-05-19 05:53:42 +00002370bool ARMDAGToDAGISel::
2371SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2372 std::vector<SDValue> &OutOps) {
2373 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002374 // Require the address to be in a register. That is safe for all ARM
2375 // variants and it is hard to do anything much smarter without knowing
2376 // how the operand is used.
2377 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002378 return false;
2379}
2380
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002381/// createARMISelDag - This pass converts a legalized DAG into a
2382/// ARM-specific DAG, ready for instruction scheduling.
2383///
Bob Wilson522ce972009-09-28 14:30:20 +00002384FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2385 CodeGenOpt::Level OptLevel) {
2386 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002387}