blob: 7e86eba6eae935ed358b30ec07e556e8dc05fea1 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000016#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037using namespace llvm;
38
Evan Chenga2c519b2010-07-30 23:33:54 +000039static cl::opt<bool>
40DisableShifterOp("disable-shifter-op", cl::Hidden,
41 cl::desc("Disable isel of shifter-op"),
42 cl::init(false));
43
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000044//===--------------------------------------------------------------------===//
45/// ARMDAGToDAGISel - ARM specific code to select ARM machine
46/// instructions for SelectionDAG operations.
47///
48namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000049
50enum AddrMode2Type {
51 AM2_BASE, // Simple AM2 (+-imm12)
52 AM2_SHOP // Shifter-op AM2
53};
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000056 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000057
Evan Chenga8e29892007-01-19 07:51:42 +000058 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
59 /// make the right decision when generating code for different targets.
60 const ARMSubtarget *Subtarget;
61
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000062public:
Bob Wilson522ce972009-09-28 14:30:20 +000063 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
64 CodeGenOpt::Level OptLevel)
65 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000066 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000067 }
68
Evan Chenga8e29892007-01-19 07:51:42 +000069 virtual const char *getPassName() const {
70 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Bob Wilsonaf4a8912009-10-08 18:51:31 +000073 /// getI32Imm - Return a target constant of type i32 with the specified
74 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000075 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000076 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000077 }
78
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000080
Evan Chengf40deed2010-10-27 23:41:30 +000081 bool isShifterOpProfitable(const SDValue &Shift,
82 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000083 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000084 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000085 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
86 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000087 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
88 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
89
Jim Grosbach82891622010-09-29 19:03:54 +000090 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
91 SDValue &Offset, SDValue &Opc);
92 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
93 SDValue &Opc) {
94 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
95 }
96
97 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
98 SDValue &Opc) {
99 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
100 }
101
102 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000105// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000106 // This always matches one way or another.
107 return true;
108 }
109
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000111 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000112 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000113 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000115 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000116 bool SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode);
117 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000118 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000119 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000120
Chris Lattner52a261b2010-09-21 20:31:19 +0000121 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000122 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000123
Chris Lattner52a261b2010-09-21 20:31:19 +0000124 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
125 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000126 SDValue &Base, SDValue &OffImm,
127 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000128 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000129 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000131 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000132 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000133 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000135
Chris Lattner52a261b2010-09-21 20:31:19 +0000136 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000137 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000138 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
139 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000140 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000142 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000144 SDValue &OffReg, SDValue &ShImm);
145
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000146 inline bool Pred_so_imm(SDNode *inN) const {
147 ConstantSDNode *N = cast<ConstantSDNode>(inN);
148 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
149 }
150
151 inline bool Pred_t2_so_imm(SDNode *inN) const {
152 ConstantSDNode *N = cast<ConstantSDNode>(inN);
153 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
154 }
155
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000156 // Include the pieces autogenerated from the target description.
157#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000158
159private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000160 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
161 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectARMIndexedLoad(SDNode *N);
163 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000164
Bob Wilson621f1952010-03-23 05:25:43 +0000165 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
166 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000167 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000168 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000169 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000170 unsigned *QOpcodes0, unsigned *QOpcodes1);
171
Bob Wilson24f995d2009-10-14 18:32:29 +0000172 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000173 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000174 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000175 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000176 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000177 unsigned *QOpcodes0, unsigned *QOpcodes1);
178
Bob Wilson96493442009-10-14 16:46:45 +0000179 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000180 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000181 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000182 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000183 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000184
Bob Wilson78dfbc32010-07-07 00:08:54 +0000185 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
186 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
187 /// generated to force the table registers to be consecutive.
188 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000189
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000190 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000191 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000192
Evan Cheng07ba9062009-11-19 21:45:22 +0000193 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000194 SDNode *SelectCMOVOp(SDNode *N);
195 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000196 ARMCC::CondCodes CCVal, SDValue CCR,
197 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000198 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000199 ARMCC::CondCodes CCVal, SDValue CCR,
200 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000201 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000202 ARMCC::CondCodes CCVal, SDValue CCR,
203 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000204 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000205 ARMCC::CondCodes CCVal, SDValue CCR,
206 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000207
Evan Chengde8aa4e2010-05-05 18:28:36 +0000208 SDNode *SelectConcatVector(SDNode *N);
209
Evan Chengaf4550f2009-07-02 01:23:32 +0000210 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
211 /// inline asm expressions.
212 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
213 char ConstraintCode,
214 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000215
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000216 // Form pairs of consecutive S, D, or Q registers.
217 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000218 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000219 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
220
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000221 // Form sequences of 4 consecutive S, D, or Q registers.
222 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000223 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000224 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000225
226 // Get the alignment operand for a NEON VLD or VST instruction.
227 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000228};
Evan Chenga8e29892007-01-19 07:51:42 +0000229}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000230
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000231/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
232/// operand. If so Imm will receive the 32-bit value.
233static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
234 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
235 Imm = cast<ConstantSDNode>(N)->getZExtValue();
236 return true;
237 }
238 return false;
239}
240
241// isInt32Immediate - This method tests to see if a constant operand.
242// If so Imm will receive the 32 bit value.
243static bool isInt32Immediate(SDValue N, unsigned &Imm) {
244 return isInt32Immediate(N.getNode(), Imm);
245}
246
247// isOpcWithIntImmediate - This method tests to see if the node is a specific
248// opcode and that it has a immediate integer right operand.
249// If so Imm will receive the 32 bit value.
250static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
251 return N->getOpcode() == Opc &&
252 isInt32Immediate(N->getOperand(1).getNode(), Imm);
253}
254
255
Evan Chengf40deed2010-10-27 23:41:30 +0000256bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
257 ARM_AM::ShiftOpc ShOpcVal,
258 unsigned ShAmt) {
259 if (!Subtarget->isCortexA9())
260 return true;
261 if (Shift.hasOneUse())
262 return true;
263 // R << 2 is free.
264 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
265}
266
Chris Lattner52a261b2010-09-21 20:31:19 +0000267bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000268 SDValue &BaseReg,
269 SDValue &ShReg,
270 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000271 if (DisableShifterOp)
272 return false;
273
Evan Cheng055b0312009-06-29 07:51:04 +0000274 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
275
276 // Don't match base register only case. That is matched to a separate
277 // lower complexity pattern with explicit register operand.
278 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000279
Evan Cheng055b0312009-06-29 07:51:04 +0000280 BaseReg = N.getOperand(0);
281 unsigned ShImmVal = 0;
282 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000283 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000284 ShImmVal = RHS->getZExtValue() & 31;
285 } else {
286 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000287 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
288 return false;
289 }
290 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
291 MVT::i32);
292 return true;
293}
294
295bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
296 SDValue &BaseReg,
297 SDValue &ShReg,
298 SDValue &Opc) {
299 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
300
301 // Don't match base register only case. That is matched to a separate
302 // lower complexity pattern with explicit register operand.
303 if (ShOpcVal == ARM_AM::no_shift) return false;
304
305 BaseReg = N.getOperand(0);
306 unsigned ShImmVal = 0;
307 // Do not check isShifterOpProfitable. This must return true.
308 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
309 ShReg = CurDAG->getRegister(0, MVT::i32);
310 ShImmVal = RHS->getZExtValue() & 31;
311 } else {
312 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000313 }
314 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000315 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000316 return true;
317}
318
Jim Grosbach3e556122010-10-26 22:37:02 +0000319bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
320 SDValue &Base,
321 SDValue &OffImm) {
322 // Match simple R + imm12 operands.
323
324 // Base only.
325 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
326 if (N.getOpcode() == ISD::FrameIndex) {
327 // Match frame index...
328 int FI = cast<FrameIndexSDNode>(N)->getIndex();
329 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
330 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
331 return true;
332 } else if (N.getOpcode() == ARMISD::Wrapper &&
333 !(Subtarget->useMovt() &&
334 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
335 Base = N.getOperand(0);
336 } else
337 Base = N;
338 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
339 return true;
340 }
341
342 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
343 int RHSC = (int)RHS->getZExtValue();
344 if (N.getOpcode() == ISD::SUB)
345 RHSC = -RHSC;
346
347 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
348 Base = N.getOperand(0);
349 if (Base.getOpcode() == ISD::FrameIndex) {
350 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
351 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
352 }
353 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
354 return true;
355 }
356 }
357
358 // Base only.
359 Base = N;
360 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
361 return true;
362}
363
364
365
366bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
367 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000368 if (N.getOpcode() == ISD::MUL &&
369 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000370 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
371 // X * [3,5,9] -> X + X * [2,4,8] etc.
372 int RHSC = (int)RHS->getZExtValue();
373 if (RHSC & 1) {
374 RHSC = RHSC & ~1;
375 ARM_AM::AddrOpc AddSub = ARM_AM::add;
376 if (RHSC < 0) {
377 AddSub = ARM_AM::sub;
378 RHSC = - RHSC;
379 }
380 if (isPowerOf2_32(RHSC)) {
381 unsigned ShAmt = Log2_32(RHSC);
382 Base = Offset = N.getOperand(0);
383 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
384 ARM_AM::lsl),
385 MVT::i32);
386 return true;
387 }
388 }
389 }
390 }
391
392 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
393 return false;
394
395 // Leave simple R +/- imm12 operands for LDRi12
396 if (N.getOpcode() == ISD::ADD) {
397 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
398 int RHSC = (int)RHS->getZExtValue();
399 if ((RHSC >= 0 && RHSC < 0x1000) ||
400 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
401 return false;
402 }
403 }
404
Evan Chengf40deed2010-10-27 23:41:30 +0000405 if (Subtarget->isCortexA9() && !N.hasOneUse())
406 // Compute R +/- (R << N) and reuse it.
407 return false;
408
Jim Grosbach3e556122010-10-26 22:37:02 +0000409 // Otherwise this is R +/- [possibly shifted] R.
410 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
411 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
412 unsigned ShAmt = 0;
413
414 Base = N.getOperand(0);
415 Offset = N.getOperand(1);
416
417 if (ShOpcVal != ARM_AM::no_shift) {
418 // Check to see if the RHS of the shift is a constant, if not, we can't fold
419 // it.
420 if (ConstantSDNode *Sh =
421 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
422 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000423 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
424 Offset = N.getOperand(1).getOperand(0);
425 else {
426 ShAmt = 0;
427 ShOpcVal = ARM_AM::no_shift;
428 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000429 } else {
430 ShOpcVal = ARM_AM::no_shift;
431 }
432 }
433
434 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000435 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
436 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000437 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
438 if (ShOpcVal != ARM_AM::no_shift) {
439 // Check to see if the RHS of the shift is a constant, if not, we can't
440 // fold it.
441 if (ConstantSDNode *Sh =
442 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
443 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000444 if (!Subtarget->isCortexA9() ||
445 (N.hasOneUse() &&
446 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
447 Offset = N.getOperand(0).getOperand(0);
448 Base = N.getOperand(1);
449 } else {
450 ShAmt = 0;
451 ShOpcVal = ARM_AM::no_shift;
452 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000453 } else {
454 ShOpcVal = ARM_AM::no_shift;
455 }
456 }
457 }
458
459 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
460 MVT::i32);
461 return true;
462}
463
464
465
466
467//-----
468
Jim Grosbach82891622010-09-29 19:03:54 +0000469AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
470 SDValue &Base,
471 SDValue &Offset,
472 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000473 if (N.getOpcode() == ISD::MUL &&
474 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000475 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
476 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000477 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000478 if (RHSC & 1) {
479 RHSC = RHSC & ~1;
480 ARM_AM::AddrOpc AddSub = ARM_AM::add;
481 if (RHSC < 0) {
482 AddSub = ARM_AM::sub;
483 RHSC = - RHSC;
484 }
485 if (isPowerOf2_32(RHSC)) {
486 unsigned ShAmt = Log2_32(RHSC);
487 Base = Offset = N.getOperand(0);
488 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
489 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000490 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000491 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000492 }
493 }
494 }
495 }
496
Evan Chenga8e29892007-01-19 07:51:42 +0000497 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
498 Base = N;
499 if (N.getOpcode() == ISD::FrameIndex) {
500 int FI = cast<FrameIndexSDNode>(N)->getIndex();
501 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000502 } else if (N.getOpcode() == ARMISD::Wrapper &&
503 !(Subtarget->useMovt() &&
504 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000505 Base = N.getOperand(0);
506 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000507 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000508 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
509 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000510 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000511 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000512 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000513
Evan Chenga8e29892007-01-19 07:51:42 +0000514 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000515 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000516 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000517 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000518 if ((RHSC >= 0 && RHSC < 0x1000) ||
519 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000520 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000521 if (Base.getOpcode() == ISD::FrameIndex) {
522 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
523 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
524 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000525 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000526
527 ARM_AM::AddrOpc AddSub = ARM_AM::add;
528 if (RHSC < 0) {
529 AddSub = ARM_AM::sub;
530 RHSC = - RHSC;
531 }
532 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000533 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000534 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000535 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000536 }
Evan Chenga8e29892007-01-19 07:51:42 +0000537 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000538 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000539
Evan Chengf40deed2010-10-27 23:41:30 +0000540 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
541 // Compute R +/- (R << N) and reuse it.
542 Base = N;
543 Offset = CurDAG->getRegister(0, MVT::i32);
544 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
545 ARM_AM::no_shift),
546 MVT::i32);
547 return AM2_BASE;
548 }
549
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000550 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000551 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
552 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
553 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000554
Evan Chenga8e29892007-01-19 07:51:42 +0000555 Base = N.getOperand(0);
556 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000557
Evan Chenga8e29892007-01-19 07:51:42 +0000558 if (ShOpcVal != ARM_AM::no_shift) {
559 // Check to see if the RHS of the shift is a constant, if not, we can't fold
560 // it.
561 if (ConstantSDNode *Sh =
562 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000563 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000564 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
565 Offset = N.getOperand(1).getOperand(0);
566 else {
567 ShAmt = 0;
568 ShOpcVal = ARM_AM::no_shift;
569 }
Evan Chenga8e29892007-01-19 07:51:42 +0000570 } else {
571 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000572 }
573 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000574
Evan Chenga8e29892007-01-19 07:51:42 +0000575 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000576 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
577 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000578 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
579 if (ShOpcVal != ARM_AM::no_shift) {
580 // Check to see if the RHS of the shift is a constant, if not, we can't
581 // fold it.
582 if (ConstantSDNode *Sh =
583 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000584 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000585 if (!Subtarget->isCortexA9() ||
586 (N.hasOneUse() &&
587 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
588 Offset = N.getOperand(0).getOperand(0);
589 Base = N.getOperand(1);
590 } else {
591 ShAmt = 0;
592 ShOpcVal = ARM_AM::no_shift;
593 }
Evan Chenga8e29892007-01-19 07:51:42 +0000594 } else {
595 ShOpcVal = ARM_AM::no_shift;
596 }
597 }
598 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000599
Evan Chenga8e29892007-01-19 07:51:42 +0000600 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000601 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000602 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000603}
604
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000605bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000606 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000607 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000608 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
609 ? cast<LoadSDNode>(Op)->getAddressingMode()
610 : cast<StoreSDNode>(Op)->getAddressingMode();
611 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
612 ? ARM_AM::add : ARM_AM::sub;
613 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000614 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000615 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000617 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
618 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000619 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000620 return true;
621 }
622 }
623
624 Offset = N;
625 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
626 unsigned ShAmt = 0;
627 if (ShOpcVal != ARM_AM::no_shift) {
628 // Check to see if the RHS of the shift is a constant, if not, we can't fold
629 // it.
630 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000631 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000632 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
633 Offset = N.getOperand(0);
634 else {
635 ShAmt = 0;
636 ShOpcVal = ARM_AM::no_shift;
637 }
Evan Chenga8e29892007-01-19 07:51:42 +0000638 } else {
639 ShOpcVal = ARM_AM::no_shift;
640 }
641 }
642
643 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000644 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000645 return true;
646}
647
Evan Chenga8e29892007-01-19 07:51:42 +0000648
Chris Lattner52a261b2010-09-21 20:31:19 +0000649bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000650 SDValue &Base, SDValue &Offset,
651 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000652 if (N.getOpcode() == ISD::SUB) {
653 // X - C is canonicalize to X + -C, no need to handle it here.
654 Base = N.getOperand(0);
655 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000656 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000657 return true;
658 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000659
Evan Chenga8e29892007-01-19 07:51:42 +0000660 if (N.getOpcode() != ISD::ADD) {
661 Base = N;
662 if (N.getOpcode() == ISD::FrameIndex) {
663 int FI = cast<FrameIndexSDNode>(N)->getIndex();
664 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
665 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000666 Offset = CurDAG->getRegister(0, MVT::i32);
667 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000668 return true;
669 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000670
Evan Chenga8e29892007-01-19 07:51:42 +0000671 // If the RHS is +/- imm8, fold into addr mode.
672 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000673 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000674 if ((RHSC >= 0 && RHSC < 256) ||
675 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000676 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000677 if (Base.getOpcode() == ISD::FrameIndex) {
678 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
679 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
680 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000681 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000682
683 ARM_AM::AddrOpc AddSub = ARM_AM::add;
684 if (RHSC < 0) {
685 AddSub = ARM_AM::sub;
686 RHSC = - RHSC;
687 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000688 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000689 return true;
690 }
691 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000692
Evan Chenga8e29892007-01-19 07:51:42 +0000693 Base = N.getOperand(0);
694 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000695 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000696 return true;
697}
698
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000699bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000700 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000701 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000702 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
703 ? cast<LoadSDNode>(Op)->getAddressingMode()
704 : cast<StoreSDNode>(Op)->getAddressingMode();
705 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
706 ? ARM_AM::add : ARM_AM::sub;
707 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000708 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000709 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000710 Offset = CurDAG->getRegister(0, MVT::i32);
711 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000712 return true;
713 }
714 }
715
716 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000717 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000718 return true;
719}
720
Chris Lattner52a261b2010-09-21 20:31:19 +0000721bool ARMDAGToDAGISel::SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode) {
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000722 Addr = N;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000723 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000724 return true;
725}
Evan Chenga8e29892007-01-19 07:51:42 +0000726
Jim Grosbach3ab56582010-10-21 19:38:40 +0000727bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000728 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000729 if (N.getOpcode() != ISD::ADD) {
730 Base = N;
731 if (N.getOpcode() == ISD::FrameIndex) {
732 int FI = cast<FrameIndexSDNode>(N)->getIndex();
733 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000734 } else if (N.getOpcode() == ARMISD::Wrapper &&
735 !(Subtarget->useMovt() &&
736 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000737 Base = N.getOperand(0);
738 }
739 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000740 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000741 return true;
742 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000743
Evan Chenga8e29892007-01-19 07:51:42 +0000744 // If the RHS is +/- imm8, fold into addr mode.
745 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000746 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000747 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
748 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000749 if ((RHSC >= 0 && RHSC < 256) ||
750 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000751 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000752 if (Base.getOpcode() == ISD::FrameIndex) {
753 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
754 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
755 }
756
757 ARM_AM::AddrOpc AddSub = ARM_AM::add;
758 if (RHSC < 0) {
759 AddSub = ARM_AM::sub;
760 RHSC = - RHSC;
761 }
762 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000763 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000764 return true;
765 }
766 }
767 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000768
Evan Chenga8e29892007-01-19 07:51:42 +0000769 Base = N;
770 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000771 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000772 return true;
773}
774
Bob Wilson665814b2010-11-01 23:40:51 +0000775bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
776 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000777 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000778
779 unsigned Alignment = 0;
780 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
781 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
782 // The maximum alignment is equal to the memory size being referenced.
783 unsigned LSNAlign = LSN->getAlignment();
784 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
785 if (LSNAlign > MemSize && MemSize > 1)
786 Alignment = MemSize;
787 } else {
788 // All other uses of addrmode6 are for intrinsics. For now just record
789 // the raw alignment value; it will be refined later based on the legal
790 // alignment operands for the intrinsic.
791 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
792 }
793
794 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000795 return true;
796}
797
Chris Lattner52a261b2010-09-21 20:31:19 +0000798bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000799 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000800 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
801 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000802 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000803 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000804 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000805 return true;
806 }
807 return false;
808}
809
Chris Lattner52a261b2010-09-21 20:31:19 +0000810bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000811 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000812 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000813 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000814 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000815 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000816 return false;
817
818 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000819 return true;
820 }
821
Evan Chenga8e29892007-01-19 07:51:42 +0000822 Base = N.getOperand(0);
823 Offset = N.getOperand(1);
824 return true;
825}
826
Evan Cheng79d43262007-01-24 02:21:22 +0000827bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000828ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000829 unsigned Scale, SDValue &Base,
830 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000831 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000832 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000833 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000834 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000835 if (N.getOpcode() == ARMISD::Wrapper &&
836 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
837 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000838 }
839
Evan Chenga8e29892007-01-19 07:51:42 +0000840 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000841 if (N.getOpcode() == ARMISD::Wrapper &&
842 !(Subtarget->useMovt() &&
843 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
844 Base = N.getOperand(0);
845 } else
846 Base = N;
847
Owen Anderson825b72b2009-08-11 20:47:22 +0000848 Offset = CurDAG->getRegister(0, MVT::i32);
849 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000850 return true;
851 }
852
Evan Chengad0e4652007-02-06 00:22:06 +0000853 // Thumb does not have [sp, r] address mode.
854 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
855 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
856 if ((LHSR && LHSR->getReg() == ARM::SP) ||
857 (RHSR && RHSR->getReg() == ARM::SP)) {
858 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000859 Offset = CurDAG->getRegister(0, MVT::i32);
860 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000861 return true;
862 }
863
Evan Chenga8e29892007-01-19 07:51:42 +0000864 // If the RHS is + imm5 * scale, fold into addr mode.
865 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000866 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000867 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
868 RHSC /= Scale;
869 if (RHSC >= 0 && RHSC < 32) {
870 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000871 Offset = CurDAG->getRegister(0, MVT::i32);
872 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000873 return true;
874 }
875 }
876 }
877
Evan Chengc38f2bc2007-01-23 22:59:13 +0000878 Base = N.getOperand(0);
879 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000880 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000881 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000882}
883
Chris Lattner52a261b2010-09-21 20:31:19 +0000884bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000885 SDValue &Base, SDValue &OffImm,
886 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000887 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000888}
889
Chris Lattner52a261b2010-09-21 20:31:19 +0000890bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000891 SDValue &Base, SDValue &OffImm,
892 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000893 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000894}
895
Chris Lattner52a261b2010-09-21 20:31:19 +0000896bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000897 SDValue &Base, SDValue &OffImm,
898 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000899 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000900}
901
Chris Lattner52a261b2010-09-21 20:31:19 +0000902bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
903 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000904 if (N.getOpcode() == ISD::FrameIndex) {
905 int FI = cast<FrameIndexSDNode>(N)->getIndex();
906 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000907 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000908 return true;
909 }
Evan Cheng79d43262007-01-24 02:21:22 +0000910
Evan Chengad0e4652007-02-06 00:22:06 +0000911 if (N.getOpcode() != ISD::ADD)
912 return false;
913
914 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000915 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
916 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000917 // If the RHS is + imm8 * scale, fold into addr mode.
918 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000919 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000920 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
921 RHSC >>= 2;
922 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000923 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000924 if (Base.getOpcode() == ISD::FrameIndex) {
925 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
926 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
927 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000928 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000929 return true;
930 }
931 }
932 }
933 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000934
Evan Chenga8e29892007-01-19 07:51:42 +0000935 return false;
936}
937
Chris Lattner52a261b2010-09-21 20:31:19 +0000938bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000939 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000940 if (DisableShifterOp)
941 return false;
942
Evan Cheng9cb9e672009-06-27 02:26:13 +0000943 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
944
945 // Don't match base register only case. That is matched to a separate
946 // lower complexity pattern with explicit register operand.
947 if (ShOpcVal == ARM_AM::no_shift) return false;
948
949 BaseReg = N.getOperand(0);
950 unsigned ShImmVal = 0;
951 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
952 ShImmVal = RHS->getZExtValue() & 31;
953 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
954 return true;
955 }
956
957 return false;
958}
959
Chris Lattner52a261b2010-09-21 20:31:19 +0000960bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000961 SDValue &Base, SDValue &OffImm) {
962 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000963
Evan Cheng3a214252009-08-11 08:52:18 +0000964 // Base only.
965 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000966 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000967 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000968 int FI = cast<FrameIndexSDNode>(N)->getIndex();
969 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000970 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000971 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000972 } else if (N.getOpcode() == ARMISD::Wrapper &&
973 !(Subtarget->useMovt() &&
974 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000975 Base = N.getOperand(0);
976 if (Base.getOpcode() == ISD::TargetConstantPool)
977 return false; // We want to select t2LDRpci instead.
978 } else
979 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000980 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000981 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000982 }
Evan Cheng055b0312009-06-29 07:51:04 +0000983
984 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000985 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000986 // Let t2LDRi8 handle (R - imm8).
987 return false;
988
Evan Cheng055b0312009-06-29 07:51:04 +0000989 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000990 if (N.getOpcode() == ISD::SUB)
991 RHSC = -RHSC;
992
993 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000994 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000995 if (Base.getOpcode() == ISD::FrameIndex) {
996 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
997 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
998 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000999 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001000 return true;
1001 }
1002 }
1003
Evan Cheng3a214252009-08-11 08:52:18 +00001004 // Base only.
1005 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001006 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001007 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001008}
1009
Chris Lattner52a261b2010-09-21 20:31:19 +00001010bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001011 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001012 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001013 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001014 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1015 int RHSC = (int)RHS->getSExtValue();
1016 if (N.getOpcode() == ISD::SUB)
1017 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001018
Evan Cheng3a214252009-08-11 08:52:18 +00001019 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1020 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001021 if (Base.getOpcode() == ISD::FrameIndex) {
1022 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1023 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1024 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001025 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001026 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001027 }
Evan Cheng055b0312009-06-29 07:51:04 +00001028 }
1029 }
1030
1031 return false;
1032}
1033
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001034bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001035 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001036 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001037 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1038 ? cast<LoadSDNode>(Op)->getAddressingMode()
1039 : cast<StoreSDNode>(Op)->getAddressingMode();
1040 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1041 int RHSC = (int)RHS->getZExtValue();
1042 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001043 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001044 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1045 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001046 return true;
1047 }
1048 }
1049
1050 return false;
1051}
1052
Chris Lattner52a261b2010-09-21 20:31:19 +00001053bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001054 SDValue &Base,
1055 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001056 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1057 if (N.getOpcode() != ISD::ADD)
1058 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001059
Evan Cheng3a214252009-08-11 08:52:18 +00001060 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1061 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1062 int RHSC = (int)RHS->getZExtValue();
1063 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1064 return false;
1065 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001066 return false;
1067 }
1068
Evan Chengf40deed2010-10-27 23:41:30 +00001069 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1070 // Compute R + (R << [1,2,3]) and reuse it.
1071 Base = N;
1072 return false;
1073 }
1074
Evan Cheng055b0312009-06-29 07:51:04 +00001075 // Look for (R + R) or (R + (R << [1,2,3])).
1076 unsigned ShAmt = 0;
1077 Base = N.getOperand(0);
1078 OffReg = N.getOperand(1);
1079
1080 // Swap if it is ((R << c) + R).
1081 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1082 if (ShOpcVal != ARM_AM::lsl) {
1083 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1084 if (ShOpcVal == ARM_AM::lsl)
1085 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001086 }
1087
Evan Cheng055b0312009-06-29 07:51:04 +00001088 if (ShOpcVal == ARM_AM::lsl) {
1089 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1090 // it.
1091 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1092 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001093 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1094 OffReg = OffReg.getOperand(0);
1095 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001096 ShAmt = 0;
1097 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001098 }
Evan Cheng055b0312009-06-29 07:51:04 +00001099 } else {
1100 ShOpcVal = ARM_AM::no_shift;
1101 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001102 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001103
Owen Anderson825b72b2009-08-11 20:47:22 +00001104 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001105
1106 return true;
1107}
1108
1109//===--------------------------------------------------------------------===//
1110
Evan Chengee568cf2007-07-05 07:15:27 +00001111/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001112static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001113 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001114}
1115
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001116SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1117 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001118 ISD::MemIndexedMode AM = LD->getAddressingMode();
1119 if (AM == ISD::UNINDEXED)
1120 return NULL;
1121
Owen Andersone50ed302009-08-10 22:56:29 +00001122 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001123 SDValue Offset, AMOpc;
1124 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1125 unsigned Opcode = 0;
1126 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001127 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001128 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001129 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1130 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001131 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001132 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001133 Match = true;
1134 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1135 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1136 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001137 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001138 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001139 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001140 Match = true;
1141 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1142 }
1143 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001144 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001145 Match = true;
1146 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1147 }
1148 }
1149 }
1150
1151 if (Match) {
1152 SDValue Chain = LD->getChain();
1153 SDValue Base = LD->getBasePtr();
1154 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001155 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001156 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001157 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001158 }
1159
1160 return NULL;
1161}
1162
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001163SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1164 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001165 ISD::MemIndexedMode AM = LD->getAddressingMode();
1166 if (AM == ISD::UNINDEXED)
1167 return NULL;
1168
Owen Andersone50ed302009-08-10 22:56:29 +00001169 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001170 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001171 SDValue Offset;
1172 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1173 unsigned Opcode = 0;
1174 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001175 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001176 switch (LoadedVT.getSimpleVT().SimpleTy) {
1177 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001178 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1179 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001180 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001181 if (isSExtLd)
1182 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1183 else
1184 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001185 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001186 case MVT::i8:
1187 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001188 if (isSExtLd)
1189 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1190 else
1191 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001192 break;
1193 default:
1194 return NULL;
1195 }
1196 Match = true;
1197 }
1198
1199 if (Match) {
1200 SDValue Chain = LD->getChain();
1201 SDValue Base = LD->getBasePtr();
1202 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001203 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001204 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001205 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001206 }
1207
1208 return NULL;
1209}
1210
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001211/// PairSRegs - Form a D register from a pair of S registers.
1212///
1213SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1214 DebugLoc dl = V0.getNode()->getDebugLoc();
1215 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1216 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001217 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1218 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001219}
1220
Evan Cheng603afbf2010-05-10 17:34:18 +00001221/// PairDRegs - Form a quad register from a pair of D registers.
1222///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001223SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1224 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001225 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1226 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001227 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1228 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001229}
1230
Evan Cheng7f687192010-05-14 00:21:45 +00001231/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001232///
1233SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1234 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001235 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1236 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001237 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1238 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1239}
1240
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001241/// QuadSRegs - Form 4 consecutive S registers.
1242///
1243SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1244 SDValue V2, SDValue V3) {
1245 DebugLoc dl = V0.getNode()->getDebugLoc();
1246 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1247 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1248 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1249 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1250 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1251 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1252}
1253
Evan Cheng7f687192010-05-14 00:21:45 +00001254/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001255///
1256SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1257 SDValue V2, SDValue V3) {
1258 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001259 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1260 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1261 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1262 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001263 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1264 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1265}
1266
Evan Cheng8f6de382010-05-16 03:27:48 +00001267/// QuadQRegs - Form 4 consecutive Q registers.
1268///
1269SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1270 SDValue V2, SDValue V3) {
1271 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001272 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1273 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1274 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1275 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001276 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1277 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1278}
1279
Bob Wilson2a6e6162010-09-23 23:42:37 +00001280/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1281/// of a NEON VLD or VST instruction. The supported values depend on the
1282/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001283SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1284 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001285 unsigned NumRegs = NumVecs;
1286 if (!is64BitVector && NumVecs < 3)
1287 NumRegs *= 2;
1288
Bob Wilson665814b2010-11-01 23:40:51 +00001289 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001290 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001291 Alignment = 32;
1292 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1293 Alignment = 16;
1294 else if (Alignment >= 8)
1295 Alignment = 8;
1296 else
1297 Alignment = 0;
1298
1299 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001300}
1301
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001302SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001303 unsigned *DOpcodes, unsigned *QOpcodes0,
1304 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001305 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001306 DebugLoc dl = N->getDebugLoc();
1307
Bob Wilson226036e2010-03-20 22:13:40 +00001308 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001309 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001310 return NULL;
1311
1312 SDValue Chain = N->getOperand(0);
1313 EVT VT = N->getValueType(0);
1314 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001315 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001316
Bob Wilson3e36f132009-10-14 17:28:52 +00001317 unsigned OpcodeIndex;
1318 switch (VT.getSimpleVT().SimpleTy) {
1319 default: llvm_unreachable("unhandled vld type");
1320 // Double-register operations:
1321 case MVT::v8i8: OpcodeIndex = 0; break;
1322 case MVT::v4i16: OpcodeIndex = 1; break;
1323 case MVT::v2f32:
1324 case MVT::v2i32: OpcodeIndex = 2; break;
1325 case MVT::v1i64: OpcodeIndex = 3; break;
1326 // Quad-register operations:
1327 case MVT::v16i8: OpcodeIndex = 0; break;
1328 case MVT::v8i16: OpcodeIndex = 1; break;
1329 case MVT::v4f32:
1330 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001331 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001332 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001333 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001334 }
1335
Bob Wilsonf5721912010-09-03 18:16:02 +00001336 EVT ResTy;
1337 if (NumVecs == 1)
1338 ResTy = VT;
1339 else {
1340 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1341 if (!is64BitVector)
1342 ResTyElts *= 2;
1343 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1344 }
1345
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001346 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001347 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001348 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001349 if (is64BitVector) {
1350 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001351 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001352 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001353 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001354 return VLd;
1355
Bob Wilsonf5721912010-09-03 18:16:02 +00001356 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001357 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001358 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001359 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001360 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001361 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001362 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001363 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001364 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001365 }
1366
Bob Wilson621f1952010-03-23 05:25:43 +00001367 if (NumVecs <= 2) {
1368 // Quad registers are directly supported for VLD1 and VLD2,
1369 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001370 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001371 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001372 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001373 if (NumVecs == 1)
1374 return VLd;
1375
Bob Wilsonf5721912010-09-03 18:16:02 +00001376 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001377 Chain = SDValue(VLd, 1);
1378
Bob Wilson3e36f132009-10-14 17:28:52 +00001379 } else {
1380 // Otherwise, quad registers are loaded with two separate instructions,
1381 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001382 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001383
Bob Wilson24f995d2009-10-14 18:32:29 +00001384 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001385 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001386 SDValue ImplDef =
1387 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1388 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1389 SDNode *VLdA =
1390 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1391 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001392
Bob Wilson24f995d2009-10-14 18:32:29 +00001393 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001394 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001395 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1396 Pred, Reg0, Chain };
1397 SDNode *VLdB =
1398 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1399 SuperReg = SDValue(VLdB, 0);
1400 Chain = SDValue(VLdB, 2);
1401 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001402
Bob Wilsonf5721912010-09-03 18:16:02 +00001403 // Extract out the Q registers.
1404 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1405 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1406 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1407 dl, VT, SuperReg);
1408 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001409 }
1410 ReplaceUses(SDValue(N, NumVecs), Chain);
1411 return NULL;
1412}
1413
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001414SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001415 unsigned *DOpcodes, unsigned *QOpcodes0,
1416 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001417 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001418 DebugLoc dl = N->getDebugLoc();
1419
Bob Wilson226036e2010-03-20 22:13:40 +00001420 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001421 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001422 return NULL;
1423
1424 SDValue Chain = N->getOperand(0);
1425 EVT VT = N->getOperand(3).getValueType();
1426 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001427 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001428
Bob Wilson24f995d2009-10-14 18:32:29 +00001429 unsigned OpcodeIndex;
1430 switch (VT.getSimpleVT().SimpleTy) {
1431 default: llvm_unreachable("unhandled vst type");
1432 // Double-register operations:
1433 case MVT::v8i8: OpcodeIndex = 0; break;
1434 case MVT::v4i16: OpcodeIndex = 1; break;
1435 case MVT::v2f32:
1436 case MVT::v2i32: OpcodeIndex = 2; break;
1437 case MVT::v1i64: OpcodeIndex = 3; break;
1438 // Quad-register operations:
1439 case MVT::v16i8: OpcodeIndex = 0; break;
1440 case MVT::v8i16: OpcodeIndex = 1; break;
1441 case MVT::v4f32:
1442 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001443 case MVT::v2i64: OpcodeIndex = 3;
1444 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1445 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001446 }
1447
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001448 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001449 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001450
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001451 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001452 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001453 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001454
1455 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001456 if (NumVecs == 1) {
1457 Ops.push_back(N->getOperand(3));
1458 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001459 SDValue RegSeq;
1460 SDValue V0 = N->getOperand(0+3);
1461 SDValue V1 = N->getOperand(1+3);
1462
1463 // Form a REG_SEQUENCE to force register allocation.
1464 if (NumVecs == 2)
1465 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1466 else {
1467 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001468 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001469 // an undef.
1470 SDValue V3 = (NumVecs == 3)
1471 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1472 : N->getOperand(3+3);
1473 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1474 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001475 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001476 }
Evan Chengac0869d2009-11-21 06:21:52 +00001477 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001478 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001479 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001480 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001481 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001482 }
1483
Bob Wilson11d98992010-03-23 06:20:33 +00001484 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001485 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001486 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001487 if (NumVecs == 1) {
1488 Ops.push_back(N->getOperand(3));
1489 } else {
1490 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001491 SDValue Q0 = N->getOperand(3);
1492 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001493 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001494 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001495 Ops.push_back(Pred);
1496 Ops.push_back(Reg0); // predicate register
1497 Ops.push_back(Chain);
1498 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001499 }
1500
1501 // Otherwise, quad registers are stored with two separate instructions,
1502 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001503
Bob Wilson07f6e802010-06-16 21:34:01 +00001504 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001505 SDValue V0 = N->getOperand(0+3);
1506 SDValue V1 = N->getOperand(1+3);
1507 SDValue V2 = N->getOperand(2+3);
1508 SDValue V3 = (NumVecs == 3)
1509 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1510 : N->getOperand(3+3);
1511 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001512
1513 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001514 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001515 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001516 Ops.push_back(Pred);
1517 Ops.push_back(Reg0); // predicate register
1518 Ops.push_back(Chain);
1519 unsigned Opc = QOpcodes0[OpcodeIndex];
1520 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001521 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001522 Chain = SDValue(VStA, 1);
1523
1524 // Store the odd D registers.
1525 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001526 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001527 Opc = QOpcodes1[OpcodeIndex];
1528 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001529 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001530 Chain = SDValue(VStB, 1);
1531 ReplaceUses(SDValue(N, 0), Chain);
1532 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001533}
1534
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001535SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001536 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001537 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001538 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001539 DebugLoc dl = N->getDebugLoc();
1540
Bob Wilson226036e2010-03-20 22:13:40 +00001541 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001542 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001543 return NULL;
1544
1545 SDValue Chain = N->getOperand(0);
1546 unsigned Lane =
1547 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001548 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001549 bool is64BitVector = VT.is64BitVector();
1550
Bob Wilson665814b2010-11-01 23:40:51 +00001551 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001552 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001553 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001554 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1555 if (Alignment > NumBytes)
1556 Alignment = NumBytes;
1557 // Alignment must be a power of two; make sure of that.
1558 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001559 if (Alignment == 1)
1560 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001561 }
Bob Wilson665814b2010-11-01 23:40:51 +00001562 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001563
Bob Wilsona7c397c2009-10-14 16:19:03 +00001564 unsigned OpcodeIndex;
1565 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001566 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001567 // Double-register operations:
1568 case MVT::v8i8: OpcodeIndex = 0; break;
1569 case MVT::v4i16: OpcodeIndex = 1; break;
1570 case MVT::v2f32:
1571 case MVT::v2i32: OpcodeIndex = 2; break;
1572 // Quad-register operations:
1573 case MVT::v8i16: OpcodeIndex = 0; break;
1574 case MVT::v4f32:
1575 case MVT::v4i32: OpcodeIndex = 1; break;
1576 }
1577
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001578 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001579 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001580
Bob Wilson8466fa12010-09-13 23:01:35 +00001581 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001582 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001583 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001584
Jim Grosbach3ab56582010-10-21 19:38:40 +00001585 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001586 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001587
Bob Wilson8466fa12010-09-13 23:01:35 +00001588 SDValue SuperReg;
1589 SDValue V0 = N->getOperand(0+3);
1590 SDValue V1 = N->getOperand(1+3);
1591 if (NumVecs == 2) {
1592 if (is64BitVector)
1593 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1594 else
1595 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001596 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001597 SDValue V2 = N->getOperand(2+3);
1598 SDValue V3 = (NumVecs == 3)
1599 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1600 : N->getOperand(3+3);
1601 if (is64BitVector)
1602 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1603 else
1604 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001605 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001606 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001607 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001608 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001609 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001610 Ops.push_back(Chain);
1611
Bob Wilson96493442009-10-14 16:46:45 +00001612 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001613 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001614
Bob Wilson8466fa12010-09-13 23:01:35 +00001615 EVT ResTy;
1616 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1617 if (!is64BitVector)
1618 ResTyElts *= 2;
1619 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001620
Bob Wilson8466fa12010-09-13 23:01:35 +00001621 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1622 Ops.data(), 7);
1623 SuperReg = SDValue(VLdLn, 0);
1624 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001625
Bob Wilson8466fa12010-09-13 23:01:35 +00001626 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001627 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1628 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1629 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1630 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1631 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001632 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1633 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001634 return NULL;
1635}
1636
Bob Wilson78dfbc32010-07-07 00:08:54 +00001637SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1638 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001639 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1640 DebugLoc dl = N->getDebugLoc();
1641 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001642 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001643
1644 // Form a REG_SEQUENCE to force register allocation.
1645 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001646 SDValue V0 = N->getOperand(FirstTblReg + 0);
1647 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001648 if (NumVecs == 2)
1649 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1650 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001651 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001652 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001653 // an undef.
1654 SDValue V3 = (NumVecs == 3)
1655 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001656 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001657 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1658 }
1659
Bob Wilson78dfbc32010-07-07 00:08:54 +00001660 SmallVector<SDValue, 6> Ops;
1661 if (IsExt)
1662 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001663 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001664 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001665 Ops.push_back(getAL(CurDAG)); // predicate
1666 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001667 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001668}
1669
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001670SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001671 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001672 if (!Subtarget->hasV6T2Ops())
1673 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001674
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001675 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1676 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1677
1678
1679 // For unsigned extracts, check for a shift right and mask
1680 unsigned And_imm = 0;
1681 if (N->getOpcode() == ISD::AND) {
1682 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1683
1684 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1685 if (And_imm & (And_imm + 1))
1686 return NULL;
1687
1688 unsigned Srl_imm = 0;
1689 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1690 Srl_imm)) {
1691 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1692
1693 unsigned Width = CountTrailingOnes_32(And_imm);
1694 unsigned LSB = Srl_imm;
1695 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1696 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1697 CurDAG->getTargetConstant(LSB, MVT::i32),
1698 CurDAG->getTargetConstant(Width, MVT::i32),
1699 getAL(CurDAG), Reg0 };
1700 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1701 }
1702 }
1703 return NULL;
1704 }
1705
1706 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001707 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001708 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001709 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1710 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001711 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001712 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1713 unsigned Width = 32 - Srl_imm;
1714 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001715 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001716 return NULL;
1717 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001718 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001719 CurDAG->getTargetConstant(LSB, MVT::i32),
1720 CurDAG->getTargetConstant(Width, MVT::i32),
1721 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001722 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001723 }
1724 }
1725 return NULL;
1726}
1727
Evan Cheng9ef48352009-11-20 00:54:03 +00001728SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001729SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001730 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1731 SDValue CPTmp0;
1732 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001733 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001734 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1735 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1736 unsigned Opc = 0;
1737 switch (SOShOp) {
1738 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1739 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1740 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1741 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1742 default:
1743 llvm_unreachable("Unknown so_reg opcode!");
1744 break;
1745 }
1746 SDValue SOShImm =
1747 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1748 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1749 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001750 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001751 }
1752 return 0;
1753}
1754
1755SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001756SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001757 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1758 SDValue CPTmp0;
1759 SDValue CPTmp1;
1760 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001761 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001762 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1763 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001764 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001765 }
1766 return 0;
1767}
1768
1769SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001770SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001771 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1772 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1773 if (!T)
1774 return 0;
1775
Jim Grosbacha4257162010-10-07 00:53:56 +00001776 unsigned TrueImm = T->getZExtValue();
1777 bool isSoImm = Pred_t2_so_imm(TrueVal.getNode());
1778 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001779 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1780 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1781 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001782 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1783 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001784 }
1785 return 0;
1786}
1787
1788SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001789SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001790 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1791 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1792 if (!T)
1793 return 0;
1794
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001795 unsigned TrueImm = T->getZExtValue();
1796 bool isSoImm = Pred_so_imm(TrueVal.getNode());
1797 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1798 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001799 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1800 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001801 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1802 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001803 }
1804 return 0;
1805}
1806
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001807SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1808 EVT VT = N->getValueType(0);
1809 SDValue FalseVal = N->getOperand(0);
1810 SDValue TrueVal = N->getOperand(1);
1811 SDValue CC = N->getOperand(2);
1812 SDValue CCR = N->getOperand(3);
1813 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001814 assert(CC.getOpcode() == ISD::Constant);
1815 assert(CCR.getOpcode() == ISD::Register);
1816 ARMCC::CondCodes CCVal =
1817 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001818
1819 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1820 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1821 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1822 // Pattern complexity = 18 cost = 1 size = 0
1823 SDValue CPTmp0;
1824 SDValue CPTmp1;
1825 SDValue CPTmp2;
1826 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001827 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001828 CCVal, CCR, InFlag);
1829 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001830 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001831 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1832 if (Res)
1833 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001834 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001835 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001836 CCVal, CCR, InFlag);
1837 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001838 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001839 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1840 if (Res)
1841 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001842 }
1843
1844 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001845 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001846 // (imm:i32):$cc)
1847 // Emits: (MOVCCi:i32 GPR:i32:$false,
1848 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1849 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001850 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001851 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001852 CCVal, CCR, InFlag);
1853 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001854 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001855 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1856 if (Res)
1857 return Res;
1858 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001859 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001860 CCVal, CCR, InFlag);
1861 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001862 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001863 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1864 if (Res)
1865 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001866 }
1867 }
1868
1869 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1870 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1871 // Pattern complexity = 6 cost = 1 size = 0
1872 //
1873 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1874 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1875 // Pattern complexity = 6 cost = 11 size = 0
1876 //
1877 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001878 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1879 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001880 unsigned Opc = 0;
1881 switch (VT.getSimpleVT().SimpleTy) {
1882 default: assert(false && "Illegal conditional move type!");
1883 break;
1884 case MVT::i32:
1885 Opc = Subtarget->isThumb()
1886 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1887 : ARM::MOVCCr;
1888 break;
1889 case MVT::f32:
1890 Opc = ARM::VMOVScc;
1891 break;
1892 case MVT::f64:
1893 Opc = ARM::VMOVDcc;
1894 break;
1895 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001896 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001897}
1898
Evan Chengde8aa4e2010-05-05 18:28:36 +00001899SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1900 // The only time a CONCAT_VECTORS operation can have legal types is when
1901 // two 64-bit vectors are concatenated to a 128-bit vector.
1902 EVT VT = N->getValueType(0);
1903 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1904 llvm_unreachable("unexpected CONCAT_VECTORS");
1905 DebugLoc dl = N->getDebugLoc();
1906 SDValue V0 = N->getOperand(0);
1907 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001908 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1909 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001910 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1911 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1912}
1913
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001914SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001915 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001916
Dan Gohmane8be6c62008-07-17 19:10:17 +00001917 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001918 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001919
1920 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001921 default: break;
1922 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001923 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001924 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001925 if (Subtarget->hasThumb2())
1926 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1927 // be done with MOV + MOVT, at worst.
1928 UseCP = 0;
1929 else {
1930 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001931 UseCP = (Val > 255 && // MOV
1932 ~Val > 255 && // MOV + MVN
1933 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001934 } else
1935 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1936 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1937 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1938 }
1939
Evan Chenga8e29892007-01-19 07:51:42 +00001940 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001941 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001942 CurDAG->getTargetConstantPool(ConstantInt::get(
1943 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001944 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001945
1946 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001947 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001948 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001949 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001950 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001951 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1952 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001953 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001954 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001955 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001956 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001957 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001958 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001959 CurDAG->getEntryNode()
1960 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001961 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00001962 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00001963 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001965 return NULL;
1966 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001967
Evan Chenga8e29892007-01-19 07:51:42 +00001968 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001969 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001970 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001971 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001972 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001973 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001974 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001975 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001976 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1977 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001978 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001979 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1980 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001981 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1982 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1983 CurDAG->getRegister(0, MVT::i32) };
1984 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001985 }
Evan Chenga8e29892007-01-19 07:51:42 +00001986 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001987 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001988 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001989 return I;
1990 break;
1991 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001992 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001993 return I;
1994 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001995 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001996 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001997 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001999 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002000 if (!RHSV) break;
2001 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002002 unsigned ShImm = Log2_32(RHSV-1);
2003 if (ShImm >= 32)
2004 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002005 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002006 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002007 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2008 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002009 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002010 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002011 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002012 } else {
2013 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002014 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002015 }
Evan Chenga8e29892007-01-19 07:51:42 +00002016 }
2017 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002018 unsigned ShImm = Log2_32(RHSV+1);
2019 if (ShImm >= 32)
2020 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002021 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002022 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002023 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2024 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002025 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002026 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2027 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002028 } else {
2029 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002030 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002031 }
Evan Chenga8e29892007-01-19 07:51:42 +00002032 }
2033 }
2034 break;
Evan Cheng20956592009-10-21 08:15:52 +00002035 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002036 // Check for unsigned bitfield extract
2037 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2038 return I;
2039
Evan Cheng20956592009-10-21 08:15:52 +00002040 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2041 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2042 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2043 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2044 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002045 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002046 if (VT != MVT::i32)
2047 break;
2048 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2049 ? ARM::t2MOVTi16
2050 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2051 if (!Opc)
2052 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002053 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002054 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2055 if (!N1C)
2056 break;
2057 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2058 SDValue N2 = N0.getOperand(1);
2059 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2060 if (!N2C)
2061 break;
2062 unsigned N1CVal = N1C->getZExtValue();
2063 unsigned N2CVal = N2C->getZExtValue();
2064 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2065 (N1CVal & 0xffffU) == 0xffffU &&
2066 (N2CVal & 0xffffU) == 0x0U) {
2067 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2068 MVT::i32);
2069 SDValue Ops[] = { N0.getOperand(0), Imm16,
2070 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2071 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2072 }
2073 }
2074 break;
2075 }
Jim Grosbache5165492009-11-09 00:11:35 +00002076 case ARMISD::VMOVRRD:
2077 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002078 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002079 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002080 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002081 if (Subtarget->isThumb1Only())
2082 break;
2083 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002084 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002085 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2086 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002087 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002088 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002089 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002090 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2091 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002092 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002093 }
Evan Chengee568cf2007-07-05 07:15:27 +00002094 }
Dan Gohman525178c2007-10-08 18:33:35 +00002095 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002096 if (Subtarget->isThumb1Only())
2097 break;
2098 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002099 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002100 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002101 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002102 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002103 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002104 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2105 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002106 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002107 }
Evan Chengee568cf2007-07-05 07:15:27 +00002108 }
Evan Chenga8e29892007-01-19 07:51:42 +00002109 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002110 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002111 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002112 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002113 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002115 if (ResNode)
2116 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002117 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002118 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002119 }
Evan Chengee568cf2007-07-05 07:15:27 +00002120 case ARMISD::BRCOND: {
2121 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2122 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2123 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002124
Evan Chengee568cf2007-07-05 07:15:27 +00002125 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2126 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2127 // Pattern complexity = 6 cost = 1 size = 0
2128
David Goodwin5e47a9a2009-06-30 18:04:13 +00002129 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2130 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2131 // Pattern complexity = 6 cost = 1 size = 0
2132
Jim Grosbach764ab522009-08-11 15:33:49 +00002133 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002134 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002135 SDValue Chain = N->getOperand(0);
2136 SDValue N1 = N->getOperand(1);
2137 SDValue N2 = N->getOperand(2);
2138 SDValue N3 = N->getOperand(3);
2139 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002140 assert(N1.getOpcode() == ISD::BasicBlock);
2141 assert(N2.getOpcode() == ISD::Constant);
2142 assert(N3.getOpcode() == ISD::Register);
2143
Dan Gohman475871a2008-07-27 21:46:04 +00002144 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002145 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002146 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002147 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002148 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2149 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002150 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002151 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002152 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002153 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002154 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002156 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002157 return NULL;
2158 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002159 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002160 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002161 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002162 EVT VT = N->getValueType(0);
2163 SDValue N0 = N->getOperand(0);
2164 SDValue N1 = N->getOperand(1);
2165 SDValue N2 = N->getOperand(2);
2166 SDValue N3 = N->getOperand(3);
2167 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002168 assert(N2.getOpcode() == ISD::Constant);
2169 assert(N3.getOpcode() == ISD::Register);
2170
Dan Gohman475871a2008-07-27 21:46:04 +00002171 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002172 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002173 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002174 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002175 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002176 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002177 default: assert(false && "Illegal conditional move type!");
2178 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002179 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002180 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002181 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002182 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002183 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002184 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002185 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002186 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002187 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002188
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002189 case ARMISD::VZIP: {
2190 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002191 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002192 switch (VT.getSimpleVT().SimpleTy) {
2193 default: return NULL;
2194 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2195 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2196 case MVT::v2f32:
2197 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2198 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2199 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2200 case MVT::v4f32:
2201 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2202 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002203 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002204 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2205 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2206 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002207 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002208 case ARMISD::VUZP: {
2209 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002210 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002211 switch (VT.getSimpleVT().SimpleTy) {
2212 default: return NULL;
2213 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2214 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2215 case MVT::v2f32:
2216 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2217 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2218 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2219 case MVT::v4f32:
2220 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2221 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002222 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002223 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2224 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2225 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002226 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002227 case ARMISD::VTRN: {
2228 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002229 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002230 switch (VT.getSimpleVT().SimpleTy) {
2231 default: return NULL;
2232 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2233 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2234 case MVT::v2f32:
2235 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2236 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2237 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2238 case MVT::v4f32:
2239 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2240 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002241 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002242 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2243 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2244 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002245 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002246 case ARMISD::BUILD_VECTOR: {
2247 EVT VecVT = N->getValueType(0);
2248 EVT EltVT = VecVT.getVectorElementType();
2249 unsigned NumElts = VecVT.getVectorNumElements();
2250 if (EltVT.getSimpleVT() == MVT::f64) {
2251 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2252 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2253 }
2254 assert(EltVT.getSimpleVT() == MVT::f32 &&
2255 "unexpected type for BUILD_VECTOR");
2256 if (NumElts == 2)
2257 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2258 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2259 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2260 N->getOperand(2), N->getOperand(3));
2261 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002262
2263 case ISD::INTRINSIC_VOID:
2264 case ISD::INTRINSIC_W_CHAIN: {
2265 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002266 switch (IntNo) {
2267 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002268 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002269
Bob Wilson621f1952010-03-23 05:25:43 +00002270 case Intrinsic::arm_neon_vld1: {
2271 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2272 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002273 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2274 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002275 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2276 }
2277
Bob Wilson31fb12f2009-08-26 17:39:53 +00002278 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002279 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2280 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2281 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2282 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002283 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002284 }
2285
2286 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002287 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2288 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2289 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2290 ARM::VLD3q16Pseudo_UPD,
2291 ARM::VLD3q32Pseudo_UPD };
2292 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2293 ARM::VLD3q16oddPseudo_UPD,
2294 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002295 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002296 }
2297
2298 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002299 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2300 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2301 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2302 ARM::VLD4q16Pseudo_UPD,
2303 ARM::VLD4q32Pseudo_UPD };
2304 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2305 ARM::VLD4q16oddPseudo_UPD,
2306 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002307 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002308 }
2309
Bob Wilson243fcc52009-09-01 04:26:28 +00002310 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002311 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2312 ARM::VLD2LNd32Pseudo };
2313 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2314 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002315 }
2316
2317 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002318 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2319 ARM::VLD3LNd32Pseudo };
2320 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2321 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002322 }
2323
2324 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002325 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2326 ARM::VLD4LNd32Pseudo };
2327 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2328 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002329 }
2330
Bob Wilson11d98992010-03-23 06:20:33 +00002331 case Intrinsic::arm_neon_vst1: {
2332 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2333 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002334 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2335 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002336 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2337 }
2338
Bob Wilson31fb12f2009-08-26 17:39:53 +00002339 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002340 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2341 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2342 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2343 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002344 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002345 }
2346
2347 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002348 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2349 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2350 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2351 ARM::VST3q16Pseudo_UPD,
2352 ARM::VST3q32Pseudo_UPD };
2353 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2354 ARM::VST3q16oddPseudo_UPD,
2355 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002356 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002357 }
2358
2359 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002360 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002361 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002362 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2363 ARM::VST4q16Pseudo_UPD,
2364 ARM::VST4q32Pseudo_UPD };
2365 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2366 ARM::VST4q16oddPseudo_UPD,
2367 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002368 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002369 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002370
2371 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002372 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2373 ARM::VST2LNd32Pseudo };
2374 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2375 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002376 }
2377
2378 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002379 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2380 ARM::VST3LNd32Pseudo };
2381 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2382 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002383 }
2384
2385 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002386 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2387 ARM::VST4LNd32Pseudo };
2388 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2389 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002390 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002391 }
Bob Wilson429009b2010-05-06 16:05:26 +00002392 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002393 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002394
Bob Wilsond491d6e2010-07-06 23:36:25 +00002395 case ISD::INTRINSIC_WO_CHAIN: {
2396 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2397 switch (IntNo) {
2398 default:
2399 break;
2400
2401 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002402 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002403 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002404 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002405 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002406 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002407
2408 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002409 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002410 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002411 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002412 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002413 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002414 }
2415 break;
2416 }
2417
Bob Wilson429009b2010-05-06 16:05:26 +00002418 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002419 return SelectConcatVector(N);
2420 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002421
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002422 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002423}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002424
Bob Wilson224c2442009-05-19 05:53:42 +00002425bool ARMDAGToDAGISel::
2426SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2427 std::vector<SDValue> &OutOps) {
2428 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002429 // Require the address to be in a register. That is safe for all ARM
2430 // variants and it is hard to do anything much smarter without knowing
2431 // how the operand is used.
2432 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002433 return false;
2434}
2435
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002436/// createARMISelDag - This pass converts a legalized DAG into a
2437/// ARM-specific DAG, ready for instruction scheduling.
2438///
Bob Wilson522ce972009-09-28 14:30:20 +00002439FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2440 CodeGenOpt::Level OptLevel) {
2441 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002442}