blob: ec66ceae2a19bd262c9bceb6bf0dab3b69d70421 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000016#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037using namespace llvm;
38
Evan Chenga2c519b2010-07-30 23:33:54 +000039static cl::opt<bool>
40DisableShifterOp("disable-shifter-op", cl::Hidden,
41 cl::desc("Disable isel of shifter-op"),
42 cl::init(false));
43
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000044//===--------------------------------------------------------------------===//
45/// ARMDAGToDAGISel - ARM specific code to select ARM machine
46/// instructions for SelectionDAG operations.
47///
48namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000049
50enum AddrMode2Type {
51 AM2_BASE, // Simple AM2 (+-imm12)
52 AM2_SHOP // Shifter-op AM2
53};
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000056 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000057
Evan Chenga8e29892007-01-19 07:51:42 +000058 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
59 /// make the right decision when generating code for different targets.
60 const ARMSubtarget *Subtarget;
61
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000062public:
Bob Wilson522ce972009-09-28 14:30:20 +000063 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
64 CodeGenOpt::Level OptLevel)
65 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000066 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000067 }
68
Evan Chenga8e29892007-01-19 07:51:42 +000069 virtual const char *getPassName() const {
70 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Bob Wilsonaf4a8912009-10-08 18:51:31 +000073 /// getI32Imm - Return a target constant of type i32 with the specified
74 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000075 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000076 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000077 }
78
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000080
Evan Chengf40deed2010-10-27 23:41:30 +000081 bool isShifterOpProfitable(const SDValue &Shift,
82 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000083 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000084 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000085 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
86 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000087 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
88 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
89
Jim Grosbach82891622010-09-29 19:03:54 +000090 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
91 SDValue &Offset, SDValue &Opc);
92 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
93 SDValue &Opc) {
94 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
95 }
96
97 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
98 SDValue &Opc) {
99 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
100 }
101
102 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000105// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000106 // This always matches one way or another.
107 return true;
108 }
109
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000111 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000112 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000113 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000115 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000116 bool SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode);
117 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000118 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000119 bool SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000120
Chris Lattner52a261b2010-09-21 20:31:19 +0000121 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000122 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000123
Chris Lattner52a261b2010-09-21 20:31:19 +0000124 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
125 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000126 SDValue &Base, SDValue &OffImm,
127 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000128 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000129 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000131 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000132 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000133 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000135
Chris Lattner52a261b2010-09-21 20:31:19 +0000136 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000137 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000138 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
139 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000140 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000142 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000144 SDValue &OffReg, SDValue &ShImm);
145
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000146 inline bool Pred_so_imm(SDNode *inN) const {
147 ConstantSDNode *N = cast<ConstantSDNode>(inN);
148 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
149 }
150
151 inline bool Pred_t2_so_imm(SDNode *inN) const {
152 ConstantSDNode *N = cast<ConstantSDNode>(inN);
153 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
154 }
155
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000156 // Include the pieces autogenerated from the target description.
157#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000158
159private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000160 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
161 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000162 SDNode *SelectARMIndexedLoad(SDNode *N);
163 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000164
Bob Wilson621f1952010-03-23 05:25:43 +0000165 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
166 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000167 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000168 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000169 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000170 unsigned *QOpcodes0, unsigned *QOpcodes1);
171
Bob Wilson24f995d2009-10-14 18:32:29 +0000172 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000173 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000174 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000175 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000176 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000177 unsigned *QOpcodes0, unsigned *QOpcodes1);
178
Bob Wilson96493442009-10-14 16:46:45 +0000179 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000180 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000181 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000182 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000183 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000184
Bob Wilson78dfbc32010-07-07 00:08:54 +0000185 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
186 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
187 /// generated to force the table registers to be consecutive.
188 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000189
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000190 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000191 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000192
Evan Cheng07ba9062009-11-19 21:45:22 +0000193 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000194 SDNode *SelectCMOVOp(SDNode *N);
195 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000196 ARMCC::CondCodes CCVal, SDValue CCR,
197 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000198 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000199 ARMCC::CondCodes CCVal, SDValue CCR,
200 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000201 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000202 ARMCC::CondCodes CCVal, SDValue CCR,
203 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000204 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000205 ARMCC::CondCodes CCVal, SDValue CCR,
206 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000207
Evan Chengde8aa4e2010-05-05 18:28:36 +0000208 SDNode *SelectConcatVector(SDNode *N);
209
Evan Chengaf4550f2009-07-02 01:23:32 +0000210 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
211 /// inline asm expressions.
212 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
213 char ConstraintCode,
214 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000215
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000216 // Form pairs of consecutive S, D, or Q registers.
217 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000218 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000219 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
220
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000221 // Form sequences of 4 consecutive S, D, or Q registers.
222 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000223 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000224 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000225};
Evan Chenga8e29892007-01-19 07:51:42 +0000226}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000227
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000228/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
229/// operand. If so Imm will receive the 32-bit value.
230static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
231 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
232 Imm = cast<ConstantSDNode>(N)->getZExtValue();
233 return true;
234 }
235 return false;
236}
237
238// isInt32Immediate - This method tests to see if a constant operand.
239// If so Imm will receive the 32 bit value.
240static bool isInt32Immediate(SDValue N, unsigned &Imm) {
241 return isInt32Immediate(N.getNode(), Imm);
242}
243
244// isOpcWithIntImmediate - This method tests to see if the node is a specific
245// opcode and that it has a immediate integer right operand.
246// If so Imm will receive the 32 bit value.
247static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
248 return N->getOpcode() == Opc &&
249 isInt32Immediate(N->getOperand(1).getNode(), Imm);
250}
251
252
Evan Chengf40deed2010-10-27 23:41:30 +0000253bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
254 ARM_AM::ShiftOpc ShOpcVal,
255 unsigned ShAmt) {
256 if (!Subtarget->isCortexA9())
257 return true;
258 if (Shift.hasOneUse())
259 return true;
260 // R << 2 is free.
261 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
262}
263
Chris Lattner52a261b2010-09-21 20:31:19 +0000264bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000265 SDValue &BaseReg,
266 SDValue &ShReg,
267 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000268 if (DisableShifterOp)
269 return false;
270
Evan Cheng055b0312009-06-29 07:51:04 +0000271 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
272
273 // Don't match base register only case. That is matched to a separate
274 // lower complexity pattern with explicit register operand.
275 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000276
Evan Cheng055b0312009-06-29 07:51:04 +0000277 BaseReg = N.getOperand(0);
278 unsigned ShImmVal = 0;
279 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000280 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000281 ShImmVal = RHS->getZExtValue() & 31;
282 } else {
283 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000284 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
285 return false;
286 }
287 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
288 MVT::i32);
289 return true;
290}
291
292bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
293 SDValue &BaseReg,
294 SDValue &ShReg,
295 SDValue &Opc) {
296 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
297
298 // Don't match base register only case. That is matched to a separate
299 // lower complexity pattern with explicit register operand.
300 if (ShOpcVal == ARM_AM::no_shift) return false;
301
302 BaseReg = N.getOperand(0);
303 unsigned ShImmVal = 0;
304 // Do not check isShifterOpProfitable. This must return true.
305 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
306 ShReg = CurDAG->getRegister(0, MVT::i32);
307 ShImmVal = RHS->getZExtValue() & 31;
308 } else {
309 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000310 }
311 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000312 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000313 return true;
314}
315
Jim Grosbach3e556122010-10-26 22:37:02 +0000316bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
317 SDValue &Base,
318 SDValue &OffImm) {
319 // Match simple R + imm12 operands.
320
321 // Base only.
322 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
323 if (N.getOpcode() == ISD::FrameIndex) {
324 // Match frame index...
325 int FI = cast<FrameIndexSDNode>(N)->getIndex();
326 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
327 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
328 return true;
329 } else if (N.getOpcode() == ARMISD::Wrapper &&
330 !(Subtarget->useMovt() &&
331 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
332 Base = N.getOperand(0);
333 } else
334 Base = N;
335 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
336 return true;
337 }
338
339 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
340 int RHSC = (int)RHS->getZExtValue();
341 if (N.getOpcode() == ISD::SUB)
342 RHSC = -RHSC;
343
344 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
345 Base = N.getOperand(0);
346 if (Base.getOpcode() == ISD::FrameIndex) {
347 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
348 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
349 }
350 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
351 return true;
352 }
353 }
354
355 // Base only.
356 Base = N;
357 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
358 return true;
359}
360
361
362
363bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
364 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000365 if (N.getOpcode() == ISD::MUL &&
366 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000367 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
368 // X * [3,5,9] -> X + X * [2,4,8] etc.
369 int RHSC = (int)RHS->getZExtValue();
370 if (RHSC & 1) {
371 RHSC = RHSC & ~1;
372 ARM_AM::AddrOpc AddSub = ARM_AM::add;
373 if (RHSC < 0) {
374 AddSub = ARM_AM::sub;
375 RHSC = - RHSC;
376 }
377 if (isPowerOf2_32(RHSC)) {
378 unsigned ShAmt = Log2_32(RHSC);
379 Base = Offset = N.getOperand(0);
380 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
381 ARM_AM::lsl),
382 MVT::i32);
383 return true;
384 }
385 }
386 }
387 }
388
389 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
390 return false;
391
392 // Leave simple R +/- imm12 operands for LDRi12
393 if (N.getOpcode() == ISD::ADD) {
394 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
395 int RHSC = (int)RHS->getZExtValue();
396 if ((RHSC >= 0 && RHSC < 0x1000) ||
397 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
398 return false;
399 }
400 }
401
Evan Chengf40deed2010-10-27 23:41:30 +0000402 if (Subtarget->isCortexA9() && !N.hasOneUse())
403 // Compute R +/- (R << N) and reuse it.
404 return false;
405
Jim Grosbach3e556122010-10-26 22:37:02 +0000406 // Otherwise this is R +/- [possibly shifted] R.
407 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
408 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
409 unsigned ShAmt = 0;
410
411 Base = N.getOperand(0);
412 Offset = N.getOperand(1);
413
414 if (ShOpcVal != ARM_AM::no_shift) {
415 // Check to see if the RHS of the shift is a constant, if not, we can't fold
416 // it.
417 if (ConstantSDNode *Sh =
418 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
419 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000420 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
421 Offset = N.getOperand(1).getOperand(0);
422 else {
423 ShAmt = 0;
424 ShOpcVal = ARM_AM::no_shift;
425 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000426 } else {
427 ShOpcVal = ARM_AM::no_shift;
428 }
429 }
430
431 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000432 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
433 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000434 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
435 if (ShOpcVal != ARM_AM::no_shift) {
436 // Check to see if the RHS of the shift is a constant, if not, we can't
437 // fold it.
438 if (ConstantSDNode *Sh =
439 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
440 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000441 if (!Subtarget->isCortexA9() ||
442 (N.hasOneUse() &&
443 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
444 Offset = N.getOperand(0).getOperand(0);
445 Base = N.getOperand(1);
446 } else {
447 ShAmt = 0;
448 ShOpcVal = ARM_AM::no_shift;
449 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000450 } else {
451 ShOpcVal = ARM_AM::no_shift;
452 }
453 }
454 }
455
456 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
457 MVT::i32);
458 return true;
459}
460
461
462
463
464//-----
465
Jim Grosbach82891622010-09-29 19:03:54 +0000466AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
467 SDValue &Base,
468 SDValue &Offset,
469 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000470 if (N.getOpcode() == ISD::MUL &&
471 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000472 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
473 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000474 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000475 if (RHSC & 1) {
476 RHSC = RHSC & ~1;
477 ARM_AM::AddrOpc AddSub = ARM_AM::add;
478 if (RHSC < 0) {
479 AddSub = ARM_AM::sub;
480 RHSC = - RHSC;
481 }
482 if (isPowerOf2_32(RHSC)) {
483 unsigned ShAmt = Log2_32(RHSC);
484 Base = Offset = N.getOperand(0);
485 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
486 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000487 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000488 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000489 }
490 }
491 }
492 }
493
Evan Chenga8e29892007-01-19 07:51:42 +0000494 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
495 Base = N;
496 if (N.getOpcode() == ISD::FrameIndex) {
497 int FI = cast<FrameIndexSDNode>(N)->getIndex();
498 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000499 } else if (N.getOpcode() == ARMISD::Wrapper &&
500 !(Subtarget->useMovt() &&
501 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000502 Base = N.getOperand(0);
503 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000504 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000505 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
506 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000507 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000508 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000509 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000510
Evan Chenga8e29892007-01-19 07:51:42 +0000511 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000512 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000513 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000514 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000515 if ((RHSC >= 0 && RHSC < 0x1000) ||
516 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000517 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000518 if (Base.getOpcode() == ISD::FrameIndex) {
519 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
520 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
521 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000522 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000523
524 ARM_AM::AddrOpc AddSub = ARM_AM::add;
525 if (RHSC < 0) {
526 AddSub = ARM_AM::sub;
527 RHSC = - RHSC;
528 }
529 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000530 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000531 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000532 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000533 }
Evan Chenga8e29892007-01-19 07:51:42 +0000534 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000535 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000536
Evan Chengf40deed2010-10-27 23:41:30 +0000537 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
538 // Compute R +/- (R << N) and reuse it.
539 Base = N;
540 Offset = CurDAG->getRegister(0, MVT::i32);
541 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
542 ARM_AM::no_shift),
543 MVT::i32);
544 return AM2_BASE;
545 }
546
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000547 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000548 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
549 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
550 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000551
Evan Chenga8e29892007-01-19 07:51:42 +0000552 Base = N.getOperand(0);
553 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000554
Evan Chenga8e29892007-01-19 07:51:42 +0000555 if (ShOpcVal != ARM_AM::no_shift) {
556 // Check to see if the RHS of the shift is a constant, if not, we can't fold
557 // it.
558 if (ConstantSDNode *Sh =
559 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000560 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000561 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
562 Offset = N.getOperand(1).getOperand(0);
563 else {
564 ShAmt = 0;
565 ShOpcVal = ARM_AM::no_shift;
566 }
Evan Chenga8e29892007-01-19 07:51:42 +0000567 } else {
568 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000569 }
570 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000571
Evan Chenga8e29892007-01-19 07:51:42 +0000572 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000573 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
574 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000575 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
576 if (ShOpcVal != ARM_AM::no_shift) {
577 // Check to see if the RHS of the shift is a constant, if not, we can't
578 // fold it.
579 if (ConstantSDNode *Sh =
580 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000581 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000582 if (!Subtarget->isCortexA9() ||
583 (N.hasOneUse() &&
584 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
585 Offset = N.getOperand(0).getOperand(0);
586 Base = N.getOperand(1);
587 } else {
588 ShAmt = 0;
589 ShOpcVal = ARM_AM::no_shift;
590 }
Evan Chenga8e29892007-01-19 07:51:42 +0000591 } else {
592 ShOpcVal = ARM_AM::no_shift;
593 }
594 }
595 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000596
Evan Chenga8e29892007-01-19 07:51:42 +0000597 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000598 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000599 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000600}
601
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000602bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000603 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000604 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000605 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
606 ? cast<LoadSDNode>(Op)->getAddressingMode()
607 : cast<StoreSDNode>(Op)->getAddressingMode();
608 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
609 ? ARM_AM::add : ARM_AM::sub;
610 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000611 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000612 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000613 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000614 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
615 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000616 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000617 return true;
618 }
619 }
620
621 Offset = N;
622 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
623 unsigned ShAmt = 0;
624 if (ShOpcVal != ARM_AM::no_shift) {
625 // Check to see if the RHS of the shift is a constant, if not, we can't fold
626 // it.
627 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000628 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000629 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
630 Offset = N.getOperand(0);
631 else {
632 ShAmt = 0;
633 ShOpcVal = ARM_AM::no_shift;
634 }
Evan Chenga8e29892007-01-19 07:51:42 +0000635 } else {
636 ShOpcVal = ARM_AM::no_shift;
637 }
638 }
639
640 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000641 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000642 return true;
643}
644
Evan Chenga8e29892007-01-19 07:51:42 +0000645
Chris Lattner52a261b2010-09-21 20:31:19 +0000646bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000647 SDValue &Base, SDValue &Offset,
648 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000649 if (N.getOpcode() == ISD::SUB) {
650 // X - C is canonicalize to X + -C, no need to handle it here.
651 Base = N.getOperand(0);
652 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000653 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000654 return true;
655 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000656
Evan Chenga8e29892007-01-19 07:51:42 +0000657 if (N.getOpcode() != ISD::ADD) {
658 Base = N;
659 if (N.getOpcode() == ISD::FrameIndex) {
660 int FI = cast<FrameIndexSDNode>(N)->getIndex();
661 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
662 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000663 Offset = CurDAG->getRegister(0, MVT::i32);
664 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000665 return true;
666 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000667
Evan Chenga8e29892007-01-19 07:51:42 +0000668 // If the RHS is +/- imm8, fold into addr mode.
669 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000670 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000671 if ((RHSC >= 0 && RHSC < 256) ||
672 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000673 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000674 if (Base.getOpcode() == ISD::FrameIndex) {
675 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
676 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
677 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000678 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000679
680 ARM_AM::AddrOpc AddSub = ARM_AM::add;
681 if (RHSC < 0) {
682 AddSub = ARM_AM::sub;
683 RHSC = - RHSC;
684 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000685 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000686 return true;
687 }
688 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000689
Evan Chenga8e29892007-01-19 07:51:42 +0000690 Base = N.getOperand(0);
691 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000692 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000693 return true;
694}
695
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000696bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000697 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000698 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000699 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
700 ? cast<LoadSDNode>(Op)->getAddressingMode()
701 : cast<StoreSDNode>(Op)->getAddressingMode();
702 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
703 ? ARM_AM::add : ARM_AM::sub;
704 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000705 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000706 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000707 Offset = CurDAG->getRegister(0, MVT::i32);
708 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000709 return true;
710 }
711 }
712
713 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000714 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000715 return true;
716}
717
Chris Lattner52a261b2010-09-21 20:31:19 +0000718bool ARMDAGToDAGISel::SelectAddrMode4(SDValue N, SDValue &Addr, SDValue &Mode) {
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000719 Addr = N;
Bob Wilsonfd7fd942010-08-28 00:20:11 +0000720 Mode = CurDAG->getTargetConstant(ARM_AM::getAM4ModeImm(ARM_AM::ia), MVT::i32);
Anton Korobeynikovbaf31082009-08-08 13:35:48 +0000721 return true;
722}
Evan Chenga8e29892007-01-19 07:51:42 +0000723
Jim Grosbach3ab56582010-10-21 19:38:40 +0000724bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000725 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000726 if (N.getOpcode() != ISD::ADD) {
727 Base = N;
728 if (N.getOpcode() == ISD::FrameIndex) {
729 int FI = cast<FrameIndexSDNode>(N)->getIndex();
730 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000731 } else if (N.getOpcode() == ARMISD::Wrapper &&
732 !(Subtarget->useMovt() &&
733 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000734 Base = N.getOperand(0);
735 }
736 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000737 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000738 return true;
739 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000740
Evan Chenga8e29892007-01-19 07:51:42 +0000741 // If the RHS is +/- imm8, fold into addr mode.
742 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000743 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000744 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
745 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000746 if ((RHSC >= 0 && RHSC < 256) ||
747 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000748 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000749 if (Base.getOpcode() == ISD::FrameIndex) {
750 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
751 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
752 }
753
754 ARM_AM::AddrOpc AddSub = ARM_AM::add;
755 if (RHSC < 0) {
756 AddSub = ARM_AM::sub;
757 RHSC = - RHSC;
758 }
759 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000760 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000761 return true;
762 }
763 }
764 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000765
Evan Chenga8e29892007-01-19 07:51:42 +0000766 Base = N;
767 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000768 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000769 return true;
770}
771
Chris Lattner52a261b2010-09-21 20:31:19 +0000772bool ARMDAGToDAGISel::SelectAddrMode6(SDValue N, SDValue &Addr, SDValue &Align){
Bob Wilson8b024a52009-07-01 23:16:05 +0000773 Addr = N;
Jim Grosbach8a5ec862009-11-07 21:25:39 +0000774 // Default to no alignment.
775 Align = CurDAG->getTargetConstant(0, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000776 return true;
777}
778
Chris Lattner52a261b2010-09-21 20:31:19 +0000779bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000780 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000781 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
782 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000783 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000784 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000785 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000786 return true;
787 }
788 return false;
789}
790
Chris Lattner52a261b2010-09-21 20:31:19 +0000791bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000792 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000793 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000794 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000795 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000796 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000797 return false;
798
799 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000800 return true;
801 }
802
Evan Chenga8e29892007-01-19 07:51:42 +0000803 Base = N.getOperand(0);
804 Offset = N.getOperand(1);
805 return true;
806}
807
Evan Cheng79d43262007-01-24 02:21:22 +0000808bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000809ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000810 unsigned Scale, SDValue &Base,
811 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000812 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000813 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000814 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000815 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000816 if (N.getOpcode() == ARMISD::Wrapper &&
817 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
818 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000819 }
820
Evan Chenga8e29892007-01-19 07:51:42 +0000821 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000822 if (N.getOpcode() == ARMISD::Wrapper &&
823 !(Subtarget->useMovt() &&
824 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
825 Base = N.getOperand(0);
826 } else
827 Base = N;
828
Owen Anderson825b72b2009-08-11 20:47:22 +0000829 Offset = CurDAG->getRegister(0, MVT::i32);
830 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000831 return true;
832 }
833
Evan Chengad0e4652007-02-06 00:22:06 +0000834 // Thumb does not have [sp, r] address mode.
835 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
836 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
837 if ((LHSR && LHSR->getReg() == ARM::SP) ||
838 (RHSR && RHSR->getReg() == ARM::SP)) {
839 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000840 Offset = CurDAG->getRegister(0, MVT::i32);
841 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000842 return true;
843 }
844
Evan Chenga8e29892007-01-19 07:51:42 +0000845 // If the RHS is + imm5 * scale, fold into addr mode.
846 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000847 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000848 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
849 RHSC /= Scale;
850 if (RHSC >= 0 && RHSC < 32) {
851 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000852 Offset = CurDAG->getRegister(0, MVT::i32);
853 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000854 return true;
855 }
856 }
857 }
858
Evan Chengc38f2bc2007-01-23 22:59:13 +0000859 Base = N.getOperand(0);
860 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000861 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000862 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000863}
864
Chris Lattner52a261b2010-09-21 20:31:19 +0000865bool ARMDAGToDAGISel::SelectThumbAddrModeS1(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000866 SDValue &Base, SDValue &OffImm,
867 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000868 return SelectThumbAddrModeRI5(N, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000869}
870
Chris Lattner52a261b2010-09-21 20:31:19 +0000871bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000872 SDValue &Base, SDValue &OffImm,
873 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000874 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000875}
876
Chris Lattner52a261b2010-09-21 20:31:19 +0000877bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000878 SDValue &Base, SDValue &OffImm,
879 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000880 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000881}
882
Chris Lattner52a261b2010-09-21 20:31:19 +0000883bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
884 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000885 if (N.getOpcode() == ISD::FrameIndex) {
886 int FI = cast<FrameIndexSDNode>(N)->getIndex();
887 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000888 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000889 return true;
890 }
Evan Cheng79d43262007-01-24 02:21:22 +0000891
Evan Chengad0e4652007-02-06 00:22:06 +0000892 if (N.getOpcode() != ISD::ADD)
893 return false;
894
895 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000896 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
897 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000898 // If the RHS is + imm8 * scale, fold into addr mode.
899 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000900 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000901 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
902 RHSC >>= 2;
903 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000904 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000905 if (Base.getOpcode() == ISD::FrameIndex) {
906 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
907 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
908 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000909 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000910 return true;
911 }
912 }
913 }
914 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000915
Evan Chenga8e29892007-01-19 07:51:42 +0000916 return false;
917}
918
Chris Lattner52a261b2010-09-21 20:31:19 +0000919bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000920 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000921 if (DisableShifterOp)
922 return false;
923
Evan Cheng9cb9e672009-06-27 02:26:13 +0000924 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
925
926 // Don't match base register only case. That is matched to a separate
927 // lower complexity pattern with explicit register operand.
928 if (ShOpcVal == ARM_AM::no_shift) return false;
929
930 BaseReg = N.getOperand(0);
931 unsigned ShImmVal = 0;
932 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
933 ShImmVal = RHS->getZExtValue() & 31;
934 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
935 return true;
936 }
937
938 return false;
939}
940
Chris Lattner52a261b2010-09-21 20:31:19 +0000941bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000942 SDValue &Base, SDValue &OffImm) {
943 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000944
Evan Cheng3a214252009-08-11 08:52:18 +0000945 // Base only.
946 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000947 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000948 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000949 int FI = cast<FrameIndexSDNode>(N)->getIndex();
950 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000951 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000952 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000953 } else if (N.getOpcode() == ARMISD::Wrapper &&
954 !(Subtarget->useMovt() &&
955 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000956 Base = N.getOperand(0);
957 if (Base.getOpcode() == ISD::TargetConstantPool)
958 return false; // We want to select t2LDRpci instead.
959 } else
960 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000961 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000962 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000963 }
Evan Cheng055b0312009-06-29 07:51:04 +0000964
965 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000966 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000967 // Let t2LDRi8 handle (R - imm8).
968 return false;
969
Evan Cheng055b0312009-06-29 07:51:04 +0000970 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000971 if (N.getOpcode() == ISD::SUB)
972 RHSC = -RHSC;
973
974 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000975 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000976 if (Base.getOpcode() == ISD::FrameIndex) {
977 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
978 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
979 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000980 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000981 return true;
982 }
983 }
984
Evan Cheng3a214252009-08-11 08:52:18 +0000985 // Base only.
986 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000987 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000988 return true;
Evan Cheng055b0312009-06-29 07:51:04 +0000989}
990
Chris Lattner52a261b2010-09-21 20:31:19 +0000991bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000992 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +0000993 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +0000994 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +0000995 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
996 int RHSC = (int)RHS->getSExtValue();
997 if (N.getOpcode() == ISD::SUB)
998 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +0000999
Evan Cheng3a214252009-08-11 08:52:18 +00001000 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1001 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001002 if (Base.getOpcode() == ISD::FrameIndex) {
1003 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1004 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1005 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001006 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001007 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001008 }
Evan Cheng055b0312009-06-29 07:51:04 +00001009 }
1010 }
1011
1012 return false;
1013}
1014
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001015bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001016 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001017 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001018 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1019 ? cast<LoadSDNode>(Op)->getAddressingMode()
1020 : cast<StoreSDNode>(Op)->getAddressingMode();
1021 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1022 int RHSC = (int)RHS->getZExtValue();
1023 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001024 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001025 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1026 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001027 return true;
1028 }
1029 }
1030
1031 return false;
1032}
1033
Chris Lattner52a261b2010-09-21 20:31:19 +00001034bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001035 SDValue &Base,
1036 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001037 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1038 if (N.getOpcode() != ISD::ADD)
1039 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001040
Evan Cheng3a214252009-08-11 08:52:18 +00001041 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1042 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1043 int RHSC = (int)RHS->getZExtValue();
1044 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1045 return false;
1046 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001047 return false;
1048 }
1049
Evan Chengf40deed2010-10-27 23:41:30 +00001050 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1051 // Compute R + (R << [1,2,3]) and reuse it.
1052 Base = N;
1053 return false;
1054 }
1055
Evan Cheng055b0312009-06-29 07:51:04 +00001056 // Look for (R + R) or (R + (R << [1,2,3])).
1057 unsigned ShAmt = 0;
1058 Base = N.getOperand(0);
1059 OffReg = N.getOperand(1);
1060
1061 // Swap if it is ((R << c) + R).
1062 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1063 if (ShOpcVal != ARM_AM::lsl) {
1064 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1065 if (ShOpcVal == ARM_AM::lsl)
1066 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001067 }
1068
Evan Cheng055b0312009-06-29 07:51:04 +00001069 if (ShOpcVal == ARM_AM::lsl) {
1070 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1071 // it.
1072 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1073 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001074 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1075 OffReg = OffReg.getOperand(0);
1076 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001077 ShAmt = 0;
1078 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001079 }
Evan Cheng055b0312009-06-29 07:51:04 +00001080 } else {
1081 ShOpcVal = ARM_AM::no_shift;
1082 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001083 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001084
Owen Anderson825b72b2009-08-11 20:47:22 +00001085 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001086
1087 return true;
1088}
1089
1090//===--------------------------------------------------------------------===//
1091
Evan Chengee568cf2007-07-05 07:15:27 +00001092/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001093static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001094 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001095}
1096
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001097SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1098 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001099 ISD::MemIndexedMode AM = LD->getAddressingMode();
1100 if (AM == ISD::UNINDEXED)
1101 return NULL;
1102
Owen Andersone50ed302009-08-10 22:56:29 +00001103 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001104 SDValue Offset, AMOpc;
1105 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1106 unsigned Opcode = 0;
1107 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001108 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001109 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001110 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1111 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001112 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001113 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001114 Match = true;
1115 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1116 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1117 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001118 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001119 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001120 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001121 Match = true;
1122 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1123 }
1124 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001125 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001126 Match = true;
1127 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1128 }
1129 }
1130 }
1131
1132 if (Match) {
1133 SDValue Chain = LD->getChain();
1134 SDValue Base = LD->getBasePtr();
1135 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001136 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001137 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001138 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001139 }
1140
1141 return NULL;
1142}
1143
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001144SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1145 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001146 ISD::MemIndexedMode AM = LD->getAddressingMode();
1147 if (AM == ISD::UNINDEXED)
1148 return NULL;
1149
Owen Andersone50ed302009-08-10 22:56:29 +00001150 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001151 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001152 SDValue Offset;
1153 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1154 unsigned Opcode = 0;
1155 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001156 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001157 switch (LoadedVT.getSimpleVT().SimpleTy) {
1158 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001159 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1160 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001161 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001162 if (isSExtLd)
1163 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1164 else
1165 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001166 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001167 case MVT::i8:
1168 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001169 if (isSExtLd)
1170 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1171 else
1172 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001173 break;
1174 default:
1175 return NULL;
1176 }
1177 Match = true;
1178 }
1179
1180 if (Match) {
1181 SDValue Chain = LD->getChain();
1182 SDValue Base = LD->getBasePtr();
1183 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001184 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001185 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001186 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001187 }
1188
1189 return NULL;
1190}
1191
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001192/// PairSRegs - Form a D register from a pair of S registers.
1193///
1194SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1195 DebugLoc dl = V0.getNode()->getDebugLoc();
1196 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1197 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001198 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1199 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001200}
1201
Evan Cheng603afbf2010-05-10 17:34:18 +00001202/// PairDRegs - Form a quad register from a pair of D registers.
1203///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001204SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1205 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001206 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1207 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001208 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1209 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001210}
1211
Evan Cheng7f687192010-05-14 00:21:45 +00001212/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001213///
1214SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1215 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001216 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1217 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001218 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1219 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1220}
1221
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001222/// QuadSRegs - Form 4 consecutive S registers.
1223///
1224SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1225 SDValue V2, SDValue V3) {
1226 DebugLoc dl = V0.getNode()->getDebugLoc();
1227 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1228 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1229 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1230 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1231 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1232 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1233}
1234
Evan Cheng7f687192010-05-14 00:21:45 +00001235/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001236///
1237SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1238 SDValue V2, SDValue V3) {
1239 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001240 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1241 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1242 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1243 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001244 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1245 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1246}
1247
Evan Cheng8f6de382010-05-16 03:27:48 +00001248/// QuadQRegs - Form 4 consecutive Q registers.
1249///
1250SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1251 SDValue V2, SDValue V3) {
1252 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001253 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1254 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1255 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1256 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001257 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1258 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1259}
1260
Bob Wilson2a6e6162010-09-23 23:42:37 +00001261/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1262/// of a NEON VLD or VST instruction. The supported values depend on the
1263/// number of registers being loaded.
1264static unsigned GetVLDSTAlign(SDNode *N, unsigned NumVecs, bool is64BitVector) {
1265 unsigned NumRegs = NumVecs;
1266 if (!is64BitVector && NumVecs < 3)
1267 NumRegs *= 2;
1268
1269 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1270 if (Alignment >= 32 && NumRegs == 4)
1271 return 32;
1272 if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1273 return 16;
1274 if (Alignment >= 8)
1275 return 8;
1276 return 0;
1277}
1278
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001279SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001280 unsigned *DOpcodes, unsigned *QOpcodes0,
1281 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001282 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001283 DebugLoc dl = N->getDebugLoc();
1284
Bob Wilson226036e2010-03-20 22:13:40 +00001285 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001286 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001287 return NULL;
1288
1289 SDValue Chain = N->getOperand(0);
1290 EVT VT = N->getValueType(0);
1291 bool is64BitVector = VT.is64BitVector();
1292
Bob Wilson2a6e6162010-09-23 23:42:37 +00001293 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001294 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1295
Bob Wilson3e36f132009-10-14 17:28:52 +00001296 unsigned OpcodeIndex;
1297 switch (VT.getSimpleVT().SimpleTy) {
1298 default: llvm_unreachable("unhandled vld type");
1299 // Double-register operations:
1300 case MVT::v8i8: OpcodeIndex = 0; break;
1301 case MVT::v4i16: OpcodeIndex = 1; break;
1302 case MVT::v2f32:
1303 case MVT::v2i32: OpcodeIndex = 2; break;
1304 case MVT::v1i64: OpcodeIndex = 3; break;
1305 // Quad-register operations:
1306 case MVT::v16i8: OpcodeIndex = 0; break;
1307 case MVT::v8i16: OpcodeIndex = 1; break;
1308 case MVT::v4f32:
1309 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001310 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001311 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001312 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001313 }
1314
Bob Wilsonf5721912010-09-03 18:16:02 +00001315 EVT ResTy;
1316 if (NumVecs == 1)
1317 ResTy = VT;
1318 else {
1319 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1320 if (!is64BitVector)
1321 ResTyElts *= 2;
1322 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1323 }
1324
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001325 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001326 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001327 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001328 if (is64BitVector) {
1329 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001330 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001331 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001332 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001333 return VLd;
1334
Bob Wilsonf5721912010-09-03 18:16:02 +00001335 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001336 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001337 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001338 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001339 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001340 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001341 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001342 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001343 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001344 }
1345
Bob Wilson621f1952010-03-23 05:25:43 +00001346 if (NumVecs <= 2) {
1347 // Quad registers are directly supported for VLD1 and VLD2,
1348 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001349 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001350 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001351 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001352 if (NumVecs == 1)
1353 return VLd;
1354
Bob Wilsonf5721912010-09-03 18:16:02 +00001355 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001356 Chain = SDValue(VLd, 1);
1357
Bob Wilson3e36f132009-10-14 17:28:52 +00001358 } else {
1359 // Otherwise, quad registers are loaded with two separate instructions,
1360 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001361 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001362
Bob Wilson24f995d2009-10-14 18:32:29 +00001363 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001364 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001365 SDValue ImplDef =
1366 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1367 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1368 SDNode *VLdA =
1369 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1370 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001371
Bob Wilson24f995d2009-10-14 18:32:29 +00001372 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001373 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001374 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1375 Pred, Reg0, Chain };
1376 SDNode *VLdB =
1377 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1378 SuperReg = SDValue(VLdB, 0);
1379 Chain = SDValue(VLdB, 2);
1380 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001381
Bob Wilsonf5721912010-09-03 18:16:02 +00001382 // Extract out the Q registers.
1383 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1384 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1385 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1386 dl, VT, SuperReg);
1387 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001388 }
1389 ReplaceUses(SDValue(N, NumVecs), Chain);
1390 return NULL;
1391}
1392
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001393SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001394 unsigned *DOpcodes, unsigned *QOpcodes0,
1395 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001396 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001397 DebugLoc dl = N->getDebugLoc();
1398
Bob Wilson226036e2010-03-20 22:13:40 +00001399 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001400 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001401 return NULL;
1402
1403 SDValue Chain = N->getOperand(0);
1404 EVT VT = N->getOperand(3).getValueType();
1405 bool is64BitVector = VT.is64BitVector();
1406
Bob Wilson2a6e6162010-09-23 23:42:37 +00001407 unsigned Alignment = GetVLDSTAlign(N, NumVecs, is64BitVector);
1408 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1409
Bob Wilson24f995d2009-10-14 18:32:29 +00001410 unsigned OpcodeIndex;
1411 switch (VT.getSimpleVT().SimpleTy) {
1412 default: llvm_unreachable("unhandled vst type");
1413 // Double-register operations:
1414 case MVT::v8i8: OpcodeIndex = 0; break;
1415 case MVT::v4i16: OpcodeIndex = 1; break;
1416 case MVT::v2f32:
1417 case MVT::v2i32: OpcodeIndex = 2; break;
1418 case MVT::v1i64: OpcodeIndex = 3; break;
1419 // Quad-register operations:
1420 case MVT::v16i8: OpcodeIndex = 0; break;
1421 case MVT::v8i16: OpcodeIndex = 1; break;
1422 case MVT::v4f32:
1423 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001424 case MVT::v2i64: OpcodeIndex = 3;
1425 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1426 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001427 }
1428
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001429 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001430 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001431
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001432 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001433 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001434 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001435
1436 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001437 if (NumVecs == 1) {
1438 Ops.push_back(N->getOperand(3));
1439 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001440 SDValue RegSeq;
1441 SDValue V0 = N->getOperand(0+3);
1442 SDValue V1 = N->getOperand(1+3);
1443
1444 // Form a REG_SEQUENCE to force register allocation.
1445 if (NumVecs == 2)
1446 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1447 else {
1448 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001449 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001450 // an undef.
1451 SDValue V3 = (NumVecs == 3)
1452 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1453 : N->getOperand(3+3);
1454 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1455 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001456 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001457 }
Evan Chengac0869d2009-11-21 06:21:52 +00001458 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001459 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001460 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001461 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001462 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001463 }
1464
Bob Wilson11d98992010-03-23 06:20:33 +00001465 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001466 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001467 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001468 if (NumVecs == 1) {
1469 Ops.push_back(N->getOperand(3));
1470 } else {
1471 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001472 SDValue Q0 = N->getOperand(3);
1473 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001474 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001475 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001476 Ops.push_back(Pred);
1477 Ops.push_back(Reg0); // predicate register
1478 Ops.push_back(Chain);
1479 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001480 }
1481
1482 // Otherwise, quad registers are stored with two separate instructions,
1483 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001484
Bob Wilson07f6e802010-06-16 21:34:01 +00001485 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001486 SDValue V0 = N->getOperand(0+3);
1487 SDValue V1 = N->getOperand(1+3);
1488 SDValue V2 = N->getOperand(2+3);
1489 SDValue V3 = (NumVecs == 3)
1490 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1491 : N->getOperand(3+3);
1492 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001493
1494 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001495 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001496 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001497 Ops.push_back(Pred);
1498 Ops.push_back(Reg0); // predicate register
1499 Ops.push_back(Chain);
1500 unsigned Opc = QOpcodes0[OpcodeIndex];
1501 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001502 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001503 Chain = SDValue(VStA, 1);
1504
1505 // Store the odd D registers.
1506 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001507 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001508 Opc = QOpcodes1[OpcodeIndex];
1509 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001510 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001511 Chain = SDValue(VStB, 1);
1512 ReplaceUses(SDValue(N, 0), Chain);
1513 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001514}
1515
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001516SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001517 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001518 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001519 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001520 DebugLoc dl = N->getDebugLoc();
1521
Bob Wilson226036e2010-03-20 22:13:40 +00001522 SDValue MemAddr, Align;
Chris Lattner52a261b2010-09-21 20:31:19 +00001523 if (!SelectAddrMode6(N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001524 return NULL;
1525
1526 SDValue Chain = N->getOperand(0);
1527 unsigned Lane =
1528 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001529 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001530 bool is64BitVector = VT.is64BitVector();
1531
Bob Wilson3454ed92010-10-19 00:16:32 +00001532 if (NumVecs != 3) {
1533 unsigned Alignment = cast<MemIntrinsicSDNode>(N)->getAlignment();
1534 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1535 if (Alignment > NumBytes)
1536 Alignment = NumBytes;
1537 // Alignment must be a power of two; make sure of that.
1538 Alignment = (Alignment & -Alignment);
1539 if (Alignment > 1)
1540 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1541 }
1542
Bob Wilsona7c397c2009-10-14 16:19:03 +00001543 unsigned OpcodeIndex;
1544 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001545 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001546 // Double-register operations:
1547 case MVT::v8i8: OpcodeIndex = 0; break;
1548 case MVT::v4i16: OpcodeIndex = 1; break;
1549 case MVT::v2f32:
1550 case MVT::v2i32: OpcodeIndex = 2; break;
1551 // Quad-register operations:
1552 case MVT::v8i16: OpcodeIndex = 0; break;
1553 case MVT::v4f32:
1554 case MVT::v4i32: OpcodeIndex = 1; break;
1555 }
1556
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001557 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001558 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001559
Bob Wilson8466fa12010-09-13 23:01:35 +00001560 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001561 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001562 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001563
Jim Grosbach3ab56582010-10-21 19:38:40 +00001564 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001565 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001566
Bob Wilson8466fa12010-09-13 23:01:35 +00001567 SDValue SuperReg;
1568 SDValue V0 = N->getOperand(0+3);
1569 SDValue V1 = N->getOperand(1+3);
1570 if (NumVecs == 2) {
1571 if (is64BitVector)
1572 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1573 else
1574 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001575 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001576 SDValue V2 = N->getOperand(2+3);
1577 SDValue V3 = (NumVecs == 3)
1578 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1579 : N->getOperand(3+3);
1580 if (is64BitVector)
1581 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1582 else
1583 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001584 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001585 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001586 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001587 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001588 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001589 Ops.push_back(Chain);
1590
Bob Wilson96493442009-10-14 16:46:45 +00001591 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001592 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001593
Bob Wilson8466fa12010-09-13 23:01:35 +00001594 EVT ResTy;
1595 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1596 if (!is64BitVector)
1597 ResTyElts *= 2;
1598 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001599
Bob Wilson8466fa12010-09-13 23:01:35 +00001600 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1601 Ops.data(), 7);
1602 SuperReg = SDValue(VLdLn, 0);
1603 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001604
Bob Wilson8466fa12010-09-13 23:01:35 +00001605 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001606 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1607 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1608 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1609 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1610 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001611 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1612 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001613 return NULL;
1614}
1615
Bob Wilson78dfbc32010-07-07 00:08:54 +00001616SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1617 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001618 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1619 DebugLoc dl = N->getDebugLoc();
1620 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001621 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001622
1623 // Form a REG_SEQUENCE to force register allocation.
1624 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001625 SDValue V0 = N->getOperand(FirstTblReg + 0);
1626 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001627 if (NumVecs == 2)
1628 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1629 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001630 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001631 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001632 // an undef.
1633 SDValue V3 = (NumVecs == 3)
1634 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001635 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001636 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1637 }
1638
Bob Wilson78dfbc32010-07-07 00:08:54 +00001639 SmallVector<SDValue, 6> Ops;
1640 if (IsExt)
1641 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001642 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001643 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001644 Ops.push_back(getAL(CurDAG)); // predicate
1645 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001646 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001647}
1648
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001649SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001650 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001651 if (!Subtarget->hasV6T2Ops())
1652 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001653
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001654 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1655 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1656
1657
1658 // For unsigned extracts, check for a shift right and mask
1659 unsigned And_imm = 0;
1660 if (N->getOpcode() == ISD::AND) {
1661 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1662
1663 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1664 if (And_imm & (And_imm + 1))
1665 return NULL;
1666
1667 unsigned Srl_imm = 0;
1668 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1669 Srl_imm)) {
1670 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1671
1672 unsigned Width = CountTrailingOnes_32(And_imm);
1673 unsigned LSB = Srl_imm;
1674 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1675 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1676 CurDAG->getTargetConstant(LSB, MVT::i32),
1677 CurDAG->getTargetConstant(Width, MVT::i32),
1678 getAL(CurDAG), Reg0 };
1679 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1680 }
1681 }
1682 return NULL;
1683 }
1684
1685 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001686 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001688 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1689 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001690 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001691 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1692 unsigned Width = 32 - Srl_imm;
1693 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001694 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001695 return NULL;
1696 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001697 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001698 CurDAG->getTargetConstant(LSB, MVT::i32),
1699 CurDAG->getTargetConstant(Width, MVT::i32),
1700 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001702 }
1703 }
1704 return NULL;
1705}
1706
Evan Cheng9ef48352009-11-20 00:54:03 +00001707SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001708SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001709 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1710 SDValue CPTmp0;
1711 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001712 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001713 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1714 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1715 unsigned Opc = 0;
1716 switch (SOShOp) {
1717 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1718 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1719 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1720 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1721 default:
1722 llvm_unreachable("Unknown so_reg opcode!");
1723 break;
1724 }
1725 SDValue SOShImm =
1726 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1727 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1728 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001729 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001730 }
1731 return 0;
1732}
1733
1734SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001735SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001736 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1737 SDValue CPTmp0;
1738 SDValue CPTmp1;
1739 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001740 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001741 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1742 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001743 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001744 }
1745 return 0;
1746}
1747
1748SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001749SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001750 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1751 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1752 if (!T)
1753 return 0;
1754
Jim Grosbacha4257162010-10-07 00:53:56 +00001755 unsigned TrueImm = T->getZExtValue();
1756 bool isSoImm = Pred_t2_so_imm(TrueVal.getNode());
1757 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001758 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1759 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1760 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001761 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1762 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001763 }
1764 return 0;
1765}
1766
1767SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001768SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001769 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1770 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1771 if (!T)
1772 return 0;
1773
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001774 unsigned TrueImm = T->getZExtValue();
1775 bool isSoImm = Pred_so_imm(TrueVal.getNode());
1776 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1777 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001778 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1779 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001780 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1781 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001782 }
1783 return 0;
1784}
1785
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001786SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1787 EVT VT = N->getValueType(0);
1788 SDValue FalseVal = N->getOperand(0);
1789 SDValue TrueVal = N->getOperand(1);
1790 SDValue CC = N->getOperand(2);
1791 SDValue CCR = N->getOperand(3);
1792 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001793 assert(CC.getOpcode() == ISD::Constant);
1794 assert(CCR.getOpcode() == ISD::Register);
1795 ARMCC::CondCodes CCVal =
1796 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001797
1798 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1799 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1800 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1801 // Pattern complexity = 18 cost = 1 size = 0
1802 SDValue CPTmp0;
1803 SDValue CPTmp1;
1804 SDValue CPTmp2;
1805 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001806 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001807 CCVal, CCR, InFlag);
1808 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001809 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001810 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1811 if (Res)
1812 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001813 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001814 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001815 CCVal, CCR, InFlag);
1816 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001817 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001818 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1819 if (Res)
1820 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001821 }
1822
1823 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001824 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001825 // (imm:i32):$cc)
1826 // Emits: (MOVCCi:i32 GPR:i32:$false,
1827 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1828 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001829 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001830 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001831 CCVal, CCR, InFlag);
1832 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001833 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001834 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1835 if (Res)
1836 return Res;
1837 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001838 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001839 CCVal, CCR, InFlag);
1840 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001841 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001842 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1843 if (Res)
1844 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001845 }
1846 }
1847
1848 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1849 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1850 // Pattern complexity = 6 cost = 1 size = 0
1851 //
1852 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1853 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1854 // Pattern complexity = 6 cost = 11 size = 0
1855 //
1856 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001857 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1858 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001859 unsigned Opc = 0;
1860 switch (VT.getSimpleVT().SimpleTy) {
1861 default: assert(false && "Illegal conditional move type!");
1862 break;
1863 case MVT::i32:
1864 Opc = Subtarget->isThumb()
1865 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1866 : ARM::MOVCCr;
1867 break;
1868 case MVT::f32:
1869 Opc = ARM::VMOVScc;
1870 break;
1871 case MVT::f64:
1872 Opc = ARM::VMOVDcc;
1873 break;
1874 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001875 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001876}
1877
Evan Chengde8aa4e2010-05-05 18:28:36 +00001878SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1879 // The only time a CONCAT_VECTORS operation can have legal types is when
1880 // two 64-bit vectors are concatenated to a 128-bit vector.
1881 EVT VT = N->getValueType(0);
1882 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1883 llvm_unreachable("unexpected CONCAT_VECTORS");
1884 DebugLoc dl = N->getDebugLoc();
1885 SDValue V0 = N->getOperand(0);
1886 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001887 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1888 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001889 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1890 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1891}
1892
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001893SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001894 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001895
Dan Gohmane8be6c62008-07-17 19:10:17 +00001896 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001897 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001898
1899 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001900 default: break;
1901 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001902 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001903 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001904 if (Subtarget->hasThumb2())
1905 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1906 // be done with MOV + MOVT, at worst.
1907 UseCP = 0;
1908 else {
1909 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001910 UseCP = (Val > 255 && // MOV
1911 ~Val > 255 && // MOV + MVN
1912 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001913 } else
1914 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1915 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1916 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1917 }
1918
Evan Chenga8e29892007-01-19 07:51:42 +00001919 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001920 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001921 CurDAG->getTargetConstantPool(ConstantInt::get(
1922 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001923 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001924
1925 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001926 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001927 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001928 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001929 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001930 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1931 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001932 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001933 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001934 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001935 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001936 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001937 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001938 CurDAG->getEntryNode()
1939 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001940 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00001941 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00001942 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001943 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001944 return NULL;
1945 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001946
Evan Chenga8e29892007-01-19 07:51:42 +00001947 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001948 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001949 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001950 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001951 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001952 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001953 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001954 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001955 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1956 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001957 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001958 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1959 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001960 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1961 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1962 CurDAG->getRegister(0, MVT::i32) };
1963 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001964 }
Evan Chenga8e29892007-01-19 07:51:42 +00001965 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001966 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001967 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001968 return I;
1969 break;
1970 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001971 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001972 return I;
1973 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001974 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001975 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001976 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001977 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001978 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001979 if (!RHSV) break;
1980 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001981 unsigned ShImm = Log2_32(RHSV-1);
1982 if (ShImm >= 32)
1983 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001984 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001985 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00001986 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
1987 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00001988 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00001989 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001990 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001991 } else {
1992 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00001993 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001994 }
Evan Chenga8e29892007-01-19 07:51:42 +00001995 }
1996 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001997 unsigned ShImm = Log2_32(RHSV+1);
1998 if (ShImm >= 32)
1999 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002000 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002001 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002002 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2003 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002004 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002005 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2006 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002007 } else {
2008 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002009 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002010 }
Evan Chenga8e29892007-01-19 07:51:42 +00002011 }
2012 }
2013 break;
Evan Cheng20956592009-10-21 08:15:52 +00002014 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002015 // Check for unsigned bitfield extract
2016 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2017 return I;
2018
Evan Cheng20956592009-10-21 08:15:52 +00002019 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2020 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2021 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2022 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2023 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002025 if (VT != MVT::i32)
2026 break;
2027 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2028 ? ARM::t2MOVTi16
2029 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2030 if (!Opc)
2031 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002033 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2034 if (!N1C)
2035 break;
2036 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2037 SDValue N2 = N0.getOperand(1);
2038 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2039 if (!N2C)
2040 break;
2041 unsigned N1CVal = N1C->getZExtValue();
2042 unsigned N2CVal = N2C->getZExtValue();
2043 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2044 (N1CVal & 0xffffU) == 0xffffU &&
2045 (N2CVal & 0xffffU) == 0x0U) {
2046 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2047 MVT::i32);
2048 SDValue Ops[] = { N0.getOperand(0), Imm16,
2049 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2050 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2051 }
2052 }
2053 break;
2054 }
Jim Grosbache5165492009-11-09 00:11:35 +00002055 case ARMISD::VMOVRRD:
2056 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002057 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002058 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002059 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002060 if (Subtarget->isThumb1Only())
2061 break;
2062 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002063 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002064 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2065 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002066 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002067 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002068 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002069 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2070 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002071 return CurDAG->getMachineNode(ARM::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002072 }
Evan Chengee568cf2007-07-05 07:15:27 +00002073 }
Dan Gohman525178c2007-10-08 18:33:35 +00002074 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002075 if (Subtarget->isThumb1Only())
2076 break;
2077 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002078 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002079 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002080 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002081 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002082 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002083 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2084 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002085 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002086 }
Evan Chengee568cf2007-07-05 07:15:27 +00002087 }
Evan Chenga8e29892007-01-19 07:51:42 +00002088 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002089 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002090 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002091 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002092 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002093 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002094 if (ResNode)
2095 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002096 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002097 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002098 }
Evan Chengee568cf2007-07-05 07:15:27 +00002099 case ARMISD::BRCOND: {
2100 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2101 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2102 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002103
Evan Chengee568cf2007-07-05 07:15:27 +00002104 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2105 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2106 // Pattern complexity = 6 cost = 1 size = 0
2107
David Goodwin5e47a9a2009-06-30 18:04:13 +00002108 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2109 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2110 // Pattern complexity = 6 cost = 1 size = 0
2111
Jim Grosbach764ab522009-08-11 15:33:49 +00002112 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002113 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 SDValue Chain = N->getOperand(0);
2115 SDValue N1 = N->getOperand(1);
2116 SDValue N2 = N->getOperand(2);
2117 SDValue N3 = N->getOperand(3);
2118 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002119 assert(N1.getOpcode() == ISD::BasicBlock);
2120 assert(N2.getOpcode() == ISD::Constant);
2121 assert(N3.getOpcode() == ISD::Register);
2122
Dan Gohman475871a2008-07-27 21:46:04 +00002123 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002124 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002125 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002126 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002127 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2128 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002129 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002131 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002132 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002133 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002134 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002135 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002136 return NULL;
2137 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002138 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002139 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002140 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002141 EVT VT = N->getValueType(0);
2142 SDValue N0 = N->getOperand(0);
2143 SDValue N1 = N->getOperand(1);
2144 SDValue N2 = N->getOperand(2);
2145 SDValue N3 = N->getOperand(3);
2146 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002147 assert(N2.getOpcode() == ISD::Constant);
2148 assert(N3.getOpcode() == ISD::Register);
2149
Dan Gohman475871a2008-07-27 21:46:04 +00002150 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002151 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002152 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002153 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002154 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002155 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002156 default: assert(false && "Illegal conditional move type!");
2157 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002158 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002159 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002160 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002161 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002162 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002163 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002164 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002165 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002166 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002167
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002168 case ARMISD::VZIP: {
2169 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002170 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002171 switch (VT.getSimpleVT().SimpleTy) {
2172 default: return NULL;
2173 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2174 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2175 case MVT::v2f32:
2176 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2177 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2178 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2179 case MVT::v4f32:
2180 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2181 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002182 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002183 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2184 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2185 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002186 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002187 case ARMISD::VUZP: {
2188 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002189 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002190 switch (VT.getSimpleVT().SimpleTy) {
2191 default: return NULL;
2192 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2193 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2194 case MVT::v2f32:
2195 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2196 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2197 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2198 case MVT::v4f32:
2199 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2200 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002201 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002202 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2203 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2204 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002205 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002206 case ARMISD::VTRN: {
2207 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002208 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002209 switch (VT.getSimpleVT().SimpleTy) {
2210 default: return NULL;
2211 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2212 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2213 case MVT::v2f32:
2214 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2215 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2216 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2217 case MVT::v4f32:
2218 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2219 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002220 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002221 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2222 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2223 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002224 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002225 case ARMISD::BUILD_VECTOR: {
2226 EVT VecVT = N->getValueType(0);
2227 EVT EltVT = VecVT.getVectorElementType();
2228 unsigned NumElts = VecVT.getVectorNumElements();
2229 if (EltVT.getSimpleVT() == MVT::f64) {
2230 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2231 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2232 }
2233 assert(EltVT.getSimpleVT() == MVT::f32 &&
2234 "unexpected type for BUILD_VECTOR");
2235 if (NumElts == 2)
2236 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2237 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2238 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2239 N->getOperand(2), N->getOperand(3));
2240 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002241
2242 case ISD::INTRINSIC_VOID:
2243 case ISD::INTRINSIC_W_CHAIN: {
2244 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002245 switch (IntNo) {
2246 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002247 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002248
Bob Wilson621f1952010-03-23 05:25:43 +00002249 case Intrinsic::arm_neon_vld1: {
2250 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2251 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002252 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2253 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002254 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2255 }
2256
Bob Wilson31fb12f2009-08-26 17:39:53 +00002257 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002258 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2259 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2260 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2261 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002262 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002263 }
2264
2265 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002266 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2267 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2268 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2269 ARM::VLD3q16Pseudo_UPD,
2270 ARM::VLD3q32Pseudo_UPD };
2271 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2272 ARM::VLD3q16oddPseudo_UPD,
2273 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002274 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002275 }
2276
2277 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002278 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2279 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2280 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2281 ARM::VLD4q16Pseudo_UPD,
2282 ARM::VLD4q32Pseudo_UPD };
2283 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2284 ARM::VLD4q16oddPseudo_UPD,
2285 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002286 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002287 }
2288
Bob Wilson243fcc52009-09-01 04:26:28 +00002289 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002290 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2291 ARM::VLD2LNd32Pseudo };
2292 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2293 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002294 }
2295
2296 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002297 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2298 ARM::VLD3LNd32Pseudo };
2299 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2300 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002301 }
2302
2303 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002304 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2305 ARM::VLD4LNd32Pseudo };
2306 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2307 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002308 }
2309
Bob Wilson11d98992010-03-23 06:20:33 +00002310 case Intrinsic::arm_neon_vst1: {
2311 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2312 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002313 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2314 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002315 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2316 }
2317
Bob Wilson31fb12f2009-08-26 17:39:53 +00002318 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002319 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2320 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2321 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2322 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002323 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002324 }
2325
2326 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002327 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2328 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2329 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2330 ARM::VST3q16Pseudo_UPD,
2331 ARM::VST3q32Pseudo_UPD };
2332 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2333 ARM::VST3q16oddPseudo_UPD,
2334 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002335 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002336 }
2337
2338 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002339 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002340 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002341 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2342 ARM::VST4q16Pseudo_UPD,
2343 ARM::VST4q32Pseudo_UPD };
2344 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2345 ARM::VST4q16oddPseudo_UPD,
2346 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002347 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002348 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002349
2350 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002351 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2352 ARM::VST2LNd32Pseudo };
2353 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2354 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002355 }
2356
2357 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002358 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2359 ARM::VST3LNd32Pseudo };
2360 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2361 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002362 }
2363
2364 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002365 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2366 ARM::VST4LNd32Pseudo };
2367 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2368 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002369 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002370 }
Bob Wilson429009b2010-05-06 16:05:26 +00002371 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002372 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002373
Bob Wilsond491d6e2010-07-06 23:36:25 +00002374 case ISD::INTRINSIC_WO_CHAIN: {
2375 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2376 switch (IntNo) {
2377 default:
2378 break;
2379
2380 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002381 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002382 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002383 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002384 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002385 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002386
2387 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002388 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002389 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002390 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002391 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002392 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002393 }
2394 break;
2395 }
2396
Bob Wilson429009b2010-05-06 16:05:26 +00002397 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002398 return SelectConcatVector(N);
2399 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002400
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002401 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002402}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002403
Bob Wilson224c2442009-05-19 05:53:42 +00002404bool ARMDAGToDAGISel::
2405SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2406 std::vector<SDValue> &OutOps) {
2407 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002408 // Require the address to be in a register. That is safe for all ARM
2409 // variants and it is hard to do anything much smarter without knowing
2410 // how the operand is used.
2411 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002412 return false;
2413}
2414
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002415/// createARMISelDag - This pass converts a legalized DAG into a
2416/// ARM-specific DAG, ready for instruction scheduling.
2417///
Bob Wilson522ce972009-09-28 14:30:20 +00002418FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2419 CodeGenOpt::Level OptLevel) {
2420 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002421}