blob: 965ec6e4d1cff578c32d3ac011d31ebeaf3daafe [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 SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000117 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000118 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000119
Chris Lattner52a261b2010-09-21 20:31:19 +0000120 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000121 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000122
Chris Lattner52a261b2010-09-21 20:31:19 +0000123 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
124 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &Base, SDValue &OffImm,
126 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000127 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000128 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000129 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000130 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000131 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000132 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000134
Chris Lattner52a261b2010-09-21 20:31:19 +0000135 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000136 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000137 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
138 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000139 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000141 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000142 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000143 SDValue &OffReg, SDValue &ShImm);
144
Evan Cheng875a6ac2010-11-12 22:42:47 +0000145 inline bool is_so_imm(unsigned Imm) const {
146 return ARM_AM::getSOImmVal(Imm) != -1;
147 }
148
149 inline bool is_so_imm_not(unsigned Imm) const {
150 return ARM_AM::getSOImmVal(~Imm) != -1;
151 }
152
153 inline bool is_t2_so_imm(unsigned Imm) const {
154 return ARM_AM::getT2SOImmVal(Imm) != -1;
155 }
156
157 inline bool is_t2_so_imm_not(unsigned Imm) const {
158 return ARM_AM::getT2SOImmVal(~Imm) != -1;
159 }
160
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000161 inline bool Pred_so_imm(SDNode *inN) const {
162 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000163 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000164 }
165
166 inline bool Pred_t2_so_imm(SDNode *inN) const {
167 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000168 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000169 }
170
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000171 // Include the pieces autogenerated from the target description.
172#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000173
174private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000175 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
176 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000177 SDNode *SelectARMIndexedLoad(SDNode *N);
178 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000179
Bob Wilson621f1952010-03-23 05:25:43 +0000180 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
181 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000182 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000183 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000184 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000185 unsigned *QOpcodes0, unsigned *QOpcodes1);
186
Bob Wilson24f995d2009-10-14 18:32:29 +0000187 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000188 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000189 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000190 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000191 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000192 unsigned *QOpcodes0, unsigned *QOpcodes1);
193
Bob Wilson96493442009-10-14 16:46:45 +0000194 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000195 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000196 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000197 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000198 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000199
Bob Wilson78dfbc32010-07-07 00:08:54 +0000200 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
201 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
202 /// generated to force the table registers to be consecutive.
203 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000204
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000205 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000206 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000207
Evan Cheng07ba9062009-11-19 21:45:22 +0000208 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000209 SDNode *SelectCMOVOp(SDNode *N);
210 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000211 ARMCC::CondCodes CCVal, SDValue CCR,
212 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000213 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000214 ARMCC::CondCodes CCVal, SDValue CCR,
215 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000216 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000217 ARMCC::CondCodes CCVal, SDValue CCR,
218 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000219 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000220 ARMCC::CondCodes CCVal, SDValue CCR,
221 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000222
Evan Chengde8aa4e2010-05-05 18:28:36 +0000223 SDNode *SelectConcatVector(SDNode *N);
224
Evan Chengaf4550f2009-07-02 01:23:32 +0000225 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
226 /// inline asm expressions.
227 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
228 char ConstraintCode,
229 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000230
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000231 // Form pairs of consecutive S, D, or Q registers.
232 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000233 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000234 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
235
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000236 // Form sequences of 4 consecutive S, D, or Q registers.
237 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000238 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000239 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000240
241 // Get the alignment operand for a NEON VLD or VST instruction.
242 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000243};
Evan Chenga8e29892007-01-19 07:51:42 +0000244}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000245
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000246/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
247/// operand. If so Imm will receive the 32-bit value.
248static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
249 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
250 Imm = cast<ConstantSDNode>(N)->getZExtValue();
251 return true;
252 }
253 return false;
254}
255
256// isInt32Immediate - This method tests to see if a constant operand.
257// If so Imm will receive the 32 bit value.
258static bool isInt32Immediate(SDValue N, unsigned &Imm) {
259 return isInt32Immediate(N.getNode(), Imm);
260}
261
262// isOpcWithIntImmediate - This method tests to see if the node is a specific
263// opcode and that it has a immediate integer right operand.
264// If so Imm will receive the 32 bit value.
265static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
266 return N->getOpcode() == Opc &&
267 isInt32Immediate(N->getOperand(1).getNode(), Imm);
268}
269
270
Evan Chengf40deed2010-10-27 23:41:30 +0000271bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
272 ARM_AM::ShiftOpc ShOpcVal,
273 unsigned ShAmt) {
274 if (!Subtarget->isCortexA9())
275 return true;
276 if (Shift.hasOneUse())
277 return true;
278 // R << 2 is free.
279 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
280}
281
Chris Lattner52a261b2010-09-21 20:31:19 +0000282bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000283 SDValue &BaseReg,
284 SDValue &ShReg,
285 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000286 if (DisableShifterOp)
287 return false;
288
Evan Cheng055b0312009-06-29 07:51:04 +0000289 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
290
291 // Don't match base register only case. That is matched to a separate
292 // lower complexity pattern with explicit register operand.
293 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000294
Evan Cheng055b0312009-06-29 07:51:04 +0000295 BaseReg = N.getOperand(0);
296 unsigned ShImmVal = 0;
297 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000298 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000299 ShImmVal = RHS->getZExtValue() & 31;
300 } else {
301 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000302 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
303 return false;
304 }
305 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
306 MVT::i32);
307 return true;
308}
309
310bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
311 SDValue &BaseReg,
312 SDValue &ShReg,
313 SDValue &Opc) {
314 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
315
316 // Don't match base register only case. That is matched to a separate
317 // lower complexity pattern with explicit register operand.
318 if (ShOpcVal == ARM_AM::no_shift) return false;
319
320 BaseReg = N.getOperand(0);
321 unsigned ShImmVal = 0;
322 // Do not check isShifterOpProfitable. This must return true.
323 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
324 ShReg = CurDAG->getRegister(0, MVT::i32);
325 ShImmVal = RHS->getZExtValue() & 31;
326 } else {
327 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000328 }
329 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000330 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000331 return true;
332}
333
Jim Grosbach3e556122010-10-26 22:37:02 +0000334bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
335 SDValue &Base,
336 SDValue &OffImm) {
337 // Match simple R + imm12 operands.
338
339 // Base only.
340 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
341 if (N.getOpcode() == ISD::FrameIndex) {
342 // Match frame index...
343 int FI = cast<FrameIndexSDNode>(N)->getIndex();
344 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
345 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
346 return true;
347 } else if (N.getOpcode() == ARMISD::Wrapper &&
348 !(Subtarget->useMovt() &&
349 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
350 Base = N.getOperand(0);
351 } else
352 Base = N;
353 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
354 return true;
355 }
356
357 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
358 int RHSC = (int)RHS->getZExtValue();
359 if (N.getOpcode() == ISD::SUB)
360 RHSC = -RHSC;
361
362 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
363 Base = N.getOperand(0);
364 if (Base.getOpcode() == ISD::FrameIndex) {
365 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
366 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
367 }
368 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
369 return true;
370 }
371 }
372
373 // Base only.
374 Base = N;
375 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
376 return true;
377}
378
379
380
381bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
382 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000383 if (N.getOpcode() == ISD::MUL &&
384 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000385 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
386 // X * [3,5,9] -> X + X * [2,4,8] etc.
387 int RHSC = (int)RHS->getZExtValue();
388 if (RHSC & 1) {
389 RHSC = RHSC & ~1;
390 ARM_AM::AddrOpc AddSub = ARM_AM::add;
391 if (RHSC < 0) {
392 AddSub = ARM_AM::sub;
393 RHSC = - RHSC;
394 }
395 if (isPowerOf2_32(RHSC)) {
396 unsigned ShAmt = Log2_32(RHSC);
397 Base = Offset = N.getOperand(0);
398 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
399 ARM_AM::lsl),
400 MVT::i32);
401 return true;
402 }
403 }
404 }
405 }
406
407 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
408 return false;
409
410 // Leave simple R +/- imm12 operands for LDRi12
411 if (N.getOpcode() == ISD::ADD) {
412 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
413 int RHSC = (int)RHS->getZExtValue();
414 if ((RHSC >= 0 && RHSC < 0x1000) ||
415 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
416 return false;
417 }
418 }
419
Evan Chengf40deed2010-10-27 23:41:30 +0000420 if (Subtarget->isCortexA9() && !N.hasOneUse())
421 // Compute R +/- (R << N) and reuse it.
422 return false;
423
Jim Grosbach3e556122010-10-26 22:37:02 +0000424 // Otherwise this is R +/- [possibly shifted] R.
425 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
426 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
427 unsigned ShAmt = 0;
428
429 Base = N.getOperand(0);
430 Offset = N.getOperand(1);
431
432 if (ShOpcVal != ARM_AM::no_shift) {
433 // Check to see if the RHS of the shift is a constant, if not, we can't fold
434 // it.
435 if (ConstantSDNode *Sh =
436 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
437 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000438 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
439 Offset = N.getOperand(1).getOperand(0);
440 else {
441 ShAmt = 0;
442 ShOpcVal = ARM_AM::no_shift;
443 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000444 } else {
445 ShOpcVal = ARM_AM::no_shift;
446 }
447 }
448
449 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000450 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
451 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000452 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
453 if (ShOpcVal != ARM_AM::no_shift) {
454 // Check to see if the RHS of the shift is a constant, if not, we can't
455 // fold it.
456 if (ConstantSDNode *Sh =
457 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
458 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000459 if (!Subtarget->isCortexA9() ||
460 (N.hasOneUse() &&
461 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
462 Offset = N.getOperand(0).getOperand(0);
463 Base = N.getOperand(1);
464 } else {
465 ShAmt = 0;
466 ShOpcVal = ARM_AM::no_shift;
467 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000468 } else {
469 ShOpcVal = ARM_AM::no_shift;
470 }
471 }
472 }
473
474 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
475 MVT::i32);
476 return true;
477}
478
479
480
481
482//-----
483
Jim Grosbach82891622010-09-29 19:03:54 +0000484AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
485 SDValue &Base,
486 SDValue &Offset,
487 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000488 if (N.getOpcode() == ISD::MUL &&
489 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000490 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
491 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000492 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000493 if (RHSC & 1) {
494 RHSC = RHSC & ~1;
495 ARM_AM::AddrOpc AddSub = ARM_AM::add;
496 if (RHSC < 0) {
497 AddSub = ARM_AM::sub;
498 RHSC = - RHSC;
499 }
500 if (isPowerOf2_32(RHSC)) {
501 unsigned ShAmt = Log2_32(RHSC);
502 Base = Offset = N.getOperand(0);
503 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
504 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000505 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000506 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000507 }
508 }
509 }
510 }
511
Evan Chenga8e29892007-01-19 07:51:42 +0000512 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
513 Base = N;
514 if (N.getOpcode() == ISD::FrameIndex) {
515 int FI = cast<FrameIndexSDNode>(N)->getIndex();
516 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000517 } else if (N.getOpcode() == ARMISD::Wrapper &&
518 !(Subtarget->useMovt() &&
519 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000520 Base = N.getOperand(0);
521 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000522 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000523 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
524 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000525 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000526 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000527 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000528
Evan Chenga8e29892007-01-19 07:51:42 +0000529 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000530 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000531 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000532 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000533 if ((RHSC >= 0 && RHSC < 0x1000) ||
534 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000535 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000536 if (Base.getOpcode() == ISD::FrameIndex) {
537 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
538 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
539 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000540 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000541
542 ARM_AM::AddrOpc AddSub = ARM_AM::add;
543 if (RHSC < 0) {
544 AddSub = ARM_AM::sub;
545 RHSC = - RHSC;
546 }
547 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000548 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000549 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000550 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000551 }
Evan Chenga8e29892007-01-19 07:51:42 +0000552 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000553 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000554
Evan Chengf40deed2010-10-27 23:41:30 +0000555 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
556 // Compute R +/- (R << N) and reuse it.
557 Base = N;
558 Offset = CurDAG->getRegister(0, MVT::i32);
559 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
560 ARM_AM::no_shift),
561 MVT::i32);
562 return AM2_BASE;
563 }
564
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000565 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000566 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
567 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
568 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000569
Evan Chenga8e29892007-01-19 07:51:42 +0000570 Base = N.getOperand(0);
571 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000572
Evan Chenga8e29892007-01-19 07:51:42 +0000573 if (ShOpcVal != ARM_AM::no_shift) {
574 // Check to see if the RHS of the shift is a constant, if not, we can't fold
575 // it.
576 if (ConstantSDNode *Sh =
577 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000578 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000579 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
580 Offset = N.getOperand(1).getOperand(0);
581 else {
582 ShAmt = 0;
583 ShOpcVal = ARM_AM::no_shift;
584 }
Evan Chenga8e29892007-01-19 07:51:42 +0000585 } else {
586 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000587 }
588 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000589
Evan Chenga8e29892007-01-19 07:51:42 +0000590 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000591 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
592 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000593 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
594 if (ShOpcVal != ARM_AM::no_shift) {
595 // Check to see if the RHS of the shift is a constant, if not, we can't
596 // fold it.
597 if (ConstantSDNode *Sh =
598 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000599 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000600 if (!Subtarget->isCortexA9() ||
601 (N.hasOneUse() &&
602 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
603 Offset = N.getOperand(0).getOperand(0);
604 Base = N.getOperand(1);
605 } else {
606 ShAmt = 0;
607 ShOpcVal = ARM_AM::no_shift;
608 }
Evan Chenga8e29892007-01-19 07:51:42 +0000609 } else {
610 ShOpcVal = ARM_AM::no_shift;
611 }
612 }
613 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000614
Evan Chenga8e29892007-01-19 07:51:42 +0000615 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000617 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000618}
619
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000620bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000621 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000622 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000623 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
624 ? cast<LoadSDNode>(Op)->getAddressingMode()
625 : cast<StoreSDNode>(Op)->getAddressingMode();
626 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
627 ? ARM_AM::add : ARM_AM::sub;
628 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000629 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000630 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000631 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000632 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
633 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000634 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000635 return true;
636 }
637 }
638
639 Offset = N;
640 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
641 unsigned ShAmt = 0;
642 if (ShOpcVal != ARM_AM::no_shift) {
643 // Check to see if the RHS of the shift is a constant, if not, we can't fold
644 // it.
645 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000646 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000647 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
648 Offset = N.getOperand(0);
649 else {
650 ShAmt = 0;
651 ShOpcVal = ARM_AM::no_shift;
652 }
Evan Chenga8e29892007-01-19 07:51:42 +0000653 } else {
654 ShOpcVal = ARM_AM::no_shift;
655 }
656 }
657
658 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000659 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000660 return true;
661}
662
Evan Chenga8e29892007-01-19 07:51:42 +0000663
Chris Lattner52a261b2010-09-21 20:31:19 +0000664bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000665 SDValue &Base, SDValue &Offset,
666 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000667 if (N.getOpcode() == ISD::SUB) {
668 // X - C is canonicalize to X + -C, no need to handle it here.
669 Base = N.getOperand(0);
670 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000671 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000672 return true;
673 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000674
Evan Chenga8e29892007-01-19 07:51:42 +0000675 if (N.getOpcode() != ISD::ADD) {
676 Base = N;
677 if (N.getOpcode() == ISD::FrameIndex) {
678 int FI = cast<FrameIndexSDNode>(N)->getIndex();
679 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
680 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000681 Offset = CurDAG->getRegister(0, MVT::i32);
682 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000683 return true;
684 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000685
Evan Chenga8e29892007-01-19 07:51:42 +0000686 // If the RHS is +/- imm8, fold into addr mode.
687 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000688 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000689 if ((RHSC >= 0 && RHSC < 256) ||
690 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000691 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000692 if (Base.getOpcode() == ISD::FrameIndex) {
693 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
694 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
695 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000696 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000697
698 ARM_AM::AddrOpc AddSub = ARM_AM::add;
699 if (RHSC < 0) {
700 AddSub = ARM_AM::sub;
701 RHSC = - RHSC;
702 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000703 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000704 return true;
705 }
706 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000707
Evan Chenga8e29892007-01-19 07:51:42 +0000708 Base = N.getOperand(0);
709 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000710 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000711 return true;
712}
713
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000714bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000715 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000716 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000717 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
718 ? cast<LoadSDNode>(Op)->getAddressingMode()
719 : cast<StoreSDNode>(Op)->getAddressingMode();
720 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
721 ? ARM_AM::add : ARM_AM::sub;
722 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000723 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000724 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000725 Offset = CurDAG->getRegister(0, MVT::i32);
726 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000727 return true;
728 }
729 }
730
731 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000732 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000733 return true;
734}
735
Jim Grosbach3ab56582010-10-21 19:38:40 +0000736bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000737 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000738 if (N.getOpcode() != ISD::ADD) {
739 Base = N;
740 if (N.getOpcode() == ISD::FrameIndex) {
741 int FI = cast<FrameIndexSDNode>(N)->getIndex();
742 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000743 } else if (N.getOpcode() == ARMISD::Wrapper &&
744 !(Subtarget->useMovt() &&
745 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000746 Base = N.getOperand(0);
747 }
748 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000749 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000750 return true;
751 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000752
Evan Chenga8e29892007-01-19 07:51:42 +0000753 // If the RHS is +/- imm8, fold into addr mode.
754 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000755 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000756 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
757 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000758 if ((RHSC >= 0 && RHSC < 256) ||
759 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000760 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000761 if (Base.getOpcode() == ISD::FrameIndex) {
762 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
763 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
764 }
765
766 ARM_AM::AddrOpc AddSub = ARM_AM::add;
767 if (RHSC < 0) {
768 AddSub = ARM_AM::sub;
769 RHSC = - RHSC;
770 }
771 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000773 return true;
774 }
775 }
776 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000777
Evan Chenga8e29892007-01-19 07:51:42 +0000778 Base = N;
779 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000780 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000781 return true;
782}
783
Bob Wilson665814b2010-11-01 23:40:51 +0000784bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
785 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000786 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000787
788 unsigned Alignment = 0;
789 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
790 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
791 // The maximum alignment is equal to the memory size being referenced.
792 unsigned LSNAlign = LSN->getAlignment();
793 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
794 if (LSNAlign > MemSize && MemSize > 1)
795 Alignment = MemSize;
796 } else {
797 // All other uses of addrmode6 are for intrinsics. For now just record
798 // the raw alignment value; it will be refined later based on the legal
799 // alignment operands for the intrinsic.
800 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
801 }
802
803 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000804 return true;
805}
806
Chris Lattner52a261b2010-09-21 20:31:19 +0000807bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000808 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000809 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
810 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000811 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000812 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000813 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000814 return true;
815 }
816 return false;
817}
818
Chris Lattner52a261b2010-09-21 20:31:19 +0000819bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000820 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000821 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000822 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000823 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000824 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000825 return false;
826
827 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000828 return true;
829 }
830
Evan Chenga8e29892007-01-19 07:51:42 +0000831 Base = N.getOperand(0);
832 Offset = N.getOperand(1);
833 return true;
834}
835
Evan Cheng79d43262007-01-24 02:21:22 +0000836bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000837ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000838 unsigned Scale, SDValue &Base,
839 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000840 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000841 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000842 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000843 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000844 if (N.getOpcode() == ARMISD::Wrapper &&
845 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
846 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000847 }
848
Evan Chenga8e29892007-01-19 07:51:42 +0000849 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000850 if (N.getOpcode() == ARMISD::Wrapper &&
851 !(Subtarget->useMovt() &&
852 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
853 Base = N.getOperand(0);
854 } else
855 Base = N;
856
Owen Anderson825b72b2009-08-11 20:47:22 +0000857 Offset = CurDAG->getRegister(0, MVT::i32);
858 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000859 return true;
860 }
861
Evan Chengad0e4652007-02-06 00:22:06 +0000862 // Thumb does not have [sp, r] address mode.
863 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
864 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
865 if ((LHSR && LHSR->getReg() == ARM::SP) ||
866 (RHSR && RHSR->getReg() == ARM::SP)) {
867 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 Offset = CurDAG->getRegister(0, MVT::i32);
869 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000870 return true;
871 }
872
Evan Chenga8e29892007-01-19 07:51:42 +0000873 // If the RHS is + imm5 * scale, fold into addr mode.
874 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000875 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000876 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
877 RHSC /= Scale;
878 if (RHSC >= 0 && RHSC < 32) {
879 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000880 Offset = CurDAG->getRegister(0, MVT::i32);
881 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000882 return true;
883 }
884 }
885 }
886
Evan Chengc38f2bc2007-01-23 22:59:13 +0000887 Base = N.getOperand(0);
888 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000889 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000890 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000891}
892
Chris Lattner52a261b2010-09-21 20:31:19 +0000893bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000894 SDValue &Base, SDValue &OffImm,
895 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000896 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000897}
898
Chris Lattner52a261b2010-09-21 20:31:19 +0000899bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000900 SDValue &Base, SDValue &OffImm,
901 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000902 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000903}
904
Chris Lattner52a261b2010-09-21 20:31:19 +0000905bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000906 SDValue &Base, SDValue &OffImm,
907 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000908 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000909}
910
Chris Lattner52a261b2010-09-21 20:31:19 +0000911bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
912 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000913 if (N.getOpcode() == ISD::FrameIndex) {
914 int FI = cast<FrameIndexSDNode>(N)->getIndex();
915 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000916 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000917 return true;
918 }
Evan Cheng79d43262007-01-24 02:21:22 +0000919
Evan Chengad0e4652007-02-06 00:22:06 +0000920 if (N.getOpcode() != ISD::ADD)
921 return false;
922
923 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000924 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
925 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000926 // If the RHS is + imm8 * scale, fold into addr mode.
927 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000928 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000929 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
930 RHSC >>= 2;
931 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000932 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000933 if (Base.getOpcode() == ISD::FrameIndex) {
934 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
935 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
936 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000937 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000938 return true;
939 }
940 }
941 }
942 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000943
Evan Chenga8e29892007-01-19 07:51:42 +0000944 return false;
945}
946
Chris Lattner52a261b2010-09-21 20:31:19 +0000947bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000948 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000949 if (DisableShifterOp)
950 return false;
951
Evan Cheng9cb9e672009-06-27 02:26:13 +0000952 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
953
954 // Don't match base register only case. That is matched to a separate
955 // lower complexity pattern with explicit register operand.
956 if (ShOpcVal == ARM_AM::no_shift) return false;
957
958 BaseReg = N.getOperand(0);
959 unsigned ShImmVal = 0;
960 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
961 ShImmVal = RHS->getZExtValue() & 31;
962 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
963 return true;
964 }
965
966 return false;
967}
968
Chris Lattner52a261b2010-09-21 20:31:19 +0000969bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000970 SDValue &Base, SDValue &OffImm) {
971 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000972
Evan Cheng3a214252009-08-11 08:52:18 +0000973 // Base only.
974 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000975 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000976 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000977 int FI = cast<FrameIndexSDNode>(N)->getIndex();
978 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000979 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000980 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000981 } else if (N.getOpcode() == ARMISD::Wrapper &&
982 !(Subtarget->useMovt() &&
983 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000984 Base = N.getOperand(0);
985 if (Base.getOpcode() == ISD::TargetConstantPool)
986 return false; // We want to select t2LDRpci instead.
987 } else
988 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000989 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000990 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000991 }
Evan Cheng055b0312009-06-29 07:51:04 +0000992
993 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000994 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000995 // Let t2LDRi8 handle (R - imm8).
996 return false;
997
Evan Cheng055b0312009-06-29 07:51:04 +0000998 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000999 if (N.getOpcode() == ISD::SUB)
1000 RHSC = -RHSC;
1001
1002 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001003 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001004 if (Base.getOpcode() == ISD::FrameIndex) {
1005 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1006 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1007 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001008 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001009 return true;
1010 }
1011 }
1012
Evan Cheng3a214252009-08-11 08:52:18 +00001013 // Base only.
1014 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001015 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001016 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001017}
1018
Chris Lattner52a261b2010-09-21 20:31:19 +00001019bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001020 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001021 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001022 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001023 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1024 int RHSC = (int)RHS->getSExtValue();
1025 if (N.getOpcode() == ISD::SUB)
1026 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001027
Evan Cheng3a214252009-08-11 08:52:18 +00001028 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1029 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001030 if (Base.getOpcode() == ISD::FrameIndex) {
1031 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1032 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1033 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001034 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001035 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001036 }
Evan Cheng055b0312009-06-29 07:51:04 +00001037 }
1038 }
1039
1040 return false;
1041}
1042
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001043bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001044 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001045 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001046 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1047 ? cast<LoadSDNode>(Op)->getAddressingMode()
1048 : cast<StoreSDNode>(Op)->getAddressingMode();
1049 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1050 int RHSC = (int)RHS->getZExtValue();
1051 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001052 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001053 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1054 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001055 return true;
1056 }
1057 }
1058
1059 return false;
1060}
1061
Chris Lattner52a261b2010-09-21 20:31:19 +00001062bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001063 SDValue &Base,
1064 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001065 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1066 if (N.getOpcode() != ISD::ADD)
1067 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001068
Evan Cheng3a214252009-08-11 08:52:18 +00001069 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1070 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1071 int RHSC = (int)RHS->getZExtValue();
1072 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1073 return false;
1074 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001075 return false;
1076 }
1077
Evan Chengf40deed2010-10-27 23:41:30 +00001078 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1079 // Compute R + (R << [1,2,3]) and reuse it.
1080 Base = N;
1081 return false;
1082 }
1083
Evan Cheng055b0312009-06-29 07:51:04 +00001084 // Look for (R + R) or (R + (R << [1,2,3])).
1085 unsigned ShAmt = 0;
1086 Base = N.getOperand(0);
1087 OffReg = N.getOperand(1);
1088
1089 // Swap if it is ((R << c) + R).
1090 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1091 if (ShOpcVal != ARM_AM::lsl) {
1092 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1093 if (ShOpcVal == ARM_AM::lsl)
1094 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001095 }
1096
Evan Cheng055b0312009-06-29 07:51:04 +00001097 if (ShOpcVal == ARM_AM::lsl) {
1098 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1099 // it.
1100 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1101 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001102 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1103 OffReg = OffReg.getOperand(0);
1104 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001105 ShAmt = 0;
1106 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001107 }
Evan Cheng055b0312009-06-29 07:51:04 +00001108 } else {
1109 ShOpcVal = ARM_AM::no_shift;
1110 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001111 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001112
Owen Anderson825b72b2009-08-11 20:47:22 +00001113 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001114
1115 return true;
1116}
1117
1118//===--------------------------------------------------------------------===//
1119
Evan Chengee568cf2007-07-05 07:15:27 +00001120/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001121static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001122 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001123}
1124
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001125SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1126 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001127 ISD::MemIndexedMode AM = LD->getAddressingMode();
1128 if (AM == ISD::UNINDEXED)
1129 return NULL;
1130
Owen Andersone50ed302009-08-10 22:56:29 +00001131 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001132 SDValue Offset, AMOpc;
1133 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1134 unsigned Opcode = 0;
1135 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001136 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001137 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001138 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1139 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001140 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001141 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001142 Match = true;
1143 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1144 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1145 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001146 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001147 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001148 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001149 Match = true;
1150 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1151 }
1152 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001153 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001154 Match = true;
1155 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1156 }
1157 }
1158 }
1159
1160 if (Match) {
1161 SDValue Chain = LD->getChain();
1162 SDValue Base = LD->getBasePtr();
1163 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001164 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001165 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001166 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001167 }
1168
1169 return NULL;
1170}
1171
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001172SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1173 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001174 ISD::MemIndexedMode AM = LD->getAddressingMode();
1175 if (AM == ISD::UNINDEXED)
1176 return NULL;
1177
Owen Andersone50ed302009-08-10 22:56:29 +00001178 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001179 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001180 SDValue Offset;
1181 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1182 unsigned Opcode = 0;
1183 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001184 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001185 switch (LoadedVT.getSimpleVT().SimpleTy) {
1186 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001187 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1188 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001189 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001190 if (isSExtLd)
1191 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1192 else
1193 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001194 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001195 case MVT::i8:
1196 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001197 if (isSExtLd)
1198 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1199 else
1200 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001201 break;
1202 default:
1203 return NULL;
1204 }
1205 Match = true;
1206 }
1207
1208 if (Match) {
1209 SDValue Chain = LD->getChain();
1210 SDValue Base = LD->getBasePtr();
1211 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001212 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001213 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001214 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001215 }
1216
1217 return NULL;
1218}
1219
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001220/// PairSRegs - Form a D register from a pair of S registers.
1221///
1222SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1223 DebugLoc dl = V0.getNode()->getDebugLoc();
1224 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1225 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001226 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1227 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001228}
1229
Evan Cheng603afbf2010-05-10 17:34:18 +00001230/// PairDRegs - Form a quad register from a pair of D registers.
1231///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001232SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1233 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001234 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1235 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001236 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1237 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001238}
1239
Evan Cheng7f687192010-05-14 00:21:45 +00001240/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001241///
1242SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1243 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001244 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1245 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001246 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1247 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1248}
1249
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001250/// QuadSRegs - Form 4 consecutive S registers.
1251///
1252SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1253 SDValue V2, SDValue V3) {
1254 DebugLoc dl = V0.getNode()->getDebugLoc();
1255 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1256 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1257 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1258 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1259 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1260 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1261}
1262
Evan Cheng7f687192010-05-14 00:21:45 +00001263/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001264///
1265SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1266 SDValue V2, SDValue V3) {
1267 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001268 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1269 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1270 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1271 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001272 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1273 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1274}
1275
Evan Cheng8f6de382010-05-16 03:27:48 +00001276/// QuadQRegs - Form 4 consecutive Q registers.
1277///
1278SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1279 SDValue V2, SDValue V3) {
1280 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001281 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1282 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1283 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1284 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001285 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1286 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1287}
1288
Bob Wilson2a6e6162010-09-23 23:42:37 +00001289/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1290/// of a NEON VLD or VST instruction. The supported values depend on the
1291/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001292SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1293 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001294 unsigned NumRegs = NumVecs;
1295 if (!is64BitVector && NumVecs < 3)
1296 NumRegs *= 2;
1297
Bob Wilson665814b2010-11-01 23:40:51 +00001298 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001299 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001300 Alignment = 32;
1301 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1302 Alignment = 16;
1303 else if (Alignment >= 8)
1304 Alignment = 8;
1305 else
1306 Alignment = 0;
1307
1308 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001309}
1310
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001311SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001312 unsigned *DOpcodes, unsigned *QOpcodes0,
1313 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001314 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001315 DebugLoc dl = N->getDebugLoc();
1316
Bob Wilson226036e2010-03-20 22:13:40 +00001317 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001318 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001319 return NULL;
1320
1321 SDValue Chain = N->getOperand(0);
1322 EVT VT = N->getValueType(0);
1323 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001324 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001325
Bob Wilson3e36f132009-10-14 17:28:52 +00001326 unsigned OpcodeIndex;
1327 switch (VT.getSimpleVT().SimpleTy) {
1328 default: llvm_unreachable("unhandled vld type");
1329 // Double-register operations:
1330 case MVT::v8i8: OpcodeIndex = 0; break;
1331 case MVT::v4i16: OpcodeIndex = 1; break;
1332 case MVT::v2f32:
1333 case MVT::v2i32: OpcodeIndex = 2; break;
1334 case MVT::v1i64: OpcodeIndex = 3; break;
1335 // Quad-register operations:
1336 case MVT::v16i8: OpcodeIndex = 0; break;
1337 case MVT::v8i16: OpcodeIndex = 1; break;
1338 case MVT::v4f32:
1339 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001340 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001341 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001342 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001343 }
1344
Bob Wilsonf5721912010-09-03 18:16:02 +00001345 EVT ResTy;
1346 if (NumVecs == 1)
1347 ResTy = VT;
1348 else {
1349 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1350 if (!is64BitVector)
1351 ResTyElts *= 2;
1352 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1353 }
1354
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001355 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001356 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001357 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001358 if (is64BitVector) {
1359 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001360 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001361 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001362 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001363 return VLd;
1364
Bob Wilsonf5721912010-09-03 18:16:02 +00001365 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001366 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001367 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001368 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001369 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001370 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001371 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001372 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001373 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001374 }
1375
Bob Wilson621f1952010-03-23 05:25:43 +00001376 if (NumVecs <= 2) {
1377 // Quad registers are directly supported for VLD1 and VLD2,
1378 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001379 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001380 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001381 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001382 if (NumVecs == 1)
1383 return VLd;
1384
Bob Wilsonf5721912010-09-03 18:16:02 +00001385 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001386 Chain = SDValue(VLd, 1);
1387
Bob Wilson3e36f132009-10-14 17:28:52 +00001388 } else {
1389 // Otherwise, quad registers are loaded with two separate instructions,
1390 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001391 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001392
Bob Wilson24f995d2009-10-14 18:32:29 +00001393 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001394 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001395 SDValue ImplDef =
1396 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1397 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1398 SDNode *VLdA =
1399 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1400 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001401
Bob Wilson24f995d2009-10-14 18:32:29 +00001402 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001403 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001404 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1405 Pred, Reg0, Chain };
1406 SDNode *VLdB =
1407 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1408 SuperReg = SDValue(VLdB, 0);
1409 Chain = SDValue(VLdB, 2);
1410 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001411
Bob Wilsonf5721912010-09-03 18:16:02 +00001412 // Extract out the Q registers.
1413 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1414 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1415 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1416 dl, VT, SuperReg);
1417 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001418 }
1419 ReplaceUses(SDValue(N, NumVecs), Chain);
1420 return NULL;
1421}
1422
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001423SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001424 unsigned *DOpcodes, unsigned *QOpcodes0,
1425 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001426 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001427 DebugLoc dl = N->getDebugLoc();
1428
Bob Wilson226036e2010-03-20 22:13:40 +00001429 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001430 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001431 return NULL;
1432
1433 SDValue Chain = N->getOperand(0);
1434 EVT VT = N->getOperand(3).getValueType();
1435 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001436 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001437
Bob Wilson24f995d2009-10-14 18:32:29 +00001438 unsigned OpcodeIndex;
1439 switch (VT.getSimpleVT().SimpleTy) {
1440 default: llvm_unreachable("unhandled vst type");
1441 // Double-register operations:
1442 case MVT::v8i8: OpcodeIndex = 0; break;
1443 case MVT::v4i16: OpcodeIndex = 1; break;
1444 case MVT::v2f32:
1445 case MVT::v2i32: OpcodeIndex = 2; break;
1446 case MVT::v1i64: OpcodeIndex = 3; break;
1447 // Quad-register operations:
1448 case MVT::v16i8: OpcodeIndex = 0; break;
1449 case MVT::v8i16: OpcodeIndex = 1; break;
1450 case MVT::v4f32:
1451 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001452 case MVT::v2i64: OpcodeIndex = 3;
1453 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1454 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001455 }
1456
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001457 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001458 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001459
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001460 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001461 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001462 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001463
1464 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001465 if (NumVecs == 1) {
1466 Ops.push_back(N->getOperand(3));
1467 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001468 SDValue RegSeq;
1469 SDValue V0 = N->getOperand(0+3);
1470 SDValue V1 = N->getOperand(1+3);
1471
1472 // Form a REG_SEQUENCE to force register allocation.
1473 if (NumVecs == 2)
1474 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1475 else {
1476 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001477 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001478 // an undef.
1479 SDValue V3 = (NumVecs == 3)
1480 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1481 : N->getOperand(3+3);
1482 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1483 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001484 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001485 }
Evan Chengac0869d2009-11-21 06:21:52 +00001486 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001487 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001488 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001489 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001490 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001491 }
1492
Bob Wilson11d98992010-03-23 06:20:33 +00001493 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001494 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001495 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001496 if (NumVecs == 1) {
1497 Ops.push_back(N->getOperand(3));
1498 } else {
1499 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001500 SDValue Q0 = N->getOperand(3);
1501 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001502 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001503 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001504 Ops.push_back(Pred);
1505 Ops.push_back(Reg0); // predicate register
1506 Ops.push_back(Chain);
1507 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001508 }
1509
1510 // Otherwise, quad registers are stored with two separate instructions,
1511 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001512
Bob Wilson07f6e802010-06-16 21:34:01 +00001513 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001514 SDValue V0 = N->getOperand(0+3);
1515 SDValue V1 = N->getOperand(1+3);
1516 SDValue V2 = N->getOperand(2+3);
1517 SDValue V3 = (NumVecs == 3)
1518 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1519 : N->getOperand(3+3);
1520 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001521
1522 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001523 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001524 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001525 Ops.push_back(Pred);
1526 Ops.push_back(Reg0); // predicate register
1527 Ops.push_back(Chain);
1528 unsigned Opc = QOpcodes0[OpcodeIndex];
1529 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001530 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001531 Chain = SDValue(VStA, 1);
1532
1533 // Store the odd D registers.
1534 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001535 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001536 Opc = QOpcodes1[OpcodeIndex];
1537 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001538 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001539 Chain = SDValue(VStB, 1);
1540 ReplaceUses(SDValue(N, 0), Chain);
1541 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001542}
1543
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001544SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001545 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001546 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001547 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001548 DebugLoc dl = N->getDebugLoc();
1549
Bob Wilson226036e2010-03-20 22:13:40 +00001550 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001551 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001552 return NULL;
1553
1554 SDValue Chain = N->getOperand(0);
1555 unsigned Lane =
1556 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001557 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001558 bool is64BitVector = VT.is64BitVector();
1559
Bob Wilson665814b2010-11-01 23:40:51 +00001560 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001561 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001562 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001563 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1564 if (Alignment > NumBytes)
1565 Alignment = NumBytes;
1566 // Alignment must be a power of two; make sure of that.
1567 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001568 if (Alignment == 1)
1569 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001570 }
Bob Wilson665814b2010-11-01 23:40:51 +00001571 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001572
Bob Wilsona7c397c2009-10-14 16:19:03 +00001573 unsigned OpcodeIndex;
1574 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001575 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001576 // Double-register operations:
1577 case MVT::v8i8: OpcodeIndex = 0; break;
1578 case MVT::v4i16: OpcodeIndex = 1; break;
1579 case MVT::v2f32:
1580 case MVT::v2i32: OpcodeIndex = 2; break;
1581 // Quad-register operations:
1582 case MVT::v8i16: OpcodeIndex = 0; break;
1583 case MVT::v4f32:
1584 case MVT::v4i32: OpcodeIndex = 1; break;
1585 }
1586
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001587 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001588 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001589
Bob Wilson8466fa12010-09-13 23:01:35 +00001590 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001591 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001592 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001593
Jim Grosbach3ab56582010-10-21 19:38:40 +00001594 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001595 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001596
Bob Wilson8466fa12010-09-13 23:01:35 +00001597 SDValue SuperReg;
1598 SDValue V0 = N->getOperand(0+3);
1599 SDValue V1 = N->getOperand(1+3);
1600 if (NumVecs == 2) {
1601 if (is64BitVector)
1602 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1603 else
1604 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001605 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001606 SDValue V2 = N->getOperand(2+3);
1607 SDValue V3 = (NumVecs == 3)
1608 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1609 : N->getOperand(3+3);
1610 if (is64BitVector)
1611 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1612 else
1613 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001614 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001615 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001616 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001617 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001618 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001619 Ops.push_back(Chain);
1620
Bob Wilson96493442009-10-14 16:46:45 +00001621 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001622 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001623
Bob Wilson8466fa12010-09-13 23:01:35 +00001624 EVT ResTy;
1625 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1626 if (!is64BitVector)
1627 ResTyElts *= 2;
1628 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001629
Bob Wilson8466fa12010-09-13 23:01:35 +00001630 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1631 Ops.data(), 7);
1632 SuperReg = SDValue(VLdLn, 0);
1633 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001634
Bob Wilson8466fa12010-09-13 23:01:35 +00001635 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001636 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1637 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1638 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1639 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1640 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001641 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1642 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001643 return NULL;
1644}
1645
Bob Wilson78dfbc32010-07-07 00:08:54 +00001646SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1647 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001648 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1649 DebugLoc dl = N->getDebugLoc();
1650 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001651 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001652
1653 // Form a REG_SEQUENCE to force register allocation.
1654 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001655 SDValue V0 = N->getOperand(FirstTblReg + 0);
1656 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001657 if (NumVecs == 2)
1658 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1659 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001660 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001661 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001662 // an undef.
1663 SDValue V3 = (NumVecs == 3)
1664 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001665 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001666 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1667 }
1668
Bob Wilson78dfbc32010-07-07 00:08:54 +00001669 SmallVector<SDValue, 6> Ops;
1670 if (IsExt)
1671 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001672 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001673 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001674 Ops.push_back(getAL(CurDAG)); // predicate
1675 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001676 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001677}
1678
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001679SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001680 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001681 if (!Subtarget->hasV6T2Ops())
1682 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001683
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001684 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1685 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1686
1687
1688 // For unsigned extracts, check for a shift right and mask
1689 unsigned And_imm = 0;
1690 if (N->getOpcode() == ISD::AND) {
1691 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1692
1693 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1694 if (And_imm & (And_imm + 1))
1695 return NULL;
1696
1697 unsigned Srl_imm = 0;
1698 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1699 Srl_imm)) {
1700 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1701
1702 unsigned Width = CountTrailingOnes_32(And_imm);
1703 unsigned LSB = Srl_imm;
1704 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1705 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1706 CurDAG->getTargetConstant(LSB, MVT::i32),
1707 CurDAG->getTargetConstant(Width, MVT::i32),
1708 getAL(CurDAG), Reg0 };
1709 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1710 }
1711 }
1712 return NULL;
1713 }
1714
1715 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001716 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001717 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001718 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1719 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001720 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001721 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1722 unsigned Width = 32 - Srl_imm;
1723 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001724 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001725 return NULL;
1726 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001727 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001728 CurDAG->getTargetConstant(LSB, MVT::i32),
1729 CurDAG->getTargetConstant(Width, MVT::i32),
1730 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001731 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001732 }
1733 }
1734 return NULL;
1735}
1736
Evan Cheng9ef48352009-11-20 00:54:03 +00001737SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001738SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001739 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1740 SDValue CPTmp0;
1741 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001742 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001743 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1744 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1745 unsigned Opc = 0;
1746 switch (SOShOp) {
1747 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1748 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1749 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1750 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1751 default:
1752 llvm_unreachable("Unknown so_reg opcode!");
1753 break;
1754 }
1755 SDValue SOShImm =
1756 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1757 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1758 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001759 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001760 }
1761 return 0;
1762}
1763
1764SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001765SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001766 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1767 SDValue CPTmp0;
1768 SDValue CPTmp1;
1769 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001770 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001771 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1772 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001773 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001774 }
1775 return 0;
1776}
1777
1778SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001779SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001780 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1781 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1782 if (!T)
1783 return 0;
1784
Jim Grosbacha4257162010-10-07 00:53:56 +00001785 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00001786 bool isSoImm = is_t2_so_imm(TrueImm);
Jim Grosbacha4257162010-10-07 00:53:56 +00001787 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00001788 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001789 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1790 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001791 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1792 MVT::i32, Ops, 5);
Evan Cheng875a6ac2010-11-12 22:42:47 +00001793 } else if (is_t2_so_imm_not(TrueImm)) {
1794 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
1795 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1796 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1797 return CurDAG->SelectNodeTo(N, ARM::t2MVNCCi, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001798 }
1799 return 0;
1800}
1801
1802SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001803SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001804 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1805 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1806 if (!T)
1807 return 0;
1808
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001809 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00001810 bool isSoImm = is_so_imm(TrueImm);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001811 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1812 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001813 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1814 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001815 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1816 MVT::i32, Ops, 5);
Evan Cheng875a6ac2010-11-12 22:42:47 +00001817 } else if (is_so_imm_not(TrueImm)) {
1818 SDValue True = CurDAG->getTargetConstant(~TrueImm, MVT::i32);
1819 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1820 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
1821 return CurDAG->SelectNodeTo(N, ARM::MVNCCi, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001822 }
1823 return 0;
1824}
1825
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001826SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1827 EVT VT = N->getValueType(0);
1828 SDValue FalseVal = N->getOperand(0);
1829 SDValue TrueVal = N->getOperand(1);
1830 SDValue CC = N->getOperand(2);
1831 SDValue CCR = N->getOperand(3);
1832 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001833 assert(CC.getOpcode() == ISD::Constant);
1834 assert(CCR.getOpcode() == ISD::Register);
1835 ARMCC::CondCodes CCVal =
1836 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001837
1838 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1839 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1840 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1841 // Pattern complexity = 18 cost = 1 size = 0
1842 SDValue CPTmp0;
1843 SDValue CPTmp1;
1844 SDValue CPTmp2;
1845 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001846 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001847 CCVal, CCR, InFlag);
1848 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001849 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001850 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1851 if (Res)
1852 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001853 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001854 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001855 CCVal, CCR, InFlag);
1856 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001857 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001858 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1859 if (Res)
1860 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001861 }
1862
1863 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001864 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001865 // (imm:i32):$cc)
1866 // Emits: (MOVCCi:i32 GPR:i32:$false,
1867 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1868 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001869 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001870 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001871 CCVal, CCR, InFlag);
1872 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001873 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001874 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1875 if (Res)
1876 return Res;
1877 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001878 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001879 CCVal, CCR, InFlag);
1880 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001881 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001882 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1883 if (Res)
1884 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001885 }
1886 }
1887
1888 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1889 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1890 // Pattern complexity = 6 cost = 1 size = 0
1891 //
1892 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1893 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1894 // Pattern complexity = 6 cost = 11 size = 0
1895 //
1896 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001897 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1898 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001899 unsigned Opc = 0;
1900 switch (VT.getSimpleVT().SimpleTy) {
1901 default: assert(false && "Illegal conditional move type!");
1902 break;
1903 case MVT::i32:
1904 Opc = Subtarget->isThumb()
1905 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1906 : ARM::MOVCCr;
1907 break;
1908 case MVT::f32:
1909 Opc = ARM::VMOVScc;
1910 break;
1911 case MVT::f64:
1912 Opc = ARM::VMOVDcc;
1913 break;
1914 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001915 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001916}
1917
Evan Chengde8aa4e2010-05-05 18:28:36 +00001918SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1919 // The only time a CONCAT_VECTORS operation can have legal types is when
1920 // two 64-bit vectors are concatenated to a 128-bit vector.
1921 EVT VT = N->getValueType(0);
1922 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1923 llvm_unreachable("unexpected CONCAT_VECTORS");
1924 DebugLoc dl = N->getDebugLoc();
1925 SDValue V0 = N->getOperand(0);
1926 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001927 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1928 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001929 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1930 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1931}
1932
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001933SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001934 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001935
Dan Gohmane8be6c62008-07-17 19:10:17 +00001936 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001937 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001938
1939 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001940 default: break;
1941 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001942 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001943 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001944 if (Subtarget->hasThumb2())
1945 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1946 // be done with MOV + MOVT, at worst.
1947 UseCP = 0;
1948 else {
1949 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001950 UseCP = (Val > 255 && // MOV
1951 ~Val > 255 && // MOV + MVN
1952 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001953 } else
1954 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1955 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1956 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1957 }
1958
Evan Chenga8e29892007-01-19 07:51:42 +00001959 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001960 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001961 CurDAG->getTargetConstantPool(ConstantInt::get(
1962 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001963 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001964
1965 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001966 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001967 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001968 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001969 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001970 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1971 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001972 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001973 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001974 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001975 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001976 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001977 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001978 CurDAG->getEntryNode()
1979 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001980 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00001981 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00001982 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001984 return NULL;
1985 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001986
Evan Chenga8e29892007-01-19 07:51:42 +00001987 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001988 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001989 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001990 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001991 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001992 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001993 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001994 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001995 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1996 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001997 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001998 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1999 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002000 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2001 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2002 CurDAG->getRegister(0, MVT::i32) };
2003 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002004 }
Evan Chenga8e29892007-01-19 07:51:42 +00002005 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002006 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002007 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002008 return I;
2009 break;
2010 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002011 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002012 return I;
2013 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002014 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002015 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002016 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002017 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002018 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002019 if (!RHSV) break;
2020 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002021 unsigned ShImm = Log2_32(RHSV-1);
2022 if (ShImm >= 32)
2023 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002025 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002026 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2027 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002028 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002029 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002030 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002031 } else {
2032 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002033 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002034 }
Evan Chenga8e29892007-01-19 07:51:42 +00002035 }
2036 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002037 unsigned ShImm = Log2_32(RHSV+1);
2038 if (ShImm >= 32)
2039 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002040 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002041 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002042 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2043 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002044 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002045 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2046 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002047 } else {
2048 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002049 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002050 }
Evan Chenga8e29892007-01-19 07:51:42 +00002051 }
2052 }
2053 break;
Evan Cheng20956592009-10-21 08:15:52 +00002054 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002055 // Check for unsigned bitfield extract
2056 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2057 return I;
2058
Evan Cheng20956592009-10-21 08:15:52 +00002059 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2060 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2061 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2062 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2063 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002064 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002065 if (VT != MVT::i32)
2066 break;
2067 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2068 ? ARM::t2MOVTi16
2069 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2070 if (!Opc)
2071 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002072 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002073 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2074 if (!N1C)
2075 break;
2076 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2077 SDValue N2 = N0.getOperand(1);
2078 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2079 if (!N2C)
2080 break;
2081 unsigned N1CVal = N1C->getZExtValue();
2082 unsigned N2CVal = N2C->getZExtValue();
2083 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2084 (N1CVal & 0xffffU) == 0xffffU &&
2085 (N2CVal & 0xffffU) == 0x0U) {
2086 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2087 MVT::i32);
2088 SDValue Ops[] = { N0.getOperand(0), Imm16,
2089 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2090 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2091 }
2092 }
2093 break;
2094 }
Jim Grosbache5165492009-11-09 00:11:35 +00002095 case ARMISD::VMOVRRD:
2096 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002097 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002098 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002099 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002100 if (Subtarget->isThumb1Only())
2101 break;
2102 if (Subtarget->isThumb()) {
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) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002106 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002107 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002108 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002109 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2110 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002111 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002112 }
Evan Chengee568cf2007-07-05 07:15:27 +00002113 }
Dan Gohman525178c2007-10-08 18:33:35 +00002114 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002115 if (Subtarget->isThumb1Only())
2116 break;
2117 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002118 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002119 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002120 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002121 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002122 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002123 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2124 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002125 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002126 }
Evan Chengee568cf2007-07-05 07:15:27 +00002127 }
Evan Chenga8e29892007-01-19 07:51:42 +00002128 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002129 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002130 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002131 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002132 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002133 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002134 if (ResNode)
2135 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002136 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002137 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002138 }
Evan Chengee568cf2007-07-05 07:15:27 +00002139 case ARMISD::BRCOND: {
2140 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2141 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2142 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002143
Evan Chengee568cf2007-07-05 07:15:27 +00002144 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2145 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2146 // Pattern complexity = 6 cost = 1 size = 0
2147
David Goodwin5e47a9a2009-06-30 18:04:13 +00002148 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2149 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2150 // Pattern complexity = 6 cost = 1 size = 0
2151
Jim Grosbach764ab522009-08-11 15:33:49 +00002152 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002153 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002154 SDValue Chain = N->getOperand(0);
2155 SDValue N1 = N->getOperand(1);
2156 SDValue N2 = N->getOperand(2);
2157 SDValue N3 = N->getOperand(3);
2158 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002159 assert(N1.getOpcode() == ISD::BasicBlock);
2160 assert(N2.getOpcode() == ISD::Constant);
2161 assert(N3.getOpcode() == ISD::Register);
2162
Dan Gohman475871a2008-07-27 21:46:04 +00002163 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002164 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002165 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002166 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002167 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2168 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002169 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002170 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002171 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002172 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002173 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002174 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002175 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002176 return NULL;
2177 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002178 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002179 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002180 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002181 EVT VT = N->getValueType(0);
2182 SDValue N0 = N->getOperand(0);
2183 SDValue N1 = N->getOperand(1);
2184 SDValue N2 = N->getOperand(2);
2185 SDValue N3 = N->getOperand(3);
2186 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002187 assert(N2.getOpcode() == ISD::Constant);
2188 assert(N3.getOpcode() == ISD::Register);
2189
Dan Gohman475871a2008-07-27 21:46:04 +00002190 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002191 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002192 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002193 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002194 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002195 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002196 default: assert(false && "Illegal conditional move type!");
2197 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002198 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002199 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002200 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002201 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002202 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002203 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002204 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002205 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002206 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002207
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002208 case ARMISD::VZIP: {
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::VZIPd8; break;
2214 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2215 case MVT::v2f32:
2216 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2217 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2218 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2219 case MVT::v4f32:
2220 case MVT::v4i32: Opc = ARM::VZIPq32; 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::VUZP: {
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::VUZPd8; break;
2233 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2234 case MVT::v2f32:
2235 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2236 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2237 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2238 case MVT::v4f32:
2239 case MVT::v4i32: Opc = ARM::VUZPq32; 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 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002246 case ARMISD::VTRN: {
2247 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002248 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002249 switch (VT.getSimpleVT().SimpleTy) {
2250 default: return NULL;
2251 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2252 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2253 case MVT::v2f32:
2254 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2255 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2256 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2257 case MVT::v4f32:
2258 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2259 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002260 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002261 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2262 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2263 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002264 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002265 case ARMISD::BUILD_VECTOR: {
2266 EVT VecVT = N->getValueType(0);
2267 EVT EltVT = VecVT.getVectorElementType();
2268 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002269 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002270 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2271 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2272 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002273 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002274 if (NumElts == 2)
2275 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2276 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2277 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2278 N->getOperand(2), N->getOperand(3));
2279 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002280
2281 case ISD::INTRINSIC_VOID:
2282 case ISD::INTRINSIC_W_CHAIN: {
2283 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002284 switch (IntNo) {
2285 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002286 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002287
Bob Wilson621f1952010-03-23 05:25:43 +00002288 case Intrinsic::arm_neon_vld1: {
2289 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2290 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002291 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2292 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002293 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2294 }
2295
Bob Wilson31fb12f2009-08-26 17:39:53 +00002296 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002297 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2298 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2299 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2300 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002302 }
2303
2304 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002305 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2306 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2307 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2308 ARM::VLD3q16Pseudo_UPD,
2309 ARM::VLD3q32Pseudo_UPD };
2310 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2311 ARM::VLD3q16oddPseudo_UPD,
2312 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002313 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002314 }
2315
2316 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002317 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2318 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2319 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2320 ARM::VLD4q16Pseudo_UPD,
2321 ARM::VLD4q32Pseudo_UPD };
2322 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2323 ARM::VLD4q16oddPseudo_UPD,
2324 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002325 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002326 }
2327
Bob Wilson243fcc52009-09-01 04:26:28 +00002328 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002329 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2330 ARM::VLD2LNd32Pseudo };
2331 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2332 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002333 }
2334
2335 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002336 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2337 ARM::VLD3LNd32Pseudo };
2338 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2339 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002340 }
2341
2342 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002343 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2344 ARM::VLD4LNd32Pseudo };
2345 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2346 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002347 }
2348
Bob Wilson11d98992010-03-23 06:20:33 +00002349 case Intrinsic::arm_neon_vst1: {
2350 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2351 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002352 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2353 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002354 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2355 }
2356
Bob Wilson31fb12f2009-08-26 17:39:53 +00002357 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002358 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2359 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2360 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2361 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002362 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002363 }
2364
2365 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002366 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2367 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2368 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2369 ARM::VST3q16Pseudo_UPD,
2370 ARM::VST3q32Pseudo_UPD };
2371 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2372 ARM::VST3q16oddPseudo_UPD,
2373 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002374 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002375 }
2376
2377 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002378 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002379 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002380 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2381 ARM::VST4q16Pseudo_UPD,
2382 ARM::VST4q32Pseudo_UPD };
2383 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2384 ARM::VST4q16oddPseudo_UPD,
2385 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002386 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002387 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002388
2389 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002390 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2391 ARM::VST2LNd32Pseudo };
2392 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2393 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002394 }
2395
2396 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002397 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2398 ARM::VST3LNd32Pseudo };
2399 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2400 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002401 }
2402
2403 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002404 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2405 ARM::VST4LNd32Pseudo };
2406 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2407 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002408 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002409 }
Bob Wilson429009b2010-05-06 16:05:26 +00002410 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002411 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002412
Bob Wilsond491d6e2010-07-06 23:36:25 +00002413 case ISD::INTRINSIC_WO_CHAIN: {
2414 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2415 switch (IntNo) {
2416 default:
2417 break;
2418
2419 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002420 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002421 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002422 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002423 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002424 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002425
2426 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002427 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002428 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002429 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002430 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002431 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002432 }
2433 break;
2434 }
2435
Bob Wilson429009b2010-05-06 16:05:26 +00002436 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002437 return SelectConcatVector(N);
2438 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002439
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002440 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002441}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002442
Bob Wilson224c2442009-05-19 05:53:42 +00002443bool ARMDAGToDAGISel::
2444SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2445 std::vector<SDValue> &OutOps) {
2446 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002447 // Require the address to be in a register. That is safe for all ARM
2448 // variants and it is hard to do anything much smarter without knowing
2449 // how the operand is used.
2450 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002451 return false;
2452}
2453
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002454/// createARMISelDag - This pass converts a legalized DAG into a
2455/// ARM-specific DAG, ready for instruction scheduling.
2456///
Bob Wilson522ce972009-09-28 14:30:20 +00002457FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2458 CodeGenOpt::Level OptLevel) {
2459 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002460}