blob: 3bddca02c3fb64431dbddcb07aaa433587594280 [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
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000039//===--------------------------------------------------------------------===//
40/// ARMDAGToDAGISel - ARM specific code to select ARM machine
41/// instructions for SelectionDAG operations.
42///
43namespace {
44class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000045 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000046
Evan Chenga8e29892007-01-19 07:51:42 +000047 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
48 /// make the right decision when generating code for different targets.
49 const ARMSubtarget *Subtarget;
50
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000051public:
Bob Wilson522ce972009-09-28 14:30:20 +000052 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
53 CodeGenOpt::Level OptLevel)
54 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000055 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000056 }
57
Evan Chenga8e29892007-01-19 07:51:42 +000058 virtual const char *getPassName() const {
59 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000060 }
61
Bob Wilsonaf4a8912009-10-08 18:51:31 +000062 /// getI32Imm - Return a target constant of type i32 with the specified
63 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000064 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000065 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000066 }
67
Dan Gohmaneeb3a002010-01-05 01:24:18 +000068 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000069
Dan Gohmaneeb3a002010-01-05 01:24:18 +000070 bool SelectShifterOperandReg(SDNode *Op, SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000071 SDValue &B, SDValue &C);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000072 bool SelectAddrMode2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000073 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000074 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000075 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000076 bool SelectAddrMode3(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000078 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +000079 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000080 bool SelectAddrMode4(SDNode *Op, SDValue N, SDValue &Addr,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +000081 SDValue &Mode);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000082 bool SelectAddrMode5(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000083 SDValue &Offset);
Bob Wilson226036e2010-03-20 22:13:40 +000084 bool SelectAddrMode6(SDNode *Op, SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000085
Dan Gohmaneeb3a002010-01-05 01:24:18 +000086 bool SelectAddrModePC(SDNode *Op, SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +000087 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +000088
Dan Gohmaneeb3a002010-01-05 01:24:18 +000089 bool SelectThumbAddrModeRR(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000090 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000091 bool SelectThumbAddrModeRI5(SDNode *Op, SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +000092 SDValue &Base, SDValue &OffImm,
93 SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000094 bool SelectThumbAddrModeS1(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000095 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000096 bool SelectThumbAddrModeS2(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000097 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +000098 bool SelectThumbAddrModeS4(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +000099 SDValue &OffImm, SDValue &Offset);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000100 bool SelectThumbAddrModeSP(SDNode *Op, SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000101 SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000102
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000103 bool SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000104 SDValue &BaseReg, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000105 bool SelectT2AddrModeImm12(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000106 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000107 bool SelectT2AddrModeImm8(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000108 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000109 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000110 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000111 bool SelectT2AddrModeImm8s4(SDNode *Op, SDValue N, SDValue &Base,
David Goodwin6647cea2009-06-30 22:50:01 +0000112 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000113 bool SelectT2AddrModeSoReg(SDNode *Op, SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000114 SDValue &OffReg, SDValue &ShImm);
115
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000116 // Include the pieces autogenerated from the target description.
117#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000118
119private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000120 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
121 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000122 SDNode *SelectARMIndexedLoad(SDNode *N);
123 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000124
Bob Wilson621f1952010-03-23 05:25:43 +0000125 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
126 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000127 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000128 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000129 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000130 unsigned *QOpcodes0, unsigned *QOpcodes1);
131
Bob Wilson24f995d2009-10-14 18:32:29 +0000132 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000133 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000134 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000135 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000136 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000137 unsigned *QOpcodes0, unsigned *QOpcodes1);
138
Bob Wilson96493442009-10-14 16:46:45 +0000139 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000140 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson96493442009-10-14 16:46:45 +0000141 /// load/store of D registers and even subregs and odd subregs of Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000142 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson96493442009-10-14 16:46:45 +0000143 unsigned *DOpcodes, unsigned *QOpcodes0,
144 unsigned *QOpcodes1);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000145
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000146 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000147 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000148
Evan Cheng07ba9062009-11-19 21:45:22 +0000149 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000150 SDNode *SelectCMOVOp(SDNode *N);
151 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000152 ARMCC::CondCodes CCVal, SDValue CCR,
153 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000154 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000155 ARMCC::CondCodes CCVal, SDValue CCR,
156 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000157 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000158 ARMCC::CondCodes CCVal, SDValue CCR,
159 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000160 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000161 ARMCC::CondCodes CCVal, SDValue CCR,
162 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000163
Evan Chengde8aa4e2010-05-05 18:28:36 +0000164 SDNode *SelectConcatVector(SDNode *N);
165
Evan Chengaf4550f2009-07-02 01:23:32 +0000166 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
167 /// inline asm expressions.
168 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
169 char ConstraintCode,
170 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000171
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000172 // Form pairs of consecutive S, D, or Q registers.
173 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000174 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000175 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
176
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000177 // Form sequences of 4 consecutive S, D, or Q registers.
178 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000179 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000180 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
181
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000182 // Form sequences of 8 consecutive D registers.
Evan Cheng5c6aba22010-05-14 18:54:59 +0000183 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
184 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000185};
Evan Chenga8e29892007-01-19 07:51:42 +0000186}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000187
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000188/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
189/// operand. If so Imm will receive the 32-bit value.
190static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
191 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
192 Imm = cast<ConstantSDNode>(N)->getZExtValue();
193 return true;
194 }
195 return false;
196}
197
198// isInt32Immediate - This method tests to see if a constant operand.
199// If so Imm will receive the 32 bit value.
200static bool isInt32Immediate(SDValue N, unsigned &Imm) {
201 return isInt32Immediate(N.getNode(), Imm);
202}
203
204// isOpcWithIntImmediate - This method tests to see if the node is a specific
205// opcode and that it has a immediate integer right operand.
206// If so Imm will receive the 32 bit value.
207static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
208 return N->getOpcode() == Opc &&
209 isInt32Immediate(N->getOperand(1).getNode(), Imm);
210}
211
212
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000213bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000214 SDValue N,
215 SDValue &BaseReg,
216 SDValue &ShReg,
217 SDValue &Opc) {
218 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
219
220 // Don't match base register only case. That is matched to a separate
221 // lower complexity pattern with explicit register operand.
222 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000223
Evan Cheng055b0312009-06-29 07:51:04 +0000224 BaseReg = N.getOperand(0);
225 unsigned ShImmVal = 0;
226 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000227 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000228 ShImmVal = RHS->getZExtValue() & 31;
229 } else {
230 ShReg = N.getOperand(1);
231 }
232 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000233 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000234 return true;
235}
236
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000237bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000238 SDValue &Base, SDValue &Offset,
239 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000240 if (N.getOpcode() == ISD::MUL) {
241 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
242 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000243 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000244 if (RHSC & 1) {
245 RHSC = RHSC & ~1;
246 ARM_AM::AddrOpc AddSub = ARM_AM::add;
247 if (RHSC < 0) {
248 AddSub = ARM_AM::sub;
249 RHSC = - RHSC;
250 }
251 if (isPowerOf2_32(RHSC)) {
252 unsigned ShAmt = Log2_32(RHSC);
253 Base = Offset = N.getOperand(0);
254 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
255 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000256 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000257 return true;
258 }
259 }
260 }
261 }
262
Evan Chenga8e29892007-01-19 07:51:42 +0000263 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
264 Base = N;
265 if (N.getOpcode() == ISD::FrameIndex) {
266 int FI = cast<FrameIndexSDNode>(N)->getIndex();
267 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000268 } else if (N.getOpcode() == ARMISD::Wrapper &&
269 !(Subtarget->useMovt() &&
270 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000271 Base = N.getOperand(0);
272 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000273 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000274 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
275 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000276 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000277 return true;
278 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000279
Evan Chenga8e29892007-01-19 07:51:42 +0000280 // Match simple R +/- imm12 operands.
281 if (N.getOpcode() == ISD::ADD)
282 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000283 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000284 if ((RHSC >= 0 && RHSC < 0x1000) ||
285 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000286 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000287 if (Base.getOpcode() == ISD::FrameIndex) {
288 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
289 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
290 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000291 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000292
293 ARM_AM::AddrOpc AddSub = ARM_AM::add;
294 if (RHSC < 0) {
295 AddSub = ARM_AM::sub;
296 RHSC = - RHSC;
297 }
298 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000299 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000300 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000301 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000302 }
Evan Chenga8e29892007-01-19 07:51:42 +0000303 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000304
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000305 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000306 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
307 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
308 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000309
Evan Chenga8e29892007-01-19 07:51:42 +0000310 Base = N.getOperand(0);
311 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000312
Evan Chenga8e29892007-01-19 07:51:42 +0000313 if (ShOpcVal != ARM_AM::no_shift) {
314 // Check to see if the RHS of the shift is a constant, if not, we can't fold
315 // it.
316 if (ConstantSDNode *Sh =
317 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000318 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000319 Offset = N.getOperand(1).getOperand(0);
320 } else {
321 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000322 }
323 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000324
Evan Chenga8e29892007-01-19 07:51:42 +0000325 // Try matching (R shl C) + (R).
326 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
327 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
328 if (ShOpcVal != ARM_AM::no_shift) {
329 // Check to see if the RHS of the shift is a constant, if not, we can't
330 // fold it.
331 if (ConstantSDNode *Sh =
332 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000333 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000334 Offset = N.getOperand(0).getOperand(0);
335 Base = N.getOperand(1);
336 } else {
337 ShOpcVal = ARM_AM::no_shift;
338 }
339 }
340 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000341
Evan Chenga8e29892007-01-19 07:51:42 +0000342 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000343 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000344 return true;
345}
346
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000347bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000348 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000349 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000350 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
351 ? cast<LoadSDNode>(Op)->getAddressingMode()
352 : cast<StoreSDNode>(Op)->getAddressingMode();
353 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
354 ? ARM_AM::add : ARM_AM::sub;
355 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000356 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000357 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000358 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000359 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
360 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000361 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000362 return true;
363 }
364 }
365
366 Offset = N;
367 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
368 unsigned ShAmt = 0;
369 if (ShOpcVal != ARM_AM::no_shift) {
370 // Check to see if the RHS of the shift is a constant, if not, we can't fold
371 // it.
372 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000373 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000374 Offset = N.getOperand(0);
375 } else {
376 ShOpcVal = ARM_AM::no_shift;
377 }
378 }
379
380 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000381 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000382 return true;
383}
384
Evan Chenga8e29892007-01-19 07:51:42 +0000385
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000386bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000387 SDValue &Base, SDValue &Offset,
388 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000389 if (N.getOpcode() == ISD::SUB) {
390 // X - C is canonicalize to X + -C, no need to handle it here.
391 Base = N.getOperand(0);
392 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000393 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000394 return true;
395 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000396
Evan Chenga8e29892007-01-19 07:51:42 +0000397 if (N.getOpcode() != ISD::ADD) {
398 Base = N;
399 if (N.getOpcode() == ISD::FrameIndex) {
400 int FI = cast<FrameIndexSDNode>(N)->getIndex();
401 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
402 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000403 Offset = CurDAG->getRegister(0, MVT::i32);
404 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000405 return true;
406 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000407
Evan Chenga8e29892007-01-19 07:51:42 +0000408 // If the RHS is +/- imm8, fold into addr mode.
409 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000410 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000411 if ((RHSC >= 0 && RHSC < 256) ||
412 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000413 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000414 if (Base.getOpcode() == ISD::FrameIndex) {
415 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
416 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
417 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000418 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000419
420 ARM_AM::AddrOpc AddSub = ARM_AM::add;
421 if (RHSC < 0) {
422 AddSub = ARM_AM::sub;
423 RHSC = - RHSC;
424 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000425 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000426 return true;
427 }
428 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000429
Evan Chenga8e29892007-01-19 07:51:42 +0000430 Base = N.getOperand(0);
431 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000432 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000433 return true;
434}
435
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000436bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000437 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000438 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000439 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
440 ? cast<LoadSDNode>(Op)->getAddressingMode()
441 : cast<StoreSDNode>(Op)->getAddressingMode();
442 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
443 ? ARM_AM::add : ARM_AM::sub;
444 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000445 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000446 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000447 Offset = CurDAG->getRegister(0, MVT::i32);
448 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000449 return true;
450 }
451 }
452
453 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000454 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000455 return true;
456}
457
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000458bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000459 SDValue &Addr, SDValue &Mode) {
460 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000461 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000462 return true;
463}
Evan Chenga8e29892007-01-19 07:51:42 +0000464
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000465bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000466 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000467 if (N.getOpcode() != ISD::ADD) {
468 Base = N;
469 if (N.getOpcode() == ISD::FrameIndex) {
470 int FI = cast<FrameIndexSDNode>(N)->getIndex();
471 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000472 } else if (N.getOpcode() == ARMISD::Wrapper &&
473 !(Subtarget->useMovt() &&
474 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000475 Base = N.getOperand(0);
476 }
477 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000478 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000479 return true;
480 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000481
Evan Chenga8e29892007-01-19 07:51:42 +0000482 // If the RHS is +/- imm8, fold into addr mode.
483 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000484 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000485 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
486 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000487 if ((RHSC >= 0 && RHSC < 256) ||
488 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000489 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000490 if (Base.getOpcode() == ISD::FrameIndex) {
491 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
492 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
493 }
494
495 ARM_AM::AddrOpc AddSub = ARM_AM::add;
496 if (RHSC < 0) {
497 AddSub = ARM_AM::sub;
498 RHSC = - RHSC;
499 }
500 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000501 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000502 return true;
503 }
504 }
505 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000506
Evan Chenga8e29892007-01-19 07:51:42 +0000507 Base = N;
508 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000509 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000510 return true;
511}
512
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000513bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000514 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000515 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000516 // Default to no alignment.
517 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000518 return true;
519}
520
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000521bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000522 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000523 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
524 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000525 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000526 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000527 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000528 return true;
529 }
530 return false;
531}
532
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000533bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000534 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000535 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000536 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000537 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000538 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000539 return false;
540
541 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000542 return true;
543 }
544
Evan Chenga8e29892007-01-19 07:51:42 +0000545 Base = N.getOperand(0);
546 Offset = N.getOperand(1);
547 return true;
548}
549
Evan Cheng79d43262007-01-24 02:21:22 +0000550bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000551ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000552 unsigned Scale, SDValue &Base,
553 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000554 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000555 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000556 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
557 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000558 if (N.getOpcode() == ARMISD::Wrapper &&
559 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
560 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000561 }
562
Evan Chenga8e29892007-01-19 07:51:42 +0000563 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000564 if (N.getOpcode() == ARMISD::Wrapper &&
565 !(Subtarget->useMovt() &&
566 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
567 Base = N.getOperand(0);
568 } else
569 Base = N;
570
Owen Anderson825b72b2009-08-11 20:47:22 +0000571 Offset = CurDAG->getRegister(0, MVT::i32);
572 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000573 return true;
574 }
575
Evan Chengad0e4652007-02-06 00:22:06 +0000576 // Thumb does not have [sp, r] address mode.
577 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
578 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
579 if ((LHSR && LHSR->getReg() == ARM::SP) ||
580 (RHSR && RHSR->getReg() == ARM::SP)) {
581 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000582 Offset = CurDAG->getRegister(0, MVT::i32);
583 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000584 return true;
585 }
586
Evan Chenga8e29892007-01-19 07:51:42 +0000587 // If the RHS is + imm5 * scale, fold into addr mode.
588 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000589 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000590 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
591 RHSC /= Scale;
592 if (RHSC >= 0 && RHSC < 32) {
593 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000594 Offset = CurDAG->getRegister(0, MVT::i32);
595 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000596 return true;
597 }
598 }
599 }
600
Evan Chengc38f2bc2007-01-23 22:59:13 +0000601 Base = N.getOperand(0);
602 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000604 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000605}
606
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000607bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000608 SDValue &Base, SDValue &OffImm,
609 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000610 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000611}
612
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000613bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000614 SDValue &Base, SDValue &OffImm,
615 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000616 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000617}
618
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000619bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000620 SDValue &Base, SDValue &OffImm,
621 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000622 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000623}
624
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000625bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000626 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000627 if (N.getOpcode() == ISD::FrameIndex) {
628 int FI = cast<FrameIndexSDNode>(N)->getIndex();
629 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000630 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000631 return true;
632 }
Evan Cheng79d43262007-01-24 02:21:22 +0000633
Evan Chengad0e4652007-02-06 00:22:06 +0000634 if (N.getOpcode() != ISD::ADD)
635 return false;
636
637 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000638 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
639 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000640 // If the RHS is + imm8 * scale, fold into addr mode.
641 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000642 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000643 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
644 RHSC >>= 2;
645 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000646 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000647 if (Base.getOpcode() == ISD::FrameIndex) {
648 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
649 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
650 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000651 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000652 return true;
653 }
654 }
655 }
656 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000657
Evan Chenga8e29892007-01-19 07:51:42 +0000658 return false;
659}
660
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000661bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000662 SDValue &BaseReg,
663 SDValue &Opc) {
664 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
665
666 // Don't match base register only case. That is matched to a separate
667 // lower complexity pattern with explicit register operand.
668 if (ShOpcVal == ARM_AM::no_shift) return false;
669
670 BaseReg = N.getOperand(0);
671 unsigned ShImmVal = 0;
672 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
673 ShImmVal = RHS->getZExtValue() & 31;
674 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
675 return true;
676 }
677
678 return false;
679}
680
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000681bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000682 SDValue &Base, SDValue &OffImm) {
683 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000684
Evan Cheng3a214252009-08-11 08:52:18 +0000685 // Base only.
686 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000687 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000688 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000689 int FI = cast<FrameIndexSDNode>(N)->getIndex();
690 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000691 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000692 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000693 } else if (N.getOpcode() == ARMISD::Wrapper &&
694 !(Subtarget->useMovt() &&
695 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000696 Base = N.getOperand(0);
697 if (Base.getOpcode() == ISD::TargetConstantPool)
698 return false; // We want to select t2LDRpci instead.
699 } else
700 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000701 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000702 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000703 }
Evan Cheng055b0312009-06-29 07:51:04 +0000704
705 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000706 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
707 // Let t2LDRi8 handle (R - imm8).
708 return false;
709
Evan Cheng055b0312009-06-29 07:51:04 +0000710 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000711 if (N.getOpcode() == ISD::SUB)
712 RHSC = -RHSC;
713
714 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000715 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000716 if (Base.getOpcode() == ISD::FrameIndex) {
717 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
718 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
719 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000720 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000721 return true;
722 }
723 }
724
Evan Cheng3a214252009-08-11 08:52:18 +0000725 // Base only.
726 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000727 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000728 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000729}
730
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000731bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000732 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000733 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000734 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000735 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
736 int RHSC = (int)RHS->getSExtValue();
737 if (N.getOpcode() == ISD::SUB)
738 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000739
Evan Cheng3a214252009-08-11 08:52:18 +0000740 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
741 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000742 if (Base.getOpcode() == ISD::FrameIndex) {
743 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
744 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
745 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000746 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000747 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000748 }
Evan Cheng055b0312009-06-29 07:51:04 +0000749 }
750 }
751
752 return false;
753}
754
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000755bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000756 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000757 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000758 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
759 ? cast<LoadSDNode>(Op)->getAddressingMode()
760 : cast<StoreSDNode>(Op)->getAddressingMode();
761 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
762 int RHSC = (int)RHS->getZExtValue();
763 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000764 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000765 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
766 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000767 return true;
768 }
769 }
770
771 return false;
772}
773
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000774bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000775 SDValue &Base, SDValue &OffImm) {
776 if (N.getOpcode() == ISD::ADD) {
777 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
778 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000779 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000780 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000781 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000782 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000783 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000784 return true;
785 }
786 }
787 } else if (N.getOpcode() == ISD::SUB) {
788 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
789 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000790 // 8 bits.
791 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
David Goodwin6647cea2009-06-30 22:50:01 +0000792 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000793 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000794 return true;
795 }
796 }
797 }
798
799 return false;
800}
801
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000802bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000803 SDValue &Base,
804 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000805 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
806 if (N.getOpcode() != ISD::ADD)
807 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000808
Evan Cheng3a214252009-08-11 08:52:18 +0000809 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
810 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
811 int RHSC = (int)RHS->getZExtValue();
812 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
813 return false;
814 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000815 return false;
816 }
817
Evan Cheng055b0312009-06-29 07:51:04 +0000818 // Look for (R + R) or (R + (R << [1,2,3])).
819 unsigned ShAmt = 0;
820 Base = N.getOperand(0);
821 OffReg = N.getOperand(1);
822
823 // Swap if it is ((R << c) + R).
824 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
825 if (ShOpcVal != ARM_AM::lsl) {
826 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
827 if (ShOpcVal == ARM_AM::lsl)
828 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000829 }
830
Evan Cheng055b0312009-06-29 07:51:04 +0000831 if (ShOpcVal == ARM_AM::lsl) {
832 // Check to see if the RHS of the shift is a constant, if not, we can't fold
833 // it.
834 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
835 ShAmt = Sh->getZExtValue();
836 if (ShAmt >= 4) {
837 ShAmt = 0;
838 ShOpcVal = ARM_AM::no_shift;
839 } else
840 OffReg = OffReg.getOperand(0);
841 } else {
842 ShOpcVal = ARM_AM::no_shift;
843 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000844 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000845
Owen Anderson825b72b2009-08-11 20:47:22 +0000846 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000847
848 return true;
849}
850
851//===--------------------------------------------------------------------===//
852
Evan Chengee568cf2007-07-05 07:15:27 +0000853/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000854static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000855 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000856}
857
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000858SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
859 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000860 ISD::MemIndexedMode AM = LD->getAddressingMode();
861 if (AM == ISD::UNINDEXED)
862 return NULL;
863
Owen Andersone50ed302009-08-10 22:56:29 +0000864 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 SDValue Offset, AMOpc;
866 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
867 unsigned Opcode = 0;
868 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000869 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000870 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000871 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
872 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000874 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000875 Match = true;
876 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
877 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
878 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000880 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000881 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000882 Match = true;
883 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
884 }
885 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Match = true;
888 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
889 }
890 }
891 }
892
893 if (Match) {
894 SDValue Chain = LD->getChain();
895 SDValue Base = LD->getBasePtr();
896 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000897 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000898 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000899 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000900 }
901
902 return NULL;
903}
904
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000905SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
906 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000907 ISD::MemIndexedMode AM = LD->getAddressingMode();
908 if (AM == ISD::UNINDEXED)
909 return NULL;
910
Owen Andersone50ed302009-08-10 22:56:29 +0000911 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000912 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000913 SDValue Offset;
914 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
915 unsigned Opcode = 0;
916 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000917 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000918 switch (LoadedVT.getSimpleVT().SimpleTy) {
919 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000920 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
921 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000922 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000923 if (isSExtLd)
924 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
925 else
926 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000927 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000928 case MVT::i8:
929 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000930 if (isSExtLd)
931 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
932 else
933 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000934 break;
935 default:
936 return NULL;
937 }
938 Match = true;
939 }
940
941 if (Match) {
942 SDValue Chain = LD->getChain();
943 SDValue Base = LD->getBasePtr();
944 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000945 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000946 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000947 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000948 }
949
950 return NULL;
951}
952
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000953/// PairSRegs - Form a D register from a pair of S registers.
954///
955SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
956 DebugLoc dl = V0.getNode()->getDebugLoc();
957 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
958 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000959 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
960 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000961}
962
Evan Cheng603afbf2010-05-10 17:34:18 +0000963/// PairDRegs - Form a quad register from a pair of D registers.
964///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000965SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
966 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000967 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
968 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000969 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
970 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000971}
972
Evan Cheng7f687192010-05-14 00:21:45 +0000973/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000974///
975SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
976 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000977 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
978 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000979 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
980 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
981}
982
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000983/// QuadSRegs - Form 4 consecutive S registers.
984///
985SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
986 SDValue V2, SDValue V3) {
987 DebugLoc dl = V0.getNode()->getDebugLoc();
988 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
989 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
990 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
991 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
992 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
993 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
994}
995
Evan Cheng7f687192010-05-14 00:21:45 +0000996/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000997///
998SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
999 SDValue V2, SDValue V3) {
1000 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001001 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1002 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1003 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1004 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001005 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1006 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1007}
1008
Evan Cheng8f6de382010-05-16 03:27:48 +00001009/// QuadQRegs - Form 4 consecutive Q registers.
1010///
1011SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1012 SDValue V2, SDValue V3) {
1013 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001014 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1015 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1016 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1017 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001018 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1019 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1020}
1021
Evan Cheng5c6aba22010-05-14 18:54:59 +00001022/// OctoDRegs - Form 8 consecutive D registers.
1023///
1024SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1025 SDValue V2, SDValue V3,
1026 SDValue V4, SDValue V5,
1027 SDValue V6, SDValue V7) {
1028 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001029 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1030 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1031 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1032 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1033 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1034 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1035 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1036 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001037 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1038 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1039 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1040}
1041
Bob Wilsona7c397c2009-10-14 16:19:03 +00001042/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1043/// for a 64-bit subregister of the vector.
1044static EVT GetNEONSubregVT(EVT VT) {
1045 switch (VT.getSimpleVT().SimpleTy) {
1046 default: llvm_unreachable("unhandled NEON type");
1047 case MVT::v16i8: return MVT::v8i8;
1048 case MVT::v8i16: return MVT::v4i16;
1049 case MVT::v4f32: return MVT::v2f32;
1050 case MVT::v4i32: return MVT::v2i32;
1051 case MVT::v2i64: return MVT::v1i64;
1052 }
1053}
1054
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001055SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001056 unsigned *DOpcodes, unsigned *QOpcodes0,
1057 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001058 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001059 DebugLoc dl = N->getDebugLoc();
1060
Bob Wilson226036e2010-03-20 22:13:40 +00001061 SDValue MemAddr, Align;
1062 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001063 return NULL;
1064
1065 SDValue Chain = N->getOperand(0);
1066 EVT VT = N->getValueType(0);
1067 bool is64BitVector = VT.is64BitVector();
1068
1069 unsigned OpcodeIndex;
1070 switch (VT.getSimpleVT().SimpleTy) {
1071 default: llvm_unreachable("unhandled vld type");
1072 // Double-register operations:
1073 case MVT::v8i8: OpcodeIndex = 0; break;
1074 case MVT::v4i16: OpcodeIndex = 1; break;
1075 case MVT::v2f32:
1076 case MVT::v2i32: OpcodeIndex = 2; break;
1077 case MVT::v1i64: OpcodeIndex = 3; break;
1078 // Quad-register operations:
1079 case MVT::v16i8: OpcodeIndex = 0; break;
1080 case MVT::v8i16: OpcodeIndex = 1; break;
1081 case MVT::v4f32:
1082 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001083 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001084 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001085 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001086 }
1087
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001088 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001089 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001090 if (is64BitVector) {
1091 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001092 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001093 std::vector<EVT> ResTys(NumVecs, VT);
1094 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001095 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson07f6e802010-06-16 21:34:01 +00001096 if (NumVecs < 2)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001097 return VLd;
1098
Evan Cheng0ce537a2010-05-11 01:19:40 +00001099 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001100 SDValue V0 = SDValue(VLd, 0);
1101 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001102
Evan Cheng0ce537a2010-05-11 01:19:40 +00001103 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001104 if (NumVecs == 2)
1105 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1106 else {
1107 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001108 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001109 SDValue V3 = (NumVecs == 3)
1110 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1111 : SDValue(VLd, 3);
1112 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1113 }
1114
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001115 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001116 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001117 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001118 dl, VT, RegSeq);
1119 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001120 }
1121 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1122 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001123 }
1124
1125 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001126 if (NumVecs <= 2) {
1127 // Quad registers are directly supported for VLD1 and VLD2,
1128 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001129 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001130 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001131 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001132 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001133 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001134 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001135
1136 // Combine the even and odd subregs to produce the result.
Bob Wilson07f6e802010-06-16 21:34:01 +00001137 if (NumVecs == 1) {
1138 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1139 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
Evan Cheng603afbf2010-05-10 17:34:18 +00001140 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001141 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1142 SDValue(VLd, 0), SDValue(VLd, 1),
1143 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1144 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1145 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
1146 ReplaceUses(SDValue(N, 0), Q0);
1147 ReplaceUses(SDValue(N, 1), Q1);
Bob Wilson3e36f132009-10-14 17:28:52 +00001148 }
1149 } else {
1150 // Otherwise, quad registers are loaded with two separate instructions,
1151 // where one loads the even registers and the other loads the odd registers.
1152
Bob Wilson3e36f132009-10-14 17:28:52 +00001153 std::vector<EVT> ResTys(NumVecs, RegVT);
1154 ResTys.push_back(MemAddr.getValueType());
1155 ResTys.push_back(MVT::Other);
1156
Bob Wilson24f995d2009-10-14 18:32:29 +00001157 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001158 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001159 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1160 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001161 Chain = SDValue(VLdA, NumVecs+1);
1162
Bob Wilson24f995d2009-10-14 18:32:29 +00001163 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001164 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001165 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1166 Align, Reg0, Pred, Reg0, Chain };
1167 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001168 Chain = SDValue(VLdB, NumVecs+1);
1169
Bob Wilson07f6e802010-06-16 21:34:01 +00001170 SDValue V0 = SDValue(VLdA, 0);
1171 SDValue V1 = SDValue(VLdB, 0);
1172 SDValue V2 = SDValue(VLdA, 1);
1173 SDValue V3 = SDValue(VLdB, 1);
1174 SDValue V4 = SDValue(VLdA, 2);
1175 SDValue V5 = SDValue(VLdB, 2);
1176 SDValue V6 = (NumVecs == 3)
1177 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1178 : SDValue(VLdA, 3);
1179 SDValue V7 = (NumVecs == 3)
1180 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1181 : SDValue(VLdB, 3);
1182 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1183 V4, V5, V6, V7), 0);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001184
Bob Wilson07f6e802010-06-16 21:34:01 +00001185 // Extract out the 3 / 4 Q registers.
1186 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1187 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1188 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1189 dl, VT, RegSeq);
1190 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001191 }
1192 }
1193 ReplaceUses(SDValue(N, NumVecs), Chain);
1194 return NULL;
1195}
1196
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001197SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001198 unsigned *DOpcodes, unsigned *QOpcodes0,
1199 unsigned *QOpcodes1) {
Bob Wilson11d98992010-03-23 06:20:33 +00001200 assert(NumVecs >=1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001201 DebugLoc dl = N->getDebugLoc();
1202
Bob Wilson226036e2010-03-20 22:13:40 +00001203 SDValue MemAddr, Align;
1204 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001205 return NULL;
1206
1207 SDValue Chain = N->getOperand(0);
1208 EVT VT = N->getOperand(3).getValueType();
1209 bool is64BitVector = VT.is64BitVector();
1210
1211 unsigned OpcodeIndex;
1212 switch (VT.getSimpleVT().SimpleTy) {
1213 default: llvm_unreachable("unhandled vst type");
1214 // Double-register operations:
1215 case MVT::v8i8: OpcodeIndex = 0; break;
1216 case MVT::v4i16: OpcodeIndex = 1; break;
1217 case MVT::v2f32:
1218 case MVT::v2i32: OpcodeIndex = 2; break;
1219 case MVT::v1i64: OpcodeIndex = 3; break;
1220 // Quad-register operations:
1221 case MVT::v16i8: OpcodeIndex = 0; break;
1222 case MVT::v8i16: OpcodeIndex = 1; break;
1223 case MVT::v4f32:
1224 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001225 case MVT::v2i64: OpcodeIndex = 3;
1226 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1227 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001228 }
1229
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001230 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001231 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001232
Bob Wilson226036e2010-03-20 22:13:40 +00001233 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001234 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001235 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001236
1237 if (is64BitVector) {
Bob Wilson07f6e802010-06-16 21:34:01 +00001238 if (NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001239 SDValue RegSeq;
1240 SDValue V0 = N->getOperand(0+3);
1241 SDValue V1 = N->getOperand(1+3);
1242
1243 // Form a REG_SEQUENCE to force register allocation.
1244 if (NumVecs == 2)
1245 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1246 else {
1247 SDValue V2 = N->getOperand(2+3);
1248 // If it's a vld3, form a quad D-register and leave the last part as
1249 // an undef.
1250 SDValue V3 = (NumVecs == 3)
1251 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1252 : N->getOperand(3+3);
1253 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1254 }
1255
1256 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001257 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001258 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001259 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001260 RegSeq));
1261 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001262 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001263 RegSeq));
1264 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001265 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001266 RegSeq));
1267 } else {
1268 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1269 Ops.push_back(N->getOperand(Vec+3));
1270 }
Evan Chengac0869d2009-11-21 06:21:52 +00001271 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001272 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001273 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001274 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001275 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001276 }
1277
1278 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001279 if (NumVecs <= 2) {
1280 // Quad registers are directly supported for VST1 and VST2,
1281 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001282 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001283 if (NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001284 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001285 SDValue Q0 = N->getOperand(3);
1286 SDValue Q1 = N->getOperand(4);
1287
1288 // Form a QQ register.
1289 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1290
1291 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001292 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001293 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001294 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001295 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001296 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001297 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001298 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001299 QQ));
1300 Ops.push_back(Pred);
1301 Ops.push_back(Reg0); // predicate register
1302 Ops.push_back(Chain);
1303 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1304 } else {
1305 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001306 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001307 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001308 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001309 N->getOperand(Vec+3)));
1310 }
1311 Ops.push_back(Pred);
1312 Ops.push_back(Reg0); // predicate register
1313 Ops.push_back(Chain);
1314 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1315 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001316 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001317 }
1318
1319 // Otherwise, quad registers are stored with two separate instructions,
1320 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001321
Bob Wilson07f6e802010-06-16 21:34:01 +00001322 // Form the QQQQ REG_SEQUENCE.
1323 SDValue V[8];
1324 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1325 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1326 N->getOperand(Vec+3));
1327 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1328 N->getOperand(Vec+3));
Evan Cheng12c24692010-05-14 22:54:52 +00001329 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001330 if (NumVecs == 3)
1331 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1332 dl, RegVT), 0);
1333
1334 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1335 V[4], V[5], V[6], V[7]), 0);
1336
1337 // Store the even D registers.
1338 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1339 Ops.push_back(Reg0); // post-access address offset
1340 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1341 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1342 RegVT, RegSeq));
1343 Ops.push_back(Pred);
1344 Ops.push_back(Reg0); // predicate register
1345 Ops.push_back(Chain);
1346 unsigned Opc = QOpcodes0[OpcodeIndex];
1347 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1348 MVT::Other, Ops.data(), NumVecs+6);
1349 Chain = SDValue(VStA, 1);
1350
1351 // Store the odd D registers.
1352 Ops[0] = SDValue(VStA, 0); // MemAddr
1353 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1354 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1355 RegVT, RegSeq);
1356 Ops[NumVecs+5] = Chain;
1357 Opc = QOpcodes1[OpcodeIndex];
1358 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1359 MVT::Other, Ops.data(), NumVecs+6);
1360 Chain = SDValue(VStB, 1);
1361 ReplaceUses(SDValue(N, 0), Chain);
1362 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001363}
1364
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001365SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001366 unsigned NumVecs, unsigned *DOpcodes,
1367 unsigned *QOpcodes0,
1368 unsigned *QOpcodes1) {
1369 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001370 DebugLoc dl = N->getDebugLoc();
1371
Bob Wilson226036e2010-03-20 22:13:40 +00001372 SDValue MemAddr, Align;
1373 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001374 return NULL;
1375
1376 SDValue Chain = N->getOperand(0);
1377 unsigned Lane =
1378 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001379 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001380 bool is64BitVector = VT.is64BitVector();
1381
Bob Wilson96493442009-10-14 16:46:45 +00001382 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001383 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001384 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001385 EVT RegVT = VT;
1386 if (!is64BitVector) {
1387 RegVT = GetNEONSubregVT(VT);
1388 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001389 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001390 }
1391
1392 unsigned OpcodeIndex;
1393 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001394 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001395 // Double-register operations:
1396 case MVT::v8i8: OpcodeIndex = 0; break;
1397 case MVT::v4i16: OpcodeIndex = 1; break;
1398 case MVT::v2f32:
1399 case MVT::v2i32: OpcodeIndex = 2; break;
1400 // Quad-register operations:
1401 case MVT::v8i16: OpcodeIndex = 0; break;
1402 case MVT::v4f32:
1403 case MVT::v4i32: OpcodeIndex = 1; break;
1404 }
1405
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001406 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001407 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001408
Bob Wilson226036e2010-03-20 22:13:40 +00001409 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001410 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001411 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001412
1413 unsigned Opc = 0;
1414 if (is64BitVector) {
1415 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001416 SDValue RegSeq;
1417 SDValue V0 = N->getOperand(0+3);
1418 SDValue V1 = N->getOperand(1+3);
1419 if (NumVecs == 2) {
1420 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001421 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001422 SDValue V2 = N->getOperand(2+3);
1423 SDValue V3 = (NumVecs == 3)
1424 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1425 : N->getOperand(3+3);
1426 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001427 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001428
1429 // Now extract the D registers back out.
1430 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1431 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1432 if (NumVecs > 2)
1433 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1434 if (NumVecs > 3)
1435 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001436 } else {
1437 // Check if this is loading the even or odd subreg of a Q register.
1438 if (Lane < NumElts) {
1439 Opc = QOpcodes0[OpcodeIndex];
1440 } else {
1441 Lane -= NumElts;
1442 Opc = QOpcodes1[OpcodeIndex];
1443 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001444
Bob Wilson07f6e802010-06-16 21:34:01 +00001445 SDValue RegSeq;
1446 SDValue V0 = N->getOperand(0+3);
1447 SDValue V1 = N->getOperand(1+3);
1448 if (NumVecs == 2) {
1449 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001450 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001451 SDValue V2 = N->getOperand(2+3);
1452 SDValue V3 = (NumVecs == 3)
1453 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1454 : N->getOperand(3+3);
1455 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001456 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001457
1458 // Extract the subregs of the input vector.
1459 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1460 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1461 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1462 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001463 }
1464 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001465 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001466 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001467 Ops.push_back(Chain);
1468
Bob Wilson96493442009-10-14 16:46:45 +00001469 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001470 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001471
Bob Wilsona7c397c2009-10-14 16:19:03 +00001472 std::vector<EVT> ResTys(NumVecs, RegVT);
1473 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001474 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1475
Bob Wilson07f6e802010-06-16 21:34:01 +00001476 // Form a REG_SEQUENCE to force register allocation.
1477 SDValue RegSeq;
1478 if (is64BitVector) {
1479 SDValue V0 = SDValue(VLdLn, 0);
1480 SDValue V1 = SDValue(VLdLn, 1);
1481 if (NumVecs == 2) {
1482 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001483 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001484 SDValue V2 = SDValue(VLdLn, 2);
1485 // If it's a vld3, form a quad D-register but discard the last part.
1486 SDValue V3 = (NumVecs == 3)
1487 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1488 : SDValue(VLdLn, 3);
1489 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001490 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001491 } else {
1492 // For 128-bit vectors, take the 64-bit results of the load and insert
1493 // them as subregs into the result.
1494 SDValue V[8];
1495 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1496 if (Even) {
1497 V[i] = SDValue(VLdLn, Vec);
1498 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1499 dl, RegVT), 0);
1500 } else {
1501 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1502 dl, RegVT), 0);
1503 V[i+1] = SDValue(VLdLn, Vec);
1504 }
1505 }
1506 if (NumVecs == 3)
1507 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1508 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001509
Bob Wilson07f6e802010-06-16 21:34:01 +00001510 if (NumVecs == 2)
1511 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1512 else
1513 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1514 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001515 }
1516
Bob Wilson07f6e802010-06-16 21:34:01 +00001517 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1518 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1519 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1520 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1521 ReplaceUses(SDValue(N, Vec),
1522 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1523 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001524 return NULL;
1525}
1526
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001527SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001528 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001529 if (!Subtarget->hasV6T2Ops())
1530 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001531
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001532 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1533 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1534
1535
1536 // For unsigned extracts, check for a shift right and mask
1537 unsigned And_imm = 0;
1538 if (N->getOpcode() == ISD::AND) {
1539 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1540
1541 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1542 if (And_imm & (And_imm + 1))
1543 return NULL;
1544
1545 unsigned Srl_imm = 0;
1546 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1547 Srl_imm)) {
1548 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1549
1550 unsigned Width = CountTrailingOnes_32(And_imm);
1551 unsigned LSB = Srl_imm;
1552 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1553 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1554 CurDAG->getTargetConstant(LSB, MVT::i32),
1555 CurDAG->getTargetConstant(Width, MVT::i32),
1556 getAL(CurDAG), Reg0 };
1557 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1558 }
1559 }
1560 return NULL;
1561 }
1562
1563 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001564 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001565 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001566 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1567 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001568 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001569 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1570 unsigned Width = 32 - Srl_imm;
1571 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001572 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001573 return NULL;
1574 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001575 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001576 CurDAG->getTargetConstant(LSB, MVT::i32),
1577 CurDAG->getTargetConstant(Width, MVT::i32),
1578 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001579 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001580 }
1581 }
1582 return NULL;
1583}
1584
Evan Cheng9ef48352009-11-20 00:54:03 +00001585SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001586SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001587 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1588 SDValue CPTmp0;
1589 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001590 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001591 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1592 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1593 unsigned Opc = 0;
1594 switch (SOShOp) {
1595 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1596 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1597 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1598 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1599 default:
1600 llvm_unreachable("Unknown so_reg opcode!");
1601 break;
1602 }
1603 SDValue SOShImm =
1604 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1605 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1606 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001607 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001608 }
1609 return 0;
1610}
1611
1612SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001613SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001614 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1615 SDValue CPTmp0;
1616 SDValue CPTmp1;
1617 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001618 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001619 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1620 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001621 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001622 }
1623 return 0;
1624}
1625
1626SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001627SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001628 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1629 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1630 if (!T)
1631 return 0;
1632
1633 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1634 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1635 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1636 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001637 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001638 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1639 }
1640 return 0;
1641}
1642
1643SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001644SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001645 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1646 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1647 if (!T)
1648 return 0;
1649
1650 if (Predicate_so_imm(TrueVal.getNode())) {
1651 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1652 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1653 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001654 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001655 ARM::MOVCCi, MVT::i32, Ops, 5);
1656 }
1657 return 0;
1658}
1659
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001660SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1661 EVT VT = N->getValueType(0);
1662 SDValue FalseVal = N->getOperand(0);
1663 SDValue TrueVal = N->getOperand(1);
1664 SDValue CC = N->getOperand(2);
1665 SDValue CCR = N->getOperand(3);
1666 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001667 assert(CC.getOpcode() == ISD::Constant);
1668 assert(CCR.getOpcode() == ISD::Register);
1669 ARMCC::CondCodes CCVal =
1670 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001671
1672 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1673 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1674 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1675 // Pattern complexity = 18 cost = 1 size = 0
1676 SDValue CPTmp0;
1677 SDValue CPTmp1;
1678 SDValue CPTmp2;
1679 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001680 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001681 CCVal, CCR, InFlag);
1682 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001683 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001684 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1685 if (Res)
1686 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001687 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001688 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001689 CCVal, CCR, InFlag);
1690 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001691 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001692 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1693 if (Res)
1694 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001695 }
1696
1697 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1698 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1699 // (imm:i32):$cc)
1700 // Emits: (MOVCCi:i32 GPR:i32:$false,
1701 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1702 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001703 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001704 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001705 CCVal, CCR, InFlag);
1706 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001707 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001708 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1709 if (Res)
1710 return Res;
1711 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001712 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001713 CCVal, CCR, InFlag);
1714 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001715 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001716 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1717 if (Res)
1718 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001719 }
1720 }
1721
1722 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1723 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1724 // Pattern complexity = 6 cost = 1 size = 0
1725 //
1726 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1727 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1728 // Pattern complexity = 6 cost = 11 size = 0
1729 //
1730 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001731 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1732 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001733 unsigned Opc = 0;
1734 switch (VT.getSimpleVT().SimpleTy) {
1735 default: assert(false && "Illegal conditional move type!");
1736 break;
1737 case MVT::i32:
1738 Opc = Subtarget->isThumb()
1739 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1740 : ARM::MOVCCr;
1741 break;
1742 case MVT::f32:
1743 Opc = ARM::VMOVScc;
1744 break;
1745 case MVT::f64:
1746 Opc = ARM::VMOVDcc;
1747 break;
1748 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001749 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001750}
1751
Evan Chengde8aa4e2010-05-05 18:28:36 +00001752SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1753 // The only time a CONCAT_VECTORS operation can have legal types is when
1754 // two 64-bit vectors are concatenated to a 128-bit vector.
1755 EVT VT = N->getValueType(0);
1756 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1757 llvm_unreachable("unexpected CONCAT_VECTORS");
1758 DebugLoc dl = N->getDebugLoc();
1759 SDValue V0 = N->getOperand(0);
1760 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001761 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1762 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001763 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1764 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1765}
1766
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001767SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001768 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001769
Dan Gohmane8be6c62008-07-17 19:10:17 +00001770 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001771 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001772
1773 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001774 default: break;
1775 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001776 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001777 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001778 if (Subtarget->hasThumb2())
1779 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1780 // be done with MOV + MOVT, at worst.
1781 UseCP = 0;
1782 else {
1783 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001784 UseCP = (Val > 255 && // MOV
1785 ~Val > 255 && // MOV + MVN
1786 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001787 } else
1788 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1789 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1790 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1791 }
1792
Evan Chenga8e29892007-01-19 07:51:42 +00001793 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001794 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001795 CurDAG->getTargetConstantPool(ConstantInt::get(
1796 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001797 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001798
1799 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001800 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001801 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001802 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001803 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001804 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1805 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001806 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001807 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001808 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001809 CurDAG->getRegister(0, MVT::i32),
1810 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001811 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001812 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001813 CurDAG->getEntryNode()
1814 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001815 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1816 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001817 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001818 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001819 return NULL;
1820 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001821
Evan Chenga8e29892007-01-19 07:51:42 +00001822 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001823 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001824 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001825 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001826 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001827 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001828 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001829 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001830 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1831 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001832 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001833 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1834 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001835 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1836 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1837 CurDAG->getRegister(0, MVT::i32) };
1838 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001839 }
Evan Chenga8e29892007-01-19 07:51:42 +00001840 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001841 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001842 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001843 return I;
1844 break;
1845 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001846 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001847 return I;
1848 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001849 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001850 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001851 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001852 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001853 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001854 if (!RHSV) break;
1855 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001856 unsigned ShImm = Log2_32(RHSV-1);
1857 if (ShImm >= 32)
1858 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001859 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001860 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001861 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1862 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001863 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001864 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001865 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001866 } else {
1867 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001868 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001869 }
Evan Chenga8e29892007-01-19 07:51:42 +00001870 }
1871 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001872 unsigned ShImm = Log2_32(RHSV+1);
1873 if (ShImm >= 32)
1874 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001875 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001876 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001877 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1878 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001879 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001880 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1881 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001882 } else {
1883 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001884 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001885 }
Evan Chenga8e29892007-01-19 07:51:42 +00001886 }
1887 }
1888 break;
Evan Cheng20956592009-10-21 08:15:52 +00001889 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001890 // Check for unsigned bitfield extract
1891 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1892 return I;
1893
Evan Cheng20956592009-10-21 08:15:52 +00001894 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1895 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1896 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1897 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1898 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001899 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001900 if (VT != MVT::i32)
1901 break;
1902 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1903 ? ARM::t2MOVTi16
1904 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1905 if (!Opc)
1906 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001907 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001908 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1909 if (!N1C)
1910 break;
1911 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1912 SDValue N2 = N0.getOperand(1);
1913 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1914 if (!N2C)
1915 break;
1916 unsigned N1CVal = N1C->getZExtValue();
1917 unsigned N2CVal = N2C->getZExtValue();
1918 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1919 (N1CVal & 0xffffU) == 0xffffU &&
1920 (N2CVal & 0xffffU) == 0x0U) {
1921 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1922 MVT::i32);
1923 SDValue Ops[] = { N0.getOperand(0), Imm16,
1924 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1925 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1926 }
1927 }
1928 break;
1929 }
Jim Grosbache5165492009-11-09 00:11:35 +00001930 case ARMISD::VMOVRRD:
1931 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001932 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001933 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001934 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001935 if (Subtarget->isThumb1Only())
1936 break;
1937 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001938 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001939 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1940 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001941 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001942 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001943 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001944 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1945 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001946 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001947 }
Evan Chengee568cf2007-07-05 07:15:27 +00001948 }
Dan Gohman525178c2007-10-08 18:33:35 +00001949 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001950 if (Subtarget->isThumb1Only())
1951 break;
1952 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001953 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001954 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001955 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001956 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001957 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001958 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1959 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001960 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001961 }
Evan Chengee568cf2007-07-05 07:15:27 +00001962 }
Evan Chenga8e29892007-01-19 07:51:42 +00001963 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00001964 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001965 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001966 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001967 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001968 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001969 if (ResNode)
1970 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001971
1972 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
1973 if (Subtarget->hasVFP2() &&
1974 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
1975 SDValue Chain = N->getOperand(0);
1976 SDValue AM5Opc =
1977 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001978 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001979 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
1980 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00001981 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1982 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
1983 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
1984 MVT::v2f64, MVT::Other, Ops, 5);
1985 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
1986 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001987 }
1988 // Other cases are autogenerated.
1989 break;
1990 }
1991 case ISD::STORE: {
1992 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
1993 if (Subtarget->hasVFP2() &&
1994 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
1995 SDValue Chain = N->getOperand(0);
1996 SDValue AM5Opc =
1997 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001998 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00001999 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2000 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2001 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002002 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2003 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2004 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2005 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2006 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002007 }
Evan Chenga8e29892007-01-19 07:51:42 +00002008 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002009 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002010 }
Evan Chengee568cf2007-07-05 07:15:27 +00002011 case ARMISD::BRCOND: {
2012 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2013 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2014 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002015
Evan Chengee568cf2007-07-05 07:15:27 +00002016 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2017 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2018 // Pattern complexity = 6 cost = 1 size = 0
2019
David Goodwin5e47a9a2009-06-30 18:04:13 +00002020 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2021 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2022 // Pattern complexity = 6 cost = 1 size = 0
2023
Jim Grosbach764ab522009-08-11 15:33:49 +00002024 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002025 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002026 SDValue Chain = N->getOperand(0);
2027 SDValue N1 = N->getOperand(1);
2028 SDValue N2 = N->getOperand(2);
2029 SDValue N3 = N->getOperand(3);
2030 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002031 assert(N1.getOpcode() == ISD::BasicBlock);
2032 assert(N2.getOpcode() == ISD::Constant);
2033 assert(N3.getOpcode() == ISD::Register);
2034
Dan Gohman475871a2008-07-27 21:46:04 +00002035 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002036 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002037 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002038 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002039 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2040 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002041 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002042 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002043 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002044 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002045 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002047 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002048 return NULL;
2049 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002050 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002051 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002052 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002053 EVT VT = N->getValueType(0);
2054 SDValue N0 = N->getOperand(0);
2055 SDValue N1 = N->getOperand(1);
2056 SDValue N2 = N->getOperand(2);
2057 SDValue N3 = N->getOperand(3);
2058 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002059 assert(N2.getOpcode() == ISD::Constant);
2060 assert(N3.getOpcode() == ISD::Register);
2061
Dan Gohman475871a2008-07-27 21:46:04 +00002062 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002063 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002064 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002065 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002066 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002067 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002068 default: assert(false && "Illegal conditional move type!");
2069 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002070 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002071 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002072 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002073 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002074 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002075 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002076 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002077 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002078 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002079
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002080 case ARMISD::VZIP: {
2081 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002082 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002083 switch (VT.getSimpleVT().SimpleTy) {
2084 default: return NULL;
2085 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2086 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2087 case MVT::v2f32:
2088 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2089 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2090 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2091 case MVT::v4f32:
2092 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2093 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002094 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002095 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2096 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2097 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002098 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002099 case ARMISD::VUZP: {
2100 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002101 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002102 switch (VT.getSimpleVT().SimpleTy) {
2103 default: return NULL;
2104 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2105 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2106 case MVT::v2f32:
2107 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2108 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2109 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2110 case MVT::v4f32:
2111 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2112 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002113 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002114 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2115 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2116 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002117 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002118 case ARMISD::VTRN: {
2119 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002120 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002121 switch (VT.getSimpleVT().SimpleTy) {
2122 default: return NULL;
2123 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2124 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2125 case MVT::v2f32:
2126 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2127 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2128 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2129 case MVT::v4f32:
2130 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2131 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002132 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002133 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2134 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2135 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002136 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002137 case ARMISD::BUILD_VECTOR: {
2138 EVT VecVT = N->getValueType(0);
2139 EVT EltVT = VecVT.getVectorElementType();
2140 unsigned NumElts = VecVT.getVectorNumElements();
2141 if (EltVT.getSimpleVT() == MVT::f64) {
2142 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2143 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2144 }
2145 assert(EltVT.getSimpleVT() == MVT::f32 &&
2146 "unexpected type for BUILD_VECTOR");
2147 if (NumElts == 2)
2148 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2149 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2150 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2151 N->getOperand(2), N->getOperand(3));
2152 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002153
2154 case ISD::INTRINSIC_VOID:
2155 case ISD::INTRINSIC_W_CHAIN: {
2156 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002157 switch (IntNo) {
2158 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002159 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002160
Bob Wilson621f1952010-03-23 05:25:43 +00002161 case Intrinsic::arm_neon_vld1: {
2162 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2163 ARM::VLD1d32, ARM::VLD1d64 };
2164 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2165 ARM::VLD1q32, ARM::VLD1q64 };
2166 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2167 }
2168
Bob Wilson31fb12f2009-08-26 17:39:53 +00002169 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002170 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002171 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002172 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002173 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002174 }
2175
2176 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002177 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002178 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002179 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2180 ARM::VLD3q16_UPD,
2181 ARM::VLD3q32_UPD };
2182 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2183 ARM::VLD3q16odd_UPD,
2184 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002185 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002186 }
2187
2188 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002189 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002190 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002191 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2192 ARM::VLD4q16_UPD,
2193 ARM::VLD4q32_UPD };
2194 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2195 ARM::VLD4q16odd_UPD,
2196 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002197 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002198 }
2199
Bob Wilson243fcc52009-09-01 04:26:28 +00002200 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002201 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002202 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2203 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002204 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002205 }
2206
2207 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002208 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002209 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2210 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002211 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002212 }
2213
2214 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002215 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002216 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2217 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002218 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002219 }
2220
Bob Wilson11d98992010-03-23 06:20:33 +00002221 case Intrinsic::arm_neon_vst1: {
2222 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2223 ARM::VST1d32, ARM::VST1d64 };
2224 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2225 ARM::VST1q32, ARM::VST1q64 };
2226 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2227 }
2228
Bob Wilson31fb12f2009-08-26 17:39:53 +00002229 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002230 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002231 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002232 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002233 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002234 }
2235
2236 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002237 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002238 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002239 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2240 ARM::VST3q16_UPD,
2241 ARM::VST3q32_UPD };
2242 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2243 ARM::VST3q16odd_UPD,
2244 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002245 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002246 }
2247
2248 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002249 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002250 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002251 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2252 ARM::VST4q16_UPD,
2253 ARM::VST4q32_UPD };
2254 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2255 ARM::VST4q16odd_UPD,
2256 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002257 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002258 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002259
2260 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002261 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002262 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2263 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002264 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002265 }
2266
2267 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002268 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002269 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2270 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002271 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002272 }
2273
2274 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002275 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002276 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2277 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002278 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002279 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002280 }
Bob Wilson429009b2010-05-06 16:05:26 +00002281 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002282 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002283
Bob Wilson429009b2010-05-06 16:05:26 +00002284 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002285 return SelectConcatVector(N);
2286 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002287
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002288 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002289}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002290
Bob Wilson224c2442009-05-19 05:53:42 +00002291bool ARMDAGToDAGISel::
2292SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2293 std::vector<SDValue> &OutOps) {
2294 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002295 // Require the address to be in a register. That is safe for all ARM
2296 // variants and it is hard to do anything much smarter without knowing
2297 // how the operand is used.
2298 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002299 return false;
2300}
2301
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002302/// createARMISelDag - This pass converts a legalized DAG into a
2303/// ARM-specific DAG, ready for instruction scheduling.
2304///
Bob Wilson522ce972009-09-28 14:30:20 +00002305FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2306 CodeGenOpt::Level OptLevel) {
2307 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002308}