blob: 8ef44d1ae83b04d62e88c0b98f640905bd8ec1f1 [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 Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000017#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000018#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
48 cl::init(false));
49
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000093 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000094 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000095 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
96 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000097 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
98 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
99
Jim Grosbach82891622010-09-29 19:03:54 +0000100 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
101 SDValue &Offset, SDValue &Opc);
102 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
105 }
106
107 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
108 SDValue &Opc) {
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
110 }
111
112 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
113 SDValue &Opc) {
114 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000115// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000116 // This always matches one way or another.
117 return true;
118 }
119
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000120 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000121 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000122 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000123 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000124 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000126 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000127 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000128 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000129 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000130
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000131 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000132
Bill Wendlingf4caf692010-12-14 03:36:38 +0000133 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000135 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
136 unsigned Scale);
137 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
140 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
141 SDValue &OffImm);
142 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
143 SDValue &OffImm);
144 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
145 SDValue &OffImm);
146 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
147 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000148 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000152 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000153 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
154 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000155 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000156 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000157 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000158 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000159 SDValue &OffReg, SDValue &ShImm);
160
Evan Cheng875a6ac2010-11-12 22:42:47 +0000161 inline bool is_so_imm(unsigned Imm) const {
162 return ARM_AM::getSOImmVal(Imm) != -1;
163 }
164
165 inline bool is_so_imm_not(unsigned Imm) const {
166 return ARM_AM::getSOImmVal(~Imm) != -1;
167 }
168
169 inline bool is_t2_so_imm(unsigned Imm) const {
170 return ARM_AM::getT2SOImmVal(Imm) != -1;
171 }
172
173 inline bool is_t2_so_imm_not(unsigned Imm) const {
174 return ARM_AM::getT2SOImmVal(~Imm) != -1;
175 }
176
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000177 inline bool Pred_so_imm(SDNode *inN) const {
178 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000179 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000180 }
181
182 inline bool Pred_t2_so_imm(SDNode *inN) const {
183 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000184 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000185 }
186
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000187 // Include the pieces autogenerated from the target description.
188#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000189
190private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000191 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
192 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000193 SDNode *SelectARMIndexedLoad(SDNode *N);
194 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000195
Bob Wilson621f1952010-03-23 05:25:43 +0000196 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
197 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000198 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000199 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000200 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
201 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000202 unsigned *QOpcodes0, unsigned *QOpcodes1);
203
Bob Wilson24f995d2009-10-14 18:32:29 +0000204 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000205 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000206 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000207 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000208 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
209 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000210 unsigned *QOpcodes0, unsigned *QOpcodes1);
211
Bob Wilson96493442009-10-14 16:46:45 +0000212 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000213 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000214 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000215 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
216 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000217 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000218
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000219 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
220 /// should be 2, 3 or 4. The opcode array specifies the instructions used
221 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000222 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
223 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000224
Bob Wilson78dfbc32010-07-07 00:08:54 +0000225 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
226 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
227 /// generated to force the table registers to be consecutive.
228 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000229
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000230 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000231 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000232
Evan Cheng07ba9062009-11-19 21:45:22 +0000233 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000234 SDNode *SelectCMOVOp(SDNode *N);
235 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000236 ARMCC::CondCodes CCVal, SDValue CCR,
237 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000238 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000239 ARMCC::CondCodes CCVal, SDValue CCR,
240 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000241 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000242 ARMCC::CondCodes CCVal, SDValue CCR,
243 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000244 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000245 ARMCC::CondCodes CCVal, SDValue CCR,
246 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000247
Evan Chengde8aa4e2010-05-05 18:28:36 +0000248 SDNode *SelectConcatVector(SDNode *N);
249
Evan Chengaf4550f2009-07-02 01:23:32 +0000250 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
251 /// inline asm expressions.
252 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
253 char ConstraintCode,
254 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000255
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000256 // Form pairs of consecutive S, D, or Q registers.
257 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000258 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000259 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
260
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000261 // Form sequences of 4 consecutive S, D, or Q registers.
262 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000263 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000264 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000265
266 // Get the alignment operand for a NEON VLD or VST instruction.
267 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000268};
Evan Chenga8e29892007-01-19 07:51:42 +0000269}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000270
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000271/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
272/// operand. If so Imm will receive the 32-bit value.
273static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
274 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
275 Imm = cast<ConstantSDNode>(N)->getZExtValue();
276 return true;
277 }
278 return false;
279}
280
281// isInt32Immediate - This method tests to see if a constant operand.
282// If so Imm will receive the 32 bit value.
283static bool isInt32Immediate(SDValue N, unsigned &Imm) {
284 return isInt32Immediate(N.getNode(), Imm);
285}
286
287// isOpcWithIntImmediate - This method tests to see if the node is a specific
288// opcode and that it has a immediate integer right operand.
289// If so Imm will receive the 32 bit value.
290static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
291 return N->getOpcode() == Opc &&
292 isInt32Immediate(N->getOperand(1).getNode(), Imm);
293}
294
Daniel Dunbarec91d522011-01-19 15:12:16 +0000295/// \brief Check whether a particular node is a constant value representable as
296/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
297///
298/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
299static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
300 int RangeMin, int RangeMax,
301 int &ScaledConstant) {
302 assert(Scale && "Invalid scale!");
303
304 // Check that this is a constant.
305 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
306 if (!C)
307 return false;
308
309 ScaledConstant = (int) C->getZExtValue();
310 if ((ScaledConstant % Scale) != 0)
311 return false;
312
313 ScaledConstant /= Scale;
314 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
315}
316
Evan Cheng48575f62010-12-05 22:04:16 +0000317/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
318/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
319/// least on current ARM implementations) which should be avoidded.
320bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
321 if (OptLevel == CodeGenOpt::None)
322 return true;
323
324 if (!CheckVMLxHazard)
325 return true;
326
327 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
328 return true;
329
330 if (!N->hasOneUse())
331 return false;
332
333 SDNode *Use = *N->use_begin();
334 if (Use->getOpcode() == ISD::CopyToReg)
335 return true;
336 if (Use->isMachineOpcode()) {
337 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
338 if (TID.mayStore())
339 return true;
340 unsigned Opcode = TID.getOpcode();
341 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
342 return true;
343 // vmlx feeding into another vmlx. We actually want to unfold
344 // the use later in the MLxExpansion pass. e.g.
345 // vmla
346 // vmla (stall 8 cycles)
347 //
348 // vmul (5 cycles)
349 // vadd (5 cycles)
350 // vmla
351 // This adds up to about 18 - 19 cycles.
352 //
353 // vmla
354 // vmul (stall 4 cycles)
355 // vadd adds up to about 14 cycles.
356 return TII->isFpMLxInstruction(Opcode);
357 }
358
359 return false;
360}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000361
Evan Chengf40deed2010-10-27 23:41:30 +0000362bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
363 ARM_AM::ShiftOpc ShOpcVal,
364 unsigned ShAmt) {
365 if (!Subtarget->isCortexA9())
366 return true;
367 if (Shift.hasOneUse())
368 return true;
369 // R << 2 is free.
370 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
371}
372
Chris Lattner52a261b2010-09-21 20:31:19 +0000373bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000374 SDValue &BaseReg,
375 SDValue &ShReg,
376 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000377 if (DisableShifterOp)
378 return false;
379
Evan Cheng055b0312009-06-29 07:51:04 +0000380 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
381
382 // Don't match base register only case. That is matched to a separate
383 // lower complexity pattern with explicit register operand.
384 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000385
Evan Cheng055b0312009-06-29 07:51:04 +0000386 BaseReg = N.getOperand(0);
387 unsigned ShImmVal = 0;
388 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000389 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000390 ShImmVal = RHS->getZExtValue() & 31;
391 } else {
392 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000393 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
394 return false;
395 }
396 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
397 MVT::i32);
398 return true;
399}
400
401bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
402 SDValue &BaseReg,
403 SDValue &ShReg,
404 SDValue &Opc) {
405 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
406
407 // Don't match base register only case. That is matched to a separate
408 // lower complexity pattern with explicit register operand.
409 if (ShOpcVal == ARM_AM::no_shift) return false;
410
411 BaseReg = N.getOperand(0);
412 unsigned ShImmVal = 0;
413 // Do not check isShifterOpProfitable. This must return true.
414 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
415 ShReg = CurDAG->getRegister(0, MVT::i32);
416 ShImmVal = RHS->getZExtValue() & 31;
417 } else {
418 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000419 }
420 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000421 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000422 return true;
423}
424
Jim Grosbach3e556122010-10-26 22:37:02 +0000425bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
426 SDValue &Base,
427 SDValue &OffImm) {
428 // Match simple R + imm12 operands.
429
430 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000431 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
432 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000433 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000434 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000435 int FI = cast<FrameIndexSDNode>(N)->getIndex();
436 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
437 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
438 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000439 }
440
441 if (N.getOpcode() == ARMISD::Wrapper &&
442 !(Subtarget->useMovt() &&
443 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000444 Base = N.getOperand(0);
445 } else
446 Base = N;
447 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
448 return true;
449 }
450
451 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
452 int RHSC = (int)RHS->getZExtValue();
453 if (N.getOpcode() == ISD::SUB)
454 RHSC = -RHSC;
455
456 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
457 Base = N.getOperand(0);
458 if (Base.getOpcode() == ISD::FrameIndex) {
459 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
460 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
461 }
462 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
463 return true;
464 }
465 }
466
467 // Base only.
468 Base = N;
469 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
470 return true;
471}
472
473
474
475bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
476 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000477 if (N.getOpcode() == ISD::MUL &&
478 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000479 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
480 // X * [3,5,9] -> X + X * [2,4,8] etc.
481 int RHSC = (int)RHS->getZExtValue();
482 if (RHSC & 1) {
483 RHSC = RHSC & ~1;
484 ARM_AM::AddrOpc AddSub = ARM_AM::add;
485 if (RHSC < 0) {
486 AddSub = ARM_AM::sub;
487 RHSC = - RHSC;
488 }
489 if (isPowerOf2_32(RHSC)) {
490 unsigned ShAmt = Log2_32(RHSC);
491 Base = Offset = N.getOperand(0);
492 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
493 ARM_AM::lsl),
494 MVT::i32);
495 return true;
496 }
497 }
498 }
499 }
500
Chris Lattner0a9481f2011-02-13 22:25:43 +0000501 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
502 // ISD::OR that is equivalent to an ISD::ADD.
503 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000504 return false;
505
506 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000507 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000508 int RHSC;
509 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
510 -0x1000+1, 0x1000, RHSC)) // 12 bits.
511 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000512 }
513
Evan Chengf40deed2010-10-27 23:41:30 +0000514 if (Subtarget->isCortexA9() && !N.hasOneUse())
515 // Compute R +/- (R << N) and reuse it.
516 return false;
517
Jim Grosbach3e556122010-10-26 22:37:02 +0000518 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000519 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
521 unsigned ShAmt = 0;
522
523 Base = N.getOperand(0);
524 Offset = N.getOperand(1);
525
526 if (ShOpcVal != ARM_AM::no_shift) {
527 // Check to see if the RHS of the shift is a constant, if not, we can't fold
528 // it.
529 if (ConstantSDNode *Sh =
530 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
531 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000532 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
533 Offset = N.getOperand(1).getOperand(0);
534 else {
535 ShAmt = 0;
536 ShOpcVal = ARM_AM::no_shift;
537 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000538 } else {
539 ShOpcVal = ARM_AM::no_shift;
540 }
541 }
542
543 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000544 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000545 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000546 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
547 if (ShOpcVal != ARM_AM::no_shift) {
548 // Check to see if the RHS of the shift is a constant, if not, we can't
549 // fold it.
550 if (ConstantSDNode *Sh =
551 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
552 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000553 if (!Subtarget->isCortexA9() ||
554 (N.hasOneUse() &&
555 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
556 Offset = N.getOperand(0).getOperand(0);
557 Base = N.getOperand(1);
558 } else {
559 ShAmt = 0;
560 ShOpcVal = ARM_AM::no_shift;
561 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000562 } else {
563 ShOpcVal = ARM_AM::no_shift;
564 }
565 }
566 }
567
568 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
569 MVT::i32);
570 return true;
571}
572
573
574
575
576//-----
577
Jim Grosbach82891622010-09-29 19:03:54 +0000578AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
579 SDValue &Base,
580 SDValue &Offset,
581 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000582 if (N.getOpcode() == ISD::MUL &&
583 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000584 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
585 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000586 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000587 if (RHSC & 1) {
588 RHSC = RHSC & ~1;
589 ARM_AM::AddrOpc AddSub = ARM_AM::add;
590 if (RHSC < 0) {
591 AddSub = ARM_AM::sub;
592 RHSC = - RHSC;
593 }
594 if (isPowerOf2_32(RHSC)) {
595 unsigned ShAmt = Log2_32(RHSC);
596 Base = Offset = N.getOperand(0);
597 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
598 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000599 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000600 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000601 }
602 }
603 }
604 }
605
Chris Lattner0a9481f2011-02-13 22:25:43 +0000606 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
607 // ISD::OR that is equivalent to an ADD.
608 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000609 Base = N;
610 if (N.getOpcode() == ISD::FrameIndex) {
611 int FI = cast<FrameIndexSDNode>(N)->getIndex();
612 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000613 } else if (N.getOpcode() == ARMISD::Wrapper &&
614 !(Subtarget->useMovt() &&
615 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000616 Base = N.getOperand(0);
617 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000618 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000619 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
620 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000621 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000622 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000623 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000624
Evan Chenga8e29892007-01-19 07:51:42 +0000625 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000626 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000627 int RHSC;
628 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
629 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
630 Base = N.getOperand(0);
631 if (Base.getOpcode() == ISD::FrameIndex) {
632 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
633 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000634 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000635 Offset = CurDAG->getRegister(0, MVT::i32);
636
637 ARM_AM::AddrOpc AddSub = ARM_AM::add;
638 if (RHSC < 0) {
639 AddSub = ARM_AM::sub;
640 RHSC = - RHSC;
641 }
642 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
643 ARM_AM::no_shift),
644 MVT::i32);
645 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000646 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000647 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000648
Evan Chengf40deed2010-10-27 23:41:30 +0000649 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
650 // Compute R +/- (R << N) and reuse it.
651 Base = N;
652 Offset = CurDAG->getRegister(0, MVT::i32);
653 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
654 ARM_AM::no_shift),
655 MVT::i32);
656 return AM2_BASE;
657 }
658
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000659 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000660 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga8e29892007-01-19 07:51:42 +0000661 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
662 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000663
Evan Chenga8e29892007-01-19 07:51:42 +0000664 Base = N.getOperand(0);
665 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000666
Evan Chenga8e29892007-01-19 07:51:42 +0000667 if (ShOpcVal != ARM_AM::no_shift) {
668 // Check to see if the RHS of the shift is a constant, if not, we can't fold
669 // it.
670 if (ConstantSDNode *Sh =
671 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000672 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000673 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
674 Offset = N.getOperand(1).getOperand(0);
675 else {
676 ShAmt = 0;
677 ShOpcVal = ARM_AM::no_shift;
678 }
Evan Chenga8e29892007-01-19 07:51:42 +0000679 } else {
680 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000681 }
682 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000683
Evan Chenga8e29892007-01-19 07:51:42 +0000684 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000685 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000686 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000687 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
688 if (ShOpcVal != ARM_AM::no_shift) {
689 // Check to see if the RHS of the shift is a constant, if not, we can't
690 // fold it.
691 if (ConstantSDNode *Sh =
692 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000693 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000694 if (!Subtarget->isCortexA9() ||
695 (N.hasOneUse() &&
696 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
697 Offset = N.getOperand(0).getOperand(0);
698 Base = N.getOperand(1);
699 } else {
700 ShAmt = 0;
701 ShOpcVal = ARM_AM::no_shift;
702 }
Evan Chenga8e29892007-01-19 07:51:42 +0000703 } else {
704 ShOpcVal = ARM_AM::no_shift;
705 }
706 }
707 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000708
Evan Chenga8e29892007-01-19 07:51:42 +0000709 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000710 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000711 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000712}
713
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000714bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000715 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000716 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000717 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
718 ? cast<LoadSDNode>(Op)->getAddressingMode()
719 : cast<StoreSDNode>(Op)->getAddressingMode();
720 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
721 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000722 int Val;
723 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
724 Offset = CurDAG->getRegister(0, MVT::i32);
725 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
726 ARM_AM::no_shift),
727 MVT::i32);
728 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000729 }
730
731 Offset = N;
732 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
733 unsigned ShAmt = 0;
734 if (ShOpcVal != ARM_AM::no_shift) {
735 // Check to see if the RHS of the shift is a constant, if not, we can't fold
736 // it.
737 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000738 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000739 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
740 Offset = N.getOperand(0);
741 else {
742 ShAmt = 0;
743 ShOpcVal = ARM_AM::no_shift;
744 }
Evan Chenga8e29892007-01-19 07:51:42 +0000745 } else {
746 ShOpcVal = ARM_AM::no_shift;
747 }
748 }
749
750 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000751 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000752 return true;
753}
754
Evan Chenga8e29892007-01-19 07:51:42 +0000755
Chris Lattner52a261b2010-09-21 20:31:19 +0000756bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000757 SDValue &Base, SDValue &Offset,
758 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000759 if (N.getOpcode() == ISD::SUB) {
760 // X - C is canonicalize to X + -C, no need to handle it here.
761 Base = N.getOperand(0);
762 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000763 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000764 return true;
765 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000766
Chris Lattner0a9481f2011-02-13 22:25:43 +0000767 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000768 Base = N;
769 if (N.getOpcode() == ISD::FrameIndex) {
770 int FI = cast<FrameIndexSDNode>(N)->getIndex();
771 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
772 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000773 Offset = CurDAG->getRegister(0, MVT::i32);
774 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000775 return true;
776 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000777
Evan Chenga8e29892007-01-19 07:51:42 +0000778 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000779 int RHSC;
780 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
781 -256 + 1, 256, RHSC)) { // 8 bits.
782 Base = N.getOperand(0);
783 if (Base.getOpcode() == ISD::FrameIndex) {
784 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
785 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000786 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000787 Offset = CurDAG->getRegister(0, MVT::i32);
788
789 ARM_AM::AddrOpc AddSub = ARM_AM::add;
790 if (RHSC < 0) {
791 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000792 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000793 }
794 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
795 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000796 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000797
Evan Chenga8e29892007-01-19 07:51:42 +0000798 Base = N.getOperand(0);
799 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000800 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000801 return true;
802}
803
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000804bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000805 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000806 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000807 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
808 ? cast<LoadSDNode>(Op)->getAddressingMode()
809 : cast<StoreSDNode>(Op)->getAddressingMode();
810 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
811 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000812 int Val;
813 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
814 Offset = CurDAG->getRegister(0, MVT::i32);
815 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
816 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000817 }
818
819 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000820 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000821 return true;
822}
823
Jim Grosbach3ab56582010-10-21 19:38:40 +0000824bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000825 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000826 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000827 Base = N;
828 if (N.getOpcode() == ISD::FrameIndex) {
829 int FI = cast<FrameIndexSDNode>(N)->getIndex();
830 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000831 } else if (N.getOpcode() == ARMISD::Wrapper &&
832 !(Subtarget->useMovt() &&
833 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000834 Base = N.getOperand(0);
835 }
836 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000837 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000838 return true;
839 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000840
Evan Chenga8e29892007-01-19 07:51:42 +0000841 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000842 int RHSC;
843 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
844 -256 + 1, 256, RHSC)) {
845 Base = N.getOperand(0);
846 if (Base.getOpcode() == ISD::FrameIndex) {
847 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
848 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000849 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000850
851 ARM_AM::AddrOpc AddSub = ARM_AM::add;
852 if (RHSC < 0) {
853 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000854 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000855 }
856 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
857 MVT::i32);
858 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000859 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000860
Evan Chenga8e29892007-01-19 07:51:42 +0000861 Base = N;
862 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000863 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000864 return true;
865}
866
Bob Wilson665814b2010-11-01 23:40:51 +0000867bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
868 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000869 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000870
871 unsigned Alignment = 0;
872 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
873 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
874 // The maximum alignment is equal to the memory size being referenced.
875 unsigned LSNAlign = LSN->getAlignment();
876 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
877 if (LSNAlign > MemSize && MemSize > 1)
878 Alignment = MemSize;
879 } else {
880 // All other uses of addrmode6 are for intrinsics. For now just record
881 // the raw alignment value; it will be refined later based on the legal
882 // alignment operands for the intrinsic.
883 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
884 }
885
886 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000887 return true;
888}
889
Bob Wilsonda525062011-02-25 06:42:42 +0000890bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
891 SDValue &Offset) {
892 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
893 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
894 if (AM != ISD::POST_INC)
895 return false;
896 Offset = N;
897 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
898 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
899 Offset = CurDAG->getRegister(0, MVT::i32);
900 }
901 return true;
902}
903
Chris Lattner52a261b2010-09-21 20:31:19 +0000904bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000905 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000906 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
907 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000908 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000909 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
910 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000911 return true;
912 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000913
Evan Chenga8e29892007-01-19 07:51:42 +0000914 return false;
915}
916
Bill Wendlingf4caf692010-12-14 03:36:38 +0000917
918//===----------------------------------------------------------------------===//
919// Thumb Addressing Modes
920//===----------------------------------------------------------------------===//
921
Chris Lattner52a261b2010-09-21 20:31:19 +0000922bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000923 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000924 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000925 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000926 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000927 return false;
928
929 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000930 return true;
931 }
932
Evan Chenga8e29892007-01-19 07:51:42 +0000933 Base = N.getOperand(0);
934 Offset = N.getOperand(1);
935 return true;
936}
937
Evan Cheng79d43262007-01-24 02:21:22 +0000938bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000939ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
940 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000941 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000942 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000943 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000944 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000945
Evan Cheng012f2d92007-01-24 08:53:17 +0000946 if (N.getOpcode() == ARMISD::Wrapper &&
947 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
948 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000949 }
950
Chris Lattner0a9481f2011-02-13 22:25:43 +0000951 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000952 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000953
Evan Chengad0e4652007-02-06 00:22:06 +0000954 // Thumb does not have [sp, r] address mode.
955 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
956 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
957 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000958 (RHSR && RHSR->getReg() == ARM::SP))
959 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000960
Daniel Dunbarec91d522011-01-19 15:12:16 +0000961 // FIXME: Why do we explicitly check for a match here and then return false?
962 // Presumably to allow something else to match, but shouldn't this be
963 // documented?
964 int RHSC;
965 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
966 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000967
968 Base = N.getOperand(0);
969 Offset = N.getOperand(1);
970 return true;
971}
972
973bool
974ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
975 SDValue &Base,
976 SDValue &Offset) {
977 return SelectThumbAddrModeRI(N, Base, Offset, 1);
978}
979
980bool
981ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
982 SDValue &Base,
983 SDValue &Offset) {
984 return SelectThumbAddrModeRI(N, Base, Offset, 2);
985}
986
987bool
988ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
989 SDValue &Base,
990 SDValue &Offset) {
991 return SelectThumbAddrModeRI(N, Base, Offset, 4);
992}
993
994bool
995ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
996 SDValue &Base, SDValue &OffImm) {
997 if (Scale == 4) {
998 SDValue TmpBase, TmpOffImm;
999 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1000 return false; // We want to select tLDRspi / tSTRspi instead.
1001
1002 if (N.getOpcode() == ARMISD::Wrapper &&
1003 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1004 return false; // We want to select tLDRpci instead.
1005 }
1006
Chris Lattner0a9481f2011-02-13 22:25:43 +00001007 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001008 if (N.getOpcode() == ARMISD::Wrapper &&
1009 !(Subtarget->useMovt() &&
1010 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1011 Base = N.getOperand(0);
1012 } else {
1013 Base = N;
1014 }
1015
Owen Anderson825b72b2009-08-11 20:47:22 +00001016 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001017 return true;
1018 }
1019
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001020 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1021 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1022 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1023 (RHSR && RHSR->getReg() == ARM::SP)) {
1024 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1025 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1026 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1027 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1028
1029 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1030 if (LHSC != 0 || RHSC != 0) return false;
1031
1032 Base = N;
1033 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1034 return true;
1035 }
1036
Evan Chenga8e29892007-01-19 07:51:42 +00001037 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001038 int RHSC;
1039 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1040 Base = N.getOperand(0);
1041 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1042 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001043 }
1044
Evan Chengc38f2bc2007-01-23 22:59:13 +00001045 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001046 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001047 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001048}
1049
Bill Wendlingf4caf692010-12-14 03:36:38 +00001050bool
1051ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1052 SDValue &OffImm) {
1053 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001054}
1055
Bill Wendlingf4caf692010-12-14 03:36:38 +00001056bool
1057ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1058 SDValue &OffImm) {
1059 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001060}
1061
Bill Wendlingf4caf692010-12-14 03:36:38 +00001062bool
1063ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1064 SDValue &OffImm) {
1065 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001066}
1067
Chris Lattner52a261b2010-09-21 20:31:19 +00001068bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1069 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001070 if (N.getOpcode() == ISD::FrameIndex) {
1071 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1072 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001073 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001074 return true;
1075 }
Evan Cheng79d43262007-01-24 02:21:22 +00001076
Chris Lattner0a9481f2011-02-13 22:25:43 +00001077 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001078 return false;
1079
1080 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001081 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1082 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001083 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001084 int RHSC;
1085 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1086 Base = N.getOperand(0);
1087 if (Base.getOpcode() == ISD::FrameIndex) {
1088 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1089 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001090 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001091 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1092 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001093 }
1094 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001095
Evan Chenga8e29892007-01-19 07:51:42 +00001096 return false;
1097}
1098
Bill Wendlingf4caf692010-12-14 03:36:38 +00001099
1100//===----------------------------------------------------------------------===//
1101// Thumb 2 Addressing Modes
1102//===----------------------------------------------------------------------===//
1103
1104
Chris Lattner52a261b2010-09-21 20:31:19 +00001105bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001106 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001107 if (DisableShifterOp)
1108 return false;
1109
Evan Cheng9cb9e672009-06-27 02:26:13 +00001110 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1111
1112 // Don't match base register only case. That is matched to a separate
1113 // lower complexity pattern with explicit register operand.
1114 if (ShOpcVal == ARM_AM::no_shift) return false;
1115
1116 BaseReg = N.getOperand(0);
1117 unsigned ShImmVal = 0;
1118 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1119 ShImmVal = RHS->getZExtValue() & 31;
1120 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1121 return true;
1122 }
1123
1124 return false;
1125}
1126
Chris Lattner52a261b2010-09-21 20:31:19 +00001127bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001128 SDValue &Base, SDValue &OffImm) {
1129 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001130
Evan Cheng3a214252009-08-11 08:52:18 +00001131 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001132 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1133 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001134 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001135 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001136 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1137 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001138 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001139 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001140 }
1141
1142 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001143 !(Subtarget->useMovt() &&
1144 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001145 Base = N.getOperand(0);
1146 if (Base.getOpcode() == ISD::TargetConstantPool)
1147 return false; // We want to select t2LDRpci instead.
1148 } else
1149 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001150 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001151 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001152 }
Evan Cheng055b0312009-06-29 07:51:04 +00001153
1154 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001155 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001156 // Let t2LDRi8 handle (R - imm8).
1157 return false;
1158
Evan Cheng055b0312009-06-29 07:51:04 +00001159 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001160 if (N.getOpcode() == ISD::SUB)
1161 RHSC = -RHSC;
1162
1163 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001164 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001165 if (Base.getOpcode() == ISD::FrameIndex) {
1166 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1167 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1168 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001169 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001170 return true;
1171 }
1172 }
1173
Evan Cheng3a214252009-08-11 08:52:18 +00001174 // Base only.
1175 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001176 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001177 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001178}
1179
Chris Lattner52a261b2010-09-21 20:31:19 +00001180bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001181 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001182 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001183 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1184 !CurDAG->isBaseWithConstantOffset(N))
1185 return false;
1186
1187 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1188 int RHSC = (int)RHS->getSExtValue();
1189 if (N.getOpcode() == ISD::SUB)
1190 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001191
Chris Lattner0a9481f2011-02-13 22:25:43 +00001192 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1193 Base = N.getOperand(0);
1194 if (Base.getOpcode() == ISD::FrameIndex) {
1195 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1196 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001197 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001198 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1199 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001200 }
1201 }
1202
1203 return false;
1204}
1205
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001206bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001207 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001208 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001209 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1210 ? cast<LoadSDNode>(Op)->getAddressingMode()
1211 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001212 int RHSC;
1213 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1214 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1215 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1216 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1217 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001218 }
1219
1220 return false;
1221}
1222
Chris Lattner52a261b2010-09-21 20:31:19 +00001223bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001224 SDValue &Base,
1225 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001226 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001227 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001228 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001229
Evan Cheng3a214252009-08-11 08:52:18 +00001230 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1231 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1232 int RHSC = (int)RHS->getZExtValue();
1233 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1234 return false;
1235 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001236 return false;
1237 }
1238
Evan Chengf40deed2010-10-27 23:41:30 +00001239 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1240 // Compute R + (R << [1,2,3]) and reuse it.
1241 Base = N;
1242 return false;
1243 }
1244
Evan Cheng055b0312009-06-29 07:51:04 +00001245 // Look for (R + R) or (R + (R << [1,2,3])).
1246 unsigned ShAmt = 0;
1247 Base = N.getOperand(0);
1248 OffReg = N.getOperand(1);
1249
1250 // Swap if it is ((R << c) + R).
1251 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1252 if (ShOpcVal != ARM_AM::lsl) {
1253 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1254 if (ShOpcVal == ARM_AM::lsl)
1255 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001256 }
1257
Evan Cheng055b0312009-06-29 07:51:04 +00001258 if (ShOpcVal == ARM_AM::lsl) {
1259 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1260 // it.
1261 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1262 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001263 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1264 OffReg = OffReg.getOperand(0);
1265 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001266 ShAmt = 0;
1267 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001268 }
Evan Cheng055b0312009-06-29 07:51:04 +00001269 } else {
1270 ShOpcVal = ARM_AM::no_shift;
1271 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001272 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001273
Owen Anderson825b72b2009-08-11 20:47:22 +00001274 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001275
1276 return true;
1277}
1278
1279//===--------------------------------------------------------------------===//
1280
Evan Chengee568cf2007-07-05 07:15:27 +00001281/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001282static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001283 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001284}
1285
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001286SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1287 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001288 ISD::MemIndexedMode AM = LD->getAddressingMode();
1289 if (AM == ISD::UNINDEXED)
1290 return NULL;
1291
Owen Andersone50ed302009-08-10 22:56:29 +00001292 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001293 SDValue Offset, AMOpc;
1294 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1295 unsigned Opcode = 0;
1296 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001297 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001298 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001299 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1300 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001301 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001302 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001303 Match = true;
1304 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1305 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1306 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001307 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001308 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001309 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001310 Match = true;
1311 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1312 }
1313 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001314 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001315 Match = true;
1316 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1317 }
1318 }
1319 }
1320
1321 if (Match) {
1322 SDValue Chain = LD->getChain();
1323 SDValue Base = LD->getBasePtr();
1324 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001325 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001326 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001327 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001328 }
1329
1330 return NULL;
1331}
1332
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001333SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1334 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001335 ISD::MemIndexedMode AM = LD->getAddressingMode();
1336 if (AM == ISD::UNINDEXED)
1337 return NULL;
1338
Owen Andersone50ed302009-08-10 22:56:29 +00001339 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001340 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001341 SDValue Offset;
1342 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1343 unsigned Opcode = 0;
1344 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001345 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001346 switch (LoadedVT.getSimpleVT().SimpleTy) {
1347 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001348 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1349 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001350 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001351 if (isSExtLd)
1352 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1353 else
1354 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001355 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001356 case MVT::i8:
1357 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001358 if (isSExtLd)
1359 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1360 else
1361 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001362 break;
1363 default:
1364 return NULL;
1365 }
1366 Match = true;
1367 }
1368
1369 if (Match) {
1370 SDValue Chain = LD->getChain();
1371 SDValue Base = LD->getBasePtr();
1372 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001373 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001374 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001375 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001376 }
1377
1378 return NULL;
1379}
1380
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001381/// PairSRegs - Form a D register from a pair of S registers.
1382///
1383SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1384 DebugLoc dl = V0.getNode()->getDebugLoc();
1385 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1386 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001387 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1388 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001389}
1390
Evan Cheng603afbf2010-05-10 17:34:18 +00001391/// PairDRegs - Form a quad register from a pair of D registers.
1392///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001393SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1394 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001395 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1396 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001397 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1398 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001399}
1400
Evan Cheng7f687192010-05-14 00:21:45 +00001401/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001402///
1403SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1404 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001405 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1406 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001407 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1408 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1409}
1410
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001411/// QuadSRegs - Form 4 consecutive S registers.
1412///
1413SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1414 SDValue V2, SDValue V3) {
1415 DebugLoc dl = V0.getNode()->getDebugLoc();
1416 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1417 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1418 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1419 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1420 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1421 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1422}
1423
Evan Cheng7f687192010-05-14 00:21:45 +00001424/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001425///
1426SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1427 SDValue V2, SDValue V3) {
1428 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001429 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1430 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1431 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1432 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001433 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1434 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1435}
1436
Evan Cheng8f6de382010-05-16 03:27:48 +00001437/// QuadQRegs - Form 4 consecutive Q registers.
1438///
1439SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1440 SDValue V2, SDValue V3) {
1441 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001442 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1443 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1444 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1445 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001446 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1447 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1448}
1449
Bob Wilson2a6e6162010-09-23 23:42:37 +00001450/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1451/// of a NEON VLD or VST instruction. The supported values depend on the
1452/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001453SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1454 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001455 unsigned NumRegs = NumVecs;
1456 if (!is64BitVector && NumVecs < 3)
1457 NumRegs *= 2;
1458
Bob Wilson665814b2010-11-01 23:40:51 +00001459 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001460 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001461 Alignment = 32;
1462 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1463 Alignment = 16;
1464 else if (Alignment >= 8)
1465 Alignment = 8;
1466 else
1467 Alignment = 0;
1468
1469 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001470}
1471
Bob Wilson1c3ef902011-02-07 17:43:21 +00001472SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001473 unsigned *DOpcodes, unsigned *QOpcodes0,
1474 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001475 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001476 DebugLoc dl = N->getDebugLoc();
1477
Bob Wilson226036e2010-03-20 22:13:40 +00001478 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001479 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1480 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001481 return NULL;
1482
1483 SDValue Chain = N->getOperand(0);
1484 EVT VT = N->getValueType(0);
1485 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001486 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001487
Bob Wilson3e36f132009-10-14 17:28:52 +00001488 unsigned OpcodeIndex;
1489 switch (VT.getSimpleVT().SimpleTy) {
1490 default: llvm_unreachable("unhandled vld type");
1491 // Double-register operations:
1492 case MVT::v8i8: OpcodeIndex = 0; break;
1493 case MVT::v4i16: OpcodeIndex = 1; break;
1494 case MVT::v2f32:
1495 case MVT::v2i32: OpcodeIndex = 2; break;
1496 case MVT::v1i64: OpcodeIndex = 3; break;
1497 // Quad-register operations:
1498 case MVT::v16i8: OpcodeIndex = 0; break;
1499 case MVT::v8i16: OpcodeIndex = 1; break;
1500 case MVT::v4f32:
1501 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001502 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001503 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001504 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001505 }
1506
Bob Wilsonf5721912010-09-03 18:16:02 +00001507 EVT ResTy;
1508 if (NumVecs == 1)
1509 ResTy = VT;
1510 else {
1511 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1512 if (!is64BitVector)
1513 ResTyElts *= 2;
1514 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1515 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001516 std::vector<EVT> ResTys;
1517 ResTys.push_back(ResTy);
1518 if (isUpdating)
1519 ResTys.push_back(MVT::i32);
1520 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001521
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001522 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001523 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001524 SDNode *VLd;
1525 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001526
Bob Wilson1c3ef902011-02-07 17:43:21 +00001527 // Double registers and VLD1/VLD2 quad registers are directly supported.
1528 if (is64BitVector || NumVecs <= 2) {
1529 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1530 QOpcodes0[OpcodeIndex]);
1531 Ops.push_back(MemAddr);
1532 Ops.push_back(Align);
1533 if (isUpdating) {
1534 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1535 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001536 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001537 Ops.push_back(Pred);
1538 Ops.push_back(Reg0);
1539 Ops.push_back(Chain);
1540 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001541
Bob Wilson3e36f132009-10-14 17:28:52 +00001542 } else {
1543 // Otherwise, quad registers are loaded with two separate instructions,
1544 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001545 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001546
Bob Wilson1c3ef902011-02-07 17:43:21 +00001547 // Load the even subregs. This is always an updating load, so that it
1548 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001549 SDValue ImplDef =
1550 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1551 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001552 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1553 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001554 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001555
Bob Wilson24f995d2009-10-14 18:32:29 +00001556 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001557 Ops.push_back(SDValue(VLdA, 1));
1558 Ops.push_back(Align);
1559 if (isUpdating) {
1560 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1561 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1562 "only constant post-increment update allowed for VLD3/4");
1563 (void)Inc;
1564 Ops.push_back(Reg0);
1565 }
1566 Ops.push_back(SDValue(VLdA, 0));
1567 Ops.push_back(Pred);
1568 Ops.push_back(Reg0);
1569 Ops.push_back(Chain);
1570 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1571 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001572 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001573
Bob Wilson1c3ef902011-02-07 17:43:21 +00001574 if (NumVecs == 1)
1575 return VLd;
1576
1577 // Extract out the subregisters.
1578 SDValue SuperReg = SDValue(VLd, 0);
1579 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1580 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1581 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1582 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1583 ReplaceUses(SDValue(N, Vec),
1584 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1585 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1586 if (isUpdating)
1587 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001588 return NULL;
1589}
1590
Bob Wilson1c3ef902011-02-07 17:43:21 +00001591SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001592 unsigned *DOpcodes, unsigned *QOpcodes0,
1593 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001594 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001595 DebugLoc dl = N->getDebugLoc();
1596
Bob Wilson226036e2010-03-20 22:13:40 +00001597 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001598 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1599 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1600 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001601 return NULL;
1602
1603 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001604 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001605 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001606 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001607
Bob Wilson24f995d2009-10-14 18:32:29 +00001608 unsigned OpcodeIndex;
1609 switch (VT.getSimpleVT().SimpleTy) {
1610 default: llvm_unreachable("unhandled vst type");
1611 // Double-register operations:
1612 case MVT::v8i8: OpcodeIndex = 0; break;
1613 case MVT::v4i16: OpcodeIndex = 1; break;
1614 case MVT::v2f32:
1615 case MVT::v2i32: OpcodeIndex = 2; break;
1616 case MVT::v1i64: OpcodeIndex = 3; break;
1617 // Quad-register operations:
1618 case MVT::v16i8: OpcodeIndex = 0; break;
1619 case MVT::v8i16: OpcodeIndex = 1; break;
1620 case MVT::v4f32:
1621 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001622 case MVT::v2i64: OpcodeIndex = 3;
1623 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1624 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001625 }
1626
Bob Wilson1c3ef902011-02-07 17:43:21 +00001627 std::vector<EVT> ResTys;
1628 if (isUpdating)
1629 ResTys.push_back(MVT::i32);
1630 ResTys.push_back(MVT::Other);
1631
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001632 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001633 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001634 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001635
Bob Wilson1c3ef902011-02-07 17:43:21 +00001636 // Double registers and VST1/VST2 quad registers are directly supported.
1637 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001638 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001639 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001640 SrcReg = N->getOperand(Vec0Idx);
1641 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001642 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001643 SDValue V0 = N->getOperand(Vec0Idx + 0);
1644 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001645 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001646 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001647 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001648 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001649 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001650 // an undef.
1651 SDValue V3 = (NumVecs == 3)
1652 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001653 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001654 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001655 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001656 } else {
1657 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001658 SDValue Q0 = N->getOperand(Vec0Idx);
1659 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001660 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001661 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001662
1663 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1664 QOpcodes0[OpcodeIndex]);
1665 Ops.push_back(MemAddr);
1666 Ops.push_back(Align);
1667 if (isUpdating) {
1668 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1669 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1670 }
1671 Ops.push_back(SrcReg);
1672 Ops.push_back(Pred);
1673 Ops.push_back(Reg0);
1674 Ops.push_back(Chain);
1675 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001676 }
1677
1678 // Otherwise, quad registers are stored with two separate instructions,
1679 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001680
Bob Wilson07f6e802010-06-16 21:34:01 +00001681 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001682 SDValue V0 = N->getOperand(Vec0Idx + 0);
1683 SDValue V1 = N->getOperand(Vec0Idx + 1);
1684 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001685 SDValue V3 = (NumVecs == 3)
1686 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001687 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001688 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001689
Bob Wilson1c3ef902011-02-07 17:43:21 +00001690 // Store the even D registers. This is always an updating store, so that it
1691 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001692 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1693 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1694 MemAddr.getValueType(),
1695 MVT::Other, OpsA, 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001696 Chain = SDValue(VStA, 1);
1697
1698 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001699 Ops.push_back(SDValue(VStA, 0));
1700 Ops.push_back(Align);
1701 if (isUpdating) {
1702 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1703 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1704 "only constant post-increment update allowed for VST3/4");
1705 (void)Inc;
1706 Ops.push_back(Reg0);
1707 }
1708 Ops.push_back(RegSeq);
1709 Ops.push_back(Pred);
1710 Ops.push_back(Reg0);
1711 Ops.push_back(Chain);
1712 return CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1713 Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001714}
1715
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001716SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001717 bool isUpdating, unsigned NumVecs,
1718 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001719 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001720 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001721 DebugLoc dl = N->getDebugLoc();
1722
Bob Wilson226036e2010-03-20 22:13:40 +00001723 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001724 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1725 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1726 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001727 return NULL;
1728
1729 SDValue Chain = N->getOperand(0);
1730 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001731 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1732 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001733 bool is64BitVector = VT.is64BitVector();
1734
Bob Wilson665814b2010-11-01 23:40:51 +00001735 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001736 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001737 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001738 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1739 if (Alignment > NumBytes)
1740 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001741 if (Alignment < 8 && Alignment < NumBytes)
1742 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001743 // Alignment must be a power of two; make sure of that.
1744 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001745 if (Alignment == 1)
1746 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001747 }
Bob Wilson665814b2010-11-01 23:40:51 +00001748 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001749
Bob Wilsona7c397c2009-10-14 16:19:03 +00001750 unsigned OpcodeIndex;
1751 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001752 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001753 // Double-register operations:
1754 case MVT::v8i8: OpcodeIndex = 0; break;
1755 case MVT::v4i16: OpcodeIndex = 1; break;
1756 case MVT::v2f32:
1757 case MVT::v2i32: OpcodeIndex = 2; break;
1758 // Quad-register operations:
1759 case MVT::v8i16: OpcodeIndex = 0; break;
1760 case MVT::v4f32:
1761 case MVT::v4i32: OpcodeIndex = 1; break;
1762 }
1763
Bob Wilson1c3ef902011-02-07 17:43:21 +00001764 std::vector<EVT> ResTys;
1765 if (IsLoad) {
1766 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1767 if (!is64BitVector)
1768 ResTyElts *= 2;
1769 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1770 MVT::i64, ResTyElts));
1771 }
1772 if (isUpdating)
1773 ResTys.push_back(MVT::i32);
1774 ResTys.push_back(MVT::Other);
1775
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001776 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001777 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001778
Bob Wilson1c3ef902011-02-07 17:43:21 +00001779 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001780 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001781 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001782 if (isUpdating) {
1783 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1784 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1785 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001786
Bob Wilson8466fa12010-09-13 23:01:35 +00001787 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001788 SDValue V0 = N->getOperand(Vec0Idx + 0);
1789 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001790 if (NumVecs == 2) {
1791 if (is64BitVector)
1792 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1793 else
1794 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001795 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001796 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001797 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1799 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001800 if (is64BitVector)
1801 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1802 else
1803 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001804 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001805 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001806 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001807 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001808 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001809 Ops.push_back(Chain);
1810
Bob Wilson1c3ef902011-02-07 17:43:21 +00001811 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1812 QOpcodes[OpcodeIndex]);
1813 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1814 Ops.data(), Ops.size());
Bob Wilson96493442009-10-14 16:46:45 +00001815 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001816 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001817
Bob Wilson8466fa12010-09-13 23:01:35 +00001818 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001819 SuperReg = SDValue(VLdLn, 0);
1820 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1821 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1822 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001823 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1824 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001825 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1826 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1827 if (isUpdating)
1828 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001829 return NULL;
1830}
1831
Bob Wilson1c3ef902011-02-07 17:43:21 +00001832SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1833 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001834 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1835 DebugLoc dl = N->getDebugLoc();
1836
1837 SDValue MemAddr, Align;
1838 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1839 return NULL;
1840
1841 SDValue Chain = N->getOperand(0);
1842 EVT VT = N->getValueType(0);
1843
1844 unsigned Alignment = 0;
1845 if (NumVecs != 3) {
1846 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1847 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1848 if (Alignment > NumBytes)
1849 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001850 if (Alignment < 8 && Alignment < NumBytes)
1851 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001852 // Alignment must be a power of two; make sure of that.
1853 Alignment = (Alignment & -Alignment);
1854 if (Alignment == 1)
1855 Alignment = 0;
1856 }
1857 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1858
1859 unsigned OpcodeIndex;
1860 switch (VT.getSimpleVT().SimpleTy) {
1861 default: llvm_unreachable("unhandled vld-dup type");
1862 case MVT::v8i8: OpcodeIndex = 0; break;
1863 case MVT::v4i16: OpcodeIndex = 1; break;
1864 case MVT::v2f32:
1865 case MVT::v2i32: OpcodeIndex = 2; break;
1866 }
1867
1868 SDValue Pred = getAL(CurDAG);
1869 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1870 SDValue SuperReg;
1871 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001872 SmallVector<SDValue, 6> Ops;
1873 Ops.push_back(MemAddr);
1874 Ops.push_back(Align);
1875 if (isUpdating) {
1876 SDValue Inc = N->getOperand(2);
1877 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1878 }
1879 Ops.push_back(Pred);
1880 Ops.push_back(Reg0);
1881 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001882
1883 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 std::vector<EVT> ResTys;
1885 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts));
1886 if (isUpdating)
1887 ResTys.push_back(MVT::i32);
1888 ResTys.push_back(MVT::Other);
1889 SDNode *VLdDup =
1890 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001891 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001892
1893 // Extract the subregisters.
1894 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1895 unsigned SubIdx = ARM::dsub_0;
1896 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1897 ReplaceUses(SDValue(N, Vec),
1898 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001899 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1900 if (isUpdating)
1901 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001902 return NULL;
1903}
1904
Bob Wilson78dfbc32010-07-07 00:08:54 +00001905SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1906 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001907 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1908 DebugLoc dl = N->getDebugLoc();
1909 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001910 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001911
1912 // Form a REG_SEQUENCE to force register allocation.
1913 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001914 SDValue V0 = N->getOperand(FirstTblReg + 0);
1915 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001916 if (NumVecs == 2)
1917 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1918 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001919 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001920 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001921 // an undef.
1922 SDValue V3 = (NumVecs == 3)
1923 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001924 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001925 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1926 }
1927
Bob Wilson78dfbc32010-07-07 00:08:54 +00001928 SmallVector<SDValue, 6> Ops;
1929 if (IsExt)
1930 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001931 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001932 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001933 Ops.push_back(getAL(CurDAG)); // predicate
1934 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001935 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001936}
1937
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001938SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001939 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001940 if (!Subtarget->hasV6T2Ops())
1941 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001942
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001943 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1944 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1945
1946
1947 // For unsigned extracts, check for a shift right and mask
1948 unsigned And_imm = 0;
1949 if (N->getOpcode() == ISD::AND) {
1950 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1951
1952 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1953 if (And_imm & (And_imm + 1))
1954 return NULL;
1955
1956 unsigned Srl_imm = 0;
1957 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1958 Srl_imm)) {
1959 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1960
1961 unsigned Width = CountTrailingOnes_32(And_imm);
1962 unsigned LSB = Srl_imm;
1963 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1964 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1965 CurDAG->getTargetConstant(LSB, MVT::i32),
1966 CurDAG->getTargetConstant(Width, MVT::i32),
1967 getAL(CurDAG), Reg0 };
1968 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1969 }
1970 }
1971 return NULL;
1972 }
1973
1974 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001975 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001977 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1978 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001980 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1981 unsigned Width = 32 - Srl_imm;
1982 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001983 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001984 return NULL;
1985 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001986 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001987 CurDAG->getTargetConstant(LSB, MVT::i32),
1988 CurDAG->getTargetConstant(Width, MVT::i32),
1989 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001990 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001991 }
1992 }
1993 return NULL;
1994}
1995
Evan Cheng9ef48352009-11-20 00:54:03 +00001996SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001997SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001998 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1999 SDValue CPTmp0;
2000 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002001 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002002 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2003 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2004 unsigned Opc = 0;
2005 switch (SOShOp) {
2006 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2007 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2008 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2009 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2010 default:
2011 llvm_unreachable("Unknown so_reg opcode!");
2012 break;
2013 }
2014 SDValue SOShImm =
2015 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2016 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2017 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002018 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002019 }
2020 return 0;
2021}
2022
2023SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002024SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002025 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2026 SDValue CPTmp0;
2027 SDValue CPTmp1;
2028 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002029 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002030 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2031 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002032 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002033 }
2034 return 0;
2035}
2036
2037SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002038SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002039 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002040 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002041 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002042 return 0;
2043
Evan Cheng63f35442010-11-13 02:25:14 +00002044 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002045 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002046 if (is_t2_so_imm(TrueImm)) {
2047 Opc = ARM::t2MOVCCi;
2048 } else if (TrueImm <= 0xffff) {
2049 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002050 } else if (is_t2_so_imm_not(TrueImm)) {
2051 TrueImm = ~TrueImm;
2052 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002053 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002054 // Large immediate.
2055 Opc = ARM::t2MOVCCi32imm;
2056 }
2057
2058 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002059 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002060 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2061 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002062 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002063 }
Evan Cheng63f35442010-11-13 02:25:14 +00002064
Evan Cheng9ef48352009-11-20 00:54:03 +00002065 return 0;
2066}
2067
2068SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002069SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002070 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002071 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2072 if (!T)
2073 return 0;
2074
Evan Cheng63f35442010-11-13 02:25:14 +00002075 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002076 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002077 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002078 if (isSoImm) {
2079 Opc = ARM::MOVCCi;
2080 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2081 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002082 } else if (is_so_imm_not(TrueImm)) {
2083 TrueImm = ~TrueImm;
2084 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002085 } else if (TrueVal.getNode()->hasOneUse() &&
2086 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002087 // Large immediate.
2088 Opc = ARM::MOVCCi32imm;
2089 }
2090
2091 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002092 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002093 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2094 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002095 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002096 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002097
Evan Cheng9ef48352009-11-20 00:54:03 +00002098 return 0;
2099}
2100
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002101SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2102 EVT VT = N->getValueType(0);
2103 SDValue FalseVal = N->getOperand(0);
2104 SDValue TrueVal = N->getOperand(1);
2105 SDValue CC = N->getOperand(2);
2106 SDValue CCR = N->getOperand(3);
2107 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002108 assert(CC.getOpcode() == ISD::Constant);
2109 assert(CCR.getOpcode() == ISD::Register);
2110 ARMCC::CondCodes CCVal =
2111 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002112
2113 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2114 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2115 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2116 // Pattern complexity = 18 cost = 1 size = 0
2117 SDValue CPTmp0;
2118 SDValue CPTmp1;
2119 SDValue CPTmp2;
2120 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002121 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002122 CCVal, CCR, InFlag);
2123 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002124 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002125 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2126 if (Res)
2127 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002128 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002129 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002130 CCVal, CCR, InFlag);
2131 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002132 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002133 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2134 if (Res)
2135 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002136 }
2137
2138 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002139 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002140 // (imm:i32):$cc)
2141 // Emits: (MOVCCi:i32 GPR:i32:$false,
2142 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2143 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002144 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002145 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002146 CCVal, CCR, InFlag);
2147 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002148 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002149 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2150 if (Res)
2151 return Res;
2152 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002153 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 CCVal, CCR, InFlag);
2155 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002156 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002157 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2158 if (Res)
2159 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002160 }
2161 }
2162
2163 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2164 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2165 // Pattern complexity = 6 cost = 1 size = 0
2166 //
2167 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2168 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2169 // Pattern complexity = 6 cost = 11 size = 0
2170 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002171 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2173 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002174 unsigned Opc = 0;
2175 switch (VT.getSimpleVT().SimpleTy) {
2176 default: assert(false && "Illegal conditional move type!");
2177 break;
2178 case MVT::i32:
2179 Opc = Subtarget->isThumb()
2180 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2181 : ARM::MOVCCr;
2182 break;
2183 case MVT::f32:
2184 Opc = ARM::VMOVScc;
2185 break;
2186 case MVT::f64:
2187 Opc = ARM::VMOVDcc;
2188 break;
2189 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002190 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002191}
2192
Evan Chengde8aa4e2010-05-05 18:28:36 +00002193SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2194 // The only time a CONCAT_VECTORS operation can have legal types is when
2195 // two 64-bit vectors are concatenated to a 128-bit vector.
2196 EVT VT = N->getValueType(0);
2197 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2198 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002199 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002200}
2201
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002202SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002203 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002204
Dan Gohmane8be6c62008-07-17 19:10:17 +00002205 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002206 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002207
2208 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002209 default: break;
2210 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002211 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002212 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002213 if (Subtarget->hasThumb2())
2214 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2215 // be done with MOV + MOVT, at worst.
2216 UseCP = 0;
2217 else {
2218 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002219 UseCP = (Val > 255 && // MOV
2220 ~Val > 255 && // MOV + MVN
2221 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002222 } else
2223 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2224 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2225 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2226 }
2227
Evan Chenga8e29892007-01-19 07:51:42 +00002228 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002229 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002230 CurDAG->getTargetConstantPool(ConstantInt::get(
2231 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002232 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002233
2234 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002235 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002236 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002237 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002238 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002239 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002240 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002241 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002242 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002243 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002244 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002245 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002246 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002247 CurDAG->getEntryNode()
2248 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002249 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002250 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002251 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002252 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002253 return NULL;
2254 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002255
Evan Chenga8e29892007-01-19 07:51:42 +00002256 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002257 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002258 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002259 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002260 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002261 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002262 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002263 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002264 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2265 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002266 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002267 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2268 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002269 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2270 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2271 CurDAG->getRegister(0, MVT::i32) };
2272 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002273 }
Evan Chenga8e29892007-01-19 07:51:42 +00002274 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002275 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002276 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002277 return I;
2278 break;
2279 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002280 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002281 return I;
2282 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002283 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002284 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002285 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002286 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002287 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002288 if (!RHSV) break;
2289 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002290 unsigned ShImm = Log2_32(RHSV-1);
2291 if (ShImm >= 32)
2292 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002293 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002294 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002295 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2296 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002297 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002298 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002299 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002300 } else {
2301 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002302 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002303 }
Evan Chenga8e29892007-01-19 07:51:42 +00002304 }
2305 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002306 unsigned ShImm = Log2_32(RHSV+1);
2307 if (ShImm >= 32)
2308 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002309 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002310 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002311 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2312 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002313 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002314 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2315 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002316 } else {
2317 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002318 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002319 }
Evan Chenga8e29892007-01-19 07:51:42 +00002320 }
2321 }
2322 break;
Evan Cheng20956592009-10-21 08:15:52 +00002323 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002324 // Check for unsigned bitfield extract
2325 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2326 return I;
2327
Evan Cheng20956592009-10-21 08:15:52 +00002328 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2329 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2330 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2331 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2332 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002333 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002334 if (VT != MVT::i32)
2335 break;
2336 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2337 ? ARM::t2MOVTi16
2338 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2339 if (!Opc)
2340 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002341 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002342 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2343 if (!N1C)
2344 break;
2345 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2346 SDValue N2 = N0.getOperand(1);
2347 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2348 if (!N2C)
2349 break;
2350 unsigned N1CVal = N1C->getZExtValue();
2351 unsigned N2CVal = N2C->getZExtValue();
2352 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2353 (N1CVal & 0xffffU) == 0xffffU &&
2354 (N2CVal & 0xffffU) == 0x0U) {
2355 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2356 MVT::i32);
2357 SDValue Ops[] = { N0.getOperand(0), Imm16,
2358 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2359 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2360 }
2361 }
2362 break;
2363 }
Jim Grosbache5165492009-11-09 00:11:35 +00002364 case ARMISD::VMOVRRD:
2365 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002366 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002367 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002368 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002369 if (Subtarget->isThumb1Only())
2370 break;
2371 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002372 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002373 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2374 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002375 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002376 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002377 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002378 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2379 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002380 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2381 ARM::UMULL : ARM::UMULLv5,
2382 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002383 }
Evan Chengee568cf2007-07-05 07:15:27 +00002384 }
Dan Gohman525178c2007-10-08 18:33:35 +00002385 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002386 if (Subtarget->isThumb1Only())
2387 break;
2388 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002389 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002390 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002391 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002392 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002393 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002394 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2395 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002396 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2397 ARM::SMULL : ARM::SMULLv5,
2398 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002399 }
Evan Chengee568cf2007-07-05 07:15:27 +00002400 }
Evan Chenga8e29892007-01-19 07:51:42 +00002401 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002402 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002403 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002404 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002405 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002406 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002407 if (ResNode)
2408 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002409 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002410 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002411 }
Evan Chengee568cf2007-07-05 07:15:27 +00002412 case ARMISD::BRCOND: {
2413 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2414 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2415 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002416
Evan Chengee568cf2007-07-05 07:15:27 +00002417 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2418 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2419 // Pattern complexity = 6 cost = 1 size = 0
2420
David Goodwin5e47a9a2009-06-30 18:04:13 +00002421 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2422 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2423 // Pattern complexity = 6 cost = 1 size = 0
2424
Jim Grosbach764ab522009-08-11 15:33:49 +00002425 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002426 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002427 SDValue Chain = N->getOperand(0);
2428 SDValue N1 = N->getOperand(1);
2429 SDValue N2 = N->getOperand(2);
2430 SDValue N3 = N->getOperand(3);
2431 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002432 assert(N1.getOpcode() == ISD::BasicBlock);
2433 assert(N2.getOpcode() == ISD::Constant);
2434 assert(N3.getOpcode() == ISD::Register);
2435
Dan Gohman475871a2008-07-27 21:46:04 +00002436 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002437 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002438 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002439 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002440 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002441 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002442 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002443 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002444 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002445 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002446 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002447 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002448 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002449 return NULL;
2450 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002451 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002452 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002453 case ARMISD::VZIP: {
2454 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002455 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002456 switch (VT.getSimpleVT().SimpleTy) {
2457 default: return NULL;
2458 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2459 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2460 case MVT::v2f32:
2461 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2462 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2463 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2464 case MVT::v4f32:
2465 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2466 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002467 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002468 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2469 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2470 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002471 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002472 case ARMISD::VUZP: {
2473 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002474 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002475 switch (VT.getSimpleVT().SimpleTy) {
2476 default: return NULL;
2477 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2478 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2479 case MVT::v2f32:
2480 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2481 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2482 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2483 case MVT::v4f32:
2484 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2485 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002486 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002487 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2488 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2489 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002490 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002491 case ARMISD::VTRN: {
2492 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002493 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002494 switch (VT.getSimpleVT().SimpleTy) {
2495 default: return NULL;
2496 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2497 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2498 case MVT::v2f32:
2499 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2500 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2501 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2502 case MVT::v4f32:
2503 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2504 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002505 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002506 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2507 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2508 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002509 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002510 case ARMISD::BUILD_VECTOR: {
2511 EVT VecVT = N->getValueType(0);
2512 EVT EltVT = VecVT.getVectorElementType();
2513 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002514 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002515 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2516 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2517 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002518 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002519 if (NumElts == 2)
2520 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2521 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2522 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2523 N->getOperand(2), N->getOperand(3));
2524 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002525
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002526 case ARMISD::VLD2DUP: {
2527 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2528 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002529 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002530 }
2531
Bob Wilson86c6d802010-11-29 19:35:29 +00002532 case ARMISD::VLD3DUP: {
2533 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2534 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002535 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002536 }
2537
Bob Wilson6c4c9822010-11-30 00:00:35 +00002538 case ARMISD::VLD4DUP: {
2539 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2540 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002541 return SelectVLDDup(N, false, 4, Opcodes);
2542 }
2543
2544 case ARMISD::VLD2DUP_UPD: {
2545 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2546 ARM::VLD2DUPd32Pseudo_UPD };
2547 return SelectVLDDup(N, true, 2, Opcodes);
2548 }
2549
2550 case ARMISD::VLD3DUP_UPD: {
2551 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2552 ARM::VLD3DUPd32Pseudo_UPD };
2553 return SelectVLDDup(N, true, 3, Opcodes);
2554 }
2555
2556 case ARMISD::VLD4DUP_UPD: {
2557 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2558 ARM::VLD4DUPd32Pseudo_UPD };
2559 return SelectVLDDup(N, true, 4, Opcodes);
2560 }
2561
2562 case ARMISD::VLD1_UPD: {
2563 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2564 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2565 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2566 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2567 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2568 }
2569
2570 case ARMISD::VLD2_UPD: {
2571 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2572 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2573 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2574 ARM::VLD2q32Pseudo_UPD };
2575 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2576 }
2577
2578 case ARMISD::VLD3_UPD: {
2579 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2580 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2581 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2582 ARM::VLD3q16Pseudo_UPD,
2583 ARM::VLD3q32Pseudo_UPD };
2584 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2585 ARM::VLD3q16oddPseudo_UPD,
2586 ARM::VLD3q32oddPseudo_UPD };
2587 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2588 }
2589
2590 case ARMISD::VLD4_UPD: {
2591 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2592 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2593 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2594 ARM::VLD4q16Pseudo_UPD,
2595 ARM::VLD4q32Pseudo_UPD };
2596 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2597 ARM::VLD4q16oddPseudo_UPD,
2598 ARM::VLD4q32oddPseudo_UPD };
2599 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2600 }
2601
2602 case ARMISD::VLD2LN_UPD: {
2603 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2604 ARM::VLD2LNd32Pseudo_UPD };
2605 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2606 ARM::VLD2LNq32Pseudo_UPD };
2607 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2608 }
2609
2610 case ARMISD::VLD3LN_UPD: {
2611 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2612 ARM::VLD3LNd32Pseudo_UPD };
2613 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2614 ARM::VLD3LNq32Pseudo_UPD };
2615 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2616 }
2617
2618 case ARMISD::VLD4LN_UPD: {
2619 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2620 ARM::VLD4LNd32Pseudo_UPD };
2621 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2622 ARM::VLD4LNq32Pseudo_UPD };
2623 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2624 }
2625
2626 case ARMISD::VST1_UPD: {
2627 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2628 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2629 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2630 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2631 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2632 }
2633
2634 case ARMISD::VST2_UPD: {
2635 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2636 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2637 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2638 ARM::VST2q32Pseudo_UPD };
2639 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2640 }
2641
2642 case ARMISD::VST3_UPD: {
2643 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2644 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2645 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2646 ARM::VST3q16Pseudo_UPD,
2647 ARM::VST3q32Pseudo_UPD };
2648 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2649 ARM::VST3q16oddPseudo_UPD,
2650 ARM::VST3q32oddPseudo_UPD };
2651 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2652 }
2653
2654 case ARMISD::VST4_UPD: {
2655 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2656 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2657 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2658 ARM::VST4q16Pseudo_UPD,
2659 ARM::VST4q32Pseudo_UPD };
2660 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2661 ARM::VST4q16oddPseudo_UPD,
2662 ARM::VST4q32oddPseudo_UPD };
2663 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2664 }
2665
2666 case ARMISD::VST2LN_UPD: {
2667 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2668 ARM::VST2LNd32Pseudo_UPD };
2669 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2670 ARM::VST2LNq32Pseudo_UPD };
2671 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2672 }
2673
2674 case ARMISD::VST3LN_UPD: {
2675 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2676 ARM::VST3LNd32Pseudo_UPD };
2677 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2678 ARM::VST3LNq32Pseudo_UPD };
2679 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2680 }
2681
2682 case ARMISD::VST4LN_UPD: {
2683 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2684 ARM::VST4LNd32Pseudo_UPD };
2685 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2686 ARM::VST4LNq32Pseudo_UPD };
2687 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002688 }
2689
Bob Wilson31fb12f2009-08-26 17:39:53 +00002690 case ISD::INTRINSIC_VOID:
2691 case ISD::INTRINSIC_W_CHAIN: {
2692 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002693 switch (IntNo) {
2694 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002695 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002696
Bob Wilson621f1952010-03-23 05:25:43 +00002697 case Intrinsic::arm_neon_vld1: {
2698 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2699 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002700 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2701 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002702 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002703 }
2704
Bob Wilson31fb12f2009-08-26 17:39:53 +00002705 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002706 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2707 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2708 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2709 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002710 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002711 }
2712
2713 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002714 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2715 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2716 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2717 ARM::VLD3q16Pseudo_UPD,
2718 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002719 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2720 ARM::VLD3q16oddPseudo,
2721 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002722 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002723 }
2724
2725 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002726 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2727 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2728 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2729 ARM::VLD4q16Pseudo_UPD,
2730 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002731 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2732 ARM::VLD4q16oddPseudo,
2733 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002734 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002735 }
2736
Bob Wilson243fcc52009-09-01 04:26:28 +00002737 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002738 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2739 ARM::VLD2LNd32Pseudo };
2740 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002741 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002742 }
2743
2744 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002745 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2746 ARM::VLD3LNd32Pseudo };
2747 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002748 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002749 }
2750
2751 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002752 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2753 ARM::VLD4LNd32Pseudo };
2754 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002755 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002756 }
2757
Bob Wilson11d98992010-03-23 06:20:33 +00002758 case Intrinsic::arm_neon_vst1: {
2759 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2760 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002761 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2762 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002763 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002764 }
2765
Bob Wilson31fb12f2009-08-26 17:39:53 +00002766 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002767 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2768 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2769 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2770 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002771 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002772 }
2773
2774 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002775 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2776 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2777 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2778 ARM::VST3q16Pseudo_UPD,
2779 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002780 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2781 ARM::VST3q16oddPseudo,
2782 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002783 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002784 }
2785
2786 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002787 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002788 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002789 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2790 ARM::VST4q16Pseudo_UPD,
2791 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002792 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2793 ARM::VST4q16oddPseudo,
2794 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002795 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002796 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002797
2798 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002799 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2800 ARM::VST2LNd32Pseudo };
2801 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002802 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002803 }
2804
2805 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002806 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2807 ARM::VST3LNd32Pseudo };
2808 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002809 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002810 }
2811
2812 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002813 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2814 ARM::VST4LNd32Pseudo };
2815 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002816 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002817 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002818 }
Bob Wilson429009b2010-05-06 16:05:26 +00002819 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002820 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002821
Bob Wilsond491d6e2010-07-06 23:36:25 +00002822 case ISD::INTRINSIC_WO_CHAIN: {
2823 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2824 switch (IntNo) {
2825 default:
2826 break;
2827
2828 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002829 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002830 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002831 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002832 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002833 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002834
2835 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002836 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002837 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002838 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002839 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002840 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002841 }
2842 break;
2843 }
2844
Bob Wilson429009b2010-05-06 16:05:26 +00002845 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002846 return SelectConcatVector(N);
2847 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002848
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002849 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002850}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002851
Bob Wilson224c2442009-05-19 05:53:42 +00002852bool ARMDAGToDAGISel::
2853SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2854 std::vector<SDValue> &OutOps) {
2855 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002856 // Require the address to be in a register. That is safe for all ARM
2857 // variants and it is hard to do anything much smarter without knowing
2858 // how the operand is used.
2859 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002860 return false;
2861}
2862
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002863/// createARMISelDag - This pass converts a legalized DAG into a
2864/// ARM-specific DAG, ready for instruction scheduling.
2865///
Bob Wilson522ce972009-09-28 14:30:20 +00002866FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2867 CodeGenOpt::Level OptLevel) {
2868 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002869}