blob: ee3ffef0e5ff47850447e8ba23df801d7c30715f [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000016#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000018#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Function.h"
22#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000023#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
25#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
27#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000029#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000030#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
36
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000037using namespace llvm;
38
Evan Chenga2c519b2010-07-30 23:33:54 +000039static cl::opt<bool>
40DisableShifterOp("disable-shifter-op", cl::Hidden,
41 cl::desc("Disable isel of shifter-op"),
42 cl::init(false));
43
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000044//===--------------------------------------------------------------------===//
45/// ARMDAGToDAGISel - ARM specific code to select ARM machine
46/// instructions for SelectionDAG operations.
47///
48namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000049
50enum AddrMode2Type {
51 AM2_BASE, // Simple AM2 (+-imm12)
52 AM2_SHOP // Shifter-op AM2
53};
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000056 ARMBaseTargetMachine &TM;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000057
Evan Chenga8e29892007-01-19 07:51:42 +000058 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
59 /// make the right decision when generating code for different targets.
60 const ARMSubtarget *Subtarget;
61
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000062public:
Bob Wilson522ce972009-09-28 14:30:20 +000063 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
64 CodeGenOpt::Level OptLevel)
65 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Chenga8e29892007-01-19 07:51:42 +000066 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000067 }
68
Evan Chenga8e29892007-01-19 07:51:42 +000069 virtual const char *getPassName() const {
70 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000071 }
72
Bob Wilsonaf4a8912009-10-08 18:51:31 +000073 /// getI32Imm - Return a target constant of type i32 with the specified
74 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000075 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000076 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000077 }
78
Dan Gohmaneeb3a002010-01-05 01:24:18 +000079 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000080
Evan Chengf40deed2010-10-27 23:41:30 +000081 bool isShifterOpProfitable(const SDValue &Shift,
82 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000083 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000084 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000085 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
86 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000087 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
88 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
89
Jim Grosbach82891622010-09-29 19:03:54 +000090 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
91 SDValue &Offset, SDValue &Opc);
92 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
93 SDValue &Opc) {
94 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
95 }
96
97 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
98 SDValue &Opc) {
99 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
100 }
101
102 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000105// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000106 // This always matches one way or another.
107 return true;
108 }
109
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000110 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000111 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000112 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000113 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000114 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000115 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000116 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000117 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000118 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000119
Chris Lattner52a261b2010-09-21 20:31:19 +0000120 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000121 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000122
Chris Lattner52a261b2010-09-21 20:31:19 +0000123 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
124 bool SelectThumbAddrModeRI5(SDValue N, unsigned Scale,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &Base, SDValue &OffImm,
126 SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000127 bool SelectThumbAddrModeS1(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000128 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000129 bool SelectThumbAddrModeS2(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000130 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000131 bool SelectThumbAddrModeS4(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000132 SDValue &OffImm, SDValue &Offset);
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000134
Chris Lattner52a261b2010-09-21 20:31:19 +0000135 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000136 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000137 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
138 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000139 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000141 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000142 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000143 SDValue &OffReg, SDValue &ShImm);
144
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000145 inline bool Pred_so_imm(SDNode *inN) const {
146 ConstantSDNode *N = cast<ConstantSDNode>(inN);
147 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
148 }
149
150 inline bool Pred_t2_so_imm(SDNode *inN) const {
151 ConstantSDNode *N = cast<ConstantSDNode>(inN);
152 return ARM_AM::getT2SOImmVal(N->getZExtValue()) != -1;
153 }
154
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000155 // Include the pieces autogenerated from the target description.
156#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000157
158private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000159 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
160 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 SDNode *SelectARMIndexedLoad(SDNode *N);
162 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000163
Bob Wilson621f1952010-03-23 05:25:43 +0000164 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
165 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000166 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000167 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000168 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000169 unsigned *QOpcodes0, unsigned *QOpcodes1);
170
Bob Wilson24f995d2009-10-14 18:32:29 +0000171 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000172 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000173 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000174 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000175 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000176 unsigned *QOpcodes0, unsigned *QOpcodes1);
177
Bob Wilson96493442009-10-14 16:46:45 +0000178 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000179 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000180 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000181 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000182 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000183
Bob Wilson78dfbc32010-07-07 00:08:54 +0000184 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
185 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
186 /// generated to force the table registers to be consecutive.
187 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000188
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000189 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000190 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000191
Evan Cheng07ba9062009-11-19 21:45:22 +0000192 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000193 SDNode *SelectCMOVOp(SDNode *N);
194 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000195 ARMCC::CondCodes CCVal, SDValue CCR,
196 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000197 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000198 ARMCC::CondCodes CCVal, SDValue CCR,
199 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000200 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000201 ARMCC::CondCodes CCVal, SDValue CCR,
202 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000203 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000204 ARMCC::CondCodes CCVal, SDValue CCR,
205 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000206
Evan Chengde8aa4e2010-05-05 18:28:36 +0000207 SDNode *SelectConcatVector(SDNode *N);
208
Evan Chengaf4550f2009-07-02 01:23:32 +0000209 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
210 /// inline asm expressions.
211 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
212 char ConstraintCode,
213 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000214
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000215 // Form pairs of consecutive S, D, or Q registers.
216 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000217 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000218 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
219
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000220 // Form sequences of 4 consecutive S, D, or Q registers.
221 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000222 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000223 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000224
225 // Get the alignment operand for a NEON VLD or VST instruction.
226 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000227};
Evan Chenga8e29892007-01-19 07:51:42 +0000228}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000229
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000230/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
231/// operand. If so Imm will receive the 32-bit value.
232static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
233 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
234 Imm = cast<ConstantSDNode>(N)->getZExtValue();
235 return true;
236 }
237 return false;
238}
239
240// isInt32Immediate - This method tests to see if a constant operand.
241// If so Imm will receive the 32 bit value.
242static bool isInt32Immediate(SDValue N, unsigned &Imm) {
243 return isInt32Immediate(N.getNode(), Imm);
244}
245
246// isOpcWithIntImmediate - This method tests to see if the node is a specific
247// opcode and that it has a immediate integer right operand.
248// If so Imm will receive the 32 bit value.
249static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
250 return N->getOpcode() == Opc &&
251 isInt32Immediate(N->getOperand(1).getNode(), Imm);
252}
253
254
Evan Chengf40deed2010-10-27 23:41:30 +0000255bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
256 ARM_AM::ShiftOpc ShOpcVal,
257 unsigned ShAmt) {
258 if (!Subtarget->isCortexA9())
259 return true;
260 if (Shift.hasOneUse())
261 return true;
262 // R << 2 is free.
263 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
264}
265
Chris Lattner52a261b2010-09-21 20:31:19 +0000266bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000267 SDValue &BaseReg,
268 SDValue &ShReg,
269 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000270 if (DisableShifterOp)
271 return false;
272
Evan Cheng055b0312009-06-29 07:51:04 +0000273 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
274
275 // Don't match base register only case. That is matched to a separate
276 // lower complexity pattern with explicit register operand.
277 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000278
Evan Cheng055b0312009-06-29 07:51:04 +0000279 BaseReg = N.getOperand(0);
280 unsigned ShImmVal = 0;
281 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000282 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000283 ShImmVal = RHS->getZExtValue() & 31;
284 } else {
285 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000286 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
287 return false;
288 }
289 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
290 MVT::i32);
291 return true;
292}
293
294bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
295 SDValue &BaseReg,
296 SDValue &ShReg,
297 SDValue &Opc) {
298 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
299
300 // Don't match base register only case. That is matched to a separate
301 // lower complexity pattern with explicit register operand.
302 if (ShOpcVal == ARM_AM::no_shift) return false;
303
304 BaseReg = N.getOperand(0);
305 unsigned ShImmVal = 0;
306 // Do not check isShifterOpProfitable. This must return true.
307 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
308 ShReg = CurDAG->getRegister(0, MVT::i32);
309 ShImmVal = RHS->getZExtValue() & 31;
310 } else {
311 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000312 }
313 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000314 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000315 return true;
316}
317
Jim Grosbach3e556122010-10-26 22:37:02 +0000318bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
319 SDValue &Base,
320 SDValue &OffImm) {
321 // Match simple R + imm12 operands.
322
323 // Base only.
324 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
325 if (N.getOpcode() == ISD::FrameIndex) {
326 // Match frame index...
327 int FI = cast<FrameIndexSDNode>(N)->getIndex();
328 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
329 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
330 return true;
331 } else if (N.getOpcode() == ARMISD::Wrapper &&
332 !(Subtarget->useMovt() &&
333 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
334 Base = N.getOperand(0);
335 } else
336 Base = N;
337 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
338 return true;
339 }
340
341 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
342 int RHSC = (int)RHS->getZExtValue();
343 if (N.getOpcode() == ISD::SUB)
344 RHSC = -RHSC;
345
346 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
347 Base = N.getOperand(0);
348 if (Base.getOpcode() == ISD::FrameIndex) {
349 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
350 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
351 }
352 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
353 return true;
354 }
355 }
356
357 // Base only.
358 Base = N;
359 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
360 return true;
361}
362
363
364
365bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
366 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000367 if (N.getOpcode() == ISD::MUL &&
368 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000369 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
370 // X * [3,5,9] -> X + X * [2,4,8] etc.
371 int RHSC = (int)RHS->getZExtValue();
372 if (RHSC & 1) {
373 RHSC = RHSC & ~1;
374 ARM_AM::AddrOpc AddSub = ARM_AM::add;
375 if (RHSC < 0) {
376 AddSub = ARM_AM::sub;
377 RHSC = - RHSC;
378 }
379 if (isPowerOf2_32(RHSC)) {
380 unsigned ShAmt = Log2_32(RHSC);
381 Base = Offset = N.getOperand(0);
382 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
383 ARM_AM::lsl),
384 MVT::i32);
385 return true;
386 }
387 }
388 }
389 }
390
391 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
392 return false;
393
394 // Leave simple R +/- imm12 operands for LDRi12
395 if (N.getOpcode() == ISD::ADD) {
396 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
397 int RHSC = (int)RHS->getZExtValue();
398 if ((RHSC >= 0 && RHSC < 0x1000) ||
399 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
400 return false;
401 }
402 }
403
Evan Chengf40deed2010-10-27 23:41:30 +0000404 if (Subtarget->isCortexA9() && !N.hasOneUse())
405 // Compute R +/- (R << N) and reuse it.
406 return false;
407
Jim Grosbach3e556122010-10-26 22:37:02 +0000408 // Otherwise this is R +/- [possibly shifted] R.
409 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
410 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
411 unsigned ShAmt = 0;
412
413 Base = N.getOperand(0);
414 Offset = N.getOperand(1);
415
416 if (ShOpcVal != ARM_AM::no_shift) {
417 // Check to see if the RHS of the shift is a constant, if not, we can't fold
418 // it.
419 if (ConstantSDNode *Sh =
420 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
421 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000422 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
423 Offset = N.getOperand(1).getOperand(0);
424 else {
425 ShAmt = 0;
426 ShOpcVal = ARM_AM::no_shift;
427 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000428 } else {
429 ShOpcVal = ARM_AM::no_shift;
430 }
431 }
432
433 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000434 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
435 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000436 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
437 if (ShOpcVal != ARM_AM::no_shift) {
438 // Check to see if the RHS of the shift is a constant, if not, we can't
439 // fold it.
440 if (ConstantSDNode *Sh =
441 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
442 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000443 if (!Subtarget->isCortexA9() ||
444 (N.hasOneUse() &&
445 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
446 Offset = N.getOperand(0).getOperand(0);
447 Base = N.getOperand(1);
448 } else {
449 ShAmt = 0;
450 ShOpcVal = ARM_AM::no_shift;
451 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000452 } else {
453 ShOpcVal = ARM_AM::no_shift;
454 }
455 }
456 }
457
458 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
459 MVT::i32);
460 return true;
461}
462
463
464
465
466//-----
467
Jim Grosbach82891622010-09-29 19:03:54 +0000468AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
469 SDValue &Base,
470 SDValue &Offset,
471 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000472 if (N.getOpcode() == ISD::MUL &&
473 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000474 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
475 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000476 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000477 if (RHSC & 1) {
478 RHSC = RHSC & ~1;
479 ARM_AM::AddrOpc AddSub = ARM_AM::add;
480 if (RHSC < 0) {
481 AddSub = ARM_AM::sub;
482 RHSC = - RHSC;
483 }
484 if (isPowerOf2_32(RHSC)) {
485 unsigned ShAmt = Log2_32(RHSC);
486 Base = Offset = N.getOperand(0);
487 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
488 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000489 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000490 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000491 }
492 }
493 }
494 }
495
Evan Chenga8e29892007-01-19 07:51:42 +0000496 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
497 Base = N;
498 if (N.getOpcode() == ISD::FrameIndex) {
499 int FI = cast<FrameIndexSDNode>(N)->getIndex();
500 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000501 } else if (N.getOpcode() == ARMISD::Wrapper &&
502 !(Subtarget->useMovt() &&
503 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000504 Base = N.getOperand(0);
505 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000506 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000507 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
508 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000509 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000510 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000511 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000512
Evan Chenga8e29892007-01-19 07:51:42 +0000513 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000514 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000515 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000516 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000517 if ((RHSC >= 0 && RHSC < 0x1000) ||
518 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000519 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000520 if (Base.getOpcode() == ISD::FrameIndex) {
521 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
522 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
523 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000524 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000525
526 ARM_AM::AddrOpc AddSub = ARM_AM::add;
527 if (RHSC < 0) {
528 AddSub = ARM_AM::sub;
529 RHSC = - RHSC;
530 }
531 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000532 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000533 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000534 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000535 }
Evan Chenga8e29892007-01-19 07:51:42 +0000536 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000537 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000538
Evan Chengf40deed2010-10-27 23:41:30 +0000539 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
540 // Compute R +/- (R << N) and reuse it.
541 Base = N;
542 Offset = CurDAG->getRegister(0, MVT::i32);
543 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
544 ARM_AM::no_shift),
545 MVT::i32);
546 return AM2_BASE;
547 }
548
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000549 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000550 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
551 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
552 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000553
Evan Chenga8e29892007-01-19 07:51:42 +0000554 Base = N.getOperand(0);
555 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000556
Evan Chenga8e29892007-01-19 07:51:42 +0000557 if (ShOpcVal != ARM_AM::no_shift) {
558 // Check to see if the RHS of the shift is a constant, if not, we can't fold
559 // it.
560 if (ConstantSDNode *Sh =
561 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000562 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000563 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
564 Offset = N.getOperand(1).getOperand(0);
565 else {
566 ShAmt = 0;
567 ShOpcVal = ARM_AM::no_shift;
568 }
Evan Chenga8e29892007-01-19 07:51:42 +0000569 } else {
570 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000571 }
572 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000573
Evan Chenga8e29892007-01-19 07:51:42 +0000574 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000575 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
576 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000577 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
578 if (ShOpcVal != ARM_AM::no_shift) {
579 // Check to see if the RHS of the shift is a constant, if not, we can't
580 // fold it.
581 if (ConstantSDNode *Sh =
582 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000583 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000584 if (!Subtarget->isCortexA9() ||
585 (N.hasOneUse() &&
586 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
587 Offset = N.getOperand(0).getOperand(0);
588 Base = N.getOperand(1);
589 } else {
590 ShAmt = 0;
591 ShOpcVal = ARM_AM::no_shift;
592 }
Evan Chenga8e29892007-01-19 07:51:42 +0000593 } else {
594 ShOpcVal = ARM_AM::no_shift;
595 }
596 }
597 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000598
Evan Chenga8e29892007-01-19 07:51:42 +0000599 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000600 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000601 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000602}
603
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000604bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000605 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000606 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000607 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
608 ? cast<LoadSDNode>(Op)->getAddressingMode()
609 : cast<StoreSDNode>(Op)->getAddressingMode();
610 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
611 ? ARM_AM::add : ARM_AM::sub;
612 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000613 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000614 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000615 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000616 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
617 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000618 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000619 return true;
620 }
621 }
622
623 Offset = N;
624 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
625 unsigned ShAmt = 0;
626 if (ShOpcVal != ARM_AM::no_shift) {
627 // Check to see if the RHS of the shift is a constant, if not, we can't fold
628 // it.
629 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000630 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000631 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
632 Offset = N.getOperand(0);
633 else {
634 ShAmt = 0;
635 ShOpcVal = ARM_AM::no_shift;
636 }
Evan Chenga8e29892007-01-19 07:51:42 +0000637 } else {
638 ShOpcVal = ARM_AM::no_shift;
639 }
640 }
641
642 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000643 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000644 return true;
645}
646
Evan Chenga8e29892007-01-19 07:51:42 +0000647
Chris Lattner52a261b2010-09-21 20:31:19 +0000648bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000649 SDValue &Base, SDValue &Offset,
650 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000651 if (N.getOpcode() == ISD::SUB) {
652 // X - C is canonicalize to X + -C, no need to handle it here.
653 Base = N.getOperand(0);
654 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000655 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000656 return true;
657 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000658
Evan Chenga8e29892007-01-19 07:51:42 +0000659 if (N.getOpcode() != ISD::ADD) {
660 Base = N;
661 if (N.getOpcode() == ISD::FrameIndex) {
662 int FI = cast<FrameIndexSDNode>(N)->getIndex();
663 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
664 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000665 Offset = CurDAG->getRegister(0, MVT::i32);
666 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000667 return true;
668 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 // If the RHS is +/- imm8, fold into addr mode.
671 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000672 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000673 if ((RHSC >= 0 && RHSC < 256) ||
674 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000675 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000676 if (Base.getOpcode() == ISD::FrameIndex) {
677 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
678 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
679 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000680 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000681
682 ARM_AM::AddrOpc AddSub = ARM_AM::add;
683 if (RHSC < 0) {
684 AddSub = ARM_AM::sub;
685 RHSC = - RHSC;
686 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000687 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000688 return true;
689 }
690 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000691
Evan Chenga8e29892007-01-19 07:51:42 +0000692 Base = N.getOperand(0);
693 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000694 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000695 return true;
696}
697
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000698bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000699 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000700 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000701 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
702 ? cast<LoadSDNode>(Op)->getAddressingMode()
703 : cast<StoreSDNode>(Op)->getAddressingMode();
704 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
705 ? ARM_AM::add : ARM_AM::sub;
706 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000707 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000708 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000709 Offset = CurDAG->getRegister(0, MVT::i32);
710 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000711 return true;
712 }
713 }
714
715 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000716 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000717 return true;
718}
719
Jim Grosbach3ab56582010-10-21 19:38:40 +0000720bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000721 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000722 if (N.getOpcode() != ISD::ADD) {
723 Base = N;
724 if (N.getOpcode() == ISD::FrameIndex) {
725 int FI = cast<FrameIndexSDNode>(N)->getIndex();
726 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000727 } else if (N.getOpcode() == ARMISD::Wrapper &&
728 !(Subtarget->useMovt() &&
729 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000730 Base = N.getOperand(0);
731 }
732 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000733 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000734 return true;
735 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000736
Evan Chenga8e29892007-01-19 07:51:42 +0000737 // If the RHS is +/- imm8, fold into addr mode.
738 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000739 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000740 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
741 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000742 if ((RHSC >= 0 && RHSC < 256) ||
743 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000744 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000745 if (Base.getOpcode() == ISD::FrameIndex) {
746 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
747 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
748 }
749
750 ARM_AM::AddrOpc AddSub = ARM_AM::add;
751 if (RHSC < 0) {
752 AddSub = ARM_AM::sub;
753 RHSC = - RHSC;
754 }
755 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000757 return true;
758 }
759 }
760 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000761
Evan Chenga8e29892007-01-19 07:51:42 +0000762 Base = N;
763 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000764 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000765 return true;
766}
767
Bob Wilson665814b2010-11-01 23:40:51 +0000768bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
769 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000770 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000771
772 unsigned Alignment = 0;
773 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
774 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
775 // The maximum alignment is equal to the memory size being referenced.
776 unsigned LSNAlign = LSN->getAlignment();
777 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
778 if (LSNAlign > MemSize && MemSize > 1)
779 Alignment = MemSize;
780 } else {
781 // All other uses of addrmode6 are for intrinsics. For now just record
782 // the raw alignment value; it will be refined later based on the legal
783 // alignment operands for the intrinsic.
784 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
785 }
786
787 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000788 return true;
789}
790
Chris Lattner52a261b2010-09-21 20:31:19 +0000791bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000792 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000793 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
794 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000795 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000796 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000797 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000798 return true;
799 }
800 return false;
801}
802
Chris Lattner52a261b2010-09-21 20:31:19 +0000803bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000804 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000805 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000806 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000807 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000808 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000809 return false;
810
811 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000812 return true;
813 }
814
Evan Chenga8e29892007-01-19 07:51:42 +0000815 Base = N.getOperand(0);
816 Offset = N.getOperand(1);
817 return true;
818}
819
Evan Cheng79d43262007-01-24 02:21:22 +0000820bool
Chris Lattner52a261b2010-09-21 20:31:19 +0000821ARMDAGToDAGISel::SelectThumbAddrModeRI5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000822 unsigned Scale, SDValue &Base,
823 SDValue &OffImm, SDValue &Offset) {
Evan Cheng79d43262007-01-24 02:21:22 +0000824 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000825 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000826 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000827 return false; // We want to select tLDRspi / tSTRspi instead.
Evan Cheng012f2d92007-01-24 08:53:17 +0000828 if (N.getOpcode() == ARMISD::Wrapper &&
829 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
830 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000831 }
832
Evan Chenga8e29892007-01-19 07:51:42 +0000833 if (N.getOpcode() != ISD::ADD) {
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000834 if (N.getOpcode() == ARMISD::Wrapper &&
835 !(Subtarget->useMovt() &&
836 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
837 Base = N.getOperand(0);
838 } else
839 Base = N;
840
Owen Anderson825b72b2009-08-11 20:47:22 +0000841 Offset = CurDAG->getRegister(0, MVT::i32);
842 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000843 return true;
844 }
845
Evan Chengad0e4652007-02-06 00:22:06 +0000846 // Thumb does not have [sp, r] address mode.
847 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
848 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
849 if ((LHSR && LHSR->getReg() == ARM::SP) ||
850 (RHSR && RHSR->getReg() == ARM::SP)) {
851 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000852 Offset = CurDAG->getRegister(0, MVT::i32);
853 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000854 return true;
855 }
856
Evan Chenga8e29892007-01-19 07:51:42 +0000857 // If the RHS is + imm5 * scale, fold into addr mode.
858 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000859 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000860 if ((RHSC & (Scale-1)) == 0) { // The constant is implicitly multiplied.
861 RHSC /= Scale;
862 if (RHSC >= 0 && RHSC < 32) {
863 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +0000864 Offset = CurDAG->getRegister(0, MVT::i32);
865 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000866 return true;
867 }
868 }
869 }
870
Evan Chengc38f2bc2007-01-23 22:59:13 +0000871 Base = N.getOperand(0);
872 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000873 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +0000874 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000875}
876
Chris Lattner52a261b2010-09-21 20:31:19 +0000877bool ARMDAGToDAGISel::SelectThumbAddrModeS1(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, 1, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000881}
882
Chris Lattner52a261b2010-09-21 20:31:19 +0000883bool ARMDAGToDAGISel::SelectThumbAddrModeS2(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000884 SDValue &Base, SDValue &OffImm,
885 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000886 return SelectThumbAddrModeRI5(N, 2, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000887}
888
Chris Lattner52a261b2010-09-21 20:31:19 +0000889bool ARMDAGToDAGISel::SelectThumbAddrModeS4(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000890 SDValue &Base, SDValue &OffImm,
891 SDValue &Offset) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000892 return SelectThumbAddrModeRI5(N, 4, Base, OffImm, Offset);
Evan Chenga8e29892007-01-19 07:51:42 +0000893}
894
Chris Lattner52a261b2010-09-21 20:31:19 +0000895bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
896 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +0000897 if (N.getOpcode() == ISD::FrameIndex) {
898 int FI = cast<FrameIndexSDNode>(N)->getIndex();
899 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000900 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000901 return true;
902 }
Evan Cheng79d43262007-01-24 02:21:22 +0000903
Evan Chengad0e4652007-02-06 00:22:06 +0000904 if (N.getOpcode() != ISD::ADD)
905 return false;
906
907 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000908 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
909 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +0000910 // If the RHS is + imm8 * scale, fold into addr mode.
911 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000912 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +0000913 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
914 RHSC >>= 2;
915 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +0000916 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +0000917 if (Base.getOpcode() == ISD::FrameIndex) {
918 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
919 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
920 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000921 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +0000922 return true;
923 }
924 }
925 }
926 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000927
Evan Chenga8e29892007-01-19 07:51:42 +0000928 return false;
929}
930
Chris Lattner52a261b2010-09-21 20:31:19 +0000931bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000932 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000933 if (DisableShifterOp)
934 return false;
935
Evan Cheng9cb9e672009-06-27 02:26:13 +0000936 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
937
938 // Don't match base register only case. That is matched to a separate
939 // lower complexity pattern with explicit register operand.
940 if (ShOpcVal == ARM_AM::no_shift) return false;
941
942 BaseReg = N.getOperand(0);
943 unsigned ShImmVal = 0;
944 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
945 ShImmVal = RHS->getZExtValue() & 31;
946 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
947 return true;
948 }
949
950 return false;
951}
952
Chris Lattner52a261b2010-09-21 20:31:19 +0000953bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000954 SDValue &Base, SDValue &OffImm) {
955 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +0000956
Evan Cheng3a214252009-08-11 08:52:18 +0000957 // Base only.
958 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +0000959 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +0000960 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +0000961 int FI = cast<FrameIndexSDNode>(N)->getIndex();
962 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000963 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +0000964 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000965 } else if (N.getOpcode() == ARMISD::Wrapper &&
966 !(Subtarget->useMovt() &&
967 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +0000968 Base = N.getOperand(0);
969 if (Base.getOpcode() == ISD::TargetConstantPool)
970 return false; // We want to select t2LDRpci instead.
971 } else
972 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000973 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +0000974 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +0000975 }
Evan Cheng055b0312009-06-29 07:51:04 +0000976
977 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000978 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +0000979 // Let t2LDRi8 handle (R - imm8).
980 return false;
981
Evan Cheng055b0312009-06-29 07:51:04 +0000982 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +0000983 if (N.getOpcode() == ISD::SUB)
984 RHSC = -RHSC;
985
986 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +0000987 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +0000988 if (Base.getOpcode() == ISD::FrameIndex) {
989 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
990 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
991 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000992 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000993 return true;
994 }
995 }
996
Evan Cheng3a214252009-08-11 08:52:18 +0000997 // Base only.
998 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000999 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001000 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001001}
1002
Chris Lattner52a261b2010-09-21 20:31:19 +00001003bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001004 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001005 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001006 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001007 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1008 int RHSC = (int)RHS->getSExtValue();
1009 if (N.getOpcode() == ISD::SUB)
1010 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001011
Evan Cheng3a214252009-08-11 08:52:18 +00001012 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1013 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001014 if (Base.getOpcode() == ISD::FrameIndex) {
1015 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1016 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1017 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001018 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001019 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001020 }
Evan Cheng055b0312009-06-29 07:51:04 +00001021 }
1022 }
1023
1024 return false;
1025}
1026
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001027bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001028 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001029 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001030 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1031 ? cast<LoadSDNode>(Op)->getAddressingMode()
1032 : cast<StoreSDNode>(Op)->getAddressingMode();
1033 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1034 int RHSC = (int)RHS->getZExtValue();
1035 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001036 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001037 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1038 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001039 return true;
1040 }
1041 }
1042
1043 return false;
1044}
1045
Chris Lattner52a261b2010-09-21 20:31:19 +00001046bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001047 SDValue &Base,
1048 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001049 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1050 if (N.getOpcode() != ISD::ADD)
1051 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001052
Evan Cheng3a214252009-08-11 08:52:18 +00001053 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1054 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1055 int RHSC = (int)RHS->getZExtValue();
1056 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1057 return false;
1058 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001059 return false;
1060 }
1061
Evan Chengf40deed2010-10-27 23:41:30 +00001062 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1063 // Compute R + (R << [1,2,3]) and reuse it.
1064 Base = N;
1065 return false;
1066 }
1067
Evan Cheng055b0312009-06-29 07:51:04 +00001068 // Look for (R + R) or (R + (R << [1,2,3])).
1069 unsigned ShAmt = 0;
1070 Base = N.getOperand(0);
1071 OffReg = N.getOperand(1);
1072
1073 // Swap if it is ((R << c) + R).
1074 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1075 if (ShOpcVal != ARM_AM::lsl) {
1076 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1077 if (ShOpcVal == ARM_AM::lsl)
1078 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001079 }
1080
Evan Cheng055b0312009-06-29 07:51:04 +00001081 if (ShOpcVal == ARM_AM::lsl) {
1082 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1083 // it.
1084 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1085 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001086 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1087 OffReg = OffReg.getOperand(0);
1088 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001089 ShAmt = 0;
1090 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001091 }
Evan Cheng055b0312009-06-29 07:51:04 +00001092 } else {
1093 ShOpcVal = ARM_AM::no_shift;
1094 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001095 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001096
Owen Anderson825b72b2009-08-11 20:47:22 +00001097 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001098
1099 return true;
1100}
1101
1102//===--------------------------------------------------------------------===//
1103
Evan Chengee568cf2007-07-05 07:15:27 +00001104/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001105static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001106 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001107}
1108
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001109SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1110 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001111 ISD::MemIndexedMode AM = LD->getAddressingMode();
1112 if (AM == ISD::UNINDEXED)
1113 return NULL;
1114
Owen Andersone50ed302009-08-10 22:56:29 +00001115 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001116 SDValue Offset, AMOpc;
1117 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1118 unsigned Opcode = 0;
1119 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001120 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001121 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001122 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1123 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001124 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001125 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001126 Match = true;
1127 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1128 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1129 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001130 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001131 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001132 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001133 Match = true;
1134 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1135 }
1136 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001137 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001138 Match = true;
1139 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1140 }
1141 }
1142 }
1143
1144 if (Match) {
1145 SDValue Chain = LD->getChain();
1146 SDValue Base = LD->getBasePtr();
1147 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001148 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001149 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001150 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001151 }
1152
1153 return NULL;
1154}
1155
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001156SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1157 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001158 ISD::MemIndexedMode AM = LD->getAddressingMode();
1159 if (AM == ISD::UNINDEXED)
1160 return NULL;
1161
Owen Andersone50ed302009-08-10 22:56:29 +00001162 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001163 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001164 SDValue Offset;
1165 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1166 unsigned Opcode = 0;
1167 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001168 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001169 switch (LoadedVT.getSimpleVT().SimpleTy) {
1170 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001171 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1172 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001173 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001174 if (isSExtLd)
1175 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1176 else
1177 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001178 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001179 case MVT::i8:
1180 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001181 if (isSExtLd)
1182 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1183 else
1184 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001185 break;
1186 default:
1187 return NULL;
1188 }
1189 Match = true;
1190 }
1191
1192 if (Match) {
1193 SDValue Chain = LD->getChain();
1194 SDValue Base = LD->getBasePtr();
1195 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001196 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001197 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001198 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001199 }
1200
1201 return NULL;
1202}
1203
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001204/// PairSRegs - Form a D register from a pair of S registers.
1205///
1206SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1207 DebugLoc dl = V0.getNode()->getDebugLoc();
1208 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1209 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001210 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1211 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001212}
1213
Evan Cheng603afbf2010-05-10 17:34:18 +00001214/// PairDRegs - Form a quad register from a pair of D registers.
1215///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001216SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1217 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001218 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1219 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001220 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1221 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001222}
1223
Evan Cheng7f687192010-05-14 00:21:45 +00001224/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001225///
1226SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1227 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001228 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1229 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001230 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1231 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1232}
1233
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001234/// QuadSRegs - Form 4 consecutive S registers.
1235///
1236SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1237 SDValue V2, SDValue V3) {
1238 DebugLoc dl = V0.getNode()->getDebugLoc();
1239 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1240 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1241 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1242 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1243 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1244 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1245}
1246
Evan Cheng7f687192010-05-14 00:21:45 +00001247/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001248///
1249SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1250 SDValue V2, SDValue V3) {
1251 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001252 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1253 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1254 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1255 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001256 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1257 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1258}
1259
Evan Cheng8f6de382010-05-16 03:27:48 +00001260/// QuadQRegs - Form 4 consecutive Q registers.
1261///
1262SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1263 SDValue V2, SDValue V3) {
1264 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001265 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1266 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1267 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1268 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001269 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1270 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1271}
1272
Bob Wilson2a6e6162010-09-23 23:42:37 +00001273/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1274/// of a NEON VLD or VST instruction. The supported values depend on the
1275/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001276SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1277 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001278 unsigned NumRegs = NumVecs;
1279 if (!is64BitVector && NumVecs < 3)
1280 NumRegs *= 2;
1281
Bob Wilson665814b2010-11-01 23:40:51 +00001282 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001283 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001284 Alignment = 32;
1285 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1286 Alignment = 16;
1287 else if (Alignment >= 8)
1288 Alignment = 8;
1289 else
1290 Alignment = 0;
1291
1292 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001293}
1294
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001295SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001296 unsigned *DOpcodes, unsigned *QOpcodes0,
1297 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001298 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001299 DebugLoc dl = N->getDebugLoc();
1300
Bob Wilson226036e2010-03-20 22:13:40 +00001301 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001302 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001303 return NULL;
1304
1305 SDValue Chain = N->getOperand(0);
1306 EVT VT = N->getValueType(0);
1307 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001308 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001309
Bob Wilson3e36f132009-10-14 17:28:52 +00001310 unsigned OpcodeIndex;
1311 switch (VT.getSimpleVT().SimpleTy) {
1312 default: llvm_unreachable("unhandled vld type");
1313 // Double-register operations:
1314 case MVT::v8i8: OpcodeIndex = 0; break;
1315 case MVT::v4i16: OpcodeIndex = 1; break;
1316 case MVT::v2f32:
1317 case MVT::v2i32: OpcodeIndex = 2; break;
1318 case MVT::v1i64: OpcodeIndex = 3; break;
1319 // Quad-register operations:
1320 case MVT::v16i8: OpcodeIndex = 0; break;
1321 case MVT::v8i16: OpcodeIndex = 1; break;
1322 case MVT::v4f32:
1323 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001324 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001325 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001326 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001327 }
1328
Bob Wilsonf5721912010-09-03 18:16:02 +00001329 EVT ResTy;
1330 if (NumVecs == 1)
1331 ResTy = VT;
1332 else {
1333 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1334 if (!is64BitVector)
1335 ResTyElts *= 2;
1336 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1337 }
1338
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001339 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001340 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001341 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001342 if (is64BitVector) {
1343 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001344 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001345 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001346 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001347 return VLd;
1348
Bob Wilsonf5721912010-09-03 18:16:02 +00001349 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001350 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001351 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001352 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001353 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001354 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001355 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001356 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001357 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001358 }
1359
Bob Wilson621f1952010-03-23 05:25:43 +00001360 if (NumVecs <= 2) {
1361 // Quad registers are directly supported for VLD1 and VLD2,
1362 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001363 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001364 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001365 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001366 if (NumVecs == 1)
1367 return VLd;
1368
Bob Wilsonf5721912010-09-03 18:16:02 +00001369 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001370 Chain = SDValue(VLd, 1);
1371
Bob Wilson3e36f132009-10-14 17:28:52 +00001372 } else {
1373 // Otherwise, quad registers are loaded with two separate instructions,
1374 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001375 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001376
Bob Wilson24f995d2009-10-14 18:32:29 +00001377 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001378 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001379 SDValue ImplDef =
1380 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1381 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1382 SDNode *VLdA =
1383 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1384 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001385
Bob Wilson24f995d2009-10-14 18:32:29 +00001386 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001387 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001388 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1389 Pred, Reg0, Chain };
1390 SDNode *VLdB =
1391 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1392 SuperReg = SDValue(VLdB, 0);
1393 Chain = SDValue(VLdB, 2);
1394 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001395
Bob Wilsonf5721912010-09-03 18:16:02 +00001396 // Extract out the Q registers.
1397 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1398 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1399 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1400 dl, VT, SuperReg);
1401 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001402 }
1403 ReplaceUses(SDValue(N, NumVecs), Chain);
1404 return NULL;
1405}
1406
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001407SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001408 unsigned *DOpcodes, unsigned *QOpcodes0,
1409 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001410 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001411 DebugLoc dl = N->getDebugLoc();
1412
Bob Wilson226036e2010-03-20 22:13:40 +00001413 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001414 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001415 return NULL;
1416
1417 SDValue Chain = N->getOperand(0);
1418 EVT VT = N->getOperand(3).getValueType();
1419 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001420 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001421
Bob Wilson24f995d2009-10-14 18:32:29 +00001422 unsigned OpcodeIndex;
1423 switch (VT.getSimpleVT().SimpleTy) {
1424 default: llvm_unreachable("unhandled vst type");
1425 // Double-register operations:
1426 case MVT::v8i8: OpcodeIndex = 0; break;
1427 case MVT::v4i16: OpcodeIndex = 1; break;
1428 case MVT::v2f32:
1429 case MVT::v2i32: OpcodeIndex = 2; break;
1430 case MVT::v1i64: OpcodeIndex = 3; break;
1431 // Quad-register operations:
1432 case MVT::v16i8: OpcodeIndex = 0; break;
1433 case MVT::v8i16: OpcodeIndex = 1; break;
1434 case MVT::v4f32:
1435 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001436 case MVT::v2i64: OpcodeIndex = 3;
1437 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1438 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001439 }
1440
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001441 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001442 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001443
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001444 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001445 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001446 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001447
1448 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001449 if (NumVecs == 1) {
1450 Ops.push_back(N->getOperand(3));
1451 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001452 SDValue RegSeq;
1453 SDValue V0 = N->getOperand(0+3);
1454 SDValue V1 = N->getOperand(1+3);
1455
1456 // Form a REG_SEQUENCE to force register allocation.
1457 if (NumVecs == 2)
1458 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1459 else {
1460 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001461 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001462 // an undef.
1463 SDValue V3 = (NumVecs == 3)
1464 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1465 : N->getOperand(3+3);
1466 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1467 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001468 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001469 }
Evan Chengac0869d2009-11-21 06:21:52 +00001470 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001471 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001472 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001473 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001474 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001475 }
1476
Bob Wilson11d98992010-03-23 06:20:33 +00001477 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001478 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001479 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001480 if (NumVecs == 1) {
1481 Ops.push_back(N->getOperand(3));
1482 } else {
1483 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001484 SDValue Q0 = N->getOperand(3);
1485 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001486 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001487 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001488 Ops.push_back(Pred);
1489 Ops.push_back(Reg0); // predicate register
1490 Ops.push_back(Chain);
1491 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001492 }
1493
1494 // Otherwise, quad registers are stored with two separate instructions,
1495 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001496
Bob Wilson07f6e802010-06-16 21:34:01 +00001497 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001498 SDValue V0 = N->getOperand(0+3);
1499 SDValue V1 = N->getOperand(1+3);
1500 SDValue V2 = N->getOperand(2+3);
1501 SDValue V3 = (NumVecs == 3)
1502 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1503 : N->getOperand(3+3);
1504 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001505
1506 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001507 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001508 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001509 Ops.push_back(Pred);
1510 Ops.push_back(Reg0); // predicate register
1511 Ops.push_back(Chain);
1512 unsigned Opc = QOpcodes0[OpcodeIndex];
1513 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001514 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001515 Chain = SDValue(VStA, 1);
1516
1517 // Store the odd D registers.
1518 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001519 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001520 Opc = QOpcodes1[OpcodeIndex];
1521 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001522 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001523 Chain = SDValue(VStB, 1);
1524 ReplaceUses(SDValue(N, 0), Chain);
1525 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001526}
1527
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001528SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001529 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001530 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001531 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001532 DebugLoc dl = N->getDebugLoc();
1533
Bob Wilson226036e2010-03-20 22:13:40 +00001534 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001535 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001536 return NULL;
1537
1538 SDValue Chain = N->getOperand(0);
1539 unsigned Lane =
1540 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001541 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001542 bool is64BitVector = VT.is64BitVector();
1543
Bob Wilson665814b2010-11-01 23:40:51 +00001544 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001545 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001546 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001547 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1548 if (Alignment > NumBytes)
1549 Alignment = NumBytes;
1550 // Alignment must be a power of two; make sure of that.
1551 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001552 if (Alignment == 1)
1553 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001554 }
Bob Wilson665814b2010-11-01 23:40:51 +00001555 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001556
Bob Wilsona7c397c2009-10-14 16:19:03 +00001557 unsigned OpcodeIndex;
1558 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001559 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001560 // Double-register operations:
1561 case MVT::v8i8: OpcodeIndex = 0; break;
1562 case MVT::v4i16: OpcodeIndex = 1; break;
1563 case MVT::v2f32:
1564 case MVT::v2i32: OpcodeIndex = 2; break;
1565 // Quad-register operations:
1566 case MVT::v8i16: OpcodeIndex = 0; break;
1567 case MVT::v4f32:
1568 case MVT::v4i32: OpcodeIndex = 1; break;
1569 }
1570
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001571 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001572 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001573
Bob Wilson8466fa12010-09-13 23:01:35 +00001574 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001575 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001576 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001577
Jim Grosbach3ab56582010-10-21 19:38:40 +00001578 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001579 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001580
Bob Wilson8466fa12010-09-13 23:01:35 +00001581 SDValue SuperReg;
1582 SDValue V0 = N->getOperand(0+3);
1583 SDValue V1 = N->getOperand(1+3);
1584 if (NumVecs == 2) {
1585 if (is64BitVector)
1586 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1587 else
1588 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001589 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001590 SDValue V2 = N->getOperand(2+3);
1591 SDValue V3 = (NumVecs == 3)
1592 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1593 : N->getOperand(3+3);
1594 if (is64BitVector)
1595 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1596 else
1597 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001598 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001599 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001600 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001601 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001602 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001603 Ops.push_back(Chain);
1604
Bob Wilson96493442009-10-14 16:46:45 +00001605 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001606 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001607
Bob Wilson8466fa12010-09-13 23:01:35 +00001608 EVT ResTy;
1609 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1610 if (!is64BitVector)
1611 ResTyElts *= 2;
1612 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001613
Bob Wilson8466fa12010-09-13 23:01:35 +00001614 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1615 Ops.data(), 7);
1616 SuperReg = SDValue(VLdLn, 0);
1617 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001618
Bob Wilson8466fa12010-09-13 23:01:35 +00001619 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001620 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1621 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1622 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1623 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1624 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001625 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1626 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001627 return NULL;
1628}
1629
Bob Wilson78dfbc32010-07-07 00:08:54 +00001630SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1631 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001632 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1633 DebugLoc dl = N->getDebugLoc();
1634 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001635 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001636
1637 // Form a REG_SEQUENCE to force register allocation.
1638 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001639 SDValue V0 = N->getOperand(FirstTblReg + 0);
1640 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001641 if (NumVecs == 2)
1642 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1643 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001644 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001645 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001646 // an undef.
1647 SDValue V3 = (NumVecs == 3)
1648 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001649 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001650 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1651 }
1652
Bob Wilson78dfbc32010-07-07 00:08:54 +00001653 SmallVector<SDValue, 6> Ops;
1654 if (IsExt)
1655 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001656 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001657 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001658 Ops.push_back(getAL(CurDAG)); // predicate
1659 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001660 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001661}
1662
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001663SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001664 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001665 if (!Subtarget->hasV6T2Ops())
1666 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001667
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001668 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1669 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1670
1671
1672 // For unsigned extracts, check for a shift right and mask
1673 unsigned And_imm = 0;
1674 if (N->getOpcode() == ISD::AND) {
1675 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1676
1677 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1678 if (And_imm & (And_imm + 1))
1679 return NULL;
1680
1681 unsigned Srl_imm = 0;
1682 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1683 Srl_imm)) {
1684 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1685
1686 unsigned Width = CountTrailingOnes_32(And_imm);
1687 unsigned LSB = Srl_imm;
1688 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1689 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1690 CurDAG->getTargetConstant(LSB, MVT::i32),
1691 CurDAG->getTargetConstant(Width, MVT::i32),
1692 getAL(CurDAG), Reg0 };
1693 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1694 }
1695 }
1696 return NULL;
1697 }
1698
1699 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001700 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001702 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1703 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001704 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001705 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1706 unsigned Width = 32 - Srl_imm;
1707 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001708 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001709 return NULL;
1710 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001711 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001712 CurDAG->getTargetConstant(LSB, MVT::i32),
1713 CurDAG->getTargetConstant(Width, MVT::i32),
1714 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001715 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001716 }
1717 }
1718 return NULL;
1719}
1720
Evan Cheng9ef48352009-11-20 00:54:03 +00001721SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001722SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001723 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1724 SDValue CPTmp0;
1725 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001726 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001727 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1728 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1729 unsigned Opc = 0;
1730 switch (SOShOp) {
1731 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1732 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1733 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1734 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1735 default:
1736 llvm_unreachable("Unknown so_reg opcode!");
1737 break;
1738 }
1739 SDValue SOShImm =
1740 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1741 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1742 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001743 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001744 }
1745 return 0;
1746}
1747
1748SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001749SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001750 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1751 SDValue CPTmp0;
1752 SDValue CPTmp1;
1753 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001754 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001755 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1756 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001757 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001758 }
1759 return 0;
1760}
1761
1762SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001763SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001764 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1765 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1766 if (!T)
1767 return 0;
1768
Jim Grosbacha4257162010-10-07 00:53:56 +00001769 unsigned TrueImm = T->getZExtValue();
1770 bool isSoImm = Pred_t2_so_imm(TrueVal.getNode());
1771 if (isSoImm || TrueImm <= 0xffff) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001772 SDValue True = CurDAG->getTargetConstant(T->getZExtValue(), MVT::i32);
1773 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1774 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbacha4257162010-10-07 00:53:56 +00001775 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::t2MOVCCi : ARM::t2MOVCCi16),
1776 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001777 }
1778 return 0;
1779}
1780
1781SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001782SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001783 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1784 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
1785 if (!T)
1786 return 0;
1787
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001788 unsigned TrueImm = T->getZExtValue();
1789 bool isSoImm = Pred_so_imm(TrueVal.getNode());
1790 if (isSoImm || (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff)) {
1791 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00001792 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1793 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001794 return CurDAG->SelectNodeTo(N, (isSoImm ? ARM::MOVCCi : ARM::MOVCCi16),
1795 MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00001796 }
1797 return 0;
1798}
1799
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001800SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
1801 EVT VT = N->getValueType(0);
1802 SDValue FalseVal = N->getOperand(0);
1803 SDValue TrueVal = N->getOperand(1);
1804 SDValue CC = N->getOperand(2);
1805 SDValue CCR = N->getOperand(3);
1806 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00001807 assert(CC.getOpcode() == ISD::Constant);
1808 assert(CCR.getOpcode() == ISD::Register);
1809 ARMCC::CondCodes CCVal =
1810 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00001811
1812 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
1813 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1814 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
1815 // Pattern complexity = 18 cost = 1 size = 0
1816 SDValue CPTmp0;
1817 SDValue CPTmp1;
1818 SDValue CPTmp2;
1819 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001820 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001821 CCVal, CCR, InFlag);
1822 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001823 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001824 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1825 if (Res)
1826 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001827 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001828 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001829 CCVal, CCR, InFlag);
1830 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001831 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001832 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1833 if (Res)
1834 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001835 }
1836
1837 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00001838 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00001839 // (imm:i32):$cc)
1840 // Emits: (MOVCCi:i32 GPR:i32:$false,
1841 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
1842 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00001843 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00001844 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001845 CCVal, CCR, InFlag);
1846 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00001847 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001848 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1849 if (Res)
1850 return Res;
1851 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001852 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001853 CCVal, CCR, InFlag);
1854 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00001855 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001856 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
1857 if (Res)
1858 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00001859 }
1860 }
1861
1862 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1863 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1864 // Pattern complexity = 6 cost = 1 size = 0
1865 //
1866 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1867 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
1868 // Pattern complexity = 6 cost = 11 size = 0
1869 //
1870 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00001871 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
1872 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00001873 unsigned Opc = 0;
1874 switch (VT.getSimpleVT().SimpleTy) {
1875 default: assert(false && "Illegal conditional move type!");
1876 break;
1877 case MVT::i32:
1878 Opc = Subtarget->isThumb()
1879 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
1880 : ARM::MOVCCr;
1881 break;
1882 case MVT::f32:
1883 Opc = ARM::VMOVScc;
1884 break;
1885 case MVT::f64:
1886 Opc = ARM::VMOVDcc;
1887 break;
1888 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001889 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00001890}
1891
Evan Chengde8aa4e2010-05-05 18:28:36 +00001892SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
1893 // The only time a CONCAT_VECTORS operation can have legal types is when
1894 // two 64-bit vectors are concatenated to a 128-bit vector.
1895 EVT VT = N->getValueType(0);
1896 if (!VT.is128BitVector() || N->getNumOperands() != 2)
1897 llvm_unreachable("unexpected CONCAT_VECTORS");
1898 DebugLoc dl = N->getDebugLoc();
1899 SDValue V0 = N->getOperand(0);
1900 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001901 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1902 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00001903 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1904 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1905}
1906
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001907SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00001908 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00001909
Dan Gohmane8be6c62008-07-17 19:10:17 +00001910 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00001911 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001912
1913 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00001914 default: break;
1915 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001916 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001917 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001918 if (Subtarget->hasThumb2())
1919 // Thumb2-aware targets have the MOVT instruction, so all immediates can
1920 // be done with MOV + MOVT, at worst.
1921 UseCP = 0;
1922 else {
1923 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00001924 UseCP = (Val > 255 && // MOV
1925 ~Val > 255 && // MOV + MVN
1926 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00001927 } else
1928 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
1929 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
1930 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
1931 }
1932
Evan Chenga8e29892007-01-19 07:51:42 +00001933 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00001934 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00001935 CurDAG->getTargetConstantPool(ConstantInt::get(
1936 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00001937 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00001938
1939 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00001940 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001941 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00001942 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00001943 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00001944 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
1945 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00001946 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00001947 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00001948 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00001949 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00001950 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001951 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00001952 CurDAG->getEntryNode()
1953 };
Dan Gohman602b0c82009-09-25 18:54:59 +00001954 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00001955 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00001956 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001957 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00001958 return NULL;
1959 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001960
Evan Chenga8e29892007-01-19 07:51:42 +00001961 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00001962 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001963 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00001964 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00001965 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00001966 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00001967 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00001968 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001969 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
1970 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00001971 } else {
David Goodwin419c6152009-07-14 18:48:51 +00001972 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
1973 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00001974 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
1975 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
1976 CurDAG->getRegister(0, MVT::i32) };
1977 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00001978 }
Evan Chenga8e29892007-01-19 07:51:42 +00001979 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001980 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001981 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001982 return I;
1983 break;
1984 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001985 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001986 return I;
1987 break;
Evan Chenga8e29892007-01-19 07:51:42 +00001988 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001989 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00001990 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001991 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001992 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00001993 if (!RHSV) break;
1994 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00001995 unsigned ShImm = Log2_32(RHSV-1);
1996 if (ShImm >= 32)
1997 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00001999 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002000 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2001 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002002 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002003 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002004 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002005 } else {
2006 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002007 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002008 }
Evan Chenga8e29892007-01-19 07:51:42 +00002009 }
2010 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002011 unsigned ShImm = Log2_32(RHSV+1);
2012 if (ShImm >= 32)
2013 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002014 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002015 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002016 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2017 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002018 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002019 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2020 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002021 } else {
2022 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002023 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002024 }
Evan Chenga8e29892007-01-19 07:51:42 +00002025 }
2026 }
2027 break;
Evan Cheng20956592009-10-21 08:15:52 +00002028 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002029 // Check for unsigned bitfield extract
2030 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2031 return I;
2032
Evan Cheng20956592009-10-21 08:15:52 +00002033 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2034 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2035 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2036 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2037 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002038 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002039 if (VT != MVT::i32)
2040 break;
2041 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2042 ? ARM::t2MOVTi16
2043 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2044 if (!Opc)
2045 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002047 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2048 if (!N1C)
2049 break;
2050 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2051 SDValue N2 = N0.getOperand(1);
2052 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2053 if (!N2C)
2054 break;
2055 unsigned N1CVal = N1C->getZExtValue();
2056 unsigned N2CVal = N2C->getZExtValue();
2057 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2058 (N1CVal & 0xffffU) == 0xffffU &&
2059 (N2CVal & 0xffffU) == 0x0U) {
2060 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2061 MVT::i32);
2062 SDValue Ops[] = { N0.getOperand(0), Imm16,
2063 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2064 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2065 }
2066 }
2067 break;
2068 }
Jim Grosbache5165492009-11-09 00:11:35 +00002069 case ARMISD::VMOVRRD:
2070 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002071 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002072 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002073 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002074 if (Subtarget->isThumb1Only())
2075 break;
2076 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002077 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002078 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2079 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002080 return CurDAG->getMachineNode(ARM::t2UMULL, 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::UMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002086 }
Evan Chengee568cf2007-07-05 07:15:27 +00002087 }
Dan Gohman525178c2007-10-08 18:33:35 +00002088 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002089 if (Subtarget->isThumb1Only())
2090 break;
2091 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002092 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002093 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002094 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002095 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002096 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002097 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2098 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002099 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002100 }
Evan Chengee568cf2007-07-05 07:15:27 +00002101 }
Evan Chenga8e29892007-01-19 07:51:42 +00002102 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002103 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002104 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002105 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002106 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002107 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002108 if (ResNode)
2109 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002110 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002111 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002112 }
Evan Chengee568cf2007-07-05 07:15:27 +00002113 case ARMISD::BRCOND: {
2114 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2115 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2116 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002117
Evan Chengee568cf2007-07-05 07:15:27 +00002118 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2119 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2120 // Pattern complexity = 6 cost = 1 size = 0
2121
David Goodwin5e47a9a2009-06-30 18:04:13 +00002122 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2123 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2124 // Pattern complexity = 6 cost = 1 size = 0
2125
Jim Grosbach764ab522009-08-11 15:33:49 +00002126 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002127 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002128 SDValue Chain = N->getOperand(0);
2129 SDValue N1 = N->getOperand(1);
2130 SDValue N2 = N->getOperand(2);
2131 SDValue N3 = N->getOperand(3);
2132 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002133 assert(N1.getOpcode() == ISD::BasicBlock);
2134 assert(N2.getOpcode() == ISD::Constant);
2135 assert(N3.getOpcode() == ISD::Register);
2136
Dan Gohman475871a2008-07-27 21:46:04 +00002137 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002138 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002139 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002140 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002141 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2142 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002143 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002144 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002145 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002146 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002147 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002149 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002150 return NULL;
2151 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002152 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002153 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002154 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 EVT VT = N->getValueType(0);
2156 SDValue N0 = N->getOperand(0);
2157 SDValue N1 = N->getOperand(1);
2158 SDValue N2 = N->getOperand(2);
2159 SDValue N3 = N->getOperand(3);
2160 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002161 assert(N2.getOpcode() == ISD::Constant);
2162 assert(N3.getOpcode() == ISD::Register);
2163
Dan Gohman475871a2008-07-27 21:46:04 +00002164 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002165 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002166 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002167 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002168 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002169 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002170 default: assert(false && "Illegal conditional move type!");
2171 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002172 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002173 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002174 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002175 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002176 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002177 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002178 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002179 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002180 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002181
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002182 case ARMISD::VZIP: {
2183 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002184 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002185 switch (VT.getSimpleVT().SimpleTy) {
2186 default: return NULL;
2187 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2188 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2189 case MVT::v2f32:
2190 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2191 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2192 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2193 case MVT::v4f32:
2194 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2195 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002196 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002197 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2198 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2199 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002200 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002201 case ARMISD::VUZP: {
2202 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002203 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002204 switch (VT.getSimpleVT().SimpleTy) {
2205 default: return NULL;
2206 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2207 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2208 case MVT::v2f32:
2209 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2210 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2211 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2212 case MVT::v4f32:
2213 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2214 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002215 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002216 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2217 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2218 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002219 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002220 case ARMISD::VTRN: {
2221 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002222 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002223 switch (VT.getSimpleVT().SimpleTy) {
2224 default: return NULL;
2225 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2226 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2227 case MVT::v2f32:
2228 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2229 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2230 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2231 case MVT::v4f32:
2232 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2233 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002234 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002235 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2236 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2237 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002238 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002239 case ARMISD::BUILD_VECTOR: {
2240 EVT VecVT = N->getValueType(0);
2241 EVT EltVT = VecVT.getVectorElementType();
2242 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002243 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002244 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2245 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2246 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002247 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002248 if (NumElts == 2)
2249 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2250 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2251 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2252 N->getOperand(2), N->getOperand(3));
2253 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002254
2255 case ISD::INTRINSIC_VOID:
2256 case ISD::INTRINSIC_W_CHAIN: {
2257 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002258 switch (IntNo) {
2259 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002260 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002261
Bob Wilson621f1952010-03-23 05:25:43 +00002262 case Intrinsic::arm_neon_vld1: {
2263 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2264 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002265 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2266 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002267 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2268 }
2269
Bob Wilson31fb12f2009-08-26 17:39:53 +00002270 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002271 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2272 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2273 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2274 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002275 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002276 }
2277
2278 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002279 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2280 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2281 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2282 ARM::VLD3q16Pseudo_UPD,
2283 ARM::VLD3q32Pseudo_UPD };
2284 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2285 ARM::VLD3q16oddPseudo_UPD,
2286 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002287 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002288 }
2289
2290 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002291 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2292 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2293 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2294 ARM::VLD4q16Pseudo_UPD,
2295 ARM::VLD4q32Pseudo_UPD };
2296 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2297 ARM::VLD4q16oddPseudo_UPD,
2298 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002299 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002300 }
2301
Bob Wilson243fcc52009-09-01 04:26:28 +00002302 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002303 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2304 ARM::VLD2LNd32Pseudo };
2305 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2306 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002307 }
2308
2309 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002310 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2311 ARM::VLD3LNd32Pseudo };
2312 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2313 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002314 }
2315
2316 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002317 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2318 ARM::VLD4LNd32Pseudo };
2319 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2320 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002321 }
2322
Bob Wilson11d98992010-03-23 06:20:33 +00002323 case Intrinsic::arm_neon_vst1: {
2324 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2325 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002326 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2327 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002328 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2329 }
2330
Bob Wilson31fb12f2009-08-26 17:39:53 +00002331 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002332 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2333 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2334 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2335 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002336 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002337 }
2338
2339 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002340 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2341 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2342 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2343 ARM::VST3q16Pseudo_UPD,
2344 ARM::VST3q32Pseudo_UPD };
2345 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2346 ARM::VST3q16oddPseudo_UPD,
2347 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002349 }
2350
2351 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002352 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002353 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002354 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2355 ARM::VST4q16Pseudo_UPD,
2356 ARM::VST4q32Pseudo_UPD };
2357 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2358 ARM::VST4q16oddPseudo_UPD,
2359 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002360 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002361 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002362
2363 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002364 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2365 ARM::VST2LNd32Pseudo };
2366 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2367 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002368 }
2369
2370 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002371 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2372 ARM::VST3LNd32Pseudo };
2373 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2374 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002375 }
2376
2377 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002378 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2379 ARM::VST4LNd32Pseudo };
2380 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2381 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002382 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002383 }
Bob Wilson429009b2010-05-06 16:05:26 +00002384 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002385 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002386
Bob Wilsond491d6e2010-07-06 23:36:25 +00002387 case ISD::INTRINSIC_WO_CHAIN: {
2388 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2389 switch (IntNo) {
2390 default:
2391 break;
2392
2393 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002394 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002395 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002396 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002397 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002398 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002399
2400 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002401 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002402 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002403 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002404 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002405 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002406 }
2407 break;
2408 }
2409
Bob Wilson429009b2010-05-06 16:05:26 +00002410 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002411 return SelectConcatVector(N);
2412 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002413
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002414 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002415}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002416
Bob Wilson224c2442009-05-19 05:53:42 +00002417bool ARMDAGToDAGISel::
2418SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2419 std::vector<SDValue> &OutOps) {
2420 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002421 // Require the address to be in a register. That is safe for all ARM
2422 // variants and it is hard to do anything much smarter without knowing
2423 // how the operand is used.
2424 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002425 return false;
2426}
2427
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002428/// createARMISelDag - This pass converts a legalized DAG into a
2429/// ARM-specific DAG, ready for instruction scheduling.
2430///
Bob Wilson522ce972009-09-28 14:30:20 +00002431FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2432 CodeGenOpt::Level OptLevel) {
2433 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002434}