blob: 8659d85924d1f90a75e50debf7407e94846e1828 [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 Cheng94cc6d32010-05-04 20:39:49 +000039static cl::opt<bool>
40UseRegSeq("neon-reg-sequence", cl::Hidden,
Evan Cheng62061242010-05-17 19:51:20 +000041 cl::desc("Use reg_sequence to model ld / st of multiple neon regs"),
42 cl::init(true));
Evan Cheng94cc6d32010-05-04 20:39:49 +000043
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
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000151 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000152 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000153
Evan Cheng07ba9062009-11-19 21:45:22 +0000154 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 SDNode *SelectCMOVOp(SDNode *N);
156 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000157 ARMCC::CondCodes CCVal, SDValue CCR,
158 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000159 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000160 ARMCC::CondCodes CCVal, SDValue CCR,
161 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000163 ARMCC::CondCodes CCVal, SDValue CCR,
164 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000165 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000166 ARMCC::CondCodes CCVal, SDValue CCR,
167 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000168
Evan Chengde8aa4e2010-05-05 18:28:36 +0000169 SDNode *SelectConcatVector(SDNode *N);
170
Evan Chengaf4550f2009-07-02 01:23:32 +0000171 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
172 /// inline asm expressions.
173 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
174 char ConstraintCode,
175 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000176
Evan Cheng603afbf2010-05-10 17:34:18 +0000177 /// PairDRegs - Form a quad register from a pair of D registers.
178 ///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000179 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000180
181 /// PairDRegs - Form a quad register pair from a pair of Q registers.
182 ///
183 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
184
185 /// QuadDRegs - Form a quad register pair from a quad of D registers.
186 ///
187 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng5c6aba22010-05-14 18:54:59 +0000188
Evan Cheng8f6de382010-05-16 03:27:48 +0000189 /// QuadQRegs - Form 4 consecutive Q registers.
190 ///
191 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
192
Evan Cheng5c6aba22010-05-14 18:54:59 +0000193 /// OctoDRegs - Form 8 consecutive D registers.
194 ///
195 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
196 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000197};
Evan Chenga8e29892007-01-19 07:51:42 +0000198}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000199
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000200/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
201/// operand. If so Imm will receive the 32-bit value.
202static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
203 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
204 Imm = cast<ConstantSDNode>(N)->getZExtValue();
205 return true;
206 }
207 return false;
208}
209
210// isInt32Immediate - This method tests to see if a constant operand.
211// If so Imm will receive the 32 bit value.
212static bool isInt32Immediate(SDValue N, unsigned &Imm) {
213 return isInt32Immediate(N.getNode(), Imm);
214}
215
216// isOpcWithIntImmediate - This method tests to see if the node is a specific
217// opcode and that it has a immediate integer right operand.
218// If so Imm will receive the 32 bit value.
219static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
220 return N->getOpcode() == Opc &&
221 isInt32Immediate(N->getOperand(1).getNode(), Imm);
222}
223
224
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000225bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000226 SDValue N,
227 SDValue &BaseReg,
228 SDValue &ShReg,
229 SDValue &Opc) {
230 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
231
232 // Don't match base register only case. That is matched to a separate
233 // lower complexity pattern with explicit register operand.
234 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000235
Evan Cheng055b0312009-06-29 07:51:04 +0000236 BaseReg = N.getOperand(0);
237 unsigned ShImmVal = 0;
238 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000239 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000240 ShImmVal = RHS->getZExtValue() & 31;
241 } else {
242 ShReg = N.getOperand(1);
243 }
244 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000245 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000246 return true;
247}
248
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000249bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000250 SDValue &Base, SDValue &Offset,
251 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000252 if (N.getOpcode() == ISD::MUL) {
253 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
254 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000255 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000256 if (RHSC & 1) {
257 RHSC = RHSC & ~1;
258 ARM_AM::AddrOpc AddSub = ARM_AM::add;
259 if (RHSC < 0) {
260 AddSub = ARM_AM::sub;
261 RHSC = - RHSC;
262 }
263 if (isPowerOf2_32(RHSC)) {
264 unsigned ShAmt = Log2_32(RHSC);
265 Base = Offset = N.getOperand(0);
266 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
267 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000268 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000269 return true;
270 }
271 }
272 }
273 }
274
Evan Chenga8e29892007-01-19 07:51:42 +0000275 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
276 Base = N;
277 if (N.getOpcode() == ISD::FrameIndex) {
278 int FI = cast<FrameIndexSDNode>(N)->getIndex();
279 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000280 } else if (N.getOpcode() == ARMISD::Wrapper &&
281 !(Subtarget->useMovt() &&
282 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000283 Base = N.getOperand(0);
284 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000285 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000286 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
287 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000288 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000289 return true;
290 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000291
Evan Chenga8e29892007-01-19 07:51:42 +0000292 // Match simple R +/- imm12 operands.
293 if (N.getOpcode() == ISD::ADD)
294 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000295 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000296 if ((RHSC >= 0 && RHSC < 0x1000) ||
297 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000298 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000299 if (Base.getOpcode() == ISD::FrameIndex) {
300 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
301 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
302 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000303 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000304
305 ARM_AM::AddrOpc AddSub = ARM_AM::add;
306 if (RHSC < 0) {
307 AddSub = ARM_AM::sub;
308 RHSC = - RHSC;
309 }
310 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000311 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000312 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000313 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000314 }
Evan Chenga8e29892007-01-19 07:51:42 +0000315 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000316
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000317 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000318 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
319 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
320 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000321
Evan Chenga8e29892007-01-19 07:51:42 +0000322 Base = N.getOperand(0);
323 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000324
Evan Chenga8e29892007-01-19 07:51:42 +0000325 if (ShOpcVal != ARM_AM::no_shift) {
326 // Check to see if the RHS of the shift is a constant, if not, we can't fold
327 // it.
328 if (ConstantSDNode *Sh =
329 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000330 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000331 Offset = N.getOperand(1).getOperand(0);
332 } else {
333 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000334 }
335 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000336
Evan Chenga8e29892007-01-19 07:51:42 +0000337 // Try matching (R shl C) + (R).
338 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
339 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
340 if (ShOpcVal != ARM_AM::no_shift) {
341 // Check to see if the RHS of the shift is a constant, if not, we can't
342 // fold it.
343 if (ConstantSDNode *Sh =
344 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000345 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000346 Offset = N.getOperand(0).getOperand(0);
347 Base = N.getOperand(1);
348 } else {
349 ShOpcVal = ARM_AM::no_shift;
350 }
351 }
352 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000353
Evan Chenga8e29892007-01-19 07:51:42 +0000354 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000355 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000356 return true;
357}
358
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000359bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000360 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000361 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000362 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
363 ? cast<LoadSDNode>(Op)->getAddressingMode()
364 : cast<StoreSDNode>(Op)->getAddressingMode();
365 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
366 ? ARM_AM::add : ARM_AM::sub;
367 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000368 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000369 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000370 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000371 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
372 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000373 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000374 return true;
375 }
376 }
377
378 Offset = N;
379 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
380 unsigned ShAmt = 0;
381 if (ShOpcVal != ARM_AM::no_shift) {
382 // Check to see if the RHS of the shift is a constant, if not, we can't fold
383 // it.
384 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000385 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000386 Offset = N.getOperand(0);
387 } else {
388 ShOpcVal = ARM_AM::no_shift;
389 }
390 }
391
392 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000393 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000394 return true;
395}
396
Evan Chenga8e29892007-01-19 07:51:42 +0000397
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000398bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000399 SDValue &Base, SDValue &Offset,
400 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000401 if (N.getOpcode() == ISD::SUB) {
402 // X - C is canonicalize to X + -C, no need to handle it here.
403 Base = N.getOperand(0);
404 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000405 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000406 return true;
407 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000408
Evan Chenga8e29892007-01-19 07:51:42 +0000409 if (N.getOpcode() != ISD::ADD) {
410 Base = N;
411 if (N.getOpcode() == ISD::FrameIndex) {
412 int FI = cast<FrameIndexSDNode>(N)->getIndex();
413 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
414 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000415 Offset = CurDAG->getRegister(0, MVT::i32);
416 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000417 return true;
418 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000419
Evan Chenga8e29892007-01-19 07:51:42 +0000420 // If the RHS is +/- imm8, fold into addr mode.
421 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000422 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000423 if ((RHSC >= 0 && RHSC < 256) ||
424 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000425 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000426 if (Base.getOpcode() == ISD::FrameIndex) {
427 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
428 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
429 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000430 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000431
432 ARM_AM::AddrOpc AddSub = ARM_AM::add;
433 if (RHSC < 0) {
434 AddSub = ARM_AM::sub;
435 RHSC = - RHSC;
436 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000437 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000438 return true;
439 }
440 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000441
Evan Chenga8e29892007-01-19 07:51:42 +0000442 Base = N.getOperand(0);
443 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000444 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000445 return true;
446}
447
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000448bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000449 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000450 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000451 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
452 ? cast<LoadSDNode>(Op)->getAddressingMode()
453 : cast<StoreSDNode>(Op)->getAddressingMode();
454 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
455 ? ARM_AM::add : ARM_AM::sub;
456 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000457 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000458 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000459 Offset = CurDAG->getRegister(0, MVT::i32);
460 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000461 return true;
462 }
463 }
464
465 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000466 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000467 return true;
468}
469
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000470bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000471 SDValue &Addr, SDValue &Mode) {
472 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000473 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000474 return true;
475}
Evan Chenga8e29892007-01-19 07:51:42 +0000476
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000477bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000478 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000479 if (N.getOpcode() != ISD::ADD) {
480 Base = N;
481 if (N.getOpcode() == ISD::FrameIndex) {
482 int FI = cast<FrameIndexSDNode>(N)->getIndex();
483 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000484 } else if (N.getOpcode() == ARMISD::Wrapper &&
485 !(Subtarget->useMovt() &&
486 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000487 Base = N.getOperand(0);
488 }
489 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000490 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000491 return true;
492 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000493
Evan Chenga8e29892007-01-19 07:51:42 +0000494 // If the RHS is +/- imm8, fold into addr mode.
495 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000496 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000497 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
498 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000499 if ((RHSC >= 0 && RHSC < 256) ||
500 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000501 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000502 if (Base.getOpcode() == ISD::FrameIndex) {
503 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
504 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
505 }
506
507 ARM_AM::AddrOpc AddSub = ARM_AM::add;
508 if (RHSC < 0) {
509 AddSub = ARM_AM::sub;
510 RHSC = - RHSC;
511 }
512 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000513 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000514 return true;
515 }
516 }
517 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000518
Evan Chenga8e29892007-01-19 07:51:42 +0000519 Base = N;
520 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000521 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000522 return true;
523}
524
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000525bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000526 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000527 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000528 // Default to no alignment.
529 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000530 return true;
531}
532
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000533bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000534 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000535 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
536 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000537 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000538 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000539 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000540 return true;
541 }
542 return false;
543}
544
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000545bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000546 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000547 // FIXME dl should come from the parent load or store, not the address
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000548 DebugLoc dl = Op->getDebugLoc();
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);
551 if (!NC || NC->getZExtValue() != 0)
552 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) {
677 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
678
679 // Don't match base register only case. That is matched to a separate
680 // lower complexity pattern with explicit register operand.
681 if (ShOpcVal == ARM_AM::no_shift) return false;
682
683 BaseReg = N.getOperand(0);
684 unsigned ShImmVal = 0;
685 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
686 ShImmVal = RHS->getZExtValue() & 31;
687 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
688 return true;
689 }
690
691 return false;
692}
693
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000694bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000695 SDValue &Base, SDValue &OffImm) {
696 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000697
Evan Cheng3a214252009-08-11 08:52:18 +0000698 // Base only.
699 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000700 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000701 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000702 int FI = cast<FrameIndexSDNode>(N)->getIndex();
703 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000704 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000705 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000706 } else if (N.getOpcode() == ARMISD::Wrapper &&
707 !(Subtarget->useMovt() &&
708 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000709 Base = N.getOperand(0);
710 if (Base.getOpcode() == ISD::TargetConstantPool)
711 return false; // We want to select t2LDRpci instead.
712 } else
713 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000714 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000715 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000716 }
Evan Cheng055b0312009-06-29 07:51:04 +0000717
718 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000719 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
720 // Let t2LDRi8 handle (R - imm8).
721 return false;
722
Evan Cheng055b0312009-06-29 07:51:04 +0000723 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000724 if (N.getOpcode() == ISD::SUB)
725 RHSC = -RHSC;
726
727 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000728 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000729 if (Base.getOpcode() == ISD::FrameIndex) {
730 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
731 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
732 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000733 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000734 return true;
735 }
736 }
737
Evan Cheng3a214252009-08-11 08:52:18 +0000738 // Base only.
739 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000740 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000741 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000742}
743
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000744bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000745 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000746 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000747 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000748 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
749 int RHSC = (int)RHS->getSExtValue();
750 if (N.getOpcode() == ISD::SUB)
751 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000752
Evan Cheng3a214252009-08-11 08:52:18 +0000753 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
754 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000755 if (Base.getOpcode() == ISD::FrameIndex) {
756 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
757 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
758 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000759 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000760 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000761 }
Evan Cheng055b0312009-06-29 07:51:04 +0000762 }
763 }
764
765 return false;
766}
767
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000768bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000769 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000770 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000771 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
772 ? cast<LoadSDNode>(Op)->getAddressingMode()
773 : cast<StoreSDNode>(Op)->getAddressingMode();
774 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
775 int RHSC = (int)RHS->getZExtValue();
776 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000777 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000778 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
779 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000780 return true;
781 }
782 }
783
784 return false;
785}
786
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000787bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000788 SDValue &Base, SDValue &OffImm) {
789 if (N.getOpcode() == ISD::ADD) {
790 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
791 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000792 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000793 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000794 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000795 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000796 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000797 return true;
798 }
799 }
800 } else if (N.getOpcode() == ISD::SUB) {
801 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
802 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000803 // 8 bits.
804 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
David Goodwin6647cea2009-06-30 22:50:01 +0000805 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000806 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000807 return true;
808 }
809 }
810 }
811
812 return false;
813}
814
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000815bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000816 SDValue &Base,
817 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000818 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
819 if (N.getOpcode() != ISD::ADD)
820 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000821
Evan Cheng3a214252009-08-11 08:52:18 +0000822 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
823 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
824 int RHSC = (int)RHS->getZExtValue();
825 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
826 return false;
827 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000828 return false;
829 }
830
Evan Cheng055b0312009-06-29 07:51:04 +0000831 // Look for (R + R) or (R + (R << [1,2,3])).
832 unsigned ShAmt = 0;
833 Base = N.getOperand(0);
834 OffReg = N.getOperand(1);
835
836 // Swap if it is ((R << c) + R).
837 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
838 if (ShOpcVal != ARM_AM::lsl) {
839 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
840 if (ShOpcVal == ARM_AM::lsl)
841 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000842 }
843
Evan Cheng055b0312009-06-29 07:51:04 +0000844 if (ShOpcVal == ARM_AM::lsl) {
845 // Check to see if the RHS of the shift is a constant, if not, we can't fold
846 // it.
847 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
848 ShAmt = Sh->getZExtValue();
849 if (ShAmt >= 4) {
850 ShAmt = 0;
851 ShOpcVal = ARM_AM::no_shift;
852 } else
853 OffReg = OffReg.getOperand(0);
854 } else {
855 ShOpcVal = ARM_AM::no_shift;
856 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000857 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000858
Owen Anderson825b72b2009-08-11 20:47:22 +0000859 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000860
861 return true;
862}
863
864//===--------------------------------------------------------------------===//
865
Evan Chengee568cf2007-07-05 07:15:27 +0000866/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000867static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000869}
870
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000871SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
872 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000873 ISD::MemIndexedMode AM = LD->getAddressingMode();
874 if (AM == ISD::UNINDEXED)
875 return NULL;
876
Owen Andersone50ed302009-08-10 22:56:29 +0000877 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000878 SDValue Offset, AMOpc;
879 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
880 unsigned Opcode = 0;
881 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000882 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000883 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000884 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
885 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000886 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000887 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000888 Match = true;
889 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
890 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
891 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000892 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000893 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000894 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000895 Match = true;
896 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
897 }
898 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000899 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000900 Match = true;
901 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
902 }
903 }
904 }
905
906 if (Match) {
907 SDValue Chain = LD->getChain();
908 SDValue Base = LD->getBasePtr();
909 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000910 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000911 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000912 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000913 }
914
915 return NULL;
916}
917
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000918SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
919 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000920 ISD::MemIndexedMode AM = LD->getAddressingMode();
921 if (AM == ISD::UNINDEXED)
922 return NULL;
923
Owen Andersone50ed302009-08-10 22:56:29 +0000924 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000925 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000926 SDValue Offset;
927 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
928 unsigned Opcode = 0;
929 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000930 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000931 switch (LoadedVT.getSimpleVT().SimpleTy) {
932 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000933 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
934 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000935 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000936 if (isSExtLd)
937 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
938 else
939 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000940 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000941 case MVT::i8:
942 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000943 if (isSExtLd)
944 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
945 else
946 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000947 break;
948 default:
949 return NULL;
950 }
951 Match = true;
952 }
953
954 if (Match) {
955 SDValue Chain = LD->getChain();
956 SDValue Base = LD->getBasePtr();
957 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000958 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000959 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000960 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000961 }
962
963 return NULL;
964}
965
Evan Cheng603afbf2010-05-10 17:34:18 +0000966/// PairDRegs - Form a quad register from a pair of D registers.
967///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000968SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
969 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000970 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
971 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +0000972 if (llvm::ModelWithRegSequence()) {
Evan Cheng94cc6d32010-05-04 20:39:49 +0000973 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
974 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
975 }
976 SDValue Undef =
977 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0);
Chris Lattner518bb532010-02-09 19:54:29 +0000978 SDNode *Pair = CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000979 VT, Undef, V0, SubReg0);
Chris Lattner518bb532010-02-09 19:54:29 +0000980 return CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl,
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000981 VT, SDValue(Pair, 0), V1, SubReg1);
982}
983
Evan Cheng7f687192010-05-14 00:21:45 +0000984/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000985///
986SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
987 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000988 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
989 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000990 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
991 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
992}
993
Evan Cheng7f687192010-05-14 00:21:45 +0000994/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000995///
996SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
997 SDValue V2, SDValue V3) {
998 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000999 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1000 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1001 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1002 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001003 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1004 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1005}
1006
Evan Cheng8f6de382010-05-16 03:27:48 +00001007/// QuadQRegs - Form 4 consecutive Q registers.
1008///
1009SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1010 SDValue V2, SDValue V3) {
1011 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001012 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1013 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1014 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1015 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001016 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1017 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1018}
1019
Evan Cheng5c6aba22010-05-14 18:54:59 +00001020/// OctoDRegs - Form 8 consecutive D registers.
1021///
1022SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1023 SDValue V2, SDValue V3,
1024 SDValue V4, SDValue V5,
1025 SDValue V6, SDValue V7) {
1026 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001027 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1028 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1029 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1030 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1031 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1032 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1033 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1034 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001035 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1036 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1037 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1038}
1039
Bob Wilsona7c397c2009-10-14 16:19:03 +00001040/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1041/// for a 64-bit subregister of the vector.
1042static EVT GetNEONSubregVT(EVT VT) {
1043 switch (VT.getSimpleVT().SimpleTy) {
1044 default: llvm_unreachable("unhandled NEON type");
1045 case MVT::v16i8: return MVT::v8i8;
1046 case MVT::v8i16: return MVT::v4i16;
1047 case MVT::v4f32: return MVT::v2f32;
1048 case MVT::v4i32: return MVT::v2i32;
1049 case MVT::v2i64: return MVT::v1i64;
1050 }
1051}
1052
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001053SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001054 unsigned *DOpcodes, unsigned *QOpcodes0,
1055 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001056 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001057 DebugLoc dl = N->getDebugLoc();
1058
Bob Wilson226036e2010-03-20 22:13:40 +00001059 SDValue MemAddr, Align;
1060 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001061 return NULL;
1062
1063 SDValue Chain = N->getOperand(0);
1064 EVT VT = N->getValueType(0);
1065 bool is64BitVector = VT.is64BitVector();
1066
1067 unsigned OpcodeIndex;
1068 switch (VT.getSimpleVT().SimpleTy) {
1069 default: llvm_unreachable("unhandled vld type");
1070 // Double-register operations:
1071 case MVT::v8i8: OpcodeIndex = 0; break;
1072 case MVT::v4i16: OpcodeIndex = 1; break;
1073 case MVT::v2f32:
1074 case MVT::v2i32: OpcodeIndex = 2; break;
1075 case MVT::v1i64: OpcodeIndex = 3; break;
1076 // Quad-register operations:
1077 case MVT::v16i8: OpcodeIndex = 0; break;
1078 case MVT::v8i16: OpcodeIndex = 1; break;
1079 case MVT::v4f32:
1080 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001081 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001082 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001083 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001084 }
1085
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001086 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001087 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001088 if (is64BitVector) {
1089 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001090 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001091 std::vector<EVT> ResTys(NumVecs, VT);
1092 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001093 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
1094 if (!llvm::ModelWithRegSequence() || NumVecs < 2)
1095 return VLd;
1096
Evan Cheng0ce537a2010-05-11 01:19:40 +00001097 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001098 SDValue V0 = SDValue(VLd, 0);
1099 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001100
Evan Cheng0ce537a2010-05-11 01:19:40 +00001101 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001102 if (NumVecs == 2)
1103 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1104 else {
1105 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001106 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001107 SDValue V3 = (NumVecs == 3)
1108 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1109 : SDValue(VLd, 3);
1110 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1111 }
1112
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001113 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001114 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001115 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001116 dl, VT, RegSeq);
1117 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001118 }
1119 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1120 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001121 }
1122
1123 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001124 if (NumVecs <= 2) {
1125 // Quad registers are directly supported for VLD1 and VLD2,
1126 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001127 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001128 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001129 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001130 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001131 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001132 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001133
1134 // Combine the even and odd subregs to produce the result.
Evan Cheng603afbf2010-05-10 17:34:18 +00001135 if (llvm::ModelWithRegSequence()) {
1136 if (NumVecs == 1) {
1137 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1138 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
1139 } else {
1140 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1141 SDValue(VLd, 0), SDValue(VLd, 1),
1142 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001143 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1144 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
Evan Cheng603afbf2010-05-10 17:34:18 +00001145 ReplaceUses(SDValue(N, 0), Q0);
1146 ReplaceUses(SDValue(N, 1), Q1);
1147 }
1148 } else {
1149 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1150 SDNode *Q = PairDRegs(VT, SDValue(VLd, 2*Vec), SDValue(VLd, 2*Vec+1));
1151 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1152 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001153 }
1154 } else {
1155 // Otherwise, quad registers are loaded with two separate instructions,
1156 // where one loads the even registers and the other loads the odd registers.
1157
Bob Wilson3e36f132009-10-14 17:28:52 +00001158 std::vector<EVT> ResTys(NumVecs, RegVT);
1159 ResTys.push_back(MemAddr.getValueType());
1160 ResTys.push_back(MVT::Other);
1161
Bob Wilson24f995d2009-10-14 18:32:29 +00001162 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001163 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001164 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1165 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001166 Chain = SDValue(VLdA, NumVecs+1);
1167
Bob Wilson24f995d2009-10-14 18:32:29 +00001168 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001169 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001170 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1171 Align, Reg0, Pred, Reg0, Chain };
1172 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001173 Chain = SDValue(VLdB, NumVecs+1);
1174
Evan Cheng5c6aba22010-05-14 18:54:59 +00001175 if (llvm::ModelWithRegSequence()) {
1176 SDValue V0 = SDValue(VLdA, 0);
1177 SDValue V1 = SDValue(VLdB, 0);
1178 SDValue V2 = SDValue(VLdA, 1);
1179 SDValue V3 = SDValue(VLdB, 1);
1180 SDValue V4 = SDValue(VLdA, 2);
1181 SDValue V5 = SDValue(VLdB, 2);
1182 SDValue V6 = (NumVecs == 3)
1183 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1184 0)
1185 : SDValue(VLdA, 3);
1186 SDValue V7 = (NumVecs == 3)
1187 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT),
1188 0)
1189 : SDValue(VLdB, 3);
1190 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1191 V4, V5, V6, V7), 0);
1192
1193 // Extract out the 3 / 4 Q registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001194 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001195 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001196 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001197 dl, VT, RegSeq);
1198 ReplaceUses(SDValue(N, Vec), Q);
1199 }
1200 } else {
1201 // Combine the even and odd subregs to produce the result.
1202 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1203 SDNode *Q = PairDRegs(VT, SDValue(VLdA, Vec), SDValue(VLdB, Vec));
1204 ReplaceUses(SDValue(N, Vec), SDValue(Q, 0));
1205 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001206 }
1207 }
1208 ReplaceUses(SDValue(N, NumVecs), Chain);
1209 return NULL;
1210}
1211
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001212SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001213 unsigned *DOpcodes, unsigned *QOpcodes0,
1214 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001215 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001216 DebugLoc dl = N->getDebugLoc();
1217
Bob Wilson226036e2010-03-20 22:13:40 +00001218 SDValue MemAddr, Align;
1219 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001220 return NULL;
1221
1222 SDValue Chain = N->getOperand(0);
1223 EVT VT = N->getOperand(3).getValueType();
1224 bool is64BitVector = VT.is64BitVector();
1225
1226 unsigned OpcodeIndex;
1227 switch (VT.getSimpleVT().SimpleTy) {
1228 default: llvm_unreachable("unhandled vst type");
1229 // Double-register operations:
1230 case MVT::v8i8: OpcodeIndex = 0; break;
1231 case MVT::v4i16: OpcodeIndex = 1; break;
1232 case MVT::v2f32:
1233 case MVT::v2i32: OpcodeIndex = 2; break;
1234 case MVT::v1i64: OpcodeIndex = 3; break;
1235 // Quad-register operations:
1236 case MVT::v16i8: OpcodeIndex = 0; break;
1237 case MVT::v8i16: OpcodeIndex = 1; break;
1238 case MVT::v4f32:
1239 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001240 case MVT::v2i64: OpcodeIndex = 3;
1241 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1242 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001243 }
1244
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001245 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001246 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001247
Bob Wilson226036e2010-03-20 22:13:40 +00001248 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001249 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001250 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001251
1252 if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001253 if (llvm::ModelWithRegSequence() && NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001254 SDValue RegSeq;
1255 SDValue V0 = N->getOperand(0+3);
1256 SDValue V1 = N->getOperand(1+3);
1257
1258 // Form a REG_SEQUENCE to force register allocation.
1259 if (NumVecs == 2)
1260 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1261 else {
1262 SDValue V2 = N->getOperand(2+3);
1263 // If it's a vld3, form a quad D-register and leave the last part as
1264 // an undef.
1265 SDValue V3 = (NumVecs == 3)
1266 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1267 : N->getOperand(3+3);
1268 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1269 }
1270
1271 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001272 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001273 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001274 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001275 RegSeq));
1276 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001277 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001278 RegSeq));
1279 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001280 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001281 RegSeq));
1282 } else {
1283 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1284 Ops.push_back(N->getOperand(Vec+3));
1285 }
Evan Chengac0869d2009-11-21 06:21:52 +00001286 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001287 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001288 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001289 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001290 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001291 }
1292
1293 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001294 if (NumVecs <= 2) {
1295 // Quad registers are directly supported for VST1 and VST2,
1296 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001297 unsigned Opc = QOpcodes0[OpcodeIndex];
Evan Cheng603afbf2010-05-10 17:34:18 +00001298 if (llvm::ModelWithRegSequence() && NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001299 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001300 SDValue Q0 = N->getOperand(3);
1301 SDValue Q1 = N->getOperand(4);
1302
1303 // Form a QQ register.
1304 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1305
1306 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001307 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001308 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001309 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001310 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001311 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001312 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001313 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001314 QQ));
1315 Ops.push_back(Pred);
1316 Ops.push_back(Reg0); // predicate register
1317 Ops.push_back(Chain);
1318 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1319 } else {
1320 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001321 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001322 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001323 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001324 N->getOperand(Vec+3)));
1325 }
1326 Ops.push_back(Pred);
1327 Ops.push_back(Reg0); // predicate register
1328 Ops.push_back(Chain);
1329 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1330 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001331 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001332 }
1333
1334 // Otherwise, quad registers are stored with two separate instructions,
1335 // where one stores the even registers and the other stores the odd registers.
Evan Cheng12c24692010-05-14 22:54:52 +00001336 if (llvm::ModelWithRegSequence()) {
Evan Cheng12c24692010-05-14 22:54:52 +00001337 // Form the QQQQ REG_SEQUENCE.
1338 SDValue V[8];
1339 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001340 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001341 N->getOperand(Vec+3));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001342 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001343 N->getOperand(Vec+3));
1344 }
1345 if (NumVecs == 3)
Evan Cheng7189fd02010-05-15 07:53:37 +00001346 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1347 dl, RegVT), 0);
1348
Evan Cheng12c24692010-05-14 22:54:52 +00001349 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1350 V[4], V[5], V[6], V[7]), 0);
Bob Wilsona43e6bf2010-03-16 23:01:13 +00001351
Evan Cheng12c24692010-05-14 22:54:52 +00001352 // Store the even D registers.
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001353 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng12c24692010-05-14 22:54:52 +00001354 Ops.push_back(Reg0); // post-access address offset
1355 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001356 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001357 RegVT, RegSeq));
1358 Ops.push_back(Pred);
1359 Ops.push_back(Reg0); // predicate register
1360 Ops.push_back(Chain);
1361 unsigned Opc = QOpcodes0[OpcodeIndex];
1362 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1363 MVT::Other, Ops.data(), NumVecs+6);
1364 Chain = SDValue(VStA, 1);
Bob Wilson24f995d2009-10-14 18:32:29 +00001365
Evan Cheng12c24692010-05-14 22:54:52 +00001366 // Store the odd D registers.
1367 Ops[0] = SDValue(VStA, 0); // MemAddr
1368 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001369 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
Evan Cheng12c24692010-05-14 22:54:52 +00001370 RegVT, RegSeq);
1371 Ops[NumVecs+5] = Chain;
1372 Opc = QOpcodes1[OpcodeIndex];
1373 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1374 MVT::Other, Ops.data(), NumVecs+6);
1375 Chain = SDValue(VStB, 1);
1376 ReplaceUses(SDValue(N, 0), Chain);
1377 return NULL;
1378 } else {
1379 Ops.push_back(Reg0); // post-access address offset
1380
1381 // Store the even subregs.
1382 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001383 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001384 N->getOperand(Vec+3)));
1385 Ops.push_back(Pred);
1386 Ops.push_back(Reg0); // predicate register
1387 Ops.push_back(Chain);
1388 unsigned Opc = QOpcodes0[OpcodeIndex];
1389 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1390 MVT::Other, Ops.data(), NumVecs+6);
1391 Chain = SDValue(VStA, 1);
1392
1393 // Store the odd subregs.
1394 Ops[0] = SDValue(VStA, 0); // MemAddr
1395 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001396 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng12c24692010-05-14 22:54:52 +00001397 N->getOperand(Vec+3));
1398 Ops[NumVecs+5] = Chain;
1399 Opc = QOpcodes1[OpcodeIndex];
1400 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1401 MVT::Other, Ops.data(), NumVecs+6);
1402 Chain = SDValue(VStB, 1);
1403 ReplaceUses(SDValue(N, 0), Chain);
1404 return NULL;
1405 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001406}
1407
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001408SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001409 unsigned NumVecs, unsigned *DOpcodes,
1410 unsigned *QOpcodes0,
1411 unsigned *QOpcodes1) {
1412 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001413 DebugLoc dl = N->getDebugLoc();
1414
Bob Wilson226036e2010-03-20 22:13:40 +00001415 SDValue MemAddr, Align;
1416 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001417 return NULL;
1418
1419 SDValue Chain = N->getOperand(0);
1420 unsigned Lane =
1421 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001422 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001423 bool is64BitVector = VT.is64BitVector();
1424
Bob Wilson96493442009-10-14 16:46:45 +00001425 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001426 unsigned NumElts = 0;
1427 int SubregIdx = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001429 EVT RegVT = VT;
1430 if (!is64BitVector) {
1431 RegVT = GetNEONSubregVT(VT);
1432 NumElts = RegVT.getVectorNumElements();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001433 SubregIdx = (Lane < NumElts) ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001434 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001435 }
1436
1437 unsigned OpcodeIndex;
1438 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001439 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001440 // Double-register operations:
1441 case MVT::v8i8: OpcodeIndex = 0; break;
1442 case MVT::v4i16: OpcodeIndex = 1; break;
1443 case MVT::v2f32:
1444 case MVT::v2i32: OpcodeIndex = 2; break;
1445 // Quad-register operations:
1446 case MVT::v8i16: OpcodeIndex = 0; break;
1447 case MVT::v4f32:
1448 case MVT::v4i32: OpcodeIndex = 1; break;
1449 }
1450
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001451 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001452 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001453
Bob Wilson226036e2010-03-20 22:13:40 +00001454 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001455 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001456 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001457
1458 unsigned Opc = 0;
1459 if (is64BitVector) {
1460 Opc = DOpcodes[OpcodeIndex];
Evan Cheng8f6de382010-05-16 03:27:48 +00001461 if (llvm::ModelWithRegSequence()) {
1462 SDValue RegSeq;
1463 SDValue V0 = N->getOperand(0+3);
1464 SDValue V1 = N->getOperand(1+3);
1465 if (NumVecs == 2) {
1466 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1467 } else {
1468 SDValue V2 = N->getOperand(2+3);
1469 SDValue V3 = (NumVecs == 3)
1470 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1471 : N->getOperand(3+3);
1472 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1473 }
1474
1475 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001476 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001477 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001478 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001479 RegSeq));
1480 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001481 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001482 RegSeq));
1483 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001484 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng8f6de382010-05-16 03:27:48 +00001485 RegSeq));
1486 } else {
1487 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1488 Ops.push_back(N->getOperand(Vec+3));
1489 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001490 } else {
1491 // Check if this is loading the even or odd subreg of a Q register.
1492 if (Lane < NumElts) {
1493 Opc = QOpcodes0[OpcodeIndex];
1494 } else {
1495 Lane -= NumElts;
1496 Opc = QOpcodes1[OpcodeIndex];
1497 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001498
1499 if (llvm::ModelWithRegSequence()) {
1500 SDValue RegSeq;
1501 SDValue V0 = N->getOperand(0+3);
1502 SDValue V1 = N->getOperand(1+3);
1503 if (NumVecs == 2) {
1504 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
1505 } else {
1506 SDValue V2 = N->getOperand(2+3);
1507 SDValue V3 = (NumVecs == 3)
1508 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1509 : N->getOperand(3+3);
1510 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
1511 }
1512
1513 // Extract the subregs of the input vector.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001514 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
Evan Cheng8f6de382010-05-16 03:27:48 +00001515 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1516 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1517 RegSeq));
1518 } else {
1519 // Extract the subregs of the input vector.
1520 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1521 Ops.push_back(CurDAG->getTargetExtractSubreg(SubregIdx, dl, RegVT,
1522 N->getOperand(Vec+3)));
1523 }
Bob Wilsona7c397c2009-10-14 16:19:03 +00001524 }
1525 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001526 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001527 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001528 Ops.push_back(Chain);
1529
Bob Wilson96493442009-10-14 16:46:45 +00001530 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001531 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001532
Bob Wilsona7c397c2009-10-14 16:19:03 +00001533 std::vector<EVT> ResTys(NumVecs, RegVT);
1534 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001535 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1536
Evan Cheng7189fd02010-05-15 07:53:37 +00001537 if (llvm::ModelWithRegSequence()) {
Evan Cheng7092c2b2010-05-15 01:36:29 +00001538 // Form a REG_SEQUENCE to force register allocation.
Evan Cheng7189fd02010-05-15 07:53:37 +00001539 SDValue RegSeq;
1540 if (is64BitVector) {
1541 SDValue V0 = SDValue(VLdLn, 0);
1542 SDValue V1 = SDValue(VLdLn, 1);
1543 if (NumVecs == 2) {
1544 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1545 } else {
1546 SDValue V2 = SDValue(VLdLn, 2);
1547 // If it's a vld3, form a quad D-register but discard the last part.
1548 SDValue V3 = (NumVecs == 3)
Evan Cheng7092c2b2010-05-15 01:36:29 +00001549 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1550 : SDValue(VLdLn, 3);
Evan Cheng7189fd02010-05-15 07:53:37 +00001551 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1552 }
1553 } else {
Jim Grosbach18f30e62010-06-02 21:53:11 +00001554 // For 128-bit vectors, take the 64-bit results of the load and insert
1555 // them as subregs into the result.
Evan Cheng7189fd02010-05-15 07:53:37 +00001556 SDValue V[8];
1557 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
Evan Cheng8f6de382010-05-16 03:27:48 +00001558 if (Even) {
Evan Cheng7189fd02010-05-15 07:53:37 +00001559 V[i] = SDValue(VLdLn, Vec);
1560 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1561 dl, RegVT), 0);
1562 } else {
1563 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1564 dl, RegVT), 0);
1565 V[i+1] = SDValue(VLdLn, Vec);
1566 }
1567 }
1568 if (NumVecs == 3)
1569 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1570 dl, RegVT), 0);
1571
1572 if (NumVecs == 2)
1573 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1574 else
1575 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1576 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001577 }
1578
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001579 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1580 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001581 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Evan Cheng7189fd02010-05-15 07:53:37 +00001582 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1583 ReplaceUses(SDValue(N, Vec),
1584 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
Evan Cheng7092c2b2010-05-15 01:36:29 +00001585 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
1586 return NULL;
1587 }
1588
Bob Wilsona7c397c2009-10-14 16:19:03 +00001589 // For a 64-bit vector load to D registers, nothing more needs to be done.
1590 if (is64BitVector)
1591 return VLdLn;
1592
1593 // For 128-bit vectors, take the 64-bit results of the load and insert them
1594 // as subregs into the result.
1595 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1596 SDValue QuadVec = CurDAG->getTargetInsertSubreg(SubregIdx, dl, VT,
1597 N->getOperand(Vec+3),
1598 SDValue(VLdLn, Vec));
1599 ReplaceUses(SDValue(N, Vec), QuadVec);
1600 }
1601
1602 Chain = SDValue(VLdLn, NumVecs);
1603 ReplaceUses(SDValue(N, NumVecs), Chain);
1604 return NULL;
1605}
1606
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001607SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001608 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001609 if (!Subtarget->hasV6T2Ops())
1610 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001611
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001612 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1613 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1614
1615
1616 // For unsigned extracts, check for a shift right and mask
1617 unsigned And_imm = 0;
1618 if (N->getOpcode() == ISD::AND) {
1619 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1620
1621 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1622 if (And_imm & (And_imm + 1))
1623 return NULL;
1624
1625 unsigned Srl_imm = 0;
1626 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1627 Srl_imm)) {
1628 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1629
1630 unsigned Width = CountTrailingOnes_32(And_imm);
1631 unsigned LSB = Srl_imm;
1632 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1633 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1634 CurDAG->getTargetConstant(LSB, MVT::i32),
1635 CurDAG->getTargetConstant(Width, MVT::i32),
1636 getAL(CurDAG), Reg0 };
1637 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1638 }
1639 }
1640 return NULL;
1641 }
1642
1643 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001644 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001645 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001646 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1647 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001648 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001649 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1650 unsigned Width = 32 - Srl_imm;
1651 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001652 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001653 return NULL;
1654 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001655 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001656 CurDAG->getTargetConstant(LSB, MVT::i32),
1657 CurDAG->getTargetConstant(Width, MVT::i32),
1658 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001659 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001660 }
1661 }
1662 return NULL;
1663}
1664
Evan Cheng9ef48352009-11-20 00:54:03 +00001665SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001666SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001667 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1668 SDValue CPTmp0;
1669 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001670 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001671 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1672 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1673 unsigned Opc = 0;
1674 switch (SOShOp) {
1675 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1676 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1677 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1678 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1679 default:
1680 llvm_unreachable("Unknown so_reg opcode!");
1681 break;
1682 }
1683 SDValue SOShImm =
1684 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1685 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1686 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001688 }
1689 return 0;
1690}
1691
1692SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001693SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001694 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1695 SDValue CPTmp0;
1696 SDValue CPTmp1;
1697 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001698 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001699 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1700 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001702 }
1703 return 0;
1704}
1705
1706SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001707SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001708 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1709 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1710 if (!T)
1711 return 0;
1712
1713 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1714 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1715 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1716 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001717 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001718 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1719 }
1720 return 0;
1721}
1722
1723SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001724SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001725 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1726 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1727 if (!T)
1728 return 0;
1729
1730 if (Predicate_so_imm(TrueVal.getNode())) {
1731 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1732 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1733 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001734 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001735 ARM::MOVCCi, MVT::i32, Ops, 5);
1736 }
1737 return 0;
1738}
1739
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001740SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1741 EVT VT = N->getValueType(0);
1742 SDValue FalseVal = N->getOperand(0);
1743 SDValue TrueVal = N->getOperand(1);
1744 SDValue CC = N->getOperand(2);
1745 SDValue CCR = N->getOperand(3);
1746 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001747 assert(CC.getOpcode() == ISD::Constant);
1748 assert(CCR.getOpcode() == ISD::Register);
1749 ARMCC::CondCodes CCVal =
1750 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001751
1752 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1753 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1754 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1755 // Pattern complexity = 18 cost = 1 size = 0
1756 SDValue CPTmp0;
1757 SDValue CPTmp1;
1758 SDValue CPTmp2;
1759 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001760 SDNode *Res = SelectT2CMOVShiftOp(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 = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001764 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1765 if (Res)
1766 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001767 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001768 SDNode *Res = SelectARMCMOVShiftOp(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 = SelectARMCMOVShiftOp(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 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1778 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1779 // (imm:i32):$cc)
1780 // Emits: (MOVCCi:i32 GPR:i32:$false,
1781 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1782 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001783 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001784 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001785 CCVal, CCR, InFlag);
1786 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001787 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001788 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1789 if (Res)
1790 return Res;
1791 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001792 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001793 CCVal, CCR, InFlag);
1794 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001795 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001796 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1797 if (Res)
1798 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001799 }
1800 }
1801
1802 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1803 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1804 // Pattern complexity = 6 cost = 1 size = 0
1805 //
1806 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1807 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1808 // Pattern complexity = 6 cost = 11 size = 0
1809 //
1810 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001811 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1812 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001813 unsigned Opc = 0;
1814 switch (VT.getSimpleVT().SimpleTy) {
1815 default: assert(false && "Illegal conditional move type!");
1816 break;
1817 case MVT::i32:
1818 Opc = Subtarget->isThumb()
1819 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1820 : ARM::MOVCCr;
1821 break;
1822 case MVT::f32:
1823 Opc = ARM::VMOVScc;
1824 break;
1825 case MVT::f64:
1826 Opc = ARM::VMOVDcc;
1827 break;
1828 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001829 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001830}
1831
Evan Chengde8aa4e2010-05-05 18:28:36 +00001832SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1833 // The only time a CONCAT_VECTORS operation can have legal types is when
1834 // two 64-bit vectors are concatenated to a 128-bit vector.
1835 EVT VT = N->getValueType(0);
1836 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1837 llvm_unreachable("unexpected CONCAT_VECTORS");
1838 DebugLoc dl = N->getDebugLoc();
1839 SDValue V0 = N->getOperand(0);
1840 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001841 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1842 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001843 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1844 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1845}
1846
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001847SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001848 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001849
Dan Gohmane8be6c62008-07-17 19:10:17 +00001850 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001851 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001852
1853 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001854 default: break;
1855 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001856 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001857 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001858 if (Subtarget->hasThumb2())
1859 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1860 // be done with MOV + MOVT, at worst.
1861 UseCP = 0;
1862 else {
1863 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001864 UseCP = (Val > 255 && // MOV
1865 ~Val > 255 && // MOV + MVN
1866 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001867 } else
1868 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1869 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1870 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1871 }
1872
Evan Chenga8e29892007-01-19 07:51:42 +00001873 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001874 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001875 CurDAG->getTargetConstantPool(ConstantInt::get(
1876 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001877 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001878
1879 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001880 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001881 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001882 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001883 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001884 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1885 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001886 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001887 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001888 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001889 CurDAG->getRegister(0, MVT::i32),
1890 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001891 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001892 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001893 CurDAG->getEntryNode()
1894 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001895 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1896 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001897 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001898 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001899 return NULL;
1900 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001901
Evan Chenga8e29892007-01-19 07:51:42 +00001902 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001903 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001904 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001905 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001906 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001907 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001908 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001909 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001910 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1911 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001912 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001913 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1914 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001915 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1916 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1917 CurDAG->getRegister(0, MVT::i32) };
1918 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001919 }
Evan Chenga8e29892007-01-19 07:51:42 +00001920 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001921 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001922 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001923 return I;
1924 break;
1925 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001926 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001927 return I;
1928 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001929 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001930 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001931 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001932 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001933 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001934 if (!RHSV) break;
1935 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001936 unsigned ShImm = Log2_32(RHSV-1);
1937 if (ShImm >= 32)
1938 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001939 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001940 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001941 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1942 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001943 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001944 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001945 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001946 } else {
1947 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001948 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001949 }
Evan Chenga8e29892007-01-19 07:51:42 +00001950 }
1951 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001952 unsigned ShImm = Log2_32(RHSV+1);
1953 if (ShImm >= 32)
1954 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001955 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001956 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001957 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1958 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001959 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001960 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1961 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001962 } else {
1963 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001964 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001965 }
Evan Chenga8e29892007-01-19 07:51:42 +00001966 }
1967 }
1968 break;
Evan Cheng20956592009-10-21 08:15:52 +00001969 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001970 // Check for unsigned bitfield extract
1971 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1972 return I;
1973
Evan Cheng20956592009-10-21 08:15:52 +00001974 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1975 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1976 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1977 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1978 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001980 if (VT != MVT::i32)
1981 break;
1982 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1983 ? ARM::t2MOVTi16
1984 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1985 if (!Opc)
1986 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001987 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001988 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1989 if (!N1C)
1990 break;
1991 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1992 SDValue N2 = N0.getOperand(1);
1993 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1994 if (!N2C)
1995 break;
1996 unsigned N1CVal = N1C->getZExtValue();
1997 unsigned N2CVal = N2C->getZExtValue();
1998 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1999 (N1CVal & 0xffffU) == 0xffffU &&
2000 (N2CVal & 0xffffU) == 0x0U) {
2001 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2002 MVT::i32);
2003 SDValue Ops[] = { N0.getOperand(0), Imm16,
2004 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2005 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2006 }
2007 }
2008 break;
2009 }
Jim Grosbache5165492009-11-09 00:11:35 +00002010 case ARMISD::VMOVRRD:
2011 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002012 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002013 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002014 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002015 if (Subtarget->isThumb1Only())
2016 break;
2017 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002018 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002019 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2020 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002021 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002022 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002023 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002024 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2025 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002026 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002027 }
Evan Chengee568cf2007-07-05 07:15:27 +00002028 }
Dan Gohman525178c2007-10-08 18:33:35 +00002029 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002030 if (Subtarget->isThumb1Only())
2031 break;
2032 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002033 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002034 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002035 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002036 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002037 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002038 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2039 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002040 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002041 }
Evan Chengee568cf2007-07-05 07:15:27 +00002042 }
Evan Chenga8e29892007-01-19 07:51:42 +00002043 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002044 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002045 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002047 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002048 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002049 if (ResNode)
2050 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002051
2052 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2053 if (Subtarget->hasVFP2() &&
2054 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2055 SDValue Chain = N->getOperand(0);
2056 SDValue AM5Opc =
2057 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002058 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002059 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2060 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002061 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2062 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2063 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2064 MVT::v2f64, MVT::Other, Ops, 5);
2065 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2066 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002067 }
2068 // Other cases are autogenerated.
2069 break;
2070 }
2071 case ISD::STORE: {
2072 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2073 if (Subtarget->hasVFP2() &&
2074 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2075 SDValue Chain = N->getOperand(0);
2076 SDValue AM5Opc =
2077 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002078 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002079 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2080 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2081 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002082 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2083 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2084 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2085 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2086 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002087 }
Evan Chenga8e29892007-01-19 07:51:42 +00002088 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002089 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002090 }
Evan Chengee568cf2007-07-05 07:15:27 +00002091 case ARMISD::BRCOND: {
2092 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2093 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2094 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002095
Evan Chengee568cf2007-07-05 07:15:27 +00002096 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2097 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2098 // Pattern complexity = 6 cost = 1 size = 0
2099
David Goodwin5e47a9a2009-06-30 18:04:13 +00002100 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2101 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2102 // Pattern complexity = 6 cost = 1 size = 0
2103
Jim Grosbach764ab522009-08-11 15:33:49 +00002104 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002105 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 SDValue Chain = N->getOperand(0);
2107 SDValue N1 = N->getOperand(1);
2108 SDValue N2 = N->getOperand(2);
2109 SDValue N3 = N->getOperand(3);
2110 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002111 assert(N1.getOpcode() == ISD::BasicBlock);
2112 assert(N2.getOpcode() == ISD::Constant);
2113 assert(N3.getOpcode() == ISD::Register);
2114
Dan Gohman475871a2008-07-27 21:46:04 +00002115 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002116 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002117 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002118 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002119 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2120 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002121 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002122 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002123 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002124 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002125 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002126 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002127 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002128 return NULL;
2129 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002130 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002131 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002132 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002133 EVT VT = N->getValueType(0);
2134 SDValue N0 = N->getOperand(0);
2135 SDValue N1 = N->getOperand(1);
2136 SDValue N2 = N->getOperand(2);
2137 SDValue N3 = N->getOperand(3);
2138 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002139 assert(N2.getOpcode() == ISD::Constant);
2140 assert(N3.getOpcode() == ISD::Register);
2141
Dan Gohman475871a2008-07-27 21:46:04 +00002142 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002143 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002144 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002145 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002146 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002147 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002148 default: assert(false && "Illegal conditional move type!");
2149 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002150 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002151 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002152 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002153 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002154 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002155 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002156 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002157 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002158 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002159
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002160 case ARMISD::VZIP: {
2161 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002162 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002163 switch (VT.getSimpleVT().SimpleTy) {
2164 default: return NULL;
2165 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2166 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2167 case MVT::v2f32:
2168 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2169 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2170 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2171 case MVT::v4f32:
2172 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2173 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002174 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002175 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2176 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2177 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002178 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002179 case ARMISD::VUZP: {
2180 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002181 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002182 switch (VT.getSimpleVT().SimpleTy) {
2183 default: return NULL;
2184 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2185 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2186 case MVT::v2f32:
2187 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2188 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2189 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2190 case MVT::v4f32:
2191 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2192 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002193 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002194 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2195 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2196 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002197 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002198 case ARMISD::VTRN: {
2199 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002200 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002201 switch (VT.getSimpleVT().SimpleTy) {
2202 default: return NULL;
2203 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2204 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2205 case MVT::v2f32:
2206 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2207 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2208 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2209 case MVT::v4f32:
2210 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2211 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002212 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002213 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2214 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2215 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002216 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002217
2218 case ISD::INTRINSIC_VOID:
2219 case ISD::INTRINSIC_W_CHAIN: {
2220 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002221 switch (IntNo) {
2222 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002223 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002224
Bob Wilson621f1952010-03-23 05:25:43 +00002225 case Intrinsic::arm_neon_vld1: {
2226 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2227 ARM::VLD1d32, ARM::VLD1d64 };
2228 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2229 ARM::VLD1q32, ARM::VLD1q64 };
2230 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2231 }
2232
Bob Wilson31fb12f2009-08-26 17:39:53 +00002233 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002234 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002235 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002236 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002237 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002238 }
2239
2240 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002241 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002242 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002243 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2244 ARM::VLD3q16_UPD,
2245 ARM::VLD3q32_UPD };
2246 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2247 ARM::VLD3q16odd_UPD,
2248 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002249 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002250 }
2251
2252 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002253 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002254 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002255 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2256 ARM::VLD4q16_UPD,
2257 ARM::VLD4q32_UPD };
2258 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2259 ARM::VLD4q16odd_UPD,
2260 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002261 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002262 }
2263
Bob Wilson243fcc52009-09-01 04:26:28 +00002264 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002265 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002266 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2267 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002268 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002269 }
2270
2271 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002272 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002273 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2274 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002275 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002276 }
2277
2278 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002279 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002280 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2281 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002282 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002283 }
2284
Bob Wilson11d98992010-03-23 06:20:33 +00002285 case Intrinsic::arm_neon_vst1: {
2286 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2287 ARM::VST1d32, ARM::VST1d64 };
2288 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2289 ARM::VST1q32, ARM::VST1q64 };
2290 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2291 }
2292
Bob Wilson31fb12f2009-08-26 17:39:53 +00002293 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002294 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002295 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002296 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002297 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002298 }
2299
2300 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002301 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002302 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002303 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2304 ARM::VST3q16_UPD,
2305 ARM::VST3q32_UPD };
2306 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2307 ARM::VST3q16odd_UPD,
2308 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002309 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002310 }
2311
2312 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002313 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002314 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002315 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2316 ARM::VST4q16_UPD,
2317 ARM::VST4q32_UPD };
2318 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2319 ARM::VST4q16odd_UPD,
2320 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002321 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002322 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002323
2324 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002325 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002326 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2327 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002328 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002329 }
2330
2331 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002332 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002333 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2334 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002335 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002336 }
2337
2338 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002339 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002340 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2341 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002342 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002343 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002344 }
Bob Wilson429009b2010-05-06 16:05:26 +00002345 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002346 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002347
Bob Wilson429009b2010-05-06 16:05:26 +00002348 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002349 return SelectConcatVector(N);
2350 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002351
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002352 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002353}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002354
Bob Wilson224c2442009-05-19 05:53:42 +00002355bool ARMDAGToDAGISel::
2356SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2357 std::vector<SDValue> &OutOps) {
2358 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002359 // Require the address to be in a register. That is safe for all ARM
2360 // variants and it is hard to do anything much smarter without knowing
2361 // how the operand is used.
2362 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002363 return false;
2364}
2365
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002366/// createARMISelDag - This pass converts a legalized DAG into a
2367/// ARM-specific DAG, ready for instruction scheduling.
2368///
Bob Wilson522ce972009-09-28 14:30:20 +00002369FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2370 CodeGenOpt::Level OptLevel) {
2371 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002372}
Evan Chengde8aa4e2010-05-05 18:28:36 +00002373
2374/// ModelWithRegSequence - Return true if isel should use REG_SEQUENCE to model
2375/// operations involving sub-registers.
2376bool llvm::ModelWithRegSequence() {
2377 return UseRegSeq;
2378}