blob: a506cffdba3483f7a8493843c0fe50d28f024024 [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);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000129
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000130 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000131
Bill Wendlingf4caf692010-12-14 03:36:38 +0000132 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000134 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
135 unsigned Scale);
136 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
137 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
140 SDValue &OffImm);
141 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
142 SDValue &OffImm);
143 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
144 SDValue &OffImm);
145 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
146 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000147 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000148
Bill Wendlingf4caf692010-12-14 03:36:38 +0000149 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000150 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000151 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000152 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
153 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000154 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000156 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000157 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000158 SDValue &OffReg, SDValue &ShImm);
159
Evan Cheng875a6ac2010-11-12 22:42:47 +0000160 inline bool is_so_imm(unsigned Imm) const {
161 return ARM_AM::getSOImmVal(Imm) != -1;
162 }
163
164 inline bool is_so_imm_not(unsigned Imm) const {
165 return ARM_AM::getSOImmVal(~Imm) != -1;
166 }
167
168 inline bool is_t2_so_imm(unsigned Imm) const {
169 return ARM_AM::getT2SOImmVal(Imm) != -1;
170 }
171
172 inline bool is_t2_so_imm_not(unsigned Imm) const {
173 return ARM_AM::getT2SOImmVal(~Imm) != -1;
174 }
175
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000176 inline bool Pred_so_imm(SDNode *inN) const {
177 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000179 }
180
181 inline bool Pred_t2_so_imm(SDNode *inN) const {
182 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000183 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000184 }
185
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000186 // Include the pieces autogenerated from the target description.
187#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000188
189private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000190 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
191 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000192 SDNode *SelectARMIndexedLoad(SDNode *N);
193 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000194
Bob Wilson621f1952010-03-23 05:25:43 +0000195 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
196 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000197 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000198 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000199 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
200 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000201 unsigned *QOpcodes0, unsigned *QOpcodes1);
202
Bob Wilson24f995d2009-10-14 18:32:29 +0000203 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000204 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000205 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000207 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
208 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000209 unsigned *QOpcodes0, unsigned *QOpcodes1);
210
Bob Wilson96493442009-10-14 16:46:45 +0000211 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000212 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000213 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000214 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
215 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000216 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000217
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000218 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
219 /// should be 2, 3 or 4. The opcode array specifies the instructions used
220 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000221 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
222 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000223
Bob Wilson78dfbc32010-07-07 00:08:54 +0000224 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
225 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
226 /// generated to force the table registers to be consecutive.
227 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000228
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000229 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000230 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000231
Evan Cheng07ba9062009-11-19 21:45:22 +0000232 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233 SDNode *SelectCMOVOp(SDNode *N);
234 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000235 ARMCC::CondCodes CCVal, SDValue CCR,
236 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000237 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000238 ARMCC::CondCodes CCVal, SDValue CCR,
239 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000240 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000241 ARMCC::CondCodes CCVal, SDValue CCR,
242 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000243 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000244 ARMCC::CondCodes CCVal, SDValue CCR,
245 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000246
Evan Chengde8aa4e2010-05-05 18:28:36 +0000247 SDNode *SelectConcatVector(SDNode *N);
248
Evan Chengaf4550f2009-07-02 01:23:32 +0000249 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
250 /// inline asm expressions.
251 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
252 char ConstraintCode,
253 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000254
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000255 // Form pairs of consecutive S, D, or Q registers.
256 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000257 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000258 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
259
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000260 // Form sequences of 4 consecutive S, D, or Q registers.
261 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000262 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000263 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000264
265 // Get the alignment operand for a NEON VLD or VST instruction.
266 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000267};
Evan Chenga8e29892007-01-19 07:51:42 +0000268}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000269
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000270/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
271/// operand. If so Imm will receive the 32-bit value.
272static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
273 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
274 Imm = cast<ConstantSDNode>(N)->getZExtValue();
275 return true;
276 }
277 return false;
278}
279
280// isInt32Immediate - This method tests to see if a constant operand.
281// If so Imm will receive the 32 bit value.
282static bool isInt32Immediate(SDValue N, unsigned &Imm) {
283 return isInt32Immediate(N.getNode(), Imm);
284}
285
286// isOpcWithIntImmediate - This method tests to see if the node is a specific
287// opcode and that it has a immediate integer right operand.
288// If so Imm will receive the 32 bit value.
289static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
290 return N->getOpcode() == Opc &&
291 isInt32Immediate(N->getOperand(1).getNode(), Imm);
292}
293
Daniel Dunbarec91d522011-01-19 15:12:16 +0000294/// \brief Check whether a particular node is a constant value representable as
295/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
296///
297/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
298static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
299 int RangeMin, int RangeMax,
300 int &ScaledConstant) {
301 assert(Scale && "Invalid scale!");
302
303 // Check that this is a constant.
304 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
305 if (!C)
306 return false;
307
308 ScaledConstant = (int) C->getZExtValue();
309 if ((ScaledConstant % Scale) != 0)
310 return false;
311
312 ScaledConstant /= Scale;
313 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
314}
315
Evan Cheng48575f62010-12-05 22:04:16 +0000316/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
317/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
318/// least on current ARM implementations) which should be avoidded.
319bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
320 if (OptLevel == CodeGenOpt::None)
321 return true;
322
323 if (!CheckVMLxHazard)
324 return true;
325
326 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
327 return true;
328
329 if (!N->hasOneUse())
330 return false;
331
332 SDNode *Use = *N->use_begin();
333 if (Use->getOpcode() == ISD::CopyToReg)
334 return true;
335 if (Use->isMachineOpcode()) {
336 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
337 if (TID.mayStore())
338 return true;
339 unsigned Opcode = TID.getOpcode();
340 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
341 return true;
342 // vmlx feeding into another vmlx. We actually want to unfold
343 // the use later in the MLxExpansion pass. e.g.
344 // vmla
345 // vmla (stall 8 cycles)
346 //
347 // vmul (5 cycles)
348 // vadd (5 cycles)
349 // vmla
350 // This adds up to about 18 - 19 cycles.
351 //
352 // vmla
353 // vmul (stall 4 cycles)
354 // vadd adds up to about 14 cycles.
355 return TII->isFpMLxInstruction(Opcode);
356 }
357
358 return false;
359}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000360
Evan Chengf40deed2010-10-27 23:41:30 +0000361bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
362 ARM_AM::ShiftOpc ShOpcVal,
363 unsigned ShAmt) {
364 if (!Subtarget->isCortexA9())
365 return true;
366 if (Shift.hasOneUse())
367 return true;
368 // R << 2 is free.
369 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
370}
371
Chris Lattner52a261b2010-09-21 20:31:19 +0000372bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000373 SDValue &BaseReg,
374 SDValue &ShReg,
375 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000376 if (DisableShifterOp)
377 return false;
378
Evan Cheng055b0312009-06-29 07:51:04 +0000379 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
380
381 // Don't match base register only case. That is matched to a separate
382 // lower complexity pattern with explicit register operand.
383 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000384
Evan Cheng055b0312009-06-29 07:51:04 +0000385 BaseReg = N.getOperand(0);
386 unsigned ShImmVal = 0;
387 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000388 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000389 ShImmVal = RHS->getZExtValue() & 31;
390 } else {
391 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000392 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
393 return false;
394 }
395 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
396 MVT::i32);
397 return true;
398}
399
400bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
401 SDValue &BaseReg,
402 SDValue &ShReg,
403 SDValue &Opc) {
404 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
405
406 // Don't match base register only case. That is matched to a separate
407 // lower complexity pattern with explicit register operand.
408 if (ShOpcVal == ARM_AM::no_shift) return false;
409
410 BaseReg = N.getOperand(0);
411 unsigned ShImmVal = 0;
412 // Do not check isShifterOpProfitable. This must return true.
413 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
414 ShReg = CurDAG->getRegister(0, MVT::i32);
415 ShImmVal = RHS->getZExtValue() & 31;
416 } else {
417 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000418 }
419 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000420 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000421 return true;
422}
423
Jim Grosbach3e556122010-10-26 22:37:02 +0000424bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
425 SDValue &Base,
426 SDValue &OffImm) {
427 // Match simple R + imm12 operands.
428
429 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000430 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
431 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000432 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000433 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000434 int FI = cast<FrameIndexSDNode>(N)->getIndex();
435 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
436 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
437 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000438 }
439
440 if (N.getOpcode() == ARMISD::Wrapper &&
441 !(Subtarget->useMovt() &&
442 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000443 Base = N.getOperand(0);
444 } else
445 Base = N;
446 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
447 return true;
448 }
449
450 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
451 int RHSC = (int)RHS->getZExtValue();
452 if (N.getOpcode() == ISD::SUB)
453 RHSC = -RHSC;
454
455 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
456 Base = N.getOperand(0);
457 if (Base.getOpcode() == ISD::FrameIndex) {
458 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
459 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
460 }
461 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
462 return true;
463 }
464 }
465
466 // Base only.
467 Base = N;
468 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
469 return true;
470}
471
472
473
474bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
475 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000476 if (N.getOpcode() == ISD::MUL &&
477 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000478 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
479 // X * [3,5,9] -> X + X * [2,4,8] etc.
480 int RHSC = (int)RHS->getZExtValue();
481 if (RHSC & 1) {
482 RHSC = RHSC & ~1;
483 ARM_AM::AddrOpc AddSub = ARM_AM::add;
484 if (RHSC < 0) {
485 AddSub = ARM_AM::sub;
486 RHSC = - RHSC;
487 }
488 if (isPowerOf2_32(RHSC)) {
489 unsigned ShAmt = Log2_32(RHSC);
490 Base = Offset = N.getOperand(0);
491 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
492 ARM_AM::lsl),
493 MVT::i32);
494 return true;
495 }
496 }
497 }
498 }
499
Chris Lattner0a9481f2011-02-13 22:25:43 +0000500 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
501 // ISD::OR that is equivalent to an ISD::ADD.
502 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000503 return false;
504
505 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000506 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000507 int RHSC;
508 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
509 -0x1000+1, 0x1000, RHSC)) // 12 bits.
510 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000511 }
512
Evan Chengf40deed2010-10-27 23:41:30 +0000513 if (Subtarget->isCortexA9() && !N.hasOneUse())
514 // Compute R +/- (R << N) and reuse it.
515 return false;
516
Jim Grosbach3e556122010-10-26 22:37:02 +0000517 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000518 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Jim Grosbach3e556122010-10-26 22:37:02 +0000519 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
520 unsigned ShAmt = 0;
521
522 Base = N.getOperand(0);
523 Offset = N.getOperand(1);
524
525 if (ShOpcVal != ARM_AM::no_shift) {
526 // Check to see if the RHS of the shift is a constant, if not, we can't fold
527 // it.
528 if (ConstantSDNode *Sh =
529 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
530 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000531 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
532 Offset = N.getOperand(1).getOperand(0);
533 else {
534 ShAmt = 0;
535 ShOpcVal = ARM_AM::no_shift;
536 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000537 } else {
538 ShOpcVal = ARM_AM::no_shift;
539 }
540 }
541
542 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000543 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000544 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000545 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
546 if (ShOpcVal != ARM_AM::no_shift) {
547 // Check to see if the RHS of the shift is a constant, if not, we can't
548 // fold it.
549 if (ConstantSDNode *Sh =
550 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
551 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000552 if (!Subtarget->isCortexA9() ||
553 (N.hasOneUse() &&
554 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
555 Offset = N.getOperand(0).getOperand(0);
556 Base = N.getOperand(1);
557 } else {
558 ShAmt = 0;
559 ShOpcVal = ARM_AM::no_shift;
560 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000561 } else {
562 ShOpcVal = ARM_AM::no_shift;
563 }
564 }
565 }
566
567 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
568 MVT::i32);
569 return true;
570}
571
572
573
574
575//-----
576
Jim Grosbach82891622010-09-29 19:03:54 +0000577AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
578 SDValue &Base,
579 SDValue &Offset,
580 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000581 if (N.getOpcode() == ISD::MUL &&
582 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000583 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
584 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000585 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000586 if (RHSC & 1) {
587 RHSC = RHSC & ~1;
588 ARM_AM::AddrOpc AddSub = ARM_AM::add;
589 if (RHSC < 0) {
590 AddSub = ARM_AM::sub;
591 RHSC = - RHSC;
592 }
593 if (isPowerOf2_32(RHSC)) {
594 unsigned ShAmt = Log2_32(RHSC);
595 Base = Offset = N.getOperand(0);
596 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
597 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000598 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000599 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000600 }
601 }
602 }
603 }
604
Chris Lattner0a9481f2011-02-13 22:25:43 +0000605 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
606 // ISD::OR that is equivalent to an ADD.
607 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000608 Base = N;
609 if (N.getOpcode() == ISD::FrameIndex) {
610 int FI = cast<FrameIndexSDNode>(N)->getIndex();
611 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000612 } else if (N.getOpcode() == ARMISD::Wrapper &&
613 !(Subtarget->useMovt() &&
614 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000615 Base = N.getOperand(0);
616 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000617 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000618 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
619 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000620 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000621 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000622 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000623
Evan Chenga8e29892007-01-19 07:51:42 +0000624 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000625 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000626 int RHSC;
627 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
628 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
629 Base = N.getOperand(0);
630 if (Base.getOpcode() == ISD::FrameIndex) {
631 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
632 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000633 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000634 Offset = CurDAG->getRegister(0, MVT::i32);
635
636 ARM_AM::AddrOpc AddSub = ARM_AM::add;
637 if (RHSC < 0) {
638 AddSub = ARM_AM::sub;
639 RHSC = - RHSC;
640 }
641 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
642 ARM_AM::no_shift),
643 MVT::i32);
644 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000645 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000646 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000647
Evan Chengf40deed2010-10-27 23:41:30 +0000648 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
649 // Compute R +/- (R << N) and reuse it.
650 Base = N;
651 Offset = CurDAG->getRegister(0, MVT::i32);
652 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
653 ARM_AM::no_shift),
654 MVT::i32);
655 return AM2_BASE;
656 }
657
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000658 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000659 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga8e29892007-01-19 07:51:42 +0000660 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
661 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000662
Evan Chenga8e29892007-01-19 07:51:42 +0000663 Base = N.getOperand(0);
664 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000665
Evan Chenga8e29892007-01-19 07:51:42 +0000666 if (ShOpcVal != ARM_AM::no_shift) {
667 // Check to see if the RHS of the shift is a constant, if not, we can't fold
668 // it.
669 if (ConstantSDNode *Sh =
670 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000671 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000672 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
673 Offset = N.getOperand(1).getOperand(0);
674 else {
675 ShAmt = 0;
676 ShOpcVal = ARM_AM::no_shift;
677 }
Evan Chenga8e29892007-01-19 07:51:42 +0000678 } else {
679 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000680 }
681 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000682
Evan Chenga8e29892007-01-19 07:51:42 +0000683 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000684 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000685 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000686 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
687 if (ShOpcVal != ARM_AM::no_shift) {
688 // Check to see if the RHS of the shift is a constant, if not, we can't
689 // fold it.
690 if (ConstantSDNode *Sh =
691 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000692 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000693 if (!Subtarget->isCortexA9() ||
694 (N.hasOneUse() &&
695 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
696 Offset = N.getOperand(0).getOperand(0);
697 Base = N.getOperand(1);
698 } else {
699 ShAmt = 0;
700 ShOpcVal = ARM_AM::no_shift;
701 }
Evan Chenga8e29892007-01-19 07:51:42 +0000702 } else {
703 ShOpcVal = ARM_AM::no_shift;
704 }
705 }
706 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000707
Evan Chenga8e29892007-01-19 07:51:42 +0000708 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000709 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000710 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000711}
712
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000713bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000714 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000715 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000716 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
717 ? cast<LoadSDNode>(Op)->getAddressingMode()
718 : cast<StoreSDNode>(Op)->getAddressingMode();
719 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
720 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000721 int Val;
722 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
723 Offset = CurDAG->getRegister(0, MVT::i32);
724 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
725 ARM_AM::no_shift),
726 MVT::i32);
727 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000728 }
729
730 Offset = N;
731 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
732 unsigned ShAmt = 0;
733 if (ShOpcVal != ARM_AM::no_shift) {
734 // Check to see if the RHS of the shift is a constant, if not, we can't fold
735 // it.
736 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000737 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000738 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
739 Offset = N.getOperand(0);
740 else {
741 ShAmt = 0;
742 ShOpcVal = ARM_AM::no_shift;
743 }
Evan Chenga8e29892007-01-19 07:51:42 +0000744 } else {
745 ShOpcVal = ARM_AM::no_shift;
746 }
747 }
748
749 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000750 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000751 return true;
752}
753
Evan Chenga8e29892007-01-19 07:51:42 +0000754
Chris Lattner52a261b2010-09-21 20:31:19 +0000755bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000756 SDValue &Base, SDValue &Offset,
757 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000758 if (N.getOpcode() == ISD::SUB) {
759 // X - C is canonicalize to X + -C, no need to handle it here.
760 Base = N.getOperand(0);
761 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000762 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000763 return true;
764 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000765
Chris Lattner0a9481f2011-02-13 22:25:43 +0000766 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000767 Base = N;
768 if (N.getOpcode() == ISD::FrameIndex) {
769 int FI = cast<FrameIndexSDNode>(N)->getIndex();
770 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
771 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 Offset = CurDAG->getRegister(0, MVT::i32);
773 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000774 return true;
775 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000776
Evan Chenga8e29892007-01-19 07:51:42 +0000777 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000778 int RHSC;
779 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
780 -256 + 1, 256, RHSC)) { // 8 bits.
781 Base = N.getOperand(0);
782 if (Base.getOpcode() == ISD::FrameIndex) {
783 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
784 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000785 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000786 Offset = CurDAG->getRegister(0, MVT::i32);
787
788 ARM_AM::AddrOpc AddSub = ARM_AM::add;
789 if (RHSC < 0) {
790 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000791 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000792 }
793 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
794 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000795 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000796
Evan Chenga8e29892007-01-19 07:51:42 +0000797 Base = N.getOperand(0);
798 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000799 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000800 return true;
801}
802
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000803bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000804 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000805 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000806 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
807 ? cast<LoadSDNode>(Op)->getAddressingMode()
808 : cast<StoreSDNode>(Op)->getAddressingMode();
809 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
810 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000811 int Val;
812 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
813 Offset = CurDAG->getRegister(0, MVT::i32);
814 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
815 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000816 }
817
818 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000819 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000820 return true;
821}
822
Jim Grosbach3ab56582010-10-21 19:38:40 +0000823bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000824 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000825 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000826 Base = N;
827 if (N.getOpcode() == ISD::FrameIndex) {
828 int FI = cast<FrameIndexSDNode>(N)->getIndex();
829 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000830 } else if (N.getOpcode() == ARMISD::Wrapper &&
831 !(Subtarget->useMovt() &&
832 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000833 Base = N.getOperand(0);
834 }
835 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000836 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000837 return true;
838 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000839
Evan Chenga8e29892007-01-19 07:51:42 +0000840 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000841 int RHSC;
842 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
843 -256 + 1, 256, RHSC)) {
844 Base = N.getOperand(0);
845 if (Base.getOpcode() == ISD::FrameIndex) {
846 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
847 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000848 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000849
850 ARM_AM::AddrOpc AddSub = ARM_AM::add;
851 if (RHSC < 0) {
852 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000853 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000854 }
855 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
856 MVT::i32);
857 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000858 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000859
Evan Chenga8e29892007-01-19 07:51:42 +0000860 Base = N;
861 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000863 return true;
864}
865
Bob Wilson665814b2010-11-01 23:40:51 +0000866bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
867 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000868 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000869
870 unsigned Alignment = 0;
871 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
872 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
873 // The maximum alignment is equal to the memory size being referenced.
874 unsigned LSNAlign = LSN->getAlignment();
875 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
876 if (LSNAlign > MemSize && MemSize > 1)
877 Alignment = MemSize;
878 } else {
879 // All other uses of addrmode6 are for intrinsics. For now just record
880 // the raw alignment value; it will be refined later based on the legal
881 // alignment operands for the intrinsic.
882 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
883 }
884
885 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000886 return true;
887}
888
Chris Lattner52a261b2010-09-21 20:31:19 +0000889bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000890 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000891 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
892 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000893 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000894 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
895 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000896 return true;
897 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000898
Evan Chenga8e29892007-01-19 07:51:42 +0000899 return false;
900}
901
Bill Wendlingf4caf692010-12-14 03:36:38 +0000902
903//===----------------------------------------------------------------------===//
904// Thumb Addressing Modes
905//===----------------------------------------------------------------------===//
906
Chris Lattner52a261b2010-09-21 20:31:19 +0000907bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000908 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000909 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000910 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000911 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000912 return false;
913
914 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000915 return true;
916 }
917
Evan Chenga8e29892007-01-19 07:51:42 +0000918 Base = N.getOperand(0);
919 Offset = N.getOperand(1);
920 return true;
921}
922
Evan Cheng79d43262007-01-24 02:21:22 +0000923bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000924ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
925 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000926 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000927 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000928 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000929 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000930
Evan Cheng012f2d92007-01-24 08:53:17 +0000931 if (N.getOpcode() == ARMISD::Wrapper &&
932 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
933 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000934 }
935
Chris Lattner0a9481f2011-02-13 22:25:43 +0000936 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000937 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000938
Evan Chengad0e4652007-02-06 00:22:06 +0000939 // Thumb does not have [sp, r] address mode.
940 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
941 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
942 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000943 (RHSR && RHSR->getReg() == ARM::SP))
944 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000945
Daniel Dunbarec91d522011-01-19 15:12:16 +0000946 // FIXME: Why do we explicitly check for a match here and then return false?
947 // Presumably to allow something else to match, but shouldn't this be
948 // documented?
949 int RHSC;
950 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
951 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000952
953 Base = N.getOperand(0);
954 Offset = N.getOperand(1);
955 return true;
956}
957
958bool
959ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
960 SDValue &Base,
961 SDValue &Offset) {
962 return SelectThumbAddrModeRI(N, Base, Offset, 1);
963}
964
965bool
966ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
967 SDValue &Base,
968 SDValue &Offset) {
969 return SelectThumbAddrModeRI(N, Base, Offset, 2);
970}
971
972bool
973ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
974 SDValue &Base,
975 SDValue &Offset) {
976 return SelectThumbAddrModeRI(N, Base, Offset, 4);
977}
978
979bool
980ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
981 SDValue &Base, SDValue &OffImm) {
982 if (Scale == 4) {
983 SDValue TmpBase, TmpOffImm;
984 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
985 return false; // We want to select tLDRspi / tSTRspi instead.
986
987 if (N.getOpcode() == ARMISD::Wrapper &&
988 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
989 return false; // We want to select tLDRpci instead.
990 }
991
Chris Lattner0a9481f2011-02-13 22:25:43 +0000992 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000993 if (N.getOpcode() == ARMISD::Wrapper &&
994 !(Subtarget->useMovt() &&
995 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
996 Base = N.getOperand(0);
997 } else {
998 Base = N;
999 }
1000
Owen Anderson825b72b2009-08-11 20:47:22 +00001001 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001002 return true;
1003 }
1004
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001005 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1006 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1007 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1008 (RHSR && RHSR->getReg() == ARM::SP)) {
1009 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1010 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1011 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1012 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1013
1014 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1015 if (LHSC != 0 || RHSC != 0) return false;
1016
1017 Base = N;
1018 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1019 return true;
1020 }
1021
Evan Chenga8e29892007-01-19 07:51:42 +00001022 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001023 int RHSC;
1024 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1025 Base = N.getOperand(0);
1026 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1027 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001028 }
1029
Evan Chengc38f2bc2007-01-23 22:59:13 +00001030 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001031 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001032 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001033}
1034
Bill Wendlingf4caf692010-12-14 03:36:38 +00001035bool
1036ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1037 SDValue &OffImm) {
1038 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001039}
1040
Bill Wendlingf4caf692010-12-14 03:36:38 +00001041bool
1042ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1043 SDValue &OffImm) {
1044 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001045}
1046
Bill Wendlingf4caf692010-12-14 03:36:38 +00001047bool
1048ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1049 SDValue &OffImm) {
1050 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001051}
1052
Chris Lattner52a261b2010-09-21 20:31:19 +00001053bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1054 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001055 if (N.getOpcode() == ISD::FrameIndex) {
1056 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1057 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001058 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001059 return true;
1060 }
Evan Cheng79d43262007-01-24 02:21:22 +00001061
Chris Lattner0a9481f2011-02-13 22:25:43 +00001062 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001063 return false;
1064
1065 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001066 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1067 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001068 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001069 int RHSC;
1070 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1071 Base = N.getOperand(0);
1072 if (Base.getOpcode() == ISD::FrameIndex) {
1073 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1074 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001075 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001076 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1077 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001078 }
1079 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001080
Evan Chenga8e29892007-01-19 07:51:42 +00001081 return false;
1082}
1083
Bill Wendlingf4caf692010-12-14 03:36:38 +00001084
1085//===----------------------------------------------------------------------===//
1086// Thumb 2 Addressing Modes
1087//===----------------------------------------------------------------------===//
1088
1089
Chris Lattner52a261b2010-09-21 20:31:19 +00001090bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001091 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001092 if (DisableShifterOp)
1093 return false;
1094
Evan Cheng9cb9e672009-06-27 02:26:13 +00001095 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1096
1097 // Don't match base register only case. That is matched to a separate
1098 // lower complexity pattern with explicit register operand.
1099 if (ShOpcVal == ARM_AM::no_shift) return false;
1100
1101 BaseReg = N.getOperand(0);
1102 unsigned ShImmVal = 0;
1103 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1104 ShImmVal = RHS->getZExtValue() & 31;
1105 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1106 return true;
1107 }
1108
1109 return false;
1110}
1111
Chris Lattner52a261b2010-09-21 20:31:19 +00001112bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001113 SDValue &Base, SDValue &OffImm) {
1114 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001115
Evan Cheng3a214252009-08-11 08:52:18 +00001116 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001117 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1118 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001119 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001120 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001121 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1122 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001123 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001124 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001125 }
1126
1127 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001128 !(Subtarget->useMovt() &&
1129 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001130 Base = N.getOperand(0);
1131 if (Base.getOpcode() == ISD::TargetConstantPool)
1132 return false; // We want to select t2LDRpci instead.
1133 } else
1134 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001135 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001136 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001137 }
Evan Cheng055b0312009-06-29 07:51:04 +00001138
1139 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001140 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001141 // Let t2LDRi8 handle (R - imm8).
1142 return false;
1143
Evan Cheng055b0312009-06-29 07:51:04 +00001144 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001145 if (N.getOpcode() == ISD::SUB)
1146 RHSC = -RHSC;
1147
1148 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001149 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001150 if (Base.getOpcode() == ISD::FrameIndex) {
1151 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1152 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1153 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001154 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001155 return true;
1156 }
1157 }
1158
Evan Cheng3a214252009-08-11 08:52:18 +00001159 // Base only.
1160 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001161 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001162 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001163}
1164
Chris Lattner52a261b2010-09-21 20:31:19 +00001165bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001166 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001167 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001168 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1169 !CurDAG->isBaseWithConstantOffset(N))
1170 return false;
1171
1172 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1173 int RHSC = (int)RHS->getSExtValue();
1174 if (N.getOpcode() == ISD::SUB)
1175 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001176
Chris Lattner0a9481f2011-02-13 22:25:43 +00001177 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1178 Base = N.getOperand(0);
1179 if (Base.getOpcode() == ISD::FrameIndex) {
1180 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1181 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001182 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001183 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1184 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001185 }
1186 }
1187
1188 return false;
1189}
1190
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001191bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001192 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001193 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001194 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1195 ? cast<LoadSDNode>(Op)->getAddressingMode()
1196 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001197 int RHSC;
1198 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1199 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1200 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1201 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1202 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001203 }
1204
1205 return false;
1206}
1207
Chris Lattner52a261b2010-09-21 20:31:19 +00001208bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001209 SDValue &Base,
1210 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001211 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001212 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001213 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001214
Evan Cheng3a214252009-08-11 08:52:18 +00001215 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1216 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1217 int RHSC = (int)RHS->getZExtValue();
1218 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1219 return false;
1220 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001221 return false;
1222 }
1223
Evan Chengf40deed2010-10-27 23:41:30 +00001224 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1225 // Compute R + (R << [1,2,3]) and reuse it.
1226 Base = N;
1227 return false;
1228 }
1229
Evan Cheng055b0312009-06-29 07:51:04 +00001230 // Look for (R + R) or (R + (R << [1,2,3])).
1231 unsigned ShAmt = 0;
1232 Base = N.getOperand(0);
1233 OffReg = N.getOperand(1);
1234
1235 // Swap if it is ((R << c) + R).
1236 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1237 if (ShOpcVal != ARM_AM::lsl) {
1238 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1239 if (ShOpcVal == ARM_AM::lsl)
1240 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001241 }
1242
Evan Cheng055b0312009-06-29 07:51:04 +00001243 if (ShOpcVal == ARM_AM::lsl) {
1244 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1245 // it.
1246 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1247 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001248 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1249 OffReg = OffReg.getOperand(0);
1250 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001251 ShAmt = 0;
1252 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001253 }
Evan Cheng055b0312009-06-29 07:51:04 +00001254 } else {
1255 ShOpcVal = ARM_AM::no_shift;
1256 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001257 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001258
Owen Anderson825b72b2009-08-11 20:47:22 +00001259 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001260
1261 return true;
1262}
1263
1264//===--------------------------------------------------------------------===//
1265
Evan Chengee568cf2007-07-05 07:15:27 +00001266/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001267static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001268 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001269}
1270
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001271SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1272 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001273 ISD::MemIndexedMode AM = LD->getAddressingMode();
1274 if (AM == ISD::UNINDEXED)
1275 return NULL;
1276
Owen Andersone50ed302009-08-10 22:56:29 +00001277 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001278 SDValue Offset, AMOpc;
1279 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1280 unsigned Opcode = 0;
1281 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001282 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001283 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001284 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1285 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001286 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001287 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001288 Match = true;
1289 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1290 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1291 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001292 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001293 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001294 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001295 Match = true;
1296 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1297 }
1298 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001299 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001300 Match = true;
1301 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1302 }
1303 }
1304 }
1305
1306 if (Match) {
1307 SDValue Chain = LD->getChain();
1308 SDValue Base = LD->getBasePtr();
1309 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001310 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001311 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001312 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001313 }
1314
1315 return NULL;
1316}
1317
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001318SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1319 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001320 ISD::MemIndexedMode AM = LD->getAddressingMode();
1321 if (AM == ISD::UNINDEXED)
1322 return NULL;
1323
Owen Andersone50ed302009-08-10 22:56:29 +00001324 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001325 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001326 SDValue Offset;
1327 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1328 unsigned Opcode = 0;
1329 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001330 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001331 switch (LoadedVT.getSimpleVT().SimpleTy) {
1332 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001333 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1334 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001335 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001336 if (isSExtLd)
1337 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1338 else
1339 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001340 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001341 case MVT::i8:
1342 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001343 if (isSExtLd)
1344 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1345 else
1346 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001347 break;
1348 default:
1349 return NULL;
1350 }
1351 Match = true;
1352 }
1353
1354 if (Match) {
1355 SDValue Chain = LD->getChain();
1356 SDValue Base = LD->getBasePtr();
1357 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001358 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001359 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001360 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001361 }
1362
1363 return NULL;
1364}
1365
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001366/// PairSRegs - Form a D register from a pair of S registers.
1367///
1368SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1369 DebugLoc dl = V0.getNode()->getDebugLoc();
1370 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1371 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001372 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1373 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001374}
1375
Evan Cheng603afbf2010-05-10 17:34:18 +00001376/// PairDRegs - Form a quad register from a pair of D registers.
1377///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001378SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1379 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001380 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1381 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001382 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1383 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001384}
1385
Evan Cheng7f687192010-05-14 00:21:45 +00001386/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001387///
1388SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1389 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001390 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1391 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001392 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1393 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1394}
1395
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001396/// QuadSRegs - Form 4 consecutive S registers.
1397///
1398SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1399 SDValue V2, SDValue V3) {
1400 DebugLoc dl = V0.getNode()->getDebugLoc();
1401 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1402 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1403 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1404 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1405 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1406 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1407}
1408
Evan Cheng7f687192010-05-14 00:21:45 +00001409/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001410///
1411SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1412 SDValue V2, SDValue V3) {
1413 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001414 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1415 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1416 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1417 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001418 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1419 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1420}
1421
Evan Cheng8f6de382010-05-16 03:27:48 +00001422/// QuadQRegs - Form 4 consecutive Q registers.
1423///
1424SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1425 SDValue V2, SDValue V3) {
1426 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001427 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1428 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1429 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1430 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001431 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1432 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1433}
1434
Bob Wilson2a6e6162010-09-23 23:42:37 +00001435/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1436/// of a NEON VLD or VST instruction. The supported values depend on the
1437/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001438SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1439 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001440 unsigned NumRegs = NumVecs;
1441 if (!is64BitVector && NumVecs < 3)
1442 NumRegs *= 2;
1443
Bob Wilson665814b2010-11-01 23:40:51 +00001444 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001445 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001446 Alignment = 32;
1447 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1448 Alignment = 16;
1449 else if (Alignment >= 8)
1450 Alignment = 8;
1451 else
1452 Alignment = 0;
1453
1454 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001455}
1456
Bob Wilson1c3ef902011-02-07 17:43:21 +00001457SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001458 unsigned *DOpcodes, unsigned *QOpcodes0,
1459 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001460 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001461 DebugLoc dl = N->getDebugLoc();
1462
Bob Wilson226036e2010-03-20 22:13:40 +00001463 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001464 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1465 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001466 return NULL;
1467
1468 SDValue Chain = N->getOperand(0);
1469 EVT VT = N->getValueType(0);
1470 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001471 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001472
Bob Wilson3e36f132009-10-14 17:28:52 +00001473 unsigned OpcodeIndex;
1474 switch (VT.getSimpleVT().SimpleTy) {
1475 default: llvm_unreachable("unhandled vld type");
1476 // Double-register operations:
1477 case MVT::v8i8: OpcodeIndex = 0; break;
1478 case MVT::v4i16: OpcodeIndex = 1; break;
1479 case MVT::v2f32:
1480 case MVT::v2i32: OpcodeIndex = 2; break;
1481 case MVT::v1i64: OpcodeIndex = 3; break;
1482 // Quad-register operations:
1483 case MVT::v16i8: OpcodeIndex = 0; break;
1484 case MVT::v8i16: OpcodeIndex = 1; break;
1485 case MVT::v4f32:
1486 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001487 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001488 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001489 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001490 }
1491
Bob Wilsonf5721912010-09-03 18:16:02 +00001492 EVT ResTy;
1493 if (NumVecs == 1)
1494 ResTy = VT;
1495 else {
1496 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1497 if (!is64BitVector)
1498 ResTyElts *= 2;
1499 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1500 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001501 std::vector<EVT> ResTys;
1502 ResTys.push_back(ResTy);
1503 if (isUpdating)
1504 ResTys.push_back(MVT::i32);
1505 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001506
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001507 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001508 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001509 SDNode *VLd;
1510 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001511
Bob Wilson1c3ef902011-02-07 17:43:21 +00001512 // Double registers and VLD1/VLD2 quad registers are directly supported.
1513 if (is64BitVector || NumVecs <= 2) {
1514 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1515 QOpcodes0[OpcodeIndex]);
1516 Ops.push_back(MemAddr);
1517 Ops.push_back(Align);
1518 if (isUpdating) {
1519 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1520 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001521 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001522 Ops.push_back(Pred);
1523 Ops.push_back(Reg0);
1524 Ops.push_back(Chain);
1525 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001526
Bob Wilson3e36f132009-10-14 17:28:52 +00001527 } else {
1528 // Otherwise, quad registers are loaded with two separate instructions,
1529 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001530 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001531
Bob Wilson1c3ef902011-02-07 17:43:21 +00001532 // Load the even subregs. This is always an updating load, so that it
1533 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001534 SDValue ImplDef =
1535 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1536 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001537 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1538 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001539 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001540
Bob Wilson24f995d2009-10-14 18:32:29 +00001541 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001542 Ops.push_back(SDValue(VLdA, 1));
1543 Ops.push_back(Align);
1544 if (isUpdating) {
1545 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1546 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1547 "only constant post-increment update allowed for VLD3/4");
1548 (void)Inc;
1549 Ops.push_back(Reg0);
1550 }
1551 Ops.push_back(SDValue(VLdA, 0));
1552 Ops.push_back(Pred);
1553 Ops.push_back(Reg0);
1554 Ops.push_back(Chain);
1555 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1556 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001557 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001558
Bob Wilson1c3ef902011-02-07 17:43:21 +00001559 if (NumVecs == 1)
1560 return VLd;
1561
1562 // Extract out the subregisters.
1563 SDValue SuperReg = SDValue(VLd, 0);
1564 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1565 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1566 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1567 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1568 ReplaceUses(SDValue(N, Vec),
1569 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1570 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1571 if (isUpdating)
1572 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001573 return NULL;
1574}
1575
Bob Wilson1c3ef902011-02-07 17:43:21 +00001576SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001577 unsigned *DOpcodes, unsigned *QOpcodes0,
1578 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001579 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001580 DebugLoc dl = N->getDebugLoc();
1581
Bob Wilson226036e2010-03-20 22:13:40 +00001582 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001583 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1584 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1585 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001586 return NULL;
1587
1588 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001589 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001590 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001591 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001592
Bob Wilson24f995d2009-10-14 18:32:29 +00001593 unsigned OpcodeIndex;
1594 switch (VT.getSimpleVT().SimpleTy) {
1595 default: llvm_unreachable("unhandled vst type");
1596 // Double-register operations:
1597 case MVT::v8i8: OpcodeIndex = 0; break;
1598 case MVT::v4i16: OpcodeIndex = 1; break;
1599 case MVT::v2f32:
1600 case MVT::v2i32: OpcodeIndex = 2; break;
1601 case MVT::v1i64: OpcodeIndex = 3; break;
1602 // Quad-register operations:
1603 case MVT::v16i8: OpcodeIndex = 0; break;
1604 case MVT::v8i16: OpcodeIndex = 1; break;
1605 case MVT::v4f32:
1606 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001607 case MVT::v2i64: OpcodeIndex = 3;
1608 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1609 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001610 }
1611
Bob Wilson1c3ef902011-02-07 17:43:21 +00001612 std::vector<EVT> ResTys;
1613 if (isUpdating)
1614 ResTys.push_back(MVT::i32);
1615 ResTys.push_back(MVT::Other);
1616
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001617 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001618 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001619 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001620
Bob Wilson1c3ef902011-02-07 17:43:21 +00001621 // Double registers and VST1/VST2 quad registers are directly supported.
1622 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001623 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001624 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001625 SrcReg = N->getOperand(Vec0Idx);
1626 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001627 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001628 SDValue V0 = N->getOperand(Vec0Idx + 0);
1629 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001630 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001631 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001632 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001633 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001634 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001635 // an undef.
1636 SDValue V3 = (NumVecs == 3)
1637 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001638 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001639 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001640 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001641 } else {
1642 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001643 SDValue Q0 = N->getOperand(Vec0Idx);
1644 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001645 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001646 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001647
1648 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1649 QOpcodes0[OpcodeIndex]);
1650 Ops.push_back(MemAddr);
1651 Ops.push_back(Align);
1652 if (isUpdating) {
1653 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1654 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1655 }
1656 Ops.push_back(SrcReg);
1657 Ops.push_back(Pred);
1658 Ops.push_back(Reg0);
1659 Ops.push_back(Chain);
1660 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001661 }
1662
1663 // Otherwise, quad registers are stored with two separate instructions,
1664 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001665
Bob Wilson07f6e802010-06-16 21:34:01 +00001666 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001667 SDValue V0 = N->getOperand(Vec0Idx + 0);
1668 SDValue V1 = N->getOperand(Vec0Idx + 1);
1669 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001670 SDValue V3 = (NumVecs == 3)
1671 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001672 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001673 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001674
Bob Wilson1c3ef902011-02-07 17:43:21 +00001675 // Store the even D registers. This is always an updating store, so that it
1676 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001677 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1678 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1679 MemAddr.getValueType(),
1680 MVT::Other, OpsA, 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001681 Chain = SDValue(VStA, 1);
1682
1683 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001684 Ops.push_back(SDValue(VStA, 0));
1685 Ops.push_back(Align);
1686 if (isUpdating) {
1687 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1688 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1689 "only constant post-increment update allowed for VST3/4");
1690 (void)Inc;
1691 Ops.push_back(Reg0);
1692 }
1693 Ops.push_back(RegSeq);
1694 Ops.push_back(Pred);
1695 Ops.push_back(Reg0);
1696 Ops.push_back(Chain);
1697 return CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1698 Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001699}
1700
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001701SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001702 bool isUpdating, unsigned NumVecs,
1703 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001704 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001705 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001706 DebugLoc dl = N->getDebugLoc();
1707
Bob Wilson226036e2010-03-20 22:13:40 +00001708 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001709 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1710 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1711 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001712 return NULL;
1713
1714 SDValue Chain = N->getOperand(0);
1715 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001716 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1717 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001718 bool is64BitVector = VT.is64BitVector();
1719
Bob Wilson665814b2010-11-01 23:40:51 +00001720 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001721 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001722 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001723 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1724 if (Alignment > NumBytes)
1725 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001726 if (Alignment < 8 && Alignment < NumBytes)
1727 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001728 // Alignment must be a power of two; make sure of that.
1729 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001730 if (Alignment == 1)
1731 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001732 }
Bob Wilson665814b2010-11-01 23:40:51 +00001733 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001734
Bob Wilsona7c397c2009-10-14 16:19:03 +00001735 unsigned OpcodeIndex;
1736 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001737 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001738 // Double-register operations:
1739 case MVT::v8i8: OpcodeIndex = 0; break;
1740 case MVT::v4i16: OpcodeIndex = 1; break;
1741 case MVT::v2f32:
1742 case MVT::v2i32: OpcodeIndex = 2; break;
1743 // Quad-register operations:
1744 case MVT::v8i16: OpcodeIndex = 0; break;
1745 case MVT::v4f32:
1746 case MVT::v4i32: OpcodeIndex = 1; break;
1747 }
1748
Bob Wilson1c3ef902011-02-07 17:43:21 +00001749 std::vector<EVT> ResTys;
1750 if (IsLoad) {
1751 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1752 if (!is64BitVector)
1753 ResTyElts *= 2;
1754 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1755 MVT::i64, ResTyElts));
1756 }
1757 if (isUpdating)
1758 ResTys.push_back(MVT::i32);
1759 ResTys.push_back(MVT::Other);
1760
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001761 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001762 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001763
Bob Wilson1c3ef902011-02-07 17:43:21 +00001764 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001765 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001766 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001767 if (isUpdating) {
1768 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1769 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1770 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001771
Bob Wilson8466fa12010-09-13 23:01:35 +00001772 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001773 SDValue V0 = N->getOperand(Vec0Idx + 0);
1774 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001775 if (NumVecs == 2) {
1776 if (is64BitVector)
1777 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1778 else
1779 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001780 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001781 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001782 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001783 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1784 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001785 if (is64BitVector)
1786 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1787 else
1788 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001789 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001790 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001791 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001792 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001793 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001794 Ops.push_back(Chain);
1795
Bob Wilson1c3ef902011-02-07 17:43:21 +00001796 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1797 QOpcodes[OpcodeIndex]);
1798 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1799 Ops.data(), Ops.size());
Bob Wilson96493442009-10-14 16:46:45 +00001800 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001801 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001802
Bob Wilson8466fa12010-09-13 23:01:35 +00001803 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001804 SuperReg = SDValue(VLdLn, 0);
1805 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1806 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1807 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001808 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1809 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001810 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1811 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1812 if (isUpdating)
1813 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 return NULL;
1815}
1816
Bob Wilson1c3ef902011-02-07 17:43:21 +00001817SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1818 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001819 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1820 DebugLoc dl = N->getDebugLoc();
1821
1822 SDValue MemAddr, Align;
1823 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1824 return NULL;
1825
1826 SDValue Chain = N->getOperand(0);
1827 EVT VT = N->getValueType(0);
1828
1829 unsigned Alignment = 0;
1830 if (NumVecs != 3) {
1831 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1832 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1833 if (Alignment > NumBytes)
1834 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001835 if (Alignment < 8 && Alignment < NumBytes)
1836 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001837 // Alignment must be a power of two; make sure of that.
1838 Alignment = (Alignment & -Alignment);
1839 if (Alignment == 1)
1840 Alignment = 0;
1841 }
1842 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1843
1844 unsigned OpcodeIndex;
1845 switch (VT.getSimpleVT().SimpleTy) {
1846 default: llvm_unreachable("unhandled vld-dup type");
1847 case MVT::v8i8: OpcodeIndex = 0; break;
1848 case MVT::v4i16: OpcodeIndex = 1; break;
1849 case MVT::v2f32:
1850 case MVT::v2i32: OpcodeIndex = 2; break;
1851 }
1852
1853 SDValue Pred = getAL(CurDAG);
1854 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1855 SDValue SuperReg;
1856 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001857 SmallVector<SDValue, 6> Ops;
1858 Ops.push_back(MemAddr);
1859 Ops.push_back(Align);
1860 if (isUpdating) {
1861 SDValue Inc = N->getOperand(2);
1862 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1863 }
1864 Ops.push_back(Pred);
1865 Ops.push_back(Reg0);
1866 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001867
1868 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001869 std::vector<EVT> ResTys;
1870 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts));
1871 if (isUpdating)
1872 ResTys.push_back(MVT::i32);
1873 ResTys.push_back(MVT::Other);
1874 SDNode *VLdDup =
1875 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001876 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001877
1878 // Extract the subregisters.
1879 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1880 unsigned SubIdx = ARM::dsub_0;
1881 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1882 ReplaceUses(SDValue(N, Vec),
1883 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1885 if (isUpdating)
1886 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001887 return NULL;
1888}
1889
Bob Wilson78dfbc32010-07-07 00:08:54 +00001890SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1891 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001892 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1893 DebugLoc dl = N->getDebugLoc();
1894 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001895 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001896
1897 // Form a REG_SEQUENCE to force register allocation.
1898 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001899 SDValue V0 = N->getOperand(FirstTblReg + 0);
1900 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001901 if (NumVecs == 2)
1902 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1903 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001904 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001905 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001906 // an undef.
1907 SDValue V3 = (NumVecs == 3)
1908 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001909 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001910 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1911 }
1912
Bob Wilson78dfbc32010-07-07 00:08:54 +00001913 SmallVector<SDValue, 6> Ops;
1914 if (IsExt)
1915 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001916 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001917 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001918 Ops.push_back(getAL(CurDAG)); // predicate
1919 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001920 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001921}
1922
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001923SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001924 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001925 if (!Subtarget->hasV6T2Ops())
1926 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001927
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001928 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1929 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1930
1931
1932 // For unsigned extracts, check for a shift right and mask
1933 unsigned And_imm = 0;
1934 if (N->getOpcode() == ISD::AND) {
1935 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1936
1937 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1938 if (And_imm & (And_imm + 1))
1939 return NULL;
1940
1941 unsigned Srl_imm = 0;
1942 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1943 Srl_imm)) {
1944 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1945
1946 unsigned Width = CountTrailingOnes_32(And_imm);
1947 unsigned LSB = Srl_imm;
1948 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1949 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1950 CurDAG->getTargetConstant(LSB, MVT::i32),
1951 CurDAG->getTargetConstant(Width, MVT::i32),
1952 getAL(CurDAG), Reg0 };
1953 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1954 }
1955 }
1956 return NULL;
1957 }
1958
1959 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001960 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001961 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001962 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1963 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001965 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1966 unsigned Width = 32 - Srl_imm;
1967 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001968 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001969 return NULL;
1970 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001972 CurDAG->getTargetConstant(LSB, MVT::i32),
1973 CurDAG->getTargetConstant(Width, MVT::i32),
1974 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001975 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001976 }
1977 }
1978 return NULL;
1979}
1980
Evan Cheng9ef48352009-11-20 00:54:03 +00001981SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001982SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001983 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1984 SDValue CPTmp0;
1985 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001986 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001987 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1988 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1989 unsigned Opc = 0;
1990 switch (SOShOp) {
1991 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1992 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1993 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1994 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1995 default:
1996 llvm_unreachable("Unknown so_reg opcode!");
1997 break;
1998 }
1999 SDValue SOShImm =
2000 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2001 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2002 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002003 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002004 }
2005 return 0;
2006}
2007
2008SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002009SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002010 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2011 SDValue CPTmp0;
2012 SDValue CPTmp1;
2013 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002014 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002015 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2016 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002017 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002018 }
2019 return 0;
2020}
2021
2022SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002023SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002024 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002025 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002026 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002027 return 0;
2028
Evan Cheng63f35442010-11-13 02:25:14 +00002029 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002030 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002031 if (is_t2_so_imm(TrueImm)) {
2032 Opc = ARM::t2MOVCCi;
2033 } else if (TrueImm <= 0xffff) {
2034 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002035 } else if (is_t2_so_imm_not(TrueImm)) {
2036 TrueImm = ~TrueImm;
2037 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002038 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002039 // Large immediate.
2040 Opc = ARM::t2MOVCCi32imm;
2041 }
2042
2043 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002044 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002045 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2046 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002047 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002048 }
Evan Cheng63f35442010-11-13 02:25:14 +00002049
Evan Cheng9ef48352009-11-20 00:54:03 +00002050 return 0;
2051}
2052
2053SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002054SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002055 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002056 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2057 if (!T)
2058 return 0;
2059
Evan Cheng63f35442010-11-13 02:25:14 +00002060 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002061 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002062 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002063 if (isSoImm) {
2064 Opc = ARM::MOVCCi;
2065 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2066 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002067 } else if (is_so_imm_not(TrueImm)) {
2068 TrueImm = ~TrueImm;
2069 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002070 } else if (TrueVal.getNode()->hasOneUse() &&
2071 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002072 // Large immediate.
2073 Opc = ARM::MOVCCi32imm;
2074 }
2075
2076 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002077 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2079 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002080 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002081 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002082
Evan Cheng9ef48352009-11-20 00:54:03 +00002083 return 0;
2084}
2085
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002086SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2087 EVT VT = N->getValueType(0);
2088 SDValue FalseVal = N->getOperand(0);
2089 SDValue TrueVal = N->getOperand(1);
2090 SDValue CC = N->getOperand(2);
2091 SDValue CCR = N->getOperand(3);
2092 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002093 assert(CC.getOpcode() == ISD::Constant);
2094 assert(CCR.getOpcode() == ISD::Register);
2095 ARMCC::CondCodes CCVal =
2096 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002097
2098 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2099 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2100 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2101 // Pattern complexity = 18 cost = 1 size = 0
2102 SDValue CPTmp0;
2103 SDValue CPTmp1;
2104 SDValue CPTmp2;
2105 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002107 CCVal, CCR, InFlag);
2108 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002109 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002110 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2111 if (Res)
2112 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002113 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002115 CCVal, CCR, InFlag);
2116 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002117 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002118 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2119 if (Res)
2120 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002121 }
2122
2123 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002124 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002125 // (imm:i32):$cc)
2126 // Emits: (MOVCCi:i32 GPR:i32:$false,
2127 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2128 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002129 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002130 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002131 CCVal, CCR, InFlag);
2132 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002133 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002134 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2135 if (Res)
2136 return Res;
2137 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002138 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002139 CCVal, CCR, InFlag);
2140 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002141 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002142 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2143 if (Res)
2144 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002145 }
2146 }
2147
2148 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2149 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2150 // Pattern complexity = 6 cost = 1 size = 0
2151 //
2152 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2153 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2154 // Pattern complexity = 6 cost = 11 size = 0
2155 //
2156 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002157 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2158 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002159 unsigned Opc = 0;
2160 switch (VT.getSimpleVT().SimpleTy) {
2161 default: assert(false && "Illegal conditional move type!");
2162 break;
2163 case MVT::i32:
2164 Opc = Subtarget->isThumb()
2165 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2166 : ARM::MOVCCr;
2167 break;
2168 case MVT::f32:
2169 Opc = ARM::VMOVScc;
2170 break;
2171 case MVT::f64:
2172 Opc = ARM::VMOVDcc;
2173 break;
2174 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002175 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002176}
2177
Evan Chengde8aa4e2010-05-05 18:28:36 +00002178SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2179 // The only time a CONCAT_VECTORS operation can have legal types is when
2180 // two 64-bit vectors are concatenated to a 128-bit vector.
2181 EVT VT = N->getValueType(0);
2182 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2183 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002184 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002185}
2186
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002187SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002188 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002189
Dan Gohmane8be6c62008-07-17 19:10:17 +00002190 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002191 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002192
2193 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002194 default: break;
2195 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002196 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002197 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002198 if (Subtarget->hasThumb2())
2199 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2200 // be done with MOV + MOVT, at worst.
2201 UseCP = 0;
2202 else {
2203 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002204 UseCP = (Val > 255 && // MOV
2205 ~Val > 255 && // MOV + MVN
2206 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002207 } else
2208 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2209 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2210 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2211 }
2212
Evan Chenga8e29892007-01-19 07:51:42 +00002213 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002214 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002215 CurDAG->getTargetConstantPool(ConstantInt::get(
2216 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002217 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002218
2219 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002220 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002221 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002222 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002223 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002224 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002225 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002226 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002227 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002228 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002229 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002230 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002231 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002232 CurDAG->getEntryNode()
2233 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002234 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002235 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002236 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002237 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002238 return NULL;
2239 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002240
Evan Chenga8e29892007-01-19 07:51:42 +00002241 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002242 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002243 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002244 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002245 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002246 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002247 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002248 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002249 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2250 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002251 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002252 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2253 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002254 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2255 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2256 CurDAG->getRegister(0, MVT::i32) };
2257 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002258 }
Evan Chenga8e29892007-01-19 07:51:42 +00002259 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002260 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002261 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002262 return I;
2263 break;
2264 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002265 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002266 return I;
2267 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002268 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002269 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002270 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002271 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002272 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002273 if (!RHSV) break;
2274 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002275 unsigned ShImm = Log2_32(RHSV-1);
2276 if (ShImm >= 32)
2277 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002278 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002279 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002280 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2281 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002282 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002283 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002284 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002285 } else {
2286 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002287 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002288 }
Evan Chenga8e29892007-01-19 07:51:42 +00002289 }
2290 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002291 unsigned ShImm = Log2_32(RHSV+1);
2292 if (ShImm >= 32)
2293 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002294 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002295 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002296 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2297 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002298 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002299 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2300 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002301 } else {
2302 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002303 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002304 }
Evan Chenga8e29892007-01-19 07:51:42 +00002305 }
2306 }
2307 break;
Evan Cheng20956592009-10-21 08:15:52 +00002308 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002309 // Check for unsigned bitfield extract
2310 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2311 return I;
2312
Evan Cheng20956592009-10-21 08:15:52 +00002313 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2314 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2315 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2316 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2317 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002319 if (VT != MVT::i32)
2320 break;
2321 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2322 ? ARM::t2MOVTi16
2323 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2324 if (!Opc)
2325 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002326 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002327 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2328 if (!N1C)
2329 break;
2330 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2331 SDValue N2 = N0.getOperand(1);
2332 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2333 if (!N2C)
2334 break;
2335 unsigned N1CVal = N1C->getZExtValue();
2336 unsigned N2CVal = N2C->getZExtValue();
2337 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2338 (N1CVal & 0xffffU) == 0xffffU &&
2339 (N2CVal & 0xffffU) == 0x0U) {
2340 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2341 MVT::i32);
2342 SDValue Ops[] = { N0.getOperand(0), Imm16,
2343 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2344 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2345 }
2346 }
2347 break;
2348 }
Jim Grosbache5165492009-11-09 00:11:35 +00002349 case ARMISD::VMOVRRD:
2350 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002351 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002352 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002353 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002354 if (Subtarget->isThumb1Only())
2355 break;
2356 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002357 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002358 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2359 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002360 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002361 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002362 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002363 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2364 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002365 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2366 ARM::UMULL : ARM::UMULLv5,
2367 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002368 }
Evan Chengee568cf2007-07-05 07:15:27 +00002369 }
Dan Gohman525178c2007-10-08 18:33:35 +00002370 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002371 if (Subtarget->isThumb1Only())
2372 break;
2373 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002374 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002375 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002376 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002377 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002378 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002379 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2380 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002381 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2382 ARM::SMULL : ARM::SMULLv5,
2383 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002384 }
Evan Chengee568cf2007-07-05 07:15:27 +00002385 }
Evan Chenga8e29892007-01-19 07:51:42 +00002386 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002387 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002388 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002389 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002390 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002391 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002392 if (ResNode)
2393 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002394 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002395 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002396 }
Evan Chengee568cf2007-07-05 07:15:27 +00002397 case ARMISD::BRCOND: {
2398 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2399 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2400 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002401
Evan Chengee568cf2007-07-05 07:15:27 +00002402 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2403 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2404 // Pattern complexity = 6 cost = 1 size = 0
2405
David Goodwin5e47a9a2009-06-30 18:04:13 +00002406 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2407 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2408 // Pattern complexity = 6 cost = 1 size = 0
2409
Jim Grosbach764ab522009-08-11 15:33:49 +00002410 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002411 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002412 SDValue Chain = N->getOperand(0);
2413 SDValue N1 = N->getOperand(1);
2414 SDValue N2 = N->getOperand(2);
2415 SDValue N3 = N->getOperand(3);
2416 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002417 assert(N1.getOpcode() == ISD::BasicBlock);
2418 assert(N2.getOpcode() == ISD::Constant);
2419 assert(N3.getOpcode() == ISD::Register);
2420
Dan Gohman475871a2008-07-27 21:46:04 +00002421 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002422 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002423 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002424 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002425 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002426 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002427 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002428 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002429 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002430 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002431 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002432 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002433 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002434 return NULL;
2435 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002436 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002437 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002438 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002439 EVT VT = N->getValueType(0);
2440 SDValue N0 = N->getOperand(0);
2441 SDValue N1 = N->getOperand(1);
2442 SDValue N2 = N->getOperand(2);
2443 SDValue N3 = N->getOperand(3);
2444 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002445 assert(N2.getOpcode() == ISD::Constant);
2446 assert(N3.getOpcode() == ISD::Register);
2447
Dan Gohman475871a2008-07-27 21:46:04 +00002448 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002449 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002450 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002451 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002452 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002453 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002454 default: assert(false && "Illegal conditional move type!");
2455 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002456 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002457 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002458 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002459 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002460 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002461 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002462 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002463 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002464 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002465
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002466 case ARMISD::VZIP: {
2467 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002468 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002469 switch (VT.getSimpleVT().SimpleTy) {
2470 default: return NULL;
2471 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2472 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2473 case MVT::v2f32:
2474 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2475 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2476 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2477 case MVT::v4f32:
2478 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2479 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002480 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002481 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2482 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2483 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002484 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002485 case ARMISD::VUZP: {
2486 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002487 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002488 switch (VT.getSimpleVT().SimpleTy) {
2489 default: return NULL;
2490 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2491 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2492 case MVT::v2f32:
2493 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2494 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2495 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2496 case MVT::v4f32:
2497 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2498 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002499 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002500 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2501 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2502 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002503 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002504 case ARMISD::VTRN: {
2505 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002506 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002507 switch (VT.getSimpleVT().SimpleTy) {
2508 default: return NULL;
2509 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2510 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2511 case MVT::v2f32:
2512 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2513 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2514 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2515 case MVT::v4f32:
2516 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2517 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002518 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002519 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2520 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2521 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002522 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002523 case ARMISD::BUILD_VECTOR: {
2524 EVT VecVT = N->getValueType(0);
2525 EVT EltVT = VecVT.getVectorElementType();
2526 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002527 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002528 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2529 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2530 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002531 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002532 if (NumElts == 2)
2533 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2534 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2535 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2536 N->getOperand(2), N->getOperand(3));
2537 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002538
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002539 case ARMISD::VLD2DUP: {
2540 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2541 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002542 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002543 }
2544
Bob Wilson86c6d802010-11-29 19:35:29 +00002545 case ARMISD::VLD3DUP: {
2546 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2547 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002548 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002549 }
2550
Bob Wilson6c4c9822010-11-30 00:00:35 +00002551 case ARMISD::VLD4DUP: {
2552 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2553 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002554 return SelectVLDDup(N, false, 4, Opcodes);
2555 }
2556
2557 case ARMISD::VLD2DUP_UPD: {
2558 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2559 ARM::VLD2DUPd32Pseudo_UPD };
2560 return SelectVLDDup(N, true, 2, Opcodes);
2561 }
2562
2563 case ARMISD::VLD3DUP_UPD: {
2564 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2565 ARM::VLD3DUPd32Pseudo_UPD };
2566 return SelectVLDDup(N, true, 3, Opcodes);
2567 }
2568
2569 case ARMISD::VLD4DUP_UPD: {
2570 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2571 ARM::VLD4DUPd32Pseudo_UPD };
2572 return SelectVLDDup(N, true, 4, Opcodes);
2573 }
2574
2575 case ARMISD::VLD1_UPD: {
2576 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2577 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2578 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2579 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2580 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2581 }
2582
2583 case ARMISD::VLD2_UPD: {
2584 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2585 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2586 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2587 ARM::VLD2q32Pseudo_UPD };
2588 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2589 }
2590
2591 case ARMISD::VLD3_UPD: {
2592 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2593 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2594 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2595 ARM::VLD3q16Pseudo_UPD,
2596 ARM::VLD3q32Pseudo_UPD };
2597 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2598 ARM::VLD3q16oddPseudo_UPD,
2599 ARM::VLD3q32oddPseudo_UPD };
2600 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2601 }
2602
2603 case ARMISD::VLD4_UPD: {
2604 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2605 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2606 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2607 ARM::VLD4q16Pseudo_UPD,
2608 ARM::VLD4q32Pseudo_UPD };
2609 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2610 ARM::VLD4q16oddPseudo_UPD,
2611 ARM::VLD4q32oddPseudo_UPD };
2612 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2613 }
2614
2615 case ARMISD::VLD2LN_UPD: {
2616 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2617 ARM::VLD2LNd32Pseudo_UPD };
2618 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2619 ARM::VLD2LNq32Pseudo_UPD };
2620 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2621 }
2622
2623 case ARMISD::VLD3LN_UPD: {
2624 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2625 ARM::VLD3LNd32Pseudo_UPD };
2626 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2627 ARM::VLD3LNq32Pseudo_UPD };
2628 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2629 }
2630
2631 case ARMISD::VLD4LN_UPD: {
2632 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2633 ARM::VLD4LNd32Pseudo_UPD };
2634 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2635 ARM::VLD4LNq32Pseudo_UPD };
2636 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2637 }
2638
2639 case ARMISD::VST1_UPD: {
2640 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2641 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2642 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2643 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2644 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2645 }
2646
2647 case ARMISD::VST2_UPD: {
2648 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2649 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2650 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2651 ARM::VST2q32Pseudo_UPD };
2652 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2653 }
2654
2655 case ARMISD::VST3_UPD: {
2656 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2657 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2658 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2659 ARM::VST3q16Pseudo_UPD,
2660 ARM::VST3q32Pseudo_UPD };
2661 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2662 ARM::VST3q16oddPseudo_UPD,
2663 ARM::VST3q32oddPseudo_UPD };
2664 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2665 }
2666
2667 case ARMISD::VST4_UPD: {
2668 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2669 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2670 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2671 ARM::VST4q16Pseudo_UPD,
2672 ARM::VST4q32Pseudo_UPD };
2673 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2674 ARM::VST4q16oddPseudo_UPD,
2675 ARM::VST4q32oddPseudo_UPD };
2676 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2677 }
2678
2679 case ARMISD::VST2LN_UPD: {
2680 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2681 ARM::VST2LNd32Pseudo_UPD };
2682 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2683 ARM::VST2LNq32Pseudo_UPD };
2684 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2685 }
2686
2687 case ARMISD::VST3LN_UPD: {
2688 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2689 ARM::VST3LNd32Pseudo_UPD };
2690 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2691 ARM::VST3LNq32Pseudo_UPD };
2692 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2693 }
2694
2695 case ARMISD::VST4LN_UPD: {
2696 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2697 ARM::VST4LNd32Pseudo_UPD };
2698 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2699 ARM::VST4LNq32Pseudo_UPD };
2700 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002701 }
2702
Bob Wilson31fb12f2009-08-26 17:39:53 +00002703 case ISD::INTRINSIC_VOID:
2704 case ISD::INTRINSIC_W_CHAIN: {
2705 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002706 switch (IntNo) {
2707 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002708 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002709
Bob Wilson621f1952010-03-23 05:25:43 +00002710 case Intrinsic::arm_neon_vld1: {
2711 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2712 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002713 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2714 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002715 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002716 }
2717
Bob Wilson31fb12f2009-08-26 17:39:53 +00002718 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002719 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2720 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2721 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2722 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002723 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002724 }
2725
2726 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002727 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2728 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2729 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2730 ARM::VLD3q16Pseudo_UPD,
2731 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002732 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2733 ARM::VLD3q16oddPseudo,
2734 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002735 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002736 }
2737
2738 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002739 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2740 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2741 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2742 ARM::VLD4q16Pseudo_UPD,
2743 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002744 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2745 ARM::VLD4q16oddPseudo,
2746 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002747 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002748 }
2749
Bob Wilson243fcc52009-09-01 04:26:28 +00002750 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002751 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2752 ARM::VLD2LNd32Pseudo };
2753 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002754 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002755 }
2756
2757 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002758 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2759 ARM::VLD3LNd32Pseudo };
2760 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002761 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002762 }
2763
2764 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002765 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2766 ARM::VLD4LNd32Pseudo };
2767 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002768 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002769 }
2770
Bob Wilson11d98992010-03-23 06:20:33 +00002771 case Intrinsic::arm_neon_vst1: {
2772 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2773 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002774 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2775 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002776 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002777 }
2778
Bob Wilson31fb12f2009-08-26 17:39:53 +00002779 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002780 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2781 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2782 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2783 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002784 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002785 }
2786
2787 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002788 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2789 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2790 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2791 ARM::VST3q16Pseudo_UPD,
2792 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002793 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2794 ARM::VST3q16oddPseudo,
2795 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002796 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002797 }
2798
2799 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002800 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002801 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002802 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2803 ARM::VST4q16Pseudo_UPD,
2804 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002805 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2806 ARM::VST4q16oddPseudo,
2807 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002808 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002809 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002810
2811 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002812 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2813 ARM::VST2LNd32Pseudo };
2814 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002815 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002816 }
2817
2818 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002819 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2820 ARM::VST3LNd32Pseudo };
2821 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002822 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002823 }
2824
2825 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002826 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2827 ARM::VST4LNd32Pseudo };
2828 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002829 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002830 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002831 }
Bob Wilson429009b2010-05-06 16:05:26 +00002832 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002833 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002834
Bob Wilsond491d6e2010-07-06 23:36:25 +00002835 case ISD::INTRINSIC_WO_CHAIN: {
2836 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2837 switch (IntNo) {
2838 default:
2839 break;
2840
2841 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002842 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002843 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002844 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002845 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002846 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002847
2848 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002849 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002850 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002851 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002852 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002853 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002854 }
2855 break;
2856 }
2857
Bob Wilson429009b2010-05-06 16:05:26 +00002858 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002859 return SelectConcatVector(N);
2860 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002861
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002862 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002863}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002864
Bob Wilson224c2442009-05-19 05:53:42 +00002865bool ARMDAGToDAGISel::
2866SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2867 std::vector<SDValue> &OutOps) {
2868 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002869 // Require the address to be in a register. That is safe for all ARM
2870 // variants and it is hard to do anything much smarter without knowing
2871 // how the operand is used.
2872 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002873 return false;
2874}
2875
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002876/// createARMISelDag - This pass converts a legalized DAG into a
2877/// ARM-specific DAG, ready for instruction scheduling.
2878///
Bob Wilson522ce972009-09-28 14:30:20 +00002879FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2880 CodeGenOpt::Level OptLevel) {
2881 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002882}