blob: 235bf36a67f2f2b68b921ed75d312610d4531dfa [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
Bob Wilsond491d6e2010-07-06 23:36:25 +0000146 /// SelectVTBL - Select NEON VTBL intrinsics. NumVecs should be 2, 3 or 4.
147 /// These are custom-selected so that a REG_SEQUENCE can be generated to
148 /// force the table registers to be consecutive.
149 SDNode *SelectVTBL(SDNode *N, unsigned NumVecs, unsigned Opc);
150
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000151 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000152 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000153
Evan Cheng07ba9062009-11-19 21:45:22 +0000154 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 SDNode *SelectCMOVOp(SDNode *N);
156 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000157 ARMCC::CondCodes CCVal, SDValue CCR,
158 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000159 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000160 ARMCC::CondCodes CCVal, SDValue CCR,
161 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000163 ARMCC::CondCodes CCVal, SDValue CCR,
164 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000165 SDNode *SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000166 ARMCC::CondCodes CCVal, SDValue CCR,
167 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000168
Evan Chengde8aa4e2010-05-05 18:28:36 +0000169 SDNode *SelectConcatVector(SDNode *N);
170
Evan Chengaf4550f2009-07-02 01:23:32 +0000171 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
172 /// inline asm expressions.
173 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
174 char ConstraintCode,
175 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000176
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000177 // Form pairs of consecutive S, D, or Q registers.
178 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000179 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000180 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
181
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000182 // Form sequences of 4 consecutive S, D, or Q registers.
183 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000184 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000185 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
186
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000187 // Form sequences of 8 consecutive D registers.
Evan Cheng5c6aba22010-05-14 18:54:59 +0000188 SDNode *OctoDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3,
189 SDValue V4, SDValue V5, SDValue V6, SDValue V7);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000190};
Evan Chenga8e29892007-01-19 07:51:42 +0000191}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000192
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000193/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
194/// operand. If so Imm will receive the 32-bit value.
195static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
196 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
197 Imm = cast<ConstantSDNode>(N)->getZExtValue();
198 return true;
199 }
200 return false;
201}
202
203// isInt32Immediate - This method tests to see if a constant operand.
204// If so Imm will receive the 32 bit value.
205static bool isInt32Immediate(SDValue N, unsigned &Imm) {
206 return isInt32Immediate(N.getNode(), Imm);
207}
208
209// isOpcWithIntImmediate - This method tests to see if the node is a specific
210// opcode and that it has a immediate integer right operand.
211// If so Imm will receive the 32 bit value.
212static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
213 return N->getOpcode() == Opc &&
214 isInt32Immediate(N->getOperand(1).getNode(), Imm);
215}
216
217
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000218bool ARMDAGToDAGISel::SelectShifterOperandReg(SDNode *Op,
Evan Cheng055b0312009-06-29 07:51:04 +0000219 SDValue N,
220 SDValue &BaseReg,
221 SDValue &ShReg,
222 SDValue &Opc) {
223 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
224
225 // Don't match base register only case. That is matched to a separate
226 // lower complexity pattern with explicit register operand.
227 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000228
Evan Cheng055b0312009-06-29 07:51:04 +0000229 BaseReg = N.getOperand(0);
230 unsigned ShImmVal = 0;
231 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000232 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000233 ShImmVal = RHS->getZExtValue() & 31;
234 } else {
235 ShReg = N.getOperand(1);
236 }
237 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000238 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000239 return true;
240}
241
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000242bool ARMDAGToDAGISel::SelectAddrMode2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000243 SDValue &Base, SDValue &Offset,
244 SDValue &Opc) {
Evan Chenga13fd102007-03-13 21:05:54 +0000245 if (N.getOpcode() == ISD::MUL) {
246 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
247 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000248 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000249 if (RHSC & 1) {
250 RHSC = RHSC & ~1;
251 ARM_AM::AddrOpc AddSub = ARM_AM::add;
252 if (RHSC < 0) {
253 AddSub = ARM_AM::sub;
254 RHSC = - RHSC;
255 }
256 if (isPowerOf2_32(RHSC)) {
257 unsigned ShAmt = Log2_32(RHSC);
258 Base = Offset = N.getOperand(0);
259 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
260 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000261 MVT::i32);
Evan Chenga13fd102007-03-13 21:05:54 +0000262 return true;
263 }
264 }
265 }
266 }
267
Evan Chenga8e29892007-01-19 07:51:42 +0000268 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
269 Base = N;
270 if (N.getOpcode() == ISD::FrameIndex) {
271 int FI = cast<FrameIndexSDNode>(N)->getIndex();
272 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000273 } else if (N.getOpcode() == ARMISD::Wrapper &&
274 !(Subtarget->useMovt() &&
275 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000276 Base = N.getOperand(0);
277 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000278 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000279 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
280 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000281 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000282 return true;
283 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000284
Evan Chenga8e29892007-01-19 07:51:42 +0000285 // Match simple R +/- imm12 operands.
286 if (N.getOpcode() == ISD::ADD)
287 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000288 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000289 if ((RHSC >= 0 && RHSC < 0x1000) ||
290 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000291 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000292 if (Base.getOpcode() == ISD::FrameIndex) {
293 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
294 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
295 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000296 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000297
298 ARM_AM::AddrOpc AddSub = ARM_AM::add;
299 if (RHSC < 0) {
300 AddSub = ARM_AM::sub;
301 RHSC = - RHSC;
302 }
303 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000304 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000305 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000306 return true;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000307 }
Evan Chenga8e29892007-01-19 07:51:42 +0000308 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000309
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000310 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000311 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
312 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
313 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000314
Evan Chenga8e29892007-01-19 07:51:42 +0000315 Base = N.getOperand(0);
316 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000317
Evan Chenga8e29892007-01-19 07:51:42 +0000318 if (ShOpcVal != ARM_AM::no_shift) {
319 // Check to see if the RHS of the shift is a constant, if not, we can't fold
320 // it.
321 if (ConstantSDNode *Sh =
322 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000323 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000324 Offset = N.getOperand(1).getOperand(0);
325 } else {
326 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000327 }
328 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000329
Evan Chenga8e29892007-01-19 07:51:42 +0000330 // Try matching (R shl C) + (R).
331 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift) {
332 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
333 if (ShOpcVal != ARM_AM::no_shift) {
334 // Check to see if the RHS of the shift is a constant, if not, we can't
335 // fold it.
336 if (ConstantSDNode *Sh =
337 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000338 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000339 Offset = N.getOperand(0).getOperand(0);
340 Base = N.getOperand(1);
341 } else {
342 ShOpcVal = ARM_AM::no_shift;
343 }
344 }
345 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000346
Evan Chenga8e29892007-01-19 07:51:42 +0000347 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000348 MVT::i32);
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000349 return true;
350}
351
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000352bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000353 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000354 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000355 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
356 ? cast<LoadSDNode>(Op)->getAddressingMode()
357 : cast<StoreSDNode>(Op)->getAddressingMode();
358 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
359 ? ARM_AM::add : ARM_AM::sub;
360 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000361 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000362 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000363 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000364 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
365 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000366 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000367 return true;
368 }
369 }
370
371 Offset = N;
372 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
373 unsigned ShAmt = 0;
374 if (ShOpcVal != ARM_AM::no_shift) {
375 // Check to see if the RHS of the shift is a constant, if not, we can't fold
376 // it.
377 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000378 ShAmt = Sh->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000379 Offset = N.getOperand(0);
380 } else {
381 ShOpcVal = ARM_AM::no_shift;
382 }
383 }
384
385 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000386 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000387 return true;
388}
389
Evan Chenga8e29892007-01-19 07:51:42 +0000390
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000391bool ARMDAGToDAGISel::SelectAddrMode3(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000392 SDValue &Base, SDValue &Offset,
393 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000394 if (N.getOpcode() == ISD::SUB) {
395 // X - C is canonicalize to X + -C, no need to handle it here.
396 Base = N.getOperand(0);
397 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000398 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000399 return true;
400 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000401
Evan Chenga8e29892007-01-19 07:51:42 +0000402 if (N.getOpcode() != ISD::ADD) {
403 Base = N;
404 if (N.getOpcode() == ISD::FrameIndex) {
405 int FI = cast<FrameIndexSDNode>(N)->getIndex();
406 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
407 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000408 Offset = CurDAG->getRegister(0, MVT::i32);
409 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000410 return true;
411 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000412
Evan Chenga8e29892007-01-19 07:51:42 +0000413 // If the RHS is +/- imm8, fold into addr mode.
414 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000415 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000416 if ((RHSC >= 0 && RHSC < 256) ||
417 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000418 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000419 if (Base.getOpcode() == ISD::FrameIndex) {
420 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
421 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
422 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000423 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000424
425 ARM_AM::AddrOpc AddSub = ARM_AM::add;
426 if (RHSC < 0) {
427 AddSub = ARM_AM::sub;
428 RHSC = - RHSC;
429 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000430 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000431 return true;
432 }
433 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000434
Evan Chenga8e29892007-01-19 07:51:42 +0000435 Base = N.getOperand(0);
436 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000437 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000438 return true;
439}
440
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000441bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000442 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000443 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000444 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
445 ? cast<LoadSDNode>(Op)->getAddressingMode()
446 : cast<StoreSDNode>(Op)->getAddressingMode();
447 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
448 ? ARM_AM::add : ARM_AM::sub;
449 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000450 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000451 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000452 Offset = CurDAG->getRegister(0, MVT::i32);
453 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000454 return true;
455 }
456 }
457
458 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000459 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000460 return true;
461}
462
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000463bool ARMDAGToDAGISel::SelectAddrMode4(SDNode *Op, SDValue N,
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000464 SDValue &Addr, SDValue &Mode) {
465 Addr = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000466 Mode = CurDAG->getTargetConstant(0, MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000467 return true;
468}
Evan Chenga8e29892007-01-19 07:51:42 +0000469
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000470bool ARMDAGToDAGISel::SelectAddrMode5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000471 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000472 if (N.getOpcode() != ISD::ADD) {
473 Base = N;
474 if (N.getOpcode() == ISD::FrameIndex) {
475 int FI = cast<FrameIndexSDNode>(N)->getIndex();
476 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000477 } else if (N.getOpcode() == ARMISD::Wrapper &&
478 !(Subtarget->useMovt() &&
479 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000480 Base = N.getOperand(0);
481 }
482 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000483 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000484 return true;
485 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000486
Evan Chenga8e29892007-01-19 07:51:42 +0000487 // If the RHS is +/- imm8, fold into addr mode.
488 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000489 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000490 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
491 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000492 if ((RHSC >= 0 && RHSC < 256) ||
493 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000494 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000495 if (Base.getOpcode() == ISD::FrameIndex) {
496 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
497 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
498 }
499
500 ARM_AM::AddrOpc AddSub = ARM_AM::add;
501 if (RHSC < 0) {
502 AddSub = ARM_AM::sub;
503 RHSC = - RHSC;
504 }
505 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000506 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000507 return true;
508 }
509 }
510 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000511
Evan Chenga8e29892007-01-19 07:51:42 +0000512 Base = N;
513 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000514 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000515 return true;
516}
517
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000518bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Op, SDValue N,
Bob Wilson226036e2010-03-20 22:13:40 +0000519 SDValue &Addr, SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000520 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000521 // Default to no alignment.
522 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000523 return true;
524}
525
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000526bool ARMDAGToDAGISel::SelectAddrModePC(SDNode *Op, SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000527 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000528 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
529 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000530 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000531 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000532 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000533 return true;
534 }
535 return false;
536}
537
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000538bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000539 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000540 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000541 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000542 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000543 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000544 return false;
545
546 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000547 return true;
548 }
549
Evan Chenga8e29892007-01-19 07:51:42 +0000550 Base = N.getOperand(0);
551 Offset = N.getOperand(1);
552 return true;
553}
554
Evan Cheng79d43262007-01-24 02:21:22 +0000555bool
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000556ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000557 unsigned Scale, SDValue &Base,
558 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000559 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000560 SDValue TmpBase, TmpOffImm;
Evan Cheng79d43262007-01-24 02:21:22 +0000561 if (SelectThumbAddrModeSP(Op, N, TmpBase, TmpOffImm))
562 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000563 if (N.getOpcode() == ARMISD::Wrapper &&
564 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
565 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000566 }
567
Evan Chenga8e29892007-01-19 07:51:42 +0000568 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000569 if (N.getOpcode() == ARMISD::Wrapper &&
570 !(Subtarget->useMovt() &&
571 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
572 Base = N.getOperand(0);
573 } else
574 Base = N;
575
Owen Anderson825b72b2009-08-11 20:47:22 +0000576 Offset = CurDAG->getRegister(0, MVT::i32);
577 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000578 return true;
579 }
580
Evan Chengad0e4652007-02-06 00:22:06 +0000581 // Thumb does not have [sp, r] address mode.
582 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
583 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
584 if ((LHSR && LHSR->getReg() == ARM::SP) ||
585 (RHSR && RHSR->getReg() == ARM::SP)) {
586 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000587 Offset = CurDAG->getRegister(0, MVT::i32);
588 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000589 return true;
590 }
591
Evan Chenga8e29892007-01-19 07:51:42 +0000592 // If the RHS is + imm5 * scale, fold into addr mode.
593 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000594 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000595 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
596 RHSC /= Scale;
597 if (RHSC >= 0 && RHSC < 32) {
598 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 Offset = CurDAG->getRegister(0, MVT::i32);
600 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000601 return true;
602 }
603 }
604 }
605
Evan Chengc38f2bc2007-01-23 22:59:13 +0000606 Base = N.getOperand(0);
607 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000608 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000609 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000610}
611
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000612bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000613 SDValue &Base, SDValue &OffImm,
614 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000615 return SelectThumbAddrModeRI5(Op, N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000616}
617
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000618bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000619 SDValue &Base, SDValue &OffImm,
620 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000621 return SelectThumbAddrModeRI5(Op, N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000622}
623
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000624bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000625 SDValue &Base, SDValue &OffImm,
626 SDValue &Offset) {
Evan Chengcea117d2007-01-30 02:35:32 +0000627 return SelectThumbAddrModeRI5(Op, N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000628}
629
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000630bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000631 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000632 if (N.getOpcode() == ISD::FrameIndex) {
633 int FI = cast<FrameIndexSDNode>(N)->getIndex();
634 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000635 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000636 return true;
637 }
Evan Cheng79d43262007-01-24 02:21:22 +0000638
Evan Chengad0e4652007-02-06 00:22:06 +0000639 if (N.getOpcode() != ISD::ADD)
640 return false;
641
642 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000643 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
644 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000645 // If the RHS is + imm8 * scale, fold into addr mode.
646 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000647 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000648 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
649 RHSC >>= 2;
650 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000651 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000652 if (Base.getOpcode() == ISD::FrameIndex) {
653 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
654 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
655 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000656 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000657 return true;
658 }
659 }
660 }
661 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000662
Evan Chenga8e29892007-01-19 07:51:42 +0000663 return false;
664}
665
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000666bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDNode *Op, SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000667 SDValue &BaseReg,
668 SDValue &Opc) {
669 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
670
671 // Don't match base register only case. That is matched to a separate
672 // lower complexity pattern with explicit register operand.
673 if (ShOpcVal == ARM_AM::no_shift) return false;
674
675 BaseReg = N.getOperand(0);
676 unsigned ShImmVal = 0;
677 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
678 ShImmVal = RHS->getZExtValue() & 31;
679 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
680 return true;
681 }
682
683 return false;
684}
685
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000686bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000687 SDValue &Base, SDValue &OffImm) {
688 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000689
Evan Cheng3a214252009-08-11 08:52:18 +0000690 // Base only.
691 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000692 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000693 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000694 int FI = cast<FrameIndexSDNode>(N)->getIndex();
695 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000696 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000697 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000698 } else if (N.getOpcode() == ARMISD::Wrapper &&
699 !(Subtarget->useMovt() &&
700 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000701 Base = N.getOperand(0);
702 if (Base.getOpcode() == ISD::TargetConstantPool)
703 return false; // We want to select t2LDRpci instead.
704 } else
705 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000706 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000707 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000708 }
Evan Cheng055b0312009-06-29 07:51:04 +0000709
710 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Evan Cheng3a214252009-08-11 08:52:18 +0000711 if (SelectT2AddrModeImm8(Op, N, Base, OffImm))
712 // Let t2LDRi8 handle (R - imm8).
713 return false;
714
Evan Cheng055b0312009-06-29 07:51:04 +0000715 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000716 if (N.getOpcode() == ISD::SUB)
717 RHSC = -RHSC;
718
719 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000720 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000721 if (Base.getOpcode() == ISD::FrameIndex) {
722 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
723 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
724 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000725 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000726 return true;
727 }
728 }
729
Evan Cheng3a214252009-08-11 08:52:18 +0000730 // Base only.
731 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000732 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000733 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000734}
735
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000736bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000737 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000738 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000739 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000740 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
741 int RHSC = (int)RHS->getSExtValue();
742 if (N.getOpcode() == ISD::SUB)
743 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000744
Evan Cheng3a214252009-08-11 08:52:18 +0000745 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
746 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +0000747 if (Base.getOpcode() == ISD::FrameIndex) {
748 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
749 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
750 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000751 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +0000752 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000753 }
Evan Cheng055b0312009-06-29 07:51:04 +0000754 }
755 }
756
757 return false;
758}
759
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000760bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000761 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000762 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +0000763 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
764 ? cast<LoadSDNode>(Op)->getAddressingMode()
765 : cast<StoreSDNode>(Op)->getAddressingMode();
766 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
767 int RHSC = (int)RHS->getZExtValue();
768 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +0000769 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +0000770 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
771 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000772 return true;
773 }
774 }
775
776 return false;
777}
778
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000779bool ARMDAGToDAGISel::SelectT2AddrModeImm8s4(SDNode *Op, SDValue N,
David Goodwin6647cea2009-06-30 22:50:01 +0000780 SDValue &Base, SDValue &OffImm) {
781 if (N.getOpcode() == ISD::ADD) {
782 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
783 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000784 // 8 bits.
Evan Cheng5c874172009-07-09 22:21:59 +0000785 if (((RHSC & 0x3) == 0) &&
Jim Grosbach18f30e62010-06-02 21:53:11 +0000786 ((RHSC >= 0 && RHSC < 0x400) || (RHSC < 0 && RHSC > -0x400))) {
David Goodwin6647cea2009-06-30 22:50:01 +0000787 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000788 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000789 return true;
790 }
791 }
792 } else if (N.getOpcode() == ISD::SUB) {
793 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
794 int RHSC = (int)RHS->getZExtValue();
Jim Grosbach18f30e62010-06-02 21:53:11 +0000795 // 8 bits.
796 if (((RHSC & 0x3) == 0) && (RHSC >= 0 && RHSC < 0x400)) {
David Goodwin6647cea2009-06-30 22:50:01 +0000797 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000798 OffImm = CurDAG->getTargetConstant(-RHSC, MVT::i32);
David Goodwin6647cea2009-06-30 22:50:01 +0000799 return true;
800 }
801 }
802 }
803
804 return false;
805}
806
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000807bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDNode *Op, SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000808 SDValue &Base,
809 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +0000810 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
811 if (N.getOpcode() != ISD::ADD)
812 return false;
Evan Cheng055b0312009-06-29 07:51:04 +0000813
Evan Cheng3a214252009-08-11 08:52:18 +0000814 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
815 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
816 int RHSC = (int)RHS->getZExtValue();
817 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
818 return false;
819 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +0000820 return false;
821 }
822
Evan Cheng055b0312009-06-29 07:51:04 +0000823 // Look for (R + R) or (R + (R << [1,2,3])).
824 unsigned ShAmt = 0;
825 Base = N.getOperand(0);
826 OffReg = N.getOperand(1);
827
828 // Swap if it is ((R << c) + R).
829 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
830 if (ShOpcVal != ARM_AM::lsl) {
831 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
832 if (ShOpcVal == ARM_AM::lsl)
833 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +0000834 }
835
Evan Cheng055b0312009-06-29 07:51:04 +0000836 if (ShOpcVal == ARM_AM::lsl) {
837 // Check to see if the RHS of the shift is a constant, if not, we can't fold
838 // it.
839 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
840 ShAmt = Sh->getZExtValue();
841 if (ShAmt >= 4) {
842 ShAmt = 0;
843 ShOpcVal = ARM_AM::no_shift;
844 } else
845 OffReg = OffReg.getOperand(0);
846 } else {
847 ShOpcVal = ARM_AM::no_shift;
848 }
David Goodwin7ecc8502009-07-15 15:50:19 +0000849 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000850
Owen Anderson825b72b2009-08-11 20:47:22 +0000851 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000852
853 return true;
854}
855
856//===--------------------------------------------------------------------===//
857
Evan Chengee568cf2007-07-05 07:15:27 +0000858/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +0000859static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000860 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +0000861}
862
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000863SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
864 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +0000865 ISD::MemIndexedMode AM = LD->getAddressingMode();
866 if (AM == ISD::UNINDEXED)
867 return NULL;
868
Owen Andersone50ed302009-08-10 22:56:29 +0000869 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +0000870 SDValue Offset, AMOpc;
871 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
872 unsigned Opcode = 0;
873 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000874 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000875 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000876 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
877 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000879 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000880 Match = true;
881 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
882 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
883 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +0000884 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000885 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000886 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000887 Match = true;
888 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
889 }
890 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000891 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +0000892 Match = true;
893 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
894 }
895 }
896 }
897
898 if (Match) {
899 SDValue Chain = LD->getChain();
900 SDValue Base = LD->getBasePtr();
901 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000902 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000903 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000904 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +0000905 }
906
907 return NULL;
908}
909
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000910SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
911 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000912 ISD::MemIndexedMode AM = LD->getAddressingMode();
913 if (AM == ISD::UNINDEXED)
914 return NULL;
915
Owen Andersone50ed302009-08-10 22:56:29 +0000916 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +0000917 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000918 SDValue Offset;
919 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
920 unsigned Opcode = 0;
921 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000922 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000923 switch (LoadedVT.getSimpleVT().SimpleTy) {
924 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000925 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
926 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000927 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000928 if (isSExtLd)
929 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
930 else
931 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000932 break;
Owen Anderson825b72b2009-08-11 20:47:22 +0000933 case MVT::i8:
934 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +0000935 if (isSExtLd)
936 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
937 else
938 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +0000939 break;
940 default:
941 return NULL;
942 }
943 Match = true;
944 }
945
946 if (Match) {
947 SDValue Chain = LD->getChain();
948 SDValue Base = LD->getBasePtr();
949 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +0000950 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000951 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +0000952 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000953 }
954
955 return NULL;
956}
957
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000958/// PairSRegs - Form a D register from a pair of S registers.
959///
960SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
961 DebugLoc dl = V0.getNode()->getDebugLoc();
962 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
963 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000964 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
965 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000966}
967
Evan Cheng603afbf2010-05-10 17:34:18 +0000968/// PairDRegs - Form a quad register from a pair of D registers.
969///
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000970SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
971 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000972 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
973 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +0000974 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
975 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000976}
977
Evan Cheng7f687192010-05-14 00:21:45 +0000978/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +0000979///
980SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
981 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +0000982 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
983 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +0000984 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
985 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
986}
987
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000988/// QuadSRegs - Form 4 consecutive S registers.
989///
990SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
991 SDValue V2, SDValue V3) {
992 DebugLoc dl = V0.getNode()->getDebugLoc();
993 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
994 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
995 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
996 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
997 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
998 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
999}
1000
Evan Cheng7f687192010-05-14 00:21:45 +00001001/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001002///
1003SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1004 SDValue V2, SDValue V3) {
1005 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001006 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1007 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1008 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1009 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001010 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1011 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1012}
1013
Evan Cheng8f6de382010-05-16 03:27:48 +00001014/// QuadQRegs - Form 4 consecutive Q registers.
1015///
1016SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1017 SDValue V2, SDValue V3) {
1018 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001019 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1020 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1021 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1022 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001023 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1024 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1025}
1026
Evan Cheng5c6aba22010-05-14 18:54:59 +00001027/// OctoDRegs - Form 8 consecutive D registers.
1028///
1029SDNode *ARMDAGToDAGISel::OctoDRegs(EVT VT, SDValue V0, SDValue V1,
1030 SDValue V2, SDValue V3,
1031 SDValue V4, SDValue V5,
1032 SDValue V6, SDValue V7) {
1033 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001034 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1035 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1036 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1037 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
1038 SDValue SubReg4 = CurDAG->getTargetConstant(ARM::dsub_4, MVT::i32);
1039 SDValue SubReg5 = CurDAG->getTargetConstant(ARM::dsub_5, MVT::i32);
1040 SDValue SubReg6 = CurDAG->getTargetConstant(ARM::dsub_6, MVT::i32);
1041 SDValue SubReg7 = CurDAG->getTargetConstant(ARM::dsub_7, MVT::i32);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001042 const SDValue Ops[] ={ V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3,
1043 V4, SubReg4, V5, SubReg5, V6, SubReg6, V7, SubReg7 };
1044 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 16);
1045}
1046
Bob Wilsona7c397c2009-10-14 16:19:03 +00001047/// GetNEONSubregVT - Given a type for a 128-bit NEON vector, return the type
1048/// for a 64-bit subregister of the vector.
1049static EVT GetNEONSubregVT(EVT VT) {
1050 switch (VT.getSimpleVT().SimpleTy) {
1051 default: llvm_unreachable("unhandled NEON type");
1052 case MVT::v16i8: return MVT::v8i8;
1053 case MVT::v8i16: return MVT::v4i16;
1054 case MVT::v4f32: return MVT::v2f32;
1055 case MVT::v4i32: return MVT::v2i32;
1056 case MVT::v2i64: return MVT::v1i64;
1057 }
1058}
1059
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001060SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001061 unsigned *DOpcodes, unsigned *QOpcodes0,
1062 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001063 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001064 DebugLoc dl = N->getDebugLoc();
1065
Bob Wilson226036e2010-03-20 22:13:40 +00001066 SDValue MemAddr, Align;
1067 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001068 return NULL;
1069
1070 SDValue Chain = N->getOperand(0);
1071 EVT VT = N->getValueType(0);
1072 bool is64BitVector = VT.is64BitVector();
1073
1074 unsigned OpcodeIndex;
1075 switch (VT.getSimpleVT().SimpleTy) {
1076 default: llvm_unreachable("unhandled vld type");
1077 // Double-register operations:
1078 case MVT::v8i8: OpcodeIndex = 0; break;
1079 case MVT::v4i16: OpcodeIndex = 1; break;
1080 case MVT::v2f32:
1081 case MVT::v2i32: OpcodeIndex = 2; break;
1082 case MVT::v1i64: OpcodeIndex = 3; break;
1083 // Quad-register operations:
1084 case MVT::v16i8: OpcodeIndex = 0; break;
1085 case MVT::v8i16: OpcodeIndex = 1; break;
1086 case MVT::v4f32:
1087 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001088 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001089 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001090 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001091 }
1092
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001093 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001094 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson3e36f132009-10-14 17:28:52 +00001095 if (is64BitVector) {
1096 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001097 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson3e36f132009-10-14 17:28:52 +00001098 std::vector<EVT> ResTys(NumVecs, VT);
1099 ResTys.push_back(MVT::Other);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001100 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson07f6e802010-06-16 21:34:01 +00001101 if (NumVecs < 2)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001102 return VLd;
1103
Evan Cheng0ce537a2010-05-11 01:19:40 +00001104 SDValue RegSeq;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001105 SDValue V0 = SDValue(VLd, 0);
1106 SDValue V1 = SDValue(VLd, 1);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001107
Evan Cheng0ce537a2010-05-11 01:19:40 +00001108 // Form a REG_SEQUENCE to force register allocation.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001109 if (NumVecs == 2)
1110 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1111 else {
1112 SDValue V2 = SDValue(VLd, 2);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001113 // If it's a vld3, form a quad D-register but discard the last part.
Evan Chenge9e2ba02010-05-10 21:26:24 +00001114 SDValue V3 = (NumVecs == 3)
1115 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1116 : SDValue(VLd, 3);
1117 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1118 }
1119
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001120 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001121 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001122 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Evan Cheng5c6aba22010-05-14 18:54:59 +00001123 dl, VT, RegSeq);
1124 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001125 }
1126 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, NumVecs));
1127 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001128 }
1129
1130 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson621f1952010-03-23 05:25:43 +00001131 if (NumVecs <= 2) {
1132 // Quad registers are directly supported for VLD1 and VLD2,
1133 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001134 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001135 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilson621f1952010-03-23 05:25:43 +00001136 std::vector<EVT> ResTys(2 * NumVecs, RegVT);
Bob Wilson3e36f132009-10-14 17:28:52 +00001137 ResTys.push_back(MVT::Other);
Bob Wilson226036e2010-03-20 22:13:40 +00001138 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops, 5);
Bob Wilson621f1952010-03-23 05:25:43 +00001139 Chain = SDValue(VLd, 2 * NumVecs);
Bob Wilson3e36f132009-10-14 17:28:52 +00001140
1141 // Combine the even and odd subregs to produce the result.
Bob Wilson07f6e802010-06-16 21:34:01 +00001142 if (NumVecs == 1) {
1143 SDNode *Q = PairDRegs(VT, SDValue(VLd, 0), SDValue(VLd, 1));
1144 ReplaceUses(SDValue(N, 0), SDValue(Q, 0));
Evan Cheng603afbf2010-05-10 17:34:18 +00001145 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001146 SDValue QQ = SDValue(QuadDRegs(MVT::v4i64,
1147 SDValue(VLd, 0), SDValue(VLd, 1),
1148 SDValue(VLd, 2), SDValue(VLd, 3)), 0);
1149 SDValue Q0 = CurDAG->getTargetExtractSubreg(ARM::qsub_0, dl, VT, QQ);
1150 SDValue Q1 = CurDAG->getTargetExtractSubreg(ARM::qsub_1, dl, VT, QQ);
1151 ReplaceUses(SDValue(N, 0), Q0);
1152 ReplaceUses(SDValue(N, 1), Q1);
Bob Wilson3e36f132009-10-14 17:28:52 +00001153 }
1154 } else {
1155 // Otherwise, quad registers are loaded with two separate instructions,
1156 // where one loads the even registers and the other loads the odd registers.
1157
Bob Wilson3e36f132009-10-14 17:28:52 +00001158 std::vector<EVT> ResTys(NumVecs, RegVT);
1159 ResTys.push_back(MemAddr.getValueType());
1160 ResTys.push_back(MVT::Other);
1161
Bob Wilson24f995d2009-10-14 18:32:29 +00001162 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001163 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001164 const SDValue OpsA[] = { MemAddr, Align, Reg0, Pred, Reg0, Chain };
1165 SDNode *VLdA = CurDAG->getMachineNode(Opc, dl, ResTys, OpsA, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001166 Chain = SDValue(VLdA, NumVecs+1);
1167
Bob Wilson24f995d2009-10-14 18:32:29 +00001168 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001169 Opc = QOpcodes1[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001170 const SDValue OpsB[] = { SDValue(VLdA, NumVecs),
1171 Align, Reg0, Pred, Reg0, Chain };
1172 SDNode *VLdB = CurDAG->getMachineNode(Opc, dl, ResTys, OpsB, 6);
Bob Wilson3e36f132009-10-14 17:28:52 +00001173 Chain = SDValue(VLdB, NumVecs+1);
1174
Bob Wilson07f6e802010-06-16 21:34:01 +00001175 SDValue V0 = SDValue(VLdA, 0);
1176 SDValue V1 = SDValue(VLdB, 0);
1177 SDValue V2 = SDValue(VLdA, 1);
1178 SDValue V3 = SDValue(VLdB, 1);
1179 SDValue V4 = SDValue(VLdA, 2);
1180 SDValue V5 = SDValue(VLdB, 2);
1181 SDValue V6 = (NumVecs == 3)
1182 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1183 : SDValue(VLdA, 3);
1184 SDValue V7 = (NumVecs == 3)
1185 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,RegVT), 0)
1186 : SDValue(VLdB, 3);
1187 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V0, V1, V2, V3,
1188 V4, V5, V6, V7), 0);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001189
Bob Wilson07f6e802010-06-16 21:34:01 +00001190 // Extract out the 3 / 4 Q registers.
1191 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1192 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1193 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1194 dl, VT, RegSeq);
1195 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001196 }
1197 }
1198 ReplaceUses(SDValue(N, NumVecs), Chain);
1199 return NULL;
1200}
1201
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001202SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001203 unsigned *DOpcodes, unsigned *QOpcodes0,
1204 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001205 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001206 DebugLoc dl = N->getDebugLoc();
1207
Bob Wilson226036e2010-03-20 22:13:40 +00001208 SDValue MemAddr, Align;
1209 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001210 return NULL;
1211
1212 SDValue Chain = N->getOperand(0);
1213 EVT VT = N->getOperand(3).getValueType();
1214 bool is64BitVector = VT.is64BitVector();
1215
1216 unsigned OpcodeIndex;
1217 switch (VT.getSimpleVT().SimpleTy) {
1218 default: llvm_unreachable("unhandled vst type");
1219 // Double-register operations:
1220 case MVT::v8i8: OpcodeIndex = 0; break;
1221 case MVT::v4i16: OpcodeIndex = 1; break;
1222 case MVT::v2f32:
1223 case MVT::v2i32: OpcodeIndex = 2; break;
1224 case MVT::v1i64: OpcodeIndex = 3; break;
1225 // Quad-register operations:
1226 case MVT::v16i8: OpcodeIndex = 0; break;
1227 case MVT::v8i16: OpcodeIndex = 1; break;
1228 case MVT::v4f32:
1229 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001230 case MVT::v2i64: OpcodeIndex = 3;
1231 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1232 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001233 }
1234
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001235 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001236 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001237
Bob Wilson226036e2010-03-20 22:13:40 +00001238 SmallVector<SDValue, 10> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001239 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001240 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001241
1242 if (is64BitVector) {
Bob Wilson07f6e802010-06-16 21:34:01 +00001243 if (NumVecs >= 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001244 SDValue RegSeq;
1245 SDValue V0 = N->getOperand(0+3);
1246 SDValue V1 = N->getOperand(1+3);
1247
1248 // Form a REG_SEQUENCE to force register allocation.
1249 if (NumVecs == 2)
1250 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1251 else {
1252 SDValue V2 = N->getOperand(2+3);
1253 // If it's a vld3, form a quad D-register and leave the last part as
1254 // an undef.
1255 SDValue V3 = (NumVecs == 3)
1256 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1257 : N->getOperand(3+3);
1258 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1259 }
1260
1261 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001262 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001263 RegSeq));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001264 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001265 RegSeq));
1266 if (NumVecs > 2)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001267 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001268 RegSeq));
1269 if (NumVecs > 3)
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001270 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,
Evan Cheng0ce537a2010-05-11 01:19:40 +00001271 RegSeq));
1272 } else {
1273 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1274 Ops.push_back(N->getOperand(Vec+3));
1275 }
Evan Chengac0869d2009-11-21 06:21:52 +00001276 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001277 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001278 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001279 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001280 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+5);
Bob Wilson24f995d2009-10-14 18:32:29 +00001281 }
1282
1283 EVT RegVT = GetNEONSubregVT(VT);
Bob Wilson11d98992010-03-23 06:20:33 +00001284 if (NumVecs <= 2) {
1285 // Quad registers are directly supported for VST1 and VST2,
1286 // storing pairs of D regs.
Bob Wilson24f995d2009-10-14 18:32:29 +00001287 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001288 if (NumVecs == 2) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001289 // First extract the pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001290 SDValue Q0 = N->getOperand(3);
1291 SDValue Q1 = N->getOperand(4);
1292
1293 // Form a QQ register.
1294 SDValue QQ = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
1295
1296 // Now extract the D registers back out.
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001297 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001298 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001299 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001300 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001301 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001302 QQ));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001303 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001304 QQ));
1305 Ops.push_back(Pred);
1306 Ops.push_back(Reg0); // predicate register
1307 Ops.push_back(Chain);
1308 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 5 + 4);
1309 } else {
1310 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001311 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001312 N->getOperand(Vec+3)));
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001313 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
Evan Cheng603afbf2010-05-10 17:34:18 +00001314 N->getOperand(Vec+3)));
1315 }
1316 Ops.push_back(Pred);
1317 Ops.push_back(Reg0); // predicate register
1318 Ops.push_back(Chain);
1319 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(),
1320 5 + 2 * NumVecs);
Bob Wilson24f995d2009-10-14 18:32:29 +00001321 }
Bob Wilson24f995d2009-10-14 18:32:29 +00001322 }
1323
1324 // Otherwise, quad registers are stored with two separate instructions,
1325 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001326
Bob Wilson07f6e802010-06-16 21:34:01 +00001327 // Form the QQQQ REG_SEQUENCE.
1328 SDValue V[8];
1329 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1330 V[i] = CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, RegVT,
1331 N->getOperand(Vec+3));
1332 V[i+1] = CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, RegVT,
1333 N->getOperand(Vec+3));
Evan Cheng12c24692010-05-14 22:54:52 +00001334 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001335 if (NumVecs == 3)
1336 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1337 dl, RegVT), 0);
1338
1339 SDValue RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1340 V[4], V[5], V[6], V[7]), 0);
1341
1342 // Store the even D registers.
1343 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1344 Ops.push_back(Reg0); // post-access address offset
1345 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1346 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec*2, dl,
1347 RegVT, RegSeq));
1348 Ops.push_back(Pred);
1349 Ops.push_back(Reg0); // predicate register
1350 Ops.push_back(Chain);
1351 unsigned Opc = QOpcodes0[OpcodeIndex];
1352 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1353 MVT::Other, Ops.data(), NumVecs+6);
1354 Chain = SDValue(VStA, 1);
1355
1356 // Store the odd D registers.
1357 Ops[0] = SDValue(VStA, 0); // MemAddr
1358 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1359 Ops[Vec+3] = CurDAG->getTargetExtractSubreg(ARM::dsub_1+Vec*2, dl,
1360 RegVT, RegSeq);
1361 Ops[NumVecs+5] = Chain;
1362 Opc = QOpcodes1[OpcodeIndex];
1363 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
1364 MVT::Other, Ops.data(), NumVecs+6);
1365 Chain = SDValue(VStB, 1);
1366 ReplaceUses(SDValue(N, 0), Chain);
1367 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001368}
1369
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001370SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001371 unsigned NumVecs, unsigned *DOpcodes,
1372 unsigned *QOpcodes0,
1373 unsigned *QOpcodes1) {
1374 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001375 DebugLoc dl = N->getDebugLoc();
1376
Bob Wilson226036e2010-03-20 22:13:40 +00001377 SDValue MemAddr, Align;
1378 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001379 return NULL;
1380
1381 SDValue Chain = N->getOperand(0);
1382 unsigned Lane =
1383 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001384 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001385 bool is64BitVector = VT.is64BitVector();
1386
Bob Wilson96493442009-10-14 16:46:45 +00001387 // Quad registers are handled by load/store of subregs. Find the subreg info.
Bob Wilsona7c397c2009-10-14 16:19:03 +00001388 unsigned NumElts = 0;
Evan Cheng8f6de382010-05-16 03:27:48 +00001389 bool Even = false;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001390 EVT RegVT = VT;
1391 if (!is64BitVector) {
1392 RegVT = GetNEONSubregVT(VT);
1393 NumElts = RegVT.getVectorNumElements();
Evan Cheng8f6de382010-05-16 03:27:48 +00001394 Even = Lane < NumElts;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001395 }
1396
1397 unsigned OpcodeIndex;
1398 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001399 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001400 // Double-register operations:
1401 case MVT::v8i8: OpcodeIndex = 0; break;
1402 case MVT::v4i16: OpcodeIndex = 1; break;
1403 case MVT::v2f32:
1404 case MVT::v2i32: OpcodeIndex = 2; break;
1405 // Quad-register operations:
1406 case MVT::v8i16: OpcodeIndex = 0; break;
1407 case MVT::v4f32:
1408 case MVT::v4i32: OpcodeIndex = 1; break;
1409 }
1410
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001411 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001412 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001413
Bob Wilson226036e2010-03-20 22:13:40 +00001414 SmallVector<SDValue, 10> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001415 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001416 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001417
1418 unsigned Opc = 0;
1419 if (is64BitVector) {
1420 Opc = DOpcodes[OpcodeIndex];
Bob Wilson07f6e802010-06-16 21:34:01 +00001421 SDValue RegSeq;
1422 SDValue V0 = N->getOperand(0+3);
1423 SDValue V1 = N->getOperand(1+3);
1424 if (NumVecs == 2) {
1425 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001426 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001427 SDValue V2 = N->getOperand(2+3);
1428 SDValue V3 = (NumVecs == 3)
1429 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1430 : N->getOperand(3+3);
1431 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001432 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001433
1434 // Now extract the D registers back out.
1435 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1436 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1437 if (NumVecs > 2)
1438 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT,RegSeq));
1439 if (NumVecs > 3)
1440 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT,RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001441 } else {
1442 // Check if this is loading the even or odd subreg of a Q register.
1443 if (Lane < NumElts) {
1444 Opc = QOpcodes0[OpcodeIndex];
1445 } else {
1446 Lane -= NumElts;
1447 Opc = QOpcodes1[OpcodeIndex];
1448 }
Evan Cheng8f6de382010-05-16 03:27:48 +00001449
Bob Wilson07f6e802010-06-16 21:34:01 +00001450 SDValue RegSeq;
1451 SDValue V0 = N->getOperand(0+3);
1452 SDValue V1 = N->getOperand(1+3);
1453 if (NumVecs == 2) {
1454 RegSeq = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001455 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001456 SDValue V2 = N->getOperand(2+3);
1457 SDValue V3 = (NumVecs == 3)
1458 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1459 : N->getOperand(3+3);
1460 RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Evan Cheng8f6de382010-05-16 03:27:48 +00001461 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001462
1463 // Extract the subregs of the input vector.
1464 unsigned SubIdx = Even ? ARM::dsub_0 : ARM::dsub_1;
1465 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1466 Ops.push_back(CurDAG->getTargetExtractSubreg(SubIdx+Vec*2, dl, RegVT,
1467 RegSeq));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001468 }
1469 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001470 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001471 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001472 Ops.push_back(Chain);
1473
Bob Wilson96493442009-10-14 16:46:45 +00001474 if (!IsLoad)
Bob Wilson226036e2010-03-20 22:13:40 +00001475 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), NumVecs+6);
Bob Wilson96493442009-10-14 16:46:45 +00001476
Bob Wilsona7c397c2009-10-14 16:19:03 +00001477 std::vector<EVT> ResTys(NumVecs, RegVT);
1478 ResTys.push_back(MVT::Other);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001479 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(),NumVecs+6);
1480
Bob Wilson07f6e802010-06-16 21:34:01 +00001481 // Form a REG_SEQUENCE to force register allocation.
1482 SDValue RegSeq;
1483 if (is64BitVector) {
1484 SDValue V0 = SDValue(VLdLn, 0);
1485 SDValue V1 = SDValue(VLdLn, 1);
1486 if (NumVecs == 2) {
1487 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng7189fd02010-05-15 07:53:37 +00001488 } else {
Bob Wilson07f6e802010-06-16 21:34:01 +00001489 SDValue V2 = SDValue(VLdLn, 2);
1490 // If it's a vld3, form a quad D-register but discard the last part.
1491 SDValue V3 = (NumVecs == 3)
1492 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1493 : SDValue(VLdLn, 3);
1494 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001495 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001496 } else {
1497 // For 128-bit vectors, take the 64-bit results of the load and insert
1498 // them as subregs into the result.
1499 SDValue V[8];
1500 for (unsigned Vec = 0, i = 0; Vec < NumVecs; ++Vec, i+=2) {
1501 if (Even) {
1502 V[i] = SDValue(VLdLn, Vec);
1503 V[i+1] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1504 dl, RegVT), 0);
1505 } else {
1506 V[i] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1507 dl, RegVT), 0);
1508 V[i+1] = SDValue(VLdLn, Vec);
1509 }
1510 }
1511 if (NumVecs == 3)
1512 V[6] = V[7] = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
1513 dl, RegVT), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001514
Bob Wilson07f6e802010-06-16 21:34:01 +00001515 if (NumVecs == 2)
1516 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V[0], V[1], V[2], V[3]), 0);
1517 else
1518 RegSeq = SDValue(OctoDRegs(MVT::v8i64, V[0], V[1], V[2], V[3],
1519 V[4], V[5], V[6], V[7]), 0);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001520 }
1521
Bob Wilson07f6e802010-06-16 21:34:01 +00001522 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1523 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1524 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1525 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1526 ReplaceUses(SDValue(N, Vec),
1527 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, RegSeq));
1528 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, NumVecs));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001529 return NULL;
1530}
1531
Bob Wilsond491d6e2010-07-06 23:36:25 +00001532SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, unsigned NumVecs, unsigned Opc) {
1533 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1534 DebugLoc dl = N->getDebugLoc();
1535 EVT VT = N->getValueType(0);
1536
1537 // Form a REG_SEQUENCE to force register allocation.
1538 SDValue RegSeq;
1539 SDValue V0 = N->getOperand(1);
1540 SDValue V1 = N->getOperand(2);
1541 if (NumVecs == 2)
1542 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1543 else {
1544 SDValue V2 = N->getOperand(3);
1545 // If it's a vtbl3, form a quad D-register and leave the last part as
1546 // an undef.
1547 SDValue V3 = (NumVecs == 3)
1548 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1549 : N->getOperand(4);
1550 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1551 }
1552
1553 // Now extract the D registers back out.
1554 SmallVector<SDValue, 5> Ops;
1555 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_0, dl, VT, RegSeq));
1556 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_1, dl, VT, RegSeq));
1557 if (NumVecs > 2)
1558 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_2, dl, VT, RegSeq));
1559 if (NumVecs > 3)
1560 Ops.push_back(CurDAG->getTargetExtractSubreg(ARM::dsub_3, dl, VT, RegSeq));
1561
1562 Ops.push_back(N->getOperand(NumVecs+1));
1563 Ops.push_back(getAL(CurDAG)); // predicate
1564 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
1565 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), NumVecs+3);
1566}
1567
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001568SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001569 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001570 if (!Subtarget->hasV6T2Ops())
1571 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001572
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001573 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1574 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1575
1576
1577 // For unsigned extracts, check for a shift right and mask
1578 unsigned And_imm = 0;
1579 if (N->getOpcode() == ISD::AND) {
1580 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1581
1582 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1583 if (And_imm & (And_imm + 1))
1584 return NULL;
1585
1586 unsigned Srl_imm = 0;
1587 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1588 Srl_imm)) {
1589 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1590
1591 unsigned Width = CountTrailingOnes_32(And_imm);
1592 unsigned LSB = Srl_imm;
1593 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1594 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1595 CurDAG->getTargetConstant(LSB, MVT::i32),
1596 CurDAG->getTargetConstant(Width, MVT::i32),
1597 getAL(CurDAG), Reg0 };
1598 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1599 }
1600 }
1601 return NULL;
1602 }
1603
1604 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001605 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001606 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001607 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1608 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001609 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001610 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1611 unsigned Width = 32 - Srl_imm;
1612 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001613 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001614 return NULL;
1615 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001616 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001617 CurDAG->getTargetConstant(LSB, MVT::i32),
1618 CurDAG->getTargetConstant(Width, MVT::i32),
1619 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001620 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001621 }
1622 }
1623 return NULL;
1624}
1625
Evan Cheng9ef48352009-11-20 00:54:03 +00001626SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001627SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001628 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1629 SDValue CPTmp0;
1630 SDValue CPTmp1;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001631 if (SelectT2ShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001632 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1633 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1634 unsigned Opc = 0;
1635 switch (SOShOp) {
1636 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1637 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1638 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1639 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1640 default:
1641 llvm_unreachable("Unknown so_reg opcode!");
1642 break;
1643 }
1644 SDValue SOShImm =
1645 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1646 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1647 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001648 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001649 }
1650 return 0;
1651}
1652
1653SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001654SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001655 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1656 SDValue CPTmp0;
1657 SDValue CPTmp1;
1658 SDValue CPTmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001659 if (SelectShifterOperandReg(N, TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001660 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1661 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001662 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001663 }
1664 return 0;
1665}
1666
1667SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001668SelectT2CMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001669 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1670 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1671 if (!T)
1672 return 0;
1673
1674 if (Predicate_t2_so_imm(TrueVal.getNode())) {
1675 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1676 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1677 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001678 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001679 ARM::t2MOVCCi, MVT::i32, Ops, 5);
1680 }
1681 return 0;
1682}
1683
1684SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001685SelectARMCMOVSoImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001686 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1687 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1688 if (!T)
1689 return 0;
1690
1691 if (Predicate_so_imm(TrueVal.getNode())) {
1692 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1693 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1694 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001695 return CurDAG->SelectNodeTo(N,
Evan Cheng9ef48352009-11-20 00:54:03 +00001696 ARM::MOVCCi, MVT::i32, Ops, 5);
1697 }
1698 return 0;
1699}
1700
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1702 EVT VT = N->getValueType(0);
1703 SDValue FalseVal = N->getOperand(0);
1704 SDValue TrueVal = N->getOperand(1);
1705 SDValue CC = N->getOperand(2);
1706 SDValue CCR = N->getOperand(3);
1707 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001708 assert(CC.getOpcode() == ISD::Constant);
1709 assert(CCR.getOpcode() == ISD::Register);
1710 ARMCC::CondCodes CCVal =
1711 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001712
1713 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1714 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1715 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1716 // Pattern complexity = 18 cost = 1 size = 0
1717 SDValue CPTmp0;
1718 SDValue CPTmp1;
1719 SDValue CPTmp2;
1720 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001721 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001722 CCVal, CCR, InFlag);
1723 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001724 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001725 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1726 if (Res)
1727 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001728 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001729 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001730 CCVal, CCR, InFlag);
1731 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001732 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001733 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1734 if (Res)
1735 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001736 }
1737
1738 // Pattern: (ARMcmov:i32 GPR:i32:$false,
1739 // (imm:i32)<<P:Predicate_so_imm>>:$true,
1740 // (imm:i32):$cc)
1741 // Emits: (MOVCCi:i32 GPR:i32:$false,
1742 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1743 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001744 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001745 SDNode *Res = SelectT2CMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001746 CCVal, CCR, InFlag);
1747 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001748 Res = SelectT2CMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001749 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1750 if (Res)
1751 return Res;
1752 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001753 SDNode *Res = SelectARMCMOVSoImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001754 CCVal, CCR, InFlag);
1755 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001756 Res = SelectARMCMOVSoImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001757 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1758 if (Res)
1759 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001760 }
1761 }
1762
1763 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1764 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1765 // Pattern complexity = 6 cost = 1 size = 0
1766 //
1767 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1768 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1769 // Pattern complexity = 6 cost = 11 size = 0
1770 //
1771 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001772 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1773 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001774 unsigned Opc = 0;
1775 switch (VT.getSimpleVT().SimpleTy) {
1776 default: assert(false && "Illegal conditional move type!");
1777 break;
1778 case MVT::i32:
1779 Opc = Subtarget->isThumb()
1780 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1781 : ARM::MOVCCr;
1782 break;
1783 case MVT::f32:
1784 Opc = ARM::VMOVScc;
1785 break;
1786 case MVT::f64:
1787 Opc = ARM::VMOVDcc;
1788 break;
1789 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001790 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001791}
1792
Evan Chengde8aa4e2010-05-05 18:28:36 +00001793SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1794 // The only time a CONCAT_VECTORS operation can have legal types is when
1795 // two 64-bit vectors are concatenated to a 128-bit vector.
1796 EVT VT = N->getValueType(0);
1797 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1798 llvm_unreachable("unexpected CONCAT_VECTORS");
1799 DebugLoc dl = N->getDebugLoc();
1800 SDValue V0 = N->getOperand(0);
1801 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001802 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1803 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001804 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1805 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1806}
1807
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001808SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001809 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001810
Dan Gohmane8be6c62008-07-17 19:10:17 +00001811 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001812 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001813
1814 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001815 default: break;
1816 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001817 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001818 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001819 if (Subtarget->hasThumb2())
1820 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1821 // be done with MOV + MOVT, at worst.
1822 UseCP = 0;
1823 else {
1824 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001825 UseCP = (Val > 255 && // MOV
1826 ~Val > 255 && // MOV + MVN
1827 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001828 } else
1829 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1830 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1831 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1832 }
1833
Evan Chenga8e29892007-01-19 07:51:42 +00001834 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001835 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001836 CurDAG->getTargetConstantPool(ConstantInt::get(
1837 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001838 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001839
1840 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001841 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001842 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001843 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001844 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001845 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1846 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001847 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001848 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001849 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001850 CurDAG->getRegister(0, MVT::i32),
1851 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001852 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001853 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001854 CurDAG->getEntryNode()
1855 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001856 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
1857 Ops, 6);
Evan Cheng012f2d92007-01-24 08:53:17 +00001858 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001859 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001860 return NULL;
1861 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001862
Evan Chenga8e29892007-01-19 07:51:42 +00001863 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001864 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001865 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001866 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001867 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001868 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001869 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001870 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001871 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1872 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001873 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001874 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1875 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001876 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1877 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1878 CurDAG->getRegister(0, MVT::i32) };
1879 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001880 }
Evan Chenga8e29892007-01-19 07:51:42 +00001881 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001882 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001883 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001884 return I;
1885 break;
1886 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001887 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001888 return I;
1889 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001890 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001891 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001892 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001893 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001894 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001895 if (!RHSV) break;
1896 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001897 unsigned ShImm = Log2_32(RHSV-1);
1898 if (ShImm >= 32)
1899 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001900 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001901 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001902 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1903 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001904 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001905 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001906 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001907 } else {
1908 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001909 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001910 }
Evan Chenga8e29892007-01-19 07:51:42 +00001911 }
1912 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001913 unsigned ShImm = Log2_32(RHSV+1);
1914 if (ShImm >= 32)
1915 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001916 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001917 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001918 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1919 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001920 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00001921 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
1922 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001923 } else {
1924 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001925 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001926 }
Evan Chenga8e29892007-01-19 07:51:42 +00001927 }
1928 }
1929 break;
Evan Cheng20956592009-10-21 08:15:52 +00001930 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001931 // Check for unsigned bitfield extract
1932 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
1933 return I;
1934
Evan Cheng20956592009-10-21 08:15:52 +00001935 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
1936 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
1937 // are entirely contributed by c2 and lower 16-bits are entirely contributed
1938 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
1939 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001940 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00001941 if (VT != MVT::i32)
1942 break;
1943 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
1944 ? ARM::t2MOVTi16
1945 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
1946 if (!Opc)
1947 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001948 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00001949 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
1950 if (!N1C)
1951 break;
1952 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
1953 SDValue N2 = N0.getOperand(1);
1954 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
1955 if (!N2C)
1956 break;
1957 unsigned N1CVal = N1C->getZExtValue();
1958 unsigned N2CVal = N2C->getZExtValue();
1959 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
1960 (N1CVal & 0xffffU) == 0xffffU &&
1961 (N2CVal & 0xffffU) == 0x0U) {
1962 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
1963 MVT::i32);
1964 SDValue Ops[] = { N0.getOperand(0), Imm16,
1965 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
1966 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
1967 }
1968 }
1969 break;
1970 }
Jim Grosbache5165492009-11-09 00:11:35 +00001971 case ARMISD::VMOVRRD:
1972 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001973 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00001974 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00001975 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001976 if (Subtarget->isThumb1Only())
1977 break;
1978 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001980 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1981 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001982 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001983 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001985 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1986 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00001987 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001988 }
Evan Chengee568cf2007-07-05 07:15:27 +00001989 }
Dan Gohman525178c2007-10-08 18:33:35 +00001990 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001991 if (Subtarget->isThumb1Only())
1992 break;
1993 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001994 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001995 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00001996 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001997 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00001999 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2000 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002001 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002002 }
Evan Chengee568cf2007-07-05 07:15:27 +00002003 }
Evan Chenga8e29892007-01-19 07:51:42 +00002004 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002005 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002006 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002007 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002008 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002010 if (ResNode)
2011 return ResNode;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002012
2013 // VLDMQ must be custom-selected for "v2f64 load" to set the AM5Opc value.
2014 if (Subtarget->hasVFP2() &&
2015 N->getValueType(0).getSimpleVT().SimpleTy == MVT::v2f64) {
2016 SDValue Chain = N->getOperand(0);
2017 SDValue AM5Opc =
2018 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002019 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002020 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2021 SDValue Ops[] = { N->getOperand(1), AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002022 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2023 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2024 SDNode *Ret = CurDAG->getMachineNode(ARM::VLDMQ, dl,
2025 MVT::v2f64, MVT::Other, Ops, 5);
2026 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2027 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002028 }
2029 // Other cases are autogenerated.
2030 break;
2031 }
2032 case ISD::STORE: {
2033 // VSTMQ must be custom-selected for "v2f64 store" to set the AM5Opc value.
2034 if (Subtarget->hasVFP2() &&
2035 N->getOperand(1).getValueType().getSimpleVT().SimpleTy == MVT::v2f64) {
2036 SDValue Chain = N->getOperand(0);
2037 SDValue AM5Opc =
2038 CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::ia, 4), MVT::i32);
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002039 SDValue Pred = getAL(CurDAG);
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002040 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2041 SDValue Ops[] = { N->getOperand(1), N->getOperand(2),
2042 AM5Opc, Pred, PredReg, Chain };
Evan Cheng3c3195c2010-05-19 06:06:09 +00002043 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2044 MemOp[0] = cast<MemSDNode>(N)->getMemOperand();
2045 SDNode *Ret = CurDAG->getMachineNode(ARM::VSTMQ, dl, MVT::Other, Ops, 6);
2046 cast<MachineSDNode>(Ret)->setMemRefs(MemOp, MemOp + 1);
2047 return Ret;
Bob Wilsondf9a4f02010-03-23 18:54:46 +00002048 }
Evan Chenga8e29892007-01-19 07:51:42 +00002049 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002050 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002051 }
Evan Chengee568cf2007-07-05 07:15:27 +00002052 case ARMISD::BRCOND: {
2053 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2054 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2055 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002056
Evan Chengee568cf2007-07-05 07:15:27 +00002057 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2058 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2059 // Pattern complexity = 6 cost = 1 size = 0
2060
David Goodwin5e47a9a2009-06-30 18:04:13 +00002061 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2062 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2063 // Pattern complexity = 6 cost = 1 size = 0
2064
Jim Grosbach764ab522009-08-11 15:33:49 +00002065 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002066 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002067 SDValue Chain = N->getOperand(0);
2068 SDValue N1 = N->getOperand(1);
2069 SDValue N2 = N->getOperand(2);
2070 SDValue N3 = N->getOperand(3);
2071 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002072 assert(N1.getOpcode() == ISD::BasicBlock);
2073 assert(N2.getOpcode() == ISD::Constant);
2074 assert(N3.getOpcode() == ISD::Register);
2075
Dan Gohman475871a2008-07-27 21:46:04 +00002076 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002077 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002078 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002079 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002080 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2081 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002082 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002083 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002084 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002085 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002086 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002087 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002088 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002089 return NULL;
2090 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002091 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002092 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002093 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002094 EVT VT = N->getValueType(0);
2095 SDValue N0 = N->getOperand(0);
2096 SDValue N1 = N->getOperand(1);
2097 SDValue N2 = N->getOperand(2);
2098 SDValue N3 = N->getOperand(3);
2099 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002100 assert(N2.getOpcode() == ISD::Constant);
2101 assert(N3.getOpcode() == ISD::Register);
2102
Dan Gohman475871a2008-07-27 21:46:04 +00002103 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002104 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002105 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002106 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002107 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002108 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002109 default: assert(false && "Illegal conditional move type!");
2110 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002111 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002112 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002113 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002114 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002115 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002116 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002117 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002118 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002119 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002120
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002121 case ARMISD::VZIP: {
2122 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002123 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002124 switch (VT.getSimpleVT().SimpleTy) {
2125 default: return NULL;
2126 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2127 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2128 case MVT::v2f32:
2129 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2130 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2131 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2132 case MVT::v4f32:
2133 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2134 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002135 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002136 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2137 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2138 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002139 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002140 case ARMISD::VUZP: {
2141 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002142 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002143 switch (VT.getSimpleVT().SimpleTy) {
2144 default: return NULL;
2145 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2146 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2147 case MVT::v2f32:
2148 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2149 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2150 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2151 case MVT::v4f32:
2152 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2153 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002154 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002155 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2156 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2157 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002158 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002159 case ARMISD::VTRN: {
2160 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002161 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002162 switch (VT.getSimpleVT().SimpleTy) {
2163 default: return NULL;
2164 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2165 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2166 case MVT::v2f32:
2167 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2168 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2169 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2170 case MVT::v4f32:
2171 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2172 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002173 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002174 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2175 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2176 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002177 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002178 case ARMISD::BUILD_VECTOR: {
2179 EVT VecVT = N->getValueType(0);
2180 EVT EltVT = VecVT.getVectorElementType();
2181 unsigned NumElts = VecVT.getVectorNumElements();
2182 if (EltVT.getSimpleVT() == MVT::f64) {
2183 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2184 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2185 }
2186 assert(EltVT.getSimpleVT() == MVT::f32 &&
2187 "unexpected type for BUILD_VECTOR");
2188 if (NumElts == 2)
2189 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2190 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2191 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2192 N->getOperand(2), N->getOperand(3));
2193 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002194
2195 case ISD::INTRINSIC_VOID:
2196 case ISD::INTRINSIC_W_CHAIN: {
2197 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002198 switch (IntNo) {
2199 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002200 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002201
Bob Wilson621f1952010-03-23 05:25:43 +00002202 case Intrinsic::arm_neon_vld1: {
2203 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2204 ARM::VLD1d32, ARM::VLD1d64 };
2205 unsigned QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
2206 ARM::VLD1q32, ARM::VLD1q64 };
2207 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2208 }
2209
Bob Wilson31fb12f2009-08-26 17:39:53 +00002210 case Intrinsic::arm_neon_vld2: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002211 unsigned DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
Bob Wilson621f1952010-03-23 05:25:43 +00002212 ARM::VLD2d32, ARM::VLD1q64 };
Bob Wilson3e36f132009-10-14 17:28:52 +00002213 unsigned QOpcodes[] = { ARM::VLD2q8, ARM::VLD2q16, ARM::VLD2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002214 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002215 }
2216
2217 case Intrinsic::arm_neon_vld3: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002218 unsigned DOpcodes[] = { ARM::VLD3d8, ARM::VLD3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002219 ARM::VLD3d32, ARM::VLD1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002220 unsigned QOpcodes0[] = { ARM::VLD3q8_UPD,
2221 ARM::VLD3q16_UPD,
2222 ARM::VLD3q32_UPD };
2223 unsigned QOpcodes1[] = { ARM::VLD3q8odd_UPD,
2224 ARM::VLD3q16odd_UPD,
2225 ARM::VLD3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002226 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002227 }
2228
2229 case Intrinsic::arm_neon_vld4: {
Bob Wilson3e36f132009-10-14 17:28:52 +00002230 unsigned DOpcodes[] = { ARM::VLD4d8, ARM::VLD4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002231 ARM::VLD4d32, ARM::VLD1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002232 unsigned QOpcodes0[] = { ARM::VLD4q8_UPD,
2233 ARM::VLD4q16_UPD,
2234 ARM::VLD4q32_UPD };
2235 unsigned QOpcodes1[] = { ARM::VLD4q8odd_UPD,
2236 ARM::VLD4q16odd_UPD,
2237 ARM::VLD4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002238 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002239 }
2240
Bob Wilson243fcc52009-09-01 04:26:28 +00002241 case Intrinsic::arm_neon_vld2lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002242 unsigned DOpcodes[] = { ARM::VLD2LNd8, ARM::VLD2LNd16, ARM::VLD2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002243 unsigned QOpcodes0[] = { ARM::VLD2LNq16, ARM::VLD2LNq32 };
2244 unsigned QOpcodes1[] = { ARM::VLD2LNq16odd, ARM::VLD2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002245 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002246 }
2247
2248 case Intrinsic::arm_neon_vld3lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002249 unsigned DOpcodes[] = { ARM::VLD3LNd8, ARM::VLD3LNd16, ARM::VLD3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002250 unsigned QOpcodes0[] = { ARM::VLD3LNq16, ARM::VLD3LNq32 };
2251 unsigned QOpcodes1[] = { ARM::VLD3LNq16odd, ARM::VLD3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002252 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002253 }
2254
2255 case Intrinsic::arm_neon_vld4lane: {
Bob Wilsona7c397c2009-10-14 16:19:03 +00002256 unsigned DOpcodes[] = { ARM::VLD4LNd8, ARM::VLD4LNd16, ARM::VLD4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002257 unsigned QOpcodes0[] = { ARM::VLD4LNq16, ARM::VLD4LNq32 };
2258 unsigned QOpcodes1[] = { ARM::VLD4LNq16odd, ARM::VLD4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002259 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson243fcc52009-09-01 04:26:28 +00002260 }
2261
Bob Wilson11d98992010-03-23 06:20:33 +00002262 case Intrinsic::arm_neon_vst1: {
2263 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2264 ARM::VST1d32, ARM::VST1d64 };
2265 unsigned QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
2266 ARM::VST1q32, ARM::VST1q64 };
2267 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2268 }
2269
Bob Wilson31fb12f2009-08-26 17:39:53 +00002270 case Intrinsic::arm_neon_vst2: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002271 unsigned DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
Bob Wilson11d98992010-03-23 06:20:33 +00002272 ARM::VST2d32, ARM::VST1q64 };
Bob Wilson24f995d2009-10-14 18:32:29 +00002273 unsigned QOpcodes[] = { ARM::VST2q8, ARM::VST2q16, ARM::VST2q32 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002274 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002275 }
2276
2277 case Intrinsic::arm_neon_vst3: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002278 unsigned DOpcodes[] = { ARM::VST3d8, ARM::VST3d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002279 ARM::VST3d32, ARM::VST1d64T };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002280 unsigned QOpcodes0[] = { ARM::VST3q8_UPD,
2281 ARM::VST3q16_UPD,
2282 ARM::VST3q32_UPD };
2283 unsigned QOpcodes1[] = { ARM::VST3q8odd_UPD,
2284 ARM::VST3q16odd_UPD,
2285 ARM::VST3q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002286 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002287 }
2288
2289 case Intrinsic::arm_neon_vst4: {
Bob Wilson24f995d2009-10-14 18:32:29 +00002290 unsigned DOpcodes[] = { ARM::VST4d8, ARM::VST4d16,
Bob Wilsona6979752010-03-22 18:13:18 +00002291 ARM::VST4d32, ARM::VST1d64Q };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002292 unsigned QOpcodes0[] = { ARM::VST4q8_UPD,
2293 ARM::VST4q16_UPD,
2294 ARM::VST4q32_UPD };
2295 unsigned QOpcodes1[] = { ARM::VST4q8odd_UPD,
2296 ARM::VST4q16odd_UPD,
2297 ARM::VST4q32odd_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002298 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002299 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002300
2301 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002302 unsigned DOpcodes[] = { ARM::VST2LNd8, ARM::VST2LNd16, ARM::VST2LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002303 unsigned QOpcodes0[] = { ARM::VST2LNq16, ARM::VST2LNq32 };
2304 unsigned QOpcodes1[] = { ARM::VST2LNq16odd, ARM::VST2LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002305 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002306 }
2307
2308 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002309 unsigned DOpcodes[] = { ARM::VST3LNd8, ARM::VST3LNd16, ARM::VST3LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002310 unsigned QOpcodes0[] = { ARM::VST3LNq16, ARM::VST3LNq32 };
2311 unsigned QOpcodes1[] = { ARM::VST3LNq16odd, ARM::VST3LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002312 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002313 }
2314
2315 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson96493442009-10-14 16:46:45 +00002316 unsigned DOpcodes[] = { ARM::VST4LNd8, ARM::VST4LNd16, ARM::VST4LNd32 };
Bob Wilson95ffecd2010-03-20 18:35:24 +00002317 unsigned QOpcodes0[] = { ARM::VST4LNq16, ARM::VST4LNq32 };
2318 unsigned QOpcodes1[] = { ARM::VST4LNq16odd, ARM::VST4LNq32odd };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002319 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002320 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002321 }
Bob Wilson429009b2010-05-06 16:05:26 +00002322 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002323 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002324
Bob Wilsond491d6e2010-07-06 23:36:25 +00002325 case ISD::INTRINSIC_WO_CHAIN: {
2326 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2327 switch (IntNo) {
2328 default:
2329 break;
2330
2331 case Intrinsic::arm_neon_vtbl2:
2332 return SelectVTBL(N, 2, ARM::VTBL2);
2333 case Intrinsic::arm_neon_vtbl3:
2334 return SelectVTBL(N, 3, ARM::VTBL3);
2335 case Intrinsic::arm_neon_vtbl4:
2336 return SelectVTBL(N, 4, ARM::VTBL4);
2337 }
2338 break;
2339 }
2340
Bob Wilson429009b2010-05-06 16:05:26 +00002341 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002342 return SelectConcatVector(N);
2343 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002344
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002345 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002346}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002347
Bob Wilson224c2442009-05-19 05:53:42 +00002348bool ARMDAGToDAGISel::
2349SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2350 std::vector<SDValue> &OutOps) {
2351 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002352 // Require the address to be in a register. That is safe for all ARM
2353 // variants and it is hard to do anything much smarter without knowing
2354 // how the operand is used.
2355 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002356 return false;
2357}
2358
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002359/// createARMISelDag - This pass converts a legalized DAG into a
2360/// ARM-specific DAG, ready for instruction scheduling.
2361///
Bob Wilson522ce972009-09-28 14:30:20 +00002362FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2363 CodeGenOpt::Level OptLevel) {
2364 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002365}