blob: 5dd84341f845b6aa0f63a517ac0bf7130c9d31b3 [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.
430 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
431 if (N.getOpcode() == ISD::FrameIndex) {
432 // Match frame index...
433 int FI = cast<FrameIndexSDNode>(N)->getIndex();
434 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
435 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
436 return true;
437 } else if (N.getOpcode() == ARMISD::Wrapper &&
438 !(Subtarget->useMovt() &&
439 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
440 Base = N.getOperand(0);
441 } else
442 Base = N;
443 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
444 return true;
445 }
446
447 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
448 int RHSC = (int)RHS->getZExtValue();
449 if (N.getOpcode() == ISD::SUB)
450 RHSC = -RHSC;
451
452 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
453 Base = N.getOperand(0);
454 if (Base.getOpcode() == ISD::FrameIndex) {
455 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
456 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
457 }
458 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
459 return true;
460 }
461 }
462
463 // Base only.
464 Base = N;
465 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
466 return true;
467}
468
469
470
471bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
472 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000473 if (N.getOpcode() == ISD::MUL &&
474 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000475 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
476 // X * [3,5,9] -> X + X * [2,4,8] etc.
477 int RHSC = (int)RHS->getZExtValue();
478 if (RHSC & 1) {
479 RHSC = RHSC & ~1;
480 ARM_AM::AddrOpc AddSub = ARM_AM::add;
481 if (RHSC < 0) {
482 AddSub = ARM_AM::sub;
483 RHSC = - RHSC;
484 }
485 if (isPowerOf2_32(RHSC)) {
486 unsigned ShAmt = Log2_32(RHSC);
487 Base = Offset = N.getOperand(0);
488 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
489 ARM_AM::lsl),
490 MVT::i32);
491 return true;
492 }
493 }
494 }
495 }
496
497 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
498 return false;
499
500 // Leave simple R +/- imm12 operands for LDRi12
501 if (N.getOpcode() == ISD::ADD) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000502 int RHSC;
503 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
504 -0x1000+1, 0x1000, RHSC)) // 12 bits.
505 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000506 }
507
Evan Chengf40deed2010-10-27 23:41:30 +0000508 if (Subtarget->isCortexA9() && !N.hasOneUse())
509 // Compute R +/- (R << N) and reuse it.
510 return false;
511
Jim Grosbach3e556122010-10-26 22:37:02 +0000512 // Otherwise this is R +/- [possibly shifted] R.
513 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
514 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
515 unsigned ShAmt = 0;
516
517 Base = N.getOperand(0);
518 Offset = N.getOperand(1);
519
520 if (ShOpcVal != ARM_AM::no_shift) {
521 // Check to see if the RHS of the shift is a constant, if not, we can't fold
522 // it.
523 if (ConstantSDNode *Sh =
524 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
525 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000526 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
527 Offset = N.getOperand(1).getOperand(0);
528 else {
529 ShAmt = 0;
530 ShOpcVal = ARM_AM::no_shift;
531 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000532 } else {
533 ShOpcVal = ARM_AM::no_shift;
534 }
535 }
536
537 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000538 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
539 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000540 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
541 if (ShOpcVal != ARM_AM::no_shift) {
542 // Check to see if the RHS of the shift is a constant, if not, we can't
543 // fold it.
544 if (ConstantSDNode *Sh =
545 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
546 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000547 if (!Subtarget->isCortexA9() ||
548 (N.hasOneUse() &&
549 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
550 Offset = N.getOperand(0).getOperand(0);
551 Base = N.getOperand(1);
552 } else {
553 ShAmt = 0;
554 ShOpcVal = ARM_AM::no_shift;
555 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000556 } else {
557 ShOpcVal = ARM_AM::no_shift;
558 }
559 }
560 }
561
562 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
563 MVT::i32);
564 return true;
565}
566
567
568
569
570//-----
571
Jim Grosbach82891622010-09-29 19:03:54 +0000572AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
573 SDValue &Base,
574 SDValue &Offset,
575 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000576 if (N.getOpcode() == ISD::MUL &&
577 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000578 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
579 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000580 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000581 if (RHSC & 1) {
582 RHSC = RHSC & ~1;
583 ARM_AM::AddrOpc AddSub = ARM_AM::add;
584 if (RHSC < 0) {
585 AddSub = ARM_AM::sub;
586 RHSC = - RHSC;
587 }
588 if (isPowerOf2_32(RHSC)) {
589 unsigned ShAmt = Log2_32(RHSC);
590 Base = Offset = N.getOperand(0);
591 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
592 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000593 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000594 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000595 }
596 }
597 }
598 }
599
Evan Chenga8e29892007-01-19 07:51:42 +0000600 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
601 Base = N;
602 if (N.getOpcode() == ISD::FrameIndex) {
603 int FI = cast<FrameIndexSDNode>(N)->getIndex();
604 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000605 } else if (N.getOpcode() == ARMISD::Wrapper &&
606 !(Subtarget->useMovt() &&
607 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000608 Base = N.getOperand(0);
609 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000611 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
612 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000613 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000614 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000615 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000616
Evan Chenga8e29892007-01-19 07:51:42 +0000617 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000618 if (N.getOpcode() == ISD::ADD) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000619 int RHSC;
620 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
621 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
622 Base = N.getOperand(0);
623 if (Base.getOpcode() == ISD::FrameIndex) {
624 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
625 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000626 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000627 Offset = CurDAG->getRegister(0, MVT::i32);
628
629 ARM_AM::AddrOpc AddSub = ARM_AM::add;
630 if (RHSC < 0) {
631 AddSub = ARM_AM::sub;
632 RHSC = - RHSC;
633 }
634 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
635 ARM_AM::no_shift),
636 MVT::i32);
637 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000638 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000639 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000640
Evan Chengf40deed2010-10-27 23:41:30 +0000641 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
642 // Compute R +/- (R << N) and reuse it.
643 Base = N;
644 Offset = CurDAG->getRegister(0, MVT::i32);
645 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
646 ARM_AM::no_shift),
647 MVT::i32);
648 return AM2_BASE;
649 }
650
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000651 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000652 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
653 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
654 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000655
Evan Chenga8e29892007-01-19 07:51:42 +0000656 Base = N.getOperand(0);
657 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000658
Evan Chenga8e29892007-01-19 07:51:42 +0000659 if (ShOpcVal != ARM_AM::no_shift) {
660 // Check to see if the RHS of the shift is a constant, if not, we can't fold
661 // it.
662 if (ConstantSDNode *Sh =
663 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000664 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000665 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
666 Offset = N.getOperand(1).getOperand(0);
667 else {
668 ShAmt = 0;
669 ShOpcVal = ARM_AM::no_shift;
670 }
Evan Chenga8e29892007-01-19 07:51:42 +0000671 } else {
672 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000673 }
674 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000675
Evan Chenga8e29892007-01-19 07:51:42 +0000676 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000677 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
678 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000679 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
680 if (ShOpcVal != ARM_AM::no_shift) {
681 // Check to see if the RHS of the shift is a constant, if not, we can't
682 // fold it.
683 if (ConstantSDNode *Sh =
684 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000685 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000686 if (!Subtarget->isCortexA9() ||
687 (N.hasOneUse() &&
688 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
689 Offset = N.getOperand(0).getOperand(0);
690 Base = N.getOperand(1);
691 } else {
692 ShAmt = 0;
693 ShOpcVal = ARM_AM::no_shift;
694 }
Evan Chenga8e29892007-01-19 07:51:42 +0000695 } else {
696 ShOpcVal = ARM_AM::no_shift;
697 }
698 }
699 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000700
Evan Chenga8e29892007-01-19 07:51:42 +0000701 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000702 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000703 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000704}
705
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000706bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000707 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000708 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000709 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
710 ? cast<LoadSDNode>(Op)->getAddressingMode()
711 : cast<StoreSDNode>(Op)->getAddressingMode();
712 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
713 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000714 int Val;
715 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
716 Offset = CurDAG->getRegister(0, MVT::i32);
717 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
718 ARM_AM::no_shift),
719 MVT::i32);
720 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000721 }
722
723 Offset = N;
724 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
725 unsigned ShAmt = 0;
726 if (ShOpcVal != ARM_AM::no_shift) {
727 // Check to see if the RHS of the shift is a constant, if not, we can't fold
728 // it.
729 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000730 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000731 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
732 Offset = N.getOperand(0);
733 else {
734 ShAmt = 0;
735 ShOpcVal = ARM_AM::no_shift;
736 }
Evan Chenga8e29892007-01-19 07:51:42 +0000737 } else {
738 ShOpcVal = ARM_AM::no_shift;
739 }
740 }
741
742 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000743 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000744 return true;
745}
746
Evan Chenga8e29892007-01-19 07:51:42 +0000747
Chris Lattner52a261b2010-09-21 20:31:19 +0000748bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000749 SDValue &Base, SDValue &Offset,
750 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000751 if (N.getOpcode() == ISD::SUB) {
752 // X - C is canonicalize to X + -C, no need to handle it here.
753 Base = N.getOperand(0);
754 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000756 return true;
757 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000758
Evan Chenga8e29892007-01-19 07:51:42 +0000759 if (N.getOpcode() != ISD::ADD) {
760 Base = N;
761 if (N.getOpcode() == ISD::FrameIndex) {
762 int FI = cast<FrameIndexSDNode>(N)->getIndex();
763 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
764 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000765 Offset = CurDAG->getRegister(0, MVT::i32);
766 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000767 return true;
768 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000769
Evan Chenga8e29892007-01-19 07:51:42 +0000770 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000771 int RHSC;
772 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
773 -256 + 1, 256, RHSC)) { // 8 bits.
774 Base = N.getOperand(0);
775 if (Base.getOpcode() == ISD::FrameIndex) {
776 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
777 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000778 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000779 Offset = CurDAG->getRegister(0, MVT::i32);
780
781 ARM_AM::AddrOpc AddSub = ARM_AM::add;
782 if (RHSC < 0) {
783 AddSub = ARM_AM::sub;
784 RHSC = - RHSC;
785 }
786 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
787 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000788 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000789
Evan Chenga8e29892007-01-19 07:51:42 +0000790 Base = N.getOperand(0);
791 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000792 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000793 return true;
794}
795
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000796bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000797 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000798 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000799 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
800 ? cast<LoadSDNode>(Op)->getAddressingMode()
801 : cast<StoreSDNode>(Op)->getAddressingMode();
802 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
803 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000804 int Val;
805 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
806 Offset = CurDAG->getRegister(0, MVT::i32);
807 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
808 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000809 }
810
811 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000812 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000813 return true;
814}
815
Jim Grosbach3ab56582010-10-21 19:38:40 +0000816bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000817 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000818 if (N.getOpcode() != ISD::ADD) {
819 Base = N;
820 if (N.getOpcode() == ISD::FrameIndex) {
821 int FI = cast<FrameIndexSDNode>(N)->getIndex();
822 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000823 } else if (N.getOpcode() == ARMISD::Wrapper &&
824 !(Subtarget->useMovt() &&
825 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000826 Base = N.getOperand(0);
827 }
828 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000829 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000830 return true;
831 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000832
Evan Chenga8e29892007-01-19 07:51:42 +0000833 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000834 int RHSC;
835 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
836 -256 + 1, 256, RHSC)) {
837 Base = N.getOperand(0);
838 if (Base.getOpcode() == ISD::FrameIndex) {
839 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
840 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000841 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000842
843 ARM_AM::AddrOpc AddSub = ARM_AM::add;
844 if (RHSC < 0) {
845 AddSub = ARM_AM::sub;
846 RHSC = - RHSC;
847 }
848 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
849 MVT::i32);
850 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000851 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000852
Evan Chenga8e29892007-01-19 07:51:42 +0000853 Base = N;
854 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000855 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000856 return true;
857}
858
Bob Wilson665814b2010-11-01 23:40:51 +0000859bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
860 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000861 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000862
863 unsigned Alignment = 0;
864 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
865 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
866 // The maximum alignment is equal to the memory size being referenced.
867 unsigned LSNAlign = LSN->getAlignment();
868 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
869 if (LSNAlign > MemSize && MemSize > 1)
870 Alignment = MemSize;
871 } else {
872 // All other uses of addrmode6 are for intrinsics. For now just record
873 // the raw alignment value; it will be refined later based on the legal
874 // alignment operands for the intrinsic.
875 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
876 }
877
878 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000879 return true;
880}
881
Chris Lattner52a261b2010-09-21 20:31:19 +0000882bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000883 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000884 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
885 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000886 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000887 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
888 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000889 return true;
890 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000891
Evan Chenga8e29892007-01-19 07:51:42 +0000892 return false;
893}
894
Bill Wendlingf4caf692010-12-14 03:36:38 +0000895
896//===----------------------------------------------------------------------===//
897// Thumb Addressing Modes
898//===----------------------------------------------------------------------===//
899
Chris Lattner52a261b2010-09-21 20:31:19 +0000900bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000901 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000902 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000903 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000904 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000905 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000906 return false;
907
908 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000909 return true;
910 }
911
Evan Chenga8e29892007-01-19 07:51:42 +0000912 Base = N.getOperand(0);
913 Offset = N.getOperand(1);
914 return true;
915}
916
Evan Cheng79d43262007-01-24 02:21:22 +0000917bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000918ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
919 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000920 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000921 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000922 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000923 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000924
Evan Cheng012f2d92007-01-24 08:53:17 +0000925 if (N.getOpcode() == ARMISD::Wrapper &&
926 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
927 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000928 }
929
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000930 if (N.getOpcode() != ISD::ADD)
931 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000932
Evan Chengad0e4652007-02-06 00:22:06 +0000933 // Thumb does not have [sp, r] address mode.
934 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
935 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
936 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000937 (RHSR && RHSR->getReg() == ARM::SP))
938 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000939
Daniel Dunbarec91d522011-01-19 15:12:16 +0000940 // FIXME: Why do we explicitly check for a match here and then return false?
941 // Presumably to allow something else to match, but shouldn't this be
942 // documented?
943 int RHSC;
944 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
945 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000946
947 Base = N.getOperand(0);
948 Offset = N.getOperand(1);
949 return true;
950}
951
952bool
953ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
954 SDValue &Base,
955 SDValue &Offset) {
956 return SelectThumbAddrModeRI(N, Base, Offset, 1);
957}
958
959bool
960ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
961 SDValue &Base,
962 SDValue &Offset) {
963 return SelectThumbAddrModeRI(N, Base, Offset, 2);
964}
965
966bool
967ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
968 SDValue &Base,
969 SDValue &Offset) {
970 return SelectThumbAddrModeRI(N, Base, Offset, 4);
971}
972
973bool
974ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
975 SDValue &Base, SDValue &OffImm) {
976 if (Scale == 4) {
977 SDValue TmpBase, TmpOffImm;
978 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
979 return false; // We want to select tLDRspi / tSTRspi instead.
980
981 if (N.getOpcode() == ARMISD::Wrapper &&
982 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
983 return false; // We want to select tLDRpci instead.
984 }
985
986 if (N.getOpcode() != ISD::ADD) {
987 if (N.getOpcode() == ARMISD::Wrapper &&
988 !(Subtarget->useMovt() &&
989 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
990 Base = N.getOperand(0);
991 } else {
992 Base = N;
993 }
994
Owen Anderson825b72b2009-08-11 20:47:22 +0000995 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000996 return true;
997 }
998
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000999 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1000 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1001 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1002 (RHSR && RHSR->getReg() == ARM::SP)) {
1003 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1004 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1005 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1006 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1007
1008 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1009 if (LHSC != 0 || RHSC != 0) return false;
1010
1011 Base = N;
1012 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1013 return true;
1014 }
1015
Evan Chenga8e29892007-01-19 07:51:42 +00001016 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001017 int RHSC;
1018 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1019 Base = N.getOperand(0);
1020 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1021 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001022 }
1023
Evan Chengc38f2bc2007-01-23 22:59:13 +00001024 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001025 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001026 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001027}
1028
Bill Wendlingf4caf692010-12-14 03:36:38 +00001029bool
1030ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1031 SDValue &OffImm) {
1032 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001033}
1034
Bill Wendlingf4caf692010-12-14 03:36:38 +00001035bool
1036ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1037 SDValue &OffImm) {
1038 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001039}
1040
Bill Wendlingf4caf692010-12-14 03:36:38 +00001041bool
1042ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1043 SDValue &OffImm) {
1044 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001045}
1046
Chris Lattner52a261b2010-09-21 20:31:19 +00001047bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1048 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001049 if (N.getOpcode() == ISD::FrameIndex) {
1050 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1051 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001052 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001053 return true;
1054 }
Evan Cheng79d43262007-01-24 02:21:22 +00001055
Evan Chengad0e4652007-02-06 00:22:06 +00001056 if (N.getOpcode() != ISD::ADD)
1057 return false;
1058
1059 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001060 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1061 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001062 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001063 int RHSC;
1064 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1065 Base = N.getOperand(0);
1066 if (Base.getOpcode() == ISD::FrameIndex) {
1067 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1068 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001069 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001070 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1071 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001072 }
1073 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001074
Evan Chenga8e29892007-01-19 07:51:42 +00001075 return false;
1076}
1077
Bill Wendlingf4caf692010-12-14 03:36:38 +00001078
1079//===----------------------------------------------------------------------===//
1080// Thumb 2 Addressing Modes
1081//===----------------------------------------------------------------------===//
1082
1083
Chris Lattner52a261b2010-09-21 20:31:19 +00001084bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001085 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001086 if (DisableShifterOp)
1087 return false;
1088
Evan Cheng9cb9e672009-06-27 02:26:13 +00001089 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1090
1091 // Don't match base register only case. That is matched to a separate
1092 // lower complexity pattern with explicit register operand.
1093 if (ShOpcVal == ARM_AM::no_shift) return false;
1094
1095 BaseReg = N.getOperand(0);
1096 unsigned ShImmVal = 0;
1097 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1098 ShImmVal = RHS->getZExtValue() & 31;
1099 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1100 return true;
1101 }
1102
1103 return false;
1104}
1105
Chris Lattner52a261b2010-09-21 20:31:19 +00001106bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001107 SDValue &Base, SDValue &OffImm) {
1108 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001109
Evan Cheng3a214252009-08-11 08:52:18 +00001110 // Base only.
1111 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001112 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001113 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001114 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1115 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001116 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001117 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001118 } else if (N.getOpcode() == ARMISD::Wrapper &&
1119 !(Subtarget->useMovt() &&
1120 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001121 Base = N.getOperand(0);
1122 if (Base.getOpcode() == ISD::TargetConstantPool)
1123 return false; // We want to select t2LDRpci instead.
1124 } else
1125 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001126 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001127 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001128 }
Evan Cheng055b0312009-06-29 07:51:04 +00001129
1130 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001131 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001132 // Let t2LDRi8 handle (R - imm8).
1133 return false;
1134
Evan Cheng055b0312009-06-29 07:51:04 +00001135 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001136 if (N.getOpcode() == ISD::SUB)
1137 RHSC = -RHSC;
1138
1139 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001140 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001141 if (Base.getOpcode() == ISD::FrameIndex) {
1142 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1143 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1144 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001145 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001146 return true;
1147 }
1148 }
1149
Evan Cheng3a214252009-08-11 08:52:18 +00001150 // Base only.
1151 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001152 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001153 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001154}
1155
Chris Lattner52a261b2010-09-21 20:31:19 +00001156bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001157 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001158 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001159 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001160 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1161 int RHSC = (int)RHS->getSExtValue();
1162 if (N.getOpcode() == ISD::SUB)
1163 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001164
Evan Cheng3a214252009-08-11 08:52:18 +00001165 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1166 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001167 if (Base.getOpcode() == ISD::FrameIndex) {
1168 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1169 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1170 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001171 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001172 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001173 }
Evan Cheng055b0312009-06-29 07:51:04 +00001174 }
1175 }
1176
1177 return false;
1178}
1179
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001180bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001181 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001182 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001183 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1184 ? cast<LoadSDNode>(Op)->getAddressingMode()
1185 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001186 int RHSC;
1187 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1188 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1189 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1190 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1191 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001192 }
1193
1194 return false;
1195}
1196
Chris Lattner52a261b2010-09-21 20:31:19 +00001197bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001198 SDValue &Base,
1199 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001200 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1201 if (N.getOpcode() != ISD::ADD)
1202 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001203
Evan Cheng3a214252009-08-11 08:52:18 +00001204 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1205 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1206 int RHSC = (int)RHS->getZExtValue();
1207 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1208 return false;
1209 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001210 return false;
1211 }
1212
Evan Chengf40deed2010-10-27 23:41:30 +00001213 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1214 // Compute R + (R << [1,2,3]) and reuse it.
1215 Base = N;
1216 return false;
1217 }
1218
Evan Cheng055b0312009-06-29 07:51:04 +00001219 // Look for (R + R) or (R + (R << [1,2,3])).
1220 unsigned ShAmt = 0;
1221 Base = N.getOperand(0);
1222 OffReg = N.getOperand(1);
1223
1224 // Swap if it is ((R << c) + R).
1225 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1226 if (ShOpcVal != ARM_AM::lsl) {
1227 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1228 if (ShOpcVal == ARM_AM::lsl)
1229 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001230 }
1231
Evan Cheng055b0312009-06-29 07:51:04 +00001232 if (ShOpcVal == ARM_AM::lsl) {
1233 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1234 // it.
1235 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1236 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001237 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1238 OffReg = OffReg.getOperand(0);
1239 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001240 ShAmt = 0;
1241 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001242 }
Evan Cheng055b0312009-06-29 07:51:04 +00001243 } else {
1244 ShOpcVal = ARM_AM::no_shift;
1245 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001246 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001247
Owen Anderson825b72b2009-08-11 20:47:22 +00001248 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001249
1250 return true;
1251}
1252
1253//===--------------------------------------------------------------------===//
1254
Evan Chengee568cf2007-07-05 07:15:27 +00001255/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001256static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001257 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001258}
1259
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001260SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1261 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001262 ISD::MemIndexedMode AM = LD->getAddressingMode();
1263 if (AM == ISD::UNINDEXED)
1264 return NULL;
1265
Owen Andersone50ed302009-08-10 22:56:29 +00001266 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001267 SDValue Offset, AMOpc;
1268 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1269 unsigned Opcode = 0;
1270 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001271 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001272 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001273 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1274 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001275 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001276 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001277 Match = true;
1278 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1279 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1280 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001281 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001282 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001283 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001284 Match = true;
1285 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1286 }
1287 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001288 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001289 Match = true;
1290 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1291 }
1292 }
1293 }
1294
1295 if (Match) {
1296 SDValue Chain = LD->getChain();
1297 SDValue Base = LD->getBasePtr();
1298 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001299 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001300 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001301 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001302 }
1303
1304 return NULL;
1305}
1306
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001307SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1308 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001309 ISD::MemIndexedMode AM = LD->getAddressingMode();
1310 if (AM == ISD::UNINDEXED)
1311 return NULL;
1312
Owen Andersone50ed302009-08-10 22:56:29 +00001313 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001314 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001315 SDValue Offset;
1316 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1317 unsigned Opcode = 0;
1318 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001319 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001320 switch (LoadedVT.getSimpleVT().SimpleTy) {
1321 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001322 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1323 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001324 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001325 if (isSExtLd)
1326 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1327 else
1328 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001329 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001330 case MVT::i8:
1331 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001332 if (isSExtLd)
1333 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1334 else
1335 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001336 break;
1337 default:
1338 return NULL;
1339 }
1340 Match = true;
1341 }
1342
1343 if (Match) {
1344 SDValue Chain = LD->getChain();
1345 SDValue Base = LD->getBasePtr();
1346 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001347 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001348 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001349 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001350 }
1351
1352 return NULL;
1353}
1354
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001355/// PairSRegs - Form a D register from a pair of S registers.
1356///
1357SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1358 DebugLoc dl = V0.getNode()->getDebugLoc();
1359 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1360 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001361 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1362 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001363}
1364
Evan Cheng603afbf2010-05-10 17:34:18 +00001365/// PairDRegs - Form a quad register from a pair of D registers.
1366///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001367SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1368 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001369 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1370 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001371 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1372 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001373}
1374
Evan Cheng7f687192010-05-14 00:21:45 +00001375/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001376///
1377SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1378 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001379 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1380 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001381 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1382 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1383}
1384
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001385/// QuadSRegs - Form 4 consecutive S registers.
1386///
1387SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1388 SDValue V2, SDValue V3) {
1389 DebugLoc dl = V0.getNode()->getDebugLoc();
1390 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1391 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1392 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1393 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1394 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1395 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1396}
1397
Evan Cheng7f687192010-05-14 00:21:45 +00001398/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001399///
1400SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1401 SDValue V2, SDValue V3) {
1402 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001403 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1404 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1405 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1406 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001407 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1408 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1409}
1410
Evan Cheng8f6de382010-05-16 03:27:48 +00001411/// QuadQRegs - Form 4 consecutive Q registers.
1412///
1413SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1414 SDValue V2, SDValue V3) {
1415 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001416 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1417 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1418 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1419 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001420 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1421 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1422}
1423
Bob Wilson2a6e6162010-09-23 23:42:37 +00001424/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1425/// of a NEON VLD or VST instruction. The supported values depend on the
1426/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001427SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1428 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001429 unsigned NumRegs = NumVecs;
1430 if (!is64BitVector && NumVecs < 3)
1431 NumRegs *= 2;
1432
Bob Wilson665814b2010-11-01 23:40:51 +00001433 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001434 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001435 Alignment = 32;
1436 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1437 Alignment = 16;
1438 else if (Alignment >= 8)
1439 Alignment = 8;
1440 else
1441 Alignment = 0;
1442
1443 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001444}
1445
Bob Wilson1c3ef902011-02-07 17:43:21 +00001446SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001447 unsigned *DOpcodes, unsigned *QOpcodes0,
1448 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001449 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001450 DebugLoc dl = N->getDebugLoc();
1451
Bob Wilson226036e2010-03-20 22:13:40 +00001452 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001453 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1454 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001455 return NULL;
1456
1457 SDValue Chain = N->getOperand(0);
1458 EVT VT = N->getValueType(0);
1459 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001460 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001461
Bob Wilson3e36f132009-10-14 17:28:52 +00001462 unsigned OpcodeIndex;
1463 switch (VT.getSimpleVT().SimpleTy) {
1464 default: llvm_unreachable("unhandled vld type");
1465 // Double-register operations:
1466 case MVT::v8i8: OpcodeIndex = 0; break;
1467 case MVT::v4i16: OpcodeIndex = 1; break;
1468 case MVT::v2f32:
1469 case MVT::v2i32: OpcodeIndex = 2; break;
1470 case MVT::v1i64: OpcodeIndex = 3; break;
1471 // Quad-register operations:
1472 case MVT::v16i8: OpcodeIndex = 0; break;
1473 case MVT::v8i16: OpcodeIndex = 1; break;
1474 case MVT::v4f32:
1475 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001476 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001477 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001478 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001479 }
1480
Bob Wilsonf5721912010-09-03 18:16:02 +00001481 EVT ResTy;
1482 if (NumVecs == 1)
1483 ResTy = VT;
1484 else {
1485 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1486 if (!is64BitVector)
1487 ResTyElts *= 2;
1488 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1489 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001490 std::vector<EVT> ResTys;
1491 ResTys.push_back(ResTy);
1492 if (isUpdating)
1493 ResTys.push_back(MVT::i32);
1494 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001495
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001496 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001497 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001498 SDNode *VLd;
1499 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001500
Bob Wilson1c3ef902011-02-07 17:43:21 +00001501 // Double registers and VLD1/VLD2 quad registers are directly supported.
1502 if (is64BitVector || NumVecs <= 2) {
1503 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1504 QOpcodes0[OpcodeIndex]);
1505 Ops.push_back(MemAddr);
1506 Ops.push_back(Align);
1507 if (isUpdating) {
1508 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1509 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001510 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001511 Ops.push_back(Pred);
1512 Ops.push_back(Reg0);
1513 Ops.push_back(Chain);
1514 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001515
Bob Wilson3e36f132009-10-14 17:28:52 +00001516 } else {
1517 // Otherwise, quad registers are loaded with two separate instructions,
1518 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001519 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001520
Bob Wilson1c3ef902011-02-07 17:43:21 +00001521 // Load the even subregs. This is always an updating load, so that it
1522 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001523 SDValue ImplDef =
1524 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1525 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001526 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1527 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001528 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001529
Bob Wilson24f995d2009-10-14 18:32:29 +00001530 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001531 Ops.push_back(SDValue(VLdA, 1));
1532 Ops.push_back(Align);
1533 if (isUpdating) {
1534 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1535 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1536 "only constant post-increment update allowed for VLD3/4");
1537 (void)Inc;
1538 Ops.push_back(Reg0);
1539 }
1540 Ops.push_back(SDValue(VLdA, 0));
1541 Ops.push_back(Pred);
1542 Ops.push_back(Reg0);
1543 Ops.push_back(Chain);
1544 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1545 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001546 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001547
Bob Wilson1c3ef902011-02-07 17:43:21 +00001548 if (NumVecs == 1)
1549 return VLd;
1550
1551 // Extract out the subregisters.
1552 SDValue SuperReg = SDValue(VLd, 0);
1553 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1554 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1555 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1556 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1557 ReplaceUses(SDValue(N, Vec),
1558 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1559 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1560 if (isUpdating)
1561 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001562 return NULL;
1563}
1564
Bob Wilson1c3ef902011-02-07 17:43:21 +00001565SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001566 unsigned *DOpcodes, unsigned *QOpcodes0,
1567 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001568 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001569 DebugLoc dl = N->getDebugLoc();
1570
Bob Wilson226036e2010-03-20 22:13:40 +00001571 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001572 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1573 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1574 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001575 return NULL;
1576
1577 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001578 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001579 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001580 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001581
Bob Wilson24f995d2009-10-14 18:32:29 +00001582 unsigned OpcodeIndex;
1583 switch (VT.getSimpleVT().SimpleTy) {
1584 default: llvm_unreachable("unhandled vst type");
1585 // Double-register operations:
1586 case MVT::v8i8: OpcodeIndex = 0; break;
1587 case MVT::v4i16: OpcodeIndex = 1; break;
1588 case MVT::v2f32:
1589 case MVT::v2i32: OpcodeIndex = 2; break;
1590 case MVT::v1i64: OpcodeIndex = 3; break;
1591 // Quad-register operations:
1592 case MVT::v16i8: OpcodeIndex = 0; break;
1593 case MVT::v8i16: OpcodeIndex = 1; break;
1594 case MVT::v4f32:
1595 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001596 case MVT::v2i64: OpcodeIndex = 3;
1597 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1598 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001599 }
1600
Bob Wilson1c3ef902011-02-07 17:43:21 +00001601 std::vector<EVT> ResTys;
1602 if (isUpdating)
1603 ResTys.push_back(MVT::i32);
1604 ResTys.push_back(MVT::Other);
1605
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001606 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001607 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001608 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001609
Bob Wilson1c3ef902011-02-07 17:43:21 +00001610 // Double registers and VST1/VST2 quad registers are directly supported.
1611 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001612 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001613 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001614 SrcReg = N->getOperand(Vec0Idx);
1615 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001616 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001617 SDValue V0 = N->getOperand(Vec0Idx + 0);
1618 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001619 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001620 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001621 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001622 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001623 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001624 // an undef.
1625 SDValue V3 = (NumVecs == 3)
1626 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001627 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001628 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001629 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001630 } else {
1631 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001632 SDValue Q0 = N->getOperand(Vec0Idx);
1633 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001634 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001635 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001636
1637 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1638 QOpcodes0[OpcodeIndex]);
1639 Ops.push_back(MemAddr);
1640 Ops.push_back(Align);
1641 if (isUpdating) {
1642 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1643 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1644 }
1645 Ops.push_back(SrcReg);
1646 Ops.push_back(Pred);
1647 Ops.push_back(Reg0);
1648 Ops.push_back(Chain);
1649 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001650 }
1651
1652 // Otherwise, quad registers are stored with two separate instructions,
1653 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001654
Bob Wilson07f6e802010-06-16 21:34:01 +00001655 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001656 SDValue V0 = N->getOperand(Vec0Idx + 0);
1657 SDValue V1 = N->getOperand(Vec0Idx + 1);
1658 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001659 SDValue V3 = (NumVecs == 3)
1660 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001661 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001662 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001663
Bob Wilson1c3ef902011-02-07 17:43:21 +00001664 // Store the even D registers. This is always an updating store, so that it
1665 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001666 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1667 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1668 MemAddr.getValueType(),
1669 MVT::Other, OpsA, 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001670 Chain = SDValue(VStA, 1);
1671
1672 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001673 Ops.push_back(SDValue(VStA, 0));
1674 Ops.push_back(Align);
1675 if (isUpdating) {
1676 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1677 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1678 "only constant post-increment update allowed for VST3/4");
1679 (void)Inc;
1680 Ops.push_back(Reg0);
1681 }
1682 Ops.push_back(RegSeq);
1683 Ops.push_back(Pred);
1684 Ops.push_back(Reg0);
1685 Ops.push_back(Chain);
1686 return CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1687 Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001688}
1689
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001690SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001691 bool isUpdating, unsigned NumVecs,
1692 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001693 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001694 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001695 DebugLoc dl = N->getDebugLoc();
1696
Bob Wilson226036e2010-03-20 22:13:40 +00001697 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001698 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1699 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1700 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001701 return NULL;
1702
1703 SDValue Chain = N->getOperand(0);
1704 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001705 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1706 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001707 bool is64BitVector = VT.is64BitVector();
1708
Bob Wilson665814b2010-11-01 23:40:51 +00001709 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001710 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001711 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001712 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1713 if (Alignment > NumBytes)
1714 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001715 if (Alignment < 8 && Alignment < NumBytes)
1716 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001717 // Alignment must be a power of two; make sure of that.
1718 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001719 if (Alignment == 1)
1720 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001721 }
Bob Wilson665814b2010-11-01 23:40:51 +00001722 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001723
Bob Wilsona7c397c2009-10-14 16:19:03 +00001724 unsigned OpcodeIndex;
1725 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001726 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001727 // Double-register operations:
1728 case MVT::v8i8: OpcodeIndex = 0; break;
1729 case MVT::v4i16: OpcodeIndex = 1; break;
1730 case MVT::v2f32:
1731 case MVT::v2i32: OpcodeIndex = 2; break;
1732 // Quad-register operations:
1733 case MVT::v8i16: OpcodeIndex = 0; break;
1734 case MVT::v4f32:
1735 case MVT::v4i32: OpcodeIndex = 1; break;
1736 }
1737
Bob Wilson1c3ef902011-02-07 17:43:21 +00001738 std::vector<EVT> ResTys;
1739 if (IsLoad) {
1740 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1741 if (!is64BitVector)
1742 ResTyElts *= 2;
1743 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1744 MVT::i64, ResTyElts));
1745 }
1746 if (isUpdating)
1747 ResTys.push_back(MVT::i32);
1748 ResTys.push_back(MVT::Other);
1749
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001750 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001751 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001752
Bob Wilson1c3ef902011-02-07 17:43:21 +00001753 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001754 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001755 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001756 if (isUpdating) {
1757 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1758 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1759 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001760
Bob Wilson8466fa12010-09-13 23:01:35 +00001761 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001762 SDValue V0 = N->getOperand(Vec0Idx + 0);
1763 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001764 if (NumVecs == 2) {
1765 if (is64BitVector)
1766 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1767 else
1768 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001769 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001770 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001771 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001772 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1773 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001774 if (is64BitVector)
1775 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1776 else
1777 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001778 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001779 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001780 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001781 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001782 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001783 Ops.push_back(Chain);
1784
Bob Wilson1c3ef902011-02-07 17:43:21 +00001785 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1786 QOpcodes[OpcodeIndex]);
1787 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1788 Ops.data(), Ops.size());
Bob Wilson96493442009-10-14 16:46:45 +00001789 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001791
Bob Wilson8466fa12010-09-13 23:01:35 +00001792 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001793 SuperReg = SDValue(VLdLn, 0);
1794 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1795 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1796 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001797 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1798 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001799 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1800 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1801 if (isUpdating)
1802 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001803 return NULL;
1804}
1805
Bob Wilson1c3ef902011-02-07 17:43:21 +00001806SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1807 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001808 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1809 DebugLoc dl = N->getDebugLoc();
1810
1811 SDValue MemAddr, Align;
1812 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1813 return NULL;
1814
1815 SDValue Chain = N->getOperand(0);
1816 EVT VT = N->getValueType(0);
1817
1818 unsigned Alignment = 0;
1819 if (NumVecs != 3) {
1820 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1821 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1822 if (Alignment > NumBytes)
1823 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001824 if (Alignment < 8 && Alignment < NumBytes)
1825 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001826 // Alignment must be a power of two; make sure of that.
1827 Alignment = (Alignment & -Alignment);
1828 if (Alignment == 1)
1829 Alignment = 0;
1830 }
1831 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1832
1833 unsigned OpcodeIndex;
1834 switch (VT.getSimpleVT().SimpleTy) {
1835 default: llvm_unreachable("unhandled vld-dup type");
1836 case MVT::v8i8: OpcodeIndex = 0; break;
1837 case MVT::v4i16: OpcodeIndex = 1; break;
1838 case MVT::v2f32:
1839 case MVT::v2i32: OpcodeIndex = 2; break;
1840 }
1841
1842 SDValue Pred = getAL(CurDAG);
1843 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1844 SDValue SuperReg;
1845 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001846 SmallVector<SDValue, 6> Ops;
1847 Ops.push_back(MemAddr);
1848 Ops.push_back(Align);
1849 if (isUpdating) {
1850 SDValue Inc = N->getOperand(2);
1851 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1852 }
1853 Ops.push_back(Pred);
1854 Ops.push_back(Reg0);
1855 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001856
1857 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001858 std::vector<EVT> ResTys;
1859 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts));
1860 if (isUpdating)
1861 ResTys.push_back(MVT::i32);
1862 ResTys.push_back(MVT::Other);
1863 SDNode *VLdDup =
1864 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001865 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001866
1867 // Extract the subregisters.
1868 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1869 unsigned SubIdx = ARM::dsub_0;
1870 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1871 ReplaceUses(SDValue(N, Vec),
1872 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001873 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1874 if (isUpdating)
1875 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001876 return NULL;
1877}
1878
Bob Wilson78dfbc32010-07-07 00:08:54 +00001879SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1880 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001881 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1882 DebugLoc dl = N->getDebugLoc();
1883 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001884 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001885
1886 // Form a REG_SEQUENCE to force register allocation.
1887 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001888 SDValue V0 = N->getOperand(FirstTblReg + 0);
1889 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001890 if (NumVecs == 2)
1891 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1892 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001893 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001894 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001895 // an undef.
1896 SDValue V3 = (NumVecs == 3)
1897 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001898 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001899 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1900 }
1901
Bob Wilson78dfbc32010-07-07 00:08:54 +00001902 SmallVector<SDValue, 6> Ops;
1903 if (IsExt)
1904 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001905 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001906 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001907 Ops.push_back(getAL(CurDAG)); // predicate
1908 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001909 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001910}
1911
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001912SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001913 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001914 if (!Subtarget->hasV6T2Ops())
1915 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001916
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001917 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1918 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1919
1920
1921 // For unsigned extracts, check for a shift right and mask
1922 unsigned And_imm = 0;
1923 if (N->getOpcode() == ISD::AND) {
1924 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1925
1926 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1927 if (And_imm & (And_imm + 1))
1928 return NULL;
1929
1930 unsigned Srl_imm = 0;
1931 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1932 Srl_imm)) {
1933 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1934
1935 unsigned Width = CountTrailingOnes_32(And_imm);
1936 unsigned LSB = Srl_imm;
1937 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1938 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1939 CurDAG->getTargetConstant(LSB, MVT::i32),
1940 CurDAG->getTargetConstant(Width, MVT::i32),
1941 getAL(CurDAG), Reg0 };
1942 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1943 }
1944 }
1945 return NULL;
1946 }
1947
1948 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001949 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001950 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001951 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1952 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001953 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001954 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1955 unsigned Width = 32 - Srl_imm;
1956 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001957 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001958 return NULL;
1959 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001960 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001961 CurDAG->getTargetConstant(LSB, MVT::i32),
1962 CurDAG->getTargetConstant(Width, MVT::i32),
1963 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001965 }
1966 }
1967 return NULL;
1968}
1969
Evan Cheng9ef48352009-11-20 00:54:03 +00001970SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001971SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001972 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1973 SDValue CPTmp0;
1974 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001975 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001976 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1977 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1978 unsigned Opc = 0;
1979 switch (SOShOp) {
1980 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1981 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1982 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1983 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1984 default:
1985 llvm_unreachable("Unknown so_reg opcode!");
1986 break;
1987 }
1988 SDValue SOShImm =
1989 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1990 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1991 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001992 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001993 }
1994 return 0;
1995}
1996
1997SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001998SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001999 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2000 SDValue CPTmp0;
2001 SDValue CPTmp1;
2002 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002003 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002004 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2005 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002006 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002007 }
2008 return 0;
2009}
2010
2011SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002012SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002013 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002014 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002015 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002016 return 0;
2017
Evan Cheng63f35442010-11-13 02:25:14 +00002018 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002019 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002020 if (is_t2_so_imm(TrueImm)) {
2021 Opc = ARM::t2MOVCCi;
2022 } else if (TrueImm <= 0xffff) {
2023 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002024 } else if (is_t2_so_imm_not(TrueImm)) {
2025 TrueImm = ~TrueImm;
2026 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002027 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002028 // Large immediate.
2029 Opc = ARM::t2MOVCCi32imm;
2030 }
2031
2032 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002033 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002034 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2035 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002036 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002037 }
Evan Cheng63f35442010-11-13 02:25:14 +00002038
Evan Cheng9ef48352009-11-20 00:54:03 +00002039 return 0;
2040}
2041
2042SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002043SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002044 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002045 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2046 if (!T)
2047 return 0;
2048
Evan Cheng63f35442010-11-13 02:25:14 +00002049 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002050 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002051 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002052 if (isSoImm) {
2053 Opc = ARM::MOVCCi;
2054 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2055 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002056 } else if (is_so_imm_not(TrueImm)) {
2057 TrueImm = ~TrueImm;
2058 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002059 } else if (TrueVal.getNode()->hasOneUse() &&
2060 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002061 // Large immediate.
2062 Opc = ARM::MOVCCi32imm;
2063 }
2064
2065 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002066 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002067 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2068 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002069 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002071
Evan Cheng9ef48352009-11-20 00:54:03 +00002072 return 0;
2073}
2074
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002075SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2076 EVT VT = N->getValueType(0);
2077 SDValue FalseVal = N->getOperand(0);
2078 SDValue TrueVal = N->getOperand(1);
2079 SDValue CC = N->getOperand(2);
2080 SDValue CCR = N->getOperand(3);
2081 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002082 assert(CC.getOpcode() == ISD::Constant);
2083 assert(CCR.getOpcode() == ISD::Register);
2084 ARMCC::CondCodes CCVal =
2085 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002086
2087 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2088 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2089 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2090 // Pattern complexity = 18 cost = 1 size = 0
2091 SDValue CPTmp0;
2092 SDValue CPTmp1;
2093 SDValue CPTmp2;
2094 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002095 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002096 CCVal, CCR, InFlag);
2097 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002098 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002099 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2100 if (Res)
2101 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002102 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002103 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002104 CCVal, CCR, InFlag);
2105 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002107 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2108 if (Res)
2109 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002110 }
2111
2112 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002113 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002114 // (imm:i32):$cc)
2115 // Emits: (MOVCCi:i32 GPR:i32:$false,
2116 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2117 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002118 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002119 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002120 CCVal, CCR, InFlag);
2121 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002122 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002123 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2124 if (Res)
2125 return Res;
2126 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002127 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002128 CCVal, CCR, InFlag);
2129 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002130 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002131 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2132 if (Res)
2133 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002134 }
2135 }
2136
2137 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2138 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2139 // Pattern complexity = 6 cost = 1 size = 0
2140 //
2141 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2142 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2143 // Pattern complexity = 6 cost = 11 size = 0
2144 //
2145 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002146 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2147 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002148 unsigned Opc = 0;
2149 switch (VT.getSimpleVT().SimpleTy) {
2150 default: assert(false && "Illegal conditional move type!");
2151 break;
2152 case MVT::i32:
2153 Opc = Subtarget->isThumb()
2154 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2155 : ARM::MOVCCr;
2156 break;
2157 case MVT::f32:
2158 Opc = ARM::VMOVScc;
2159 break;
2160 case MVT::f64:
2161 Opc = ARM::VMOVDcc;
2162 break;
2163 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002164 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002165}
2166
Evan Chengde8aa4e2010-05-05 18:28:36 +00002167SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2168 // The only time a CONCAT_VECTORS operation can have legal types is when
2169 // two 64-bit vectors are concatenated to a 128-bit vector.
2170 EVT VT = N->getValueType(0);
2171 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2172 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002173 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002174}
2175
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002176SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002177 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002178
Dan Gohmane8be6c62008-07-17 19:10:17 +00002179 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002180 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002181
2182 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002183 default: break;
2184 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002185 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002186 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002187 if (Subtarget->hasThumb2())
2188 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2189 // be done with MOV + MOVT, at worst.
2190 UseCP = 0;
2191 else {
2192 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002193 UseCP = (Val > 255 && // MOV
2194 ~Val > 255 && // MOV + MVN
2195 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002196 } else
2197 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2198 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2199 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2200 }
2201
Evan Chenga8e29892007-01-19 07:51:42 +00002202 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002203 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002204 CurDAG->getTargetConstantPool(ConstantInt::get(
2205 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002206 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002207
2208 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002209 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002210 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002211 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002212 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002213 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002214 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002215 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002216 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002217 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002218 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002219 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002220 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002221 CurDAG->getEntryNode()
2222 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002223 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002224 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002225 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002226 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002227 return NULL;
2228 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002229
Evan Chenga8e29892007-01-19 07:51:42 +00002230 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002231 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002232 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002233 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002234 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002235 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002236 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002237 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002238 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2239 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002240 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002241 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2242 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002243 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2244 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2245 CurDAG->getRegister(0, MVT::i32) };
2246 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002247 }
Evan Chenga8e29892007-01-19 07:51:42 +00002248 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002249 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002250 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002251 return I;
2252 break;
2253 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002254 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002255 return I;
2256 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002257 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002258 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002259 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002260 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002261 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002262 if (!RHSV) break;
2263 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002264 unsigned ShImm = Log2_32(RHSV-1);
2265 if (ShImm >= 32)
2266 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002267 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002268 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002269 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2270 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002271 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002272 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002273 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002274 } else {
2275 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002276 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002277 }
Evan Chenga8e29892007-01-19 07:51:42 +00002278 }
2279 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002280 unsigned ShImm = Log2_32(RHSV+1);
2281 if (ShImm >= 32)
2282 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002283 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002284 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002285 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2286 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002287 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002288 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2289 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002290 } else {
2291 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002292 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002293 }
Evan Chenga8e29892007-01-19 07:51:42 +00002294 }
2295 }
2296 break;
Evan Cheng20956592009-10-21 08:15:52 +00002297 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002298 // Check for unsigned bitfield extract
2299 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2300 return I;
2301
Evan Cheng20956592009-10-21 08:15:52 +00002302 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2303 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2304 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2305 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2306 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002307 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002308 if (VT != MVT::i32)
2309 break;
2310 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2311 ? ARM::t2MOVTi16
2312 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2313 if (!Opc)
2314 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002315 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002316 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2317 if (!N1C)
2318 break;
2319 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2320 SDValue N2 = N0.getOperand(1);
2321 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2322 if (!N2C)
2323 break;
2324 unsigned N1CVal = N1C->getZExtValue();
2325 unsigned N2CVal = N2C->getZExtValue();
2326 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2327 (N1CVal & 0xffffU) == 0xffffU &&
2328 (N2CVal & 0xffffU) == 0x0U) {
2329 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2330 MVT::i32);
2331 SDValue Ops[] = { N0.getOperand(0), Imm16,
2332 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2333 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2334 }
2335 }
2336 break;
2337 }
Jim Grosbache5165492009-11-09 00:11:35 +00002338 case ARMISD::VMOVRRD:
2339 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002340 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002341 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002342 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002343 if (Subtarget->isThumb1Only())
2344 break;
2345 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002346 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002347 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2348 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002349 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002350 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002351 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002352 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2353 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002354 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2355 ARM::UMULL : ARM::UMULLv5,
2356 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002357 }
Evan Chengee568cf2007-07-05 07:15:27 +00002358 }
Dan Gohman525178c2007-10-08 18:33:35 +00002359 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002360 if (Subtarget->isThumb1Only())
2361 break;
2362 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002363 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002364 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002365 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002366 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002367 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002368 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2369 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002370 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2371 ARM::SMULL : ARM::SMULLv5,
2372 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002373 }
Evan Chengee568cf2007-07-05 07:15:27 +00002374 }
Evan Chenga8e29892007-01-19 07:51:42 +00002375 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002376 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002377 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002378 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002379 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002380 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002381 if (ResNode)
2382 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002383 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002384 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002385 }
Evan Chengee568cf2007-07-05 07:15:27 +00002386 case ARMISD::BRCOND: {
2387 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2388 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2389 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002390
Evan Chengee568cf2007-07-05 07:15:27 +00002391 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2392 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2393 // Pattern complexity = 6 cost = 1 size = 0
2394
David Goodwin5e47a9a2009-06-30 18:04:13 +00002395 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2396 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2397 // Pattern complexity = 6 cost = 1 size = 0
2398
Jim Grosbach764ab522009-08-11 15:33:49 +00002399 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002400 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002401 SDValue Chain = N->getOperand(0);
2402 SDValue N1 = N->getOperand(1);
2403 SDValue N2 = N->getOperand(2);
2404 SDValue N3 = N->getOperand(3);
2405 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002406 assert(N1.getOpcode() == ISD::BasicBlock);
2407 assert(N2.getOpcode() == ISD::Constant);
2408 assert(N3.getOpcode() == ISD::Register);
2409
Dan Gohman475871a2008-07-27 21:46:04 +00002410 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002411 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002412 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002413 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002414 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002415 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002416 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002417 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002418 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002419 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002420 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002421 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002422 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002423 return NULL;
2424 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002425 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002426 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002427 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002428 EVT VT = N->getValueType(0);
2429 SDValue N0 = N->getOperand(0);
2430 SDValue N1 = N->getOperand(1);
2431 SDValue N2 = N->getOperand(2);
2432 SDValue N3 = N->getOperand(3);
2433 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002434 assert(N2.getOpcode() == ISD::Constant);
2435 assert(N3.getOpcode() == ISD::Register);
2436
Dan Gohman475871a2008-07-27 21:46:04 +00002437 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002438 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002439 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002440 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002441 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002442 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002443 default: assert(false && "Illegal conditional move type!");
2444 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002445 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002446 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002447 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002448 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002449 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002450 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002451 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002452 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002453 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002454
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002455 case ARMISD::VZIP: {
2456 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002457 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002458 switch (VT.getSimpleVT().SimpleTy) {
2459 default: return NULL;
2460 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2461 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2462 case MVT::v2f32:
2463 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2464 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2465 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2466 case MVT::v4f32:
2467 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2468 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002469 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002470 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2471 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2472 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002473 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002474 case ARMISD::VUZP: {
2475 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002476 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002477 switch (VT.getSimpleVT().SimpleTy) {
2478 default: return NULL;
2479 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2480 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2481 case MVT::v2f32:
2482 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2483 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2484 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2485 case MVT::v4f32:
2486 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2487 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002488 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002489 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2490 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2491 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002492 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002493 case ARMISD::VTRN: {
2494 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002495 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002496 switch (VT.getSimpleVT().SimpleTy) {
2497 default: return NULL;
2498 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2499 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2500 case MVT::v2f32:
2501 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2502 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2503 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2504 case MVT::v4f32:
2505 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2506 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002507 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002508 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2509 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2510 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002511 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002512 case ARMISD::BUILD_VECTOR: {
2513 EVT VecVT = N->getValueType(0);
2514 EVT EltVT = VecVT.getVectorElementType();
2515 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002516 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002517 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2518 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2519 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002520 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002521 if (NumElts == 2)
2522 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2523 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2524 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2525 N->getOperand(2), N->getOperand(3));
2526 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002527
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002528 case ARMISD::VLD2DUP: {
2529 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2530 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002531 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002532 }
2533
Bob Wilson86c6d802010-11-29 19:35:29 +00002534 case ARMISD::VLD3DUP: {
2535 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2536 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002537 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002538 }
2539
Bob Wilson6c4c9822010-11-30 00:00:35 +00002540 case ARMISD::VLD4DUP: {
2541 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2542 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002543 return SelectVLDDup(N, false, 4, Opcodes);
2544 }
2545
2546 case ARMISD::VLD2DUP_UPD: {
2547 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2548 ARM::VLD2DUPd32Pseudo_UPD };
2549 return SelectVLDDup(N, true, 2, Opcodes);
2550 }
2551
2552 case ARMISD::VLD3DUP_UPD: {
2553 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2554 ARM::VLD3DUPd32Pseudo_UPD };
2555 return SelectVLDDup(N, true, 3, Opcodes);
2556 }
2557
2558 case ARMISD::VLD4DUP_UPD: {
2559 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2560 ARM::VLD4DUPd32Pseudo_UPD };
2561 return SelectVLDDup(N, true, 4, Opcodes);
2562 }
2563
2564 case ARMISD::VLD1_UPD: {
2565 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2566 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2567 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2568 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2569 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2570 }
2571
2572 case ARMISD::VLD2_UPD: {
2573 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2574 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2575 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2576 ARM::VLD2q32Pseudo_UPD };
2577 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2578 }
2579
2580 case ARMISD::VLD3_UPD: {
2581 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2582 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2583 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2584 ARM::VLD3q16Pseudo_UPD,
2585 ARM::VLD3q32Pseudo_UPD };
2586 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2587 ARM::VLD3q16oddPseudo_UPD,
2588 ARM::VLD3q32oddPseudo_UPD };
2589 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2590 }
2591
2592 case ARMISD::VLD4_UPD: {
2593 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2594 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2595 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2596 ARM::VLD4q16Pseudo_UPD,
2597 ARM::VLD4q32Pseudo_UPD };
2598 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2599 ARM::VLD4q16oddPseudo_UPD,
2600 ARM::VLD4q32oddPseudo_UPD };
2601 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2602 }
2603
2604 case ARMISD::VLD2LN_UPD: {
2605 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2606 ARM::VLD2LNd32Pseudo_UPD };
2607 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2608 ARM::VLD2LNq32Pseudo_UPD };
2609 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2610 }
2611
2612 case ARMISD::VLD3LN_UPD: {
2613 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2614 ARM::VLD3LNd32Pseudo_UPD };
2615 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2616 ARM::VLD3LNq32Pseudo_UPD };
2617 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2618 }
2619
2620 case ARMISD::VLD4LN_UPD: {
2621 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2622 ARM::VLD4LNd32Pseudo_UPD };
2623 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2624 ARM::VLD4LNq32Pseudo_UPD };
2625 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2626 }
2627
2628 case ARMISD::VST1_UPD: {
2629 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2630 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2631 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2632 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2633 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2634 }
2635
2636 case ARMISD::VST2_UPD: {
2637 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2638 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2639 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2640 ARM::VST2q32Pseudo_UPD };
2641 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2642 }
2643
2644 case ARMISD::VST3_UPD: {
2645 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2646 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2647 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2648 ARM::VST3q16Pseudo_UPD,
2649 ARM::VST3q32Pseudo_UPD };
2650 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2651 ARM::VST3q16oddPseudo_UPD,
2652 ARM::VST3q32oddPseudo_UPD };
2653 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2654 }
2655
2656 case ARMISD::VST4_UPD: {
2657 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2658 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2659 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2660 ARM::VST4q16Pseudo_UPD,
2661 ARM::VST4q32Pseudo_UPD };
2662 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2663 ARM::VST4q16oddPseudo_UPD,
2664 ARM::VST4q32oddPseudo_UPD };
2665 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2666 }
2667
2668 case ARMISD::VST2LN_UPD: {
2669 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2670 ARM::VST2LNd32Pseudo_UPD };
2671 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2672 ARM::VST2LNq32Pseudo_UPD };
2673 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2674 }
2675
2676 case ARMISD::VST3LN_UPD: {
2677 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2678 ARM::VST3LNd32Pseudo_UPD };
2679 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2680 ARM::VST3LNq32Pseudo_UPD };
2681 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2682 }
2683
2684 case ARMISD::VST4LN_UPD: {
2685 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2686 ARM::VST4LNd32Pseudo_UPD };
2687 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2688 ARM::VST4LNq32Pseudo_UPD };
2689 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002690 }
2691
Bob Wilson31fb12f2009-08-26 17:39:53 +00002692 case ISD::INTRINSIC_VOID:
2693 case ISD::INTRINSIC_W_CHAIN: {
2694 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002695 switch (IntNo) {
2696 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002697 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002698
Bob Wilson621f1952010-03-23 05:25:43 +00002699 case Intrinsic::arm_neon_vld1: {
2700 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2701 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002702 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2703 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002704 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002705 }
2706
Bob Wilson31fb12f2009-08-26 17:39:53 +00002707 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002708 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2709 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2710 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2711 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002712 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002713 }
2714
2715 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002716 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2717 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2718 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2719 ARM::VLD3q16Pseudo_UPD,
2720 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002721 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2722 ARM::VLD3q16oddPseudo,
2723 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002724 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002725 }
2726
2727 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002728 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2729 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2730 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2731 ARM::VLD4q16Pseudo_UPD,
2732 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002733 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2734 ARM::VLD4q16oddPseudo,
2735 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002736 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002737 }
2738
Bob Wilson243fcc52009-09-01 04:26:28 +00002739 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002740 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2741 ARM::VLD2LNd32Pseudo };
2742 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002743 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002744 }
2745
2746 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002747 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2748 ARM::VLD3LNd32Pseudo };
2749 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002750 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002751 }
2752
2753 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002754 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2755 ARM::VLD4LNd32Pseudo };
2756 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002757 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002758 }
2759
Bob Wilson11d98992010-03-23 06:20:33 +00002760 case Intrinsic::arm_neon_vst1: {
2761 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2762 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002763 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2764 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002765 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002766 }
2767
Bob Wilson31fb12f2009-08-26 17:39:53 +00002768 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002769 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2770 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2771 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2772 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002773 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002774 }
2775
2776 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002777 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2778 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2779 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2780 ARM::VST3q16Pseudo_UPD,
2781 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002782 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2783 ARM::VST3q16oddPseudo,
2784 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002785 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002786 }
2787
2788 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002789 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002790 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002791 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2792 ARM::VST4q16Pseudo_UPD,
2793 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002794 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2795 ARM::VST4q16oddPseudo,
2796 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002797 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002798 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002799
2800 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002801 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2802 ARM::VST2LNd32Pseudo };
2803 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002804 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002805 }
2806
2807 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002808 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2809 ARM::VST3LNd32Pseudo };
2810 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002811 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002812 }
2813
2814 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002815 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2816 ARM::VST4LNd32Pseudo };
2817 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002818 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002819 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002820 }
Bob Wilson429009b2010-05-06 16:05:26 +00002821 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002822 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002823
Bob Wilsond491d6e2010-07-06 23:36:25 +00002824 case ISD::INTRINSIC_WO_CHAIN: {
2825 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2826 switch (IntNo) {
2827 default:
2828 break;
2829
2830 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002831 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002832 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002833 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002834 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002835 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002836
2837 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002838 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002839 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002840 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002841 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002842 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002843 }
2844 break;
2845 }
2846
Bob Wilson429009b2010-05-06 16:05:26 +00002847 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002848 return SelectConcatVector(N);
2849 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002850
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002851 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002852}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002853
Bob Wilson224c2442009-05-19 05:53:42 +00002854bool ARMDAGToDAGISel::
2855SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2856 std::vector<SDValue> &OutOps) {
2857 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002858 // Require the address to be in a register. That is safe for all ARM
2859 // variants and it is hard to do anything much smarter without knowing
2860 // how the operand is used.
2861 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002862 return false;
2863}
2864
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002865/// createARMISelDag - This pass converts a legalized DAG into a
2866/// ARM-specific DAG, ready for instruction scheduling.
2867///
Bob Wilson522ce972009-09-28 14:30:20 +00002868FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2869 CodeGenOpt::Level OptLevel) {
2870 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002871}