blob: f1e6b70453fcf488806c82ccc1268637f721d729 [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"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.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"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
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);
Owen Anderson92a20222011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000107 }
108
Jim Grosbach3e556122010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach82891622010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
Owen Anderson793e7962011-07-26 20:54:26 +0000132 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
133 SDValue &Offset, SDValue &Opc);
134 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000136 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
137 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000138 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000144 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000145 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000146 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000147
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000148 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000152 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
153 unsigned Scale);
154 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
156 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
157 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
158 SDValue &OffImm);
159 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
160 SDValue &OffImm);
161 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
162 SDValue &OffImm);
163 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
164 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000166
Bill Wendlingf4caf692010-12-14 03:36:38 +0000167 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000168 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000169 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
171 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000172 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000173 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000174 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000176 SDValue &OffReg, SDValue &ShImm);
177
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 inline bool is_so_imm(unsigned Imm) const {
179 return ARM_AM::getSOImmVal(Imm) != -1;
180 }
181
182 inline bool is_so_imm_not(unsigned Imm) const {
183 return ARM_AM::getSOImmVal(~Imm) != -1;
184 }
185
186 inline bool is_t2_so_imm(unsigned Imm) const {
187 return ARM_AM::getT2SOImmVal(Imm) != -1;
188 }
189
190 inline bool is_t2_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getT2SOImmVal(~Imm) != -1;
192 }
193
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000194 // Include the pieces autogenerated from the target description.
195#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000196
197private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000198 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
199 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000200 SDNode *SelectARMIndexedLoad(SDNode *N);
201 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000202
Bob Wilson621f1952010-03-23 05:25:43 +0000203 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
204 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000205 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000207 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
208 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000209 unsigned *QOpcodes0, unsigned *QOpcodes1);
210
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000213 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000214 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000215 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
216 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000217 unsigned *QOpcodes0, unsigned *QOpcodes1);
218
Bob Wilson96493442009-10-14 16:46:45 +0000219 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000220 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000221 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000222 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
223 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000224 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000226 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
227 /// should be 2, 3 or 4. The opcode array specifies the instructions used
228 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000229 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
230 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231
Bob Wilson78dfbc32010-07-07 00:08:54 +0000232 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
233 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
234 /// generated to force the table registers to be consecutive.
235 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000236
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000237 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000238 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000239
Evan Cheng07ba9062009-11-19 21:45:22 +0000240 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000241 SDNode *SelectCMOVOp(SDNode *N);
242 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000243 ARMCC::CondCodes CCVal, SDValue CCR,
244 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000245 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000248 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000251 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000254
Evan Chengde8aa4e2010-05-05 18:28:36 +0000255 SDNode *SelectConcatVector(SDNode *N);
256
Evan Chengaf4550f2009-07-02 01:23:32 +0000257 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
258 /// inline asm expressions.
259 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
260 char ConstraintCode,
261 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000262
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000263 // Form pairs of consecutive S, D, or Q registers.
264 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000265 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000266 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
267
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000268 // Form sequences of 4 consecutive S, D, or Q registers.
269 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000270 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000271 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000272
273 // Get the alignment operand for a NEON VLD or VST instruction.
274 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000275};
Evan Chenga8e29892007-01-19 07:51:42 +0000276}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000277
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000278/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
279/// operand. If so Imm will receive the 32-bit value.
280static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
281 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
282 Imm = cast<ConstantSDNode>(N)->getZExtValue();
283 return true;
284 }
285 return false;
286}
287
288// isInt32Immediate - This method tests to see if a constant operand.
289// If so Imm will receive the 32 bit value.
290static bool isInt32Immediate(SDValue N, unsigned &Imm) {
291 return isInt32Immediate(N.getNode(), Imm);
292}
293
294// isOpcWithIntImmediate - This method tests to see if the node is a specific
295// opcode and that it has a immediate integer right operand.
296// If so Imm will receive the 32 bit value.
297static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
298 return N->getOpcode() == Opc &&
299 isInt32Immediate(N->getOperand(1).getNode(), Imm);
300}
301
Daniel Dunbarec91d522011-01-19 15:12:16 +0000302/// \brief Check whether a particular node is a constant value representable as
303/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
304///
305/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
306static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
307 int RangeMin, int RangeMax,
308 int &ScaledConstant) {
309 assert(Scale && "Invalid scale!");
310
311 // Check that this is a constant.
312 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
313 if (!C)
314 return false;
315
316 ScaledConstant = (int) C->getZExtValue();
317 if ((ScaledConstant % Scale) != 0)
318 return false;
319
320 ScaledConstant /= Scale;
321 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
322}
323
Evan Cheng48575f62010-12-05 22:04:16 +0000324/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
325/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
326/// least on current ARM implementations) which should be avoidded.
327bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
328 if (OptLevel == CodeGenOpt::None)
329 return true;
330
331 if (!CheckVMLxHazard)
332 return true;
333
334 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
335 return true;
336
337 if (!N->hasOneUse())
338 return false;
339
340 SDNode *Use = *N->use_begin();
341 if (Use->getOpcode() == ISD::CopyToReg)
342 return true;
343 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000344 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
345 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000346 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000347 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000348 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
349 return true;
350 // vmlx feeding into another vmlx. We actually want to unfold
351 // the use later in the MLxExpansion pass. e.g.
352 // vmla
353 // vmla (stall 8 cycles)
354 //
355 // vmul (5 cycles)
356 // vadd (5 cycles)
357 // vmla
358 // This adds up to about 18 - 19 cycles.
359 //
360 // vmla
361 // vmul (stall 4 cycles)
362 // vadd adds up to about 14 cycles.
363 return TII->isFpMLxInstruction(Opcode);
364 }
365
366 return false;
367}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000368
Evan Chengf40deed2010-10-27 23:41:30 +0000369bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
370 ARM_AM::ShiftOpc ShOpcVal,
371 unsigned ShAmt) {
372 if (!Subtarget->isCortexA9())
373 return true;
374 if (Shift.hasOneUse())
375 return true;
376 // R << 2 is free.
377 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
378}
379
Owen Anderson92a20222011-07-21 18:54:16 +0000380bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000381 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000382 SDValue &Opc,
383 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000384 if (DisableShifterOp)
385 return false;
386
Evan Chengee04a6d2011-07-20 23:34:39 +0000387 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000388
389 // Don't match base register only case. That is matched to a separate
390 // lower complexity pattern with explicit register operand.
391 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000392
Evan Cheng055b0312009-06-29 07:51:04 +0000393 BaseReg = N.getOperand(0);
394 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000395 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
396 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000397 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000398 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
399 MVT::i32);
400 return true;
401}
402
Owen Anderson92a20222011-07-21 18:54:16 +0000403bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
404 SDValue &BaseReg,
405 SDValue &ShReg,
406 SDValue &Opc,
407 bool CheckProfitability) {
408 if (DisableShifterOp)
409 return false;
410
411 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
412
413 // Don't match base register only case. That is matched to a separate
414 // lower complexity pattern with explicit register operand.
415 if (ShOpcVal == ARM_AM::no_shift) return false;
416
417 BaseReg = N.getOperand(0);
418 unsigned ShImmVal = 0;
419 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
420 if (RHS) return false;
421
422 ShReg = N.getOperand(1);
423 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
424 return false;
425 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
426 MVT::i32);
427 return true;
428}
429
430
Jim Grosbach3e556122010-10-26 22:37:02 +0000431bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
432 SDValue &Base,
433 SDValue &OffImm) {
434 // Match simple R + imm12 operands.
435
436 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000437 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
438 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000439 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000440 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000441 int FI = cast<FrameIndexSDNode>(N)->getIndex();
442 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
443 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
444 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000445 }
Owen Anderson099e5552011-03-18 19:46:58 +0000446
Chris Lattner0a9481f2011-02-13 22:25:43 +0000447 if (N.getOpcode() == ARMISD::Wrapper &&
448 !(Subtarget->useMovt() &&
449 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000450 Base = N.getOperand(0);
451 } else
452 Base = N;
453 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
454 return true;
455 }
456
457 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
458 int RHSC = (int)RHS->getZExtValue();
459 if (N.getOpcode() == ISD::SUB)
460 RHSC = -RHSC;
461
462 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
463 Base = N.getOperand(0);
464 if (Base.getOpcode() == ISD::FrameIndex) {
465 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
466 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
467 }
468 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
469 return true;
470 }
471 }
472
473 // Base only.
474 Base = N;
475 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
476 return true;
477}
478
479
480
481bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
482 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000483 if (N.getOpcode() == ISD::MUL &&
484 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000485 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
486 // X * [3,5,9] -> X + X * [2,4,8] etc.
487 int RHSC = (int)RHS->getZExtValue();
488 if (RHSC & 1) {
489 RHSC = RHSC & ~1;
490 ARM_AM::AddrOpc AddSub = ARM_AM::add;
491 if (RHSC < 0) {
492 AddSub = ARM_AM::sub;
493 RHSC = - RHSC;
494 }
495 if (isPowerOf2_32(RHSC)) {
496 unsigned ShAmt = Log2_32(RHSC);
497 Base = Offset = N.getOperand(0);
498 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
499 ARM_AM::lsl),
500 MVT::i32);
501 return true;
502 }
503 }
504 }
505 }
506
Chris Lattner0a9481f2011-02-13 22:25:43 +0000507 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
508 // ISD::OR that is equivalent to an ISD::ADD.
509 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000510 return false;
511
512 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000513 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000514 int RHSC;
515 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
516 -0x1000+1, 0x1000, RHSC)) // 12 bits.
517 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000518 }
519
Evan Chengf40deed2010-10-27 23:41:30 +0000520 if (Subtarget->isCortexA9() && !N.hasOneUse())
521 // Compute R +/- (R << N) and reuse it.
522 return false;
523
Jim Grosbach3e556122010-10-26 22:37:02 +0000524 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000525 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000526 ARM_AM::ShiftOpc ShOpcVal =
527 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000528 unsigned ShAmt = 0;
529
530 Base = N.getOperand(0);
531 Offset = N.getOperand(1);
532
533 if (ShOpcVal != ARM_AM::no_shift) {
534 // Check to see if the RHS of the shift is a constant, if not, we can't fold
535 // it.
536 if (ConstantSDNode *Sh =
537 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
538 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000539 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
540 Offset = N.getOperand(1).getOperand(0);
541 else {
542 ShAmt = 0;
543 ShOpcVal = ARM_AM::no_shift;
544 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000545 } else {
546 ShOpcVal = ARM_AM::no_shift;
547 }
548 }
549
550 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000551 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000552 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000553 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000554 if (ShOpcVal != ARM_AM::no_shift) {
555 // Check to see if the RHS of the shift is a constant, if not, we can't
556 // fold it.
557 if (ConstantSDNode *Sh =
558 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
559 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000560 if (!Subtarget->isCortexA9() ||
561 (N.hasOneUse() &&
562 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
563 Offset = N.getOperand(0).getOperand(0);
564 Base = N.getOperand(1);
565 } else {
566 ShAmt = 0;
567 ShOpcVal = ARM_AM::no_shift;
568 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000569 } else {
570 ShOpcVal = ARM_AM::no_shift;
571 }
572 }
573 }
574
575 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
576 MVT::i32);
577 return true;
578}
579
580
581
582
583//-----
584
Jim Grosbach82891622010-09-29 19:03:54 +0000585AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
586 SDValue &Base,
587 SDValue &Offset,
588 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000589 if (N.getOpcode() == ISD::MUL &&
590 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000591 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
592 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000593 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000594 if (RHSC & 1) {
595 RHSC = RHSC & ~1;
596 ARM_AM::AddrOpc AddSub = ARM_AM::add;
597 if (RHSC < 0) {
598 AddSub = ARM_AM::sub;
599 RHSC = - RHSC;
600 }
601 if (isPowerOf2_32(RHSC)) {
602 unsigned ShAmt = Log2_32(RHSC);
603 Base = Offset = N.getOperand(0);
604 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
605 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000607 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000608 }
609 }
610 }
611 }
612
Chris Lattner0a9481f2011-02-13 22:25:43 +0000613 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
614 // ISD::OR that is equivalent to an ADD.
615 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000616 Base = N;
617 if (N.getOpcode() == ISD::FrameIndex) {
618 int FI = cast<FrameIndexSDNode>(N)->getIndex();
619 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000620 } else if (N.getOpcode() == ARMISD::Wrapper &&
621 !(Subtarget->useMovt() &&
622 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000623 Base = N.getOperand(0);
624 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000626 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
627 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000629 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000630 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000631
Evan Chenga8e29892007-01-19 07:51:42 +0000632 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000633 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000634 int RHSC;
635 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
636 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
637 Base = N.getOperand(0);
638 if (Base.getOpcode() == ISD::FrameIndex) {
639 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
640 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000641 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000642 Offset = CurDAG->getRegister(0, MVT::i32);
643
644 ARM_AM::AddrOpc AddSub = ARM_AM::add;
645 if (RHSC < 0) {
646 AddSub = ARM_AM::sub;
647 RHSC = - RHSC;
648 }
649 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
650 ARM_AM::no_shift),
651 MVT::i32);
652 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000653 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000654 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000655
Evan Chengf40deed2010-10-27 23:41:30 +0000656 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
657 // Compute R +/- (R << N) and reuse it.
658 Base = N;
659 Offset = CurDAG->getRegister(0, MVT::i32);
660 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
661 ARM_AM::no_shift),
662 MVT::i32);
663 return AM2_BASE;
664 }
665
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000666 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000667 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000668 ARM_AM::ShiftOpc ShOpcVal =
669 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000670 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000671
Evan Chenga8e29892007-01-19 07:51:42 +0000672 Base = N.getOperand(0);
673 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000674
Evan Chenga8e29892007-01-19 07:51:42 +0000675 if (ShOpcVal != ARM_AM::no_shift) {
676 // Check to see if the RHS of the shift is a constant, if not, we can't fold
677 // it.
678 if (ConstantSDNode *Sh =
679 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000680 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000681 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
682 Offset = N.getOperand(1).getOperand(0);
683 else {
684 ShAmt = 0;
685 ShOpcVal = ARM_AM::no_shift;
686 }
Evan Chenga8e29892007-01-19 07:51:42 +0000687 } else {
688 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000689 }
690 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000691
Evan Chenga8e29892007-01-19 07:51:42 +0000692 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000693 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000694 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000695 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000696 if (ShOpcVal != ARM_AM::no_shift) {
697 // Check to see if the RHS of the shift is a constant, if not, we can't
698 // fold it.
699 if (ConstantSDNode *Sh =
700 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000701 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000702 if (!Subtarget->isCortexA9() ||
703 (N.hasOneUse() &&
704 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
705 Offset = N.getOperand(0).getOperand(0);
706 Base = N.getOperand(1);
707 } else {
708 ShAmt = 0;
709 ShOpcVal = ARM_AM::no_shift;
710 }
Evan Chenga8e29892007-01-19 07:51:42 +0000711 } else {
712 ShOpcVal = ARM_AM::no_shift;
713 }
714 }
715 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000716
Evan Chenga8e29892007-01-19 07:51:42 +0000717 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000718 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000719 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000720}
721
Owen Anderson793e7962011-07-26 20:54:26 +0000722bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000723 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000724 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000725 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
726 ? cast<LoadSDNode>(Op)->getAddressingMode()
727 : cast<StoreSDNode>(Op)->getAddressingMode();
728 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
729 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000730 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000731 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
732 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000733
734 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000735 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000736 unsigned ShAmt = 0;
737 if (ShOpcVal != ARM_AM::no_shift) {
738 // Check to see if the RHS of the shift is a constant, if not, we can't fold
739 // it.
740 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000741 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000742 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
743 Offset = N.getOperand(0);
744 else {
745 ShAmt = 0;
746 ShOpcVal = ARM_AM::no_shift;
747 }
Evan Chenga8e29892007-01-19 07:51:42 +0000748 } else {
749 ShOpcVal = ARM_AM::no_shift;
750 }
751 }
752
753 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000754 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000755 return true;
756}
757
Owen Andersonc4e16de2011-08-29 20:16:50 +0000758bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
759 SDValue &Offset, SDValue &Opc) {
760 int Val;
761 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
762 Offset = CurDAG->getRegister(0, MVT::i32);
763 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
764 return true;
765 }
766
767 return false;
768}
769
770
Owen Anderson793e7962011-07-26 20:54:26 +0000771bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
772 SDValue &Offset, SDValue &Opc) {
773 unsigned Opcode = Op->getOpcode();
774 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
775 ? cast<LoadSDNode>(Op)->getAddressingMode()
776 : cast<StoreSDNode>(Op)->getAddressingMode();
777 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
778 ? ARM_AM::add : ARM_AM::sub;
779 int Val;
780 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
781 Offset = CurDAG->getRegister(0, MVT::i32);
782 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
783 ARM_AM::no_shift),
784 MVT::i32);
785 return true;
786 }
787
788 return false;
789}
790
Jim Grosbach19dec202011-08-05 20:35:44 +0000791bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
792 Base = N;
793 return true;
794}
Evan Chenga8e29892007-01-19 07:51:42 +0000795
Chris Lattner52a261b2010-09-21 20:31:19 +0000796bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000797 SDValue &Base, SDValue &Offset,
798 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000799 if (N.getOpcode() == ISD::SUB) {
800 // X - C is canonicalize to X + -C, no need to handle it here.
801 Base = N.getOperand(0);
802 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000804 return true;
805 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000806
Chris Lattner0a9481f2011-02-13 22:25:43 +0000807 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000808 Base = N;
809 if (N.getOpcode() == ISD::FrameIndex) {
810 int FI = cast<FrameIndexSDNode>(N)->getIndex();
811 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
812 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000813 Offset = CurDAG->getRegister(0, MVT::i32);
814 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000815 return true;
816 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000817
Evan Chenga8e29892007-01-19 07:51:42 +0000818 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000819 int RHSC;
820 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
821 -256 + 1, 256, RHSC)) { // 8 bits.
822 Base = N.getOperand(0);
823 if (Base.getOpcode() == ISD::FrameIndex) {
824 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
825 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000826 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000827 Offset = CurDAG->getRegister(0, MVT::i32);
828
829 ARM_AM::AddrOpc AddSub = ARM_AM::add;
830 if (RHSC < 0) {
831 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000832 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000833 }
834 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
835 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000836 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000837
Evan Chenga8e29892007-01-19 07:51:42 +0000838 Base = N.getOperand(0);
839 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000840 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000841 return true;
842}
843
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000844bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000845 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000846 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000847 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
848 ? cast<LoadSDNode>(Op)->getAddressingMode()
849 : cast<StoreSDNode>(Op)->getAddressingMode();
850 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
851 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000852 int Val;
853 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
854 Offset = CurDAG->getRegister(0, MVT::i32);
855 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
856 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000857 }
858
859 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000860 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000861 return true;
862}
863
Jim Grosbach3ab56582010-10-21 19:38:40 +0000864bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000865 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000866 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000867 Base = N;
868 if (N.getOpcode() == ISD::FrameIndex) {
869 int FI = cast<FrameIndexSDNode>(N)->getIndex();
870 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000871 } else if (N.getOpcode() == ARMISD::Wrapper &&
872 !(Subtarget->useMovt() &&
873 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000874 Base = N.getOperand(0);
875 }
876 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000877 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000878 return true;
879 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000880
Evan Chenga8e29892007-01-19 07:51:42 +0000881 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000882 int RHSC;
883 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
884 -256 + 1, 256, RHSC)) {
885 Base = N.getOperand(0);
886 if (Base.getOpcode() == ISD::FrameIndex) {
887 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
888 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000889 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000890
891 ARM_AM::AddrOpc AddSub = ARM_AM::add;
892 if (RHSC < 0) {
893 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000894 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000895 }
896 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
897 MVT::i32);
898 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000899 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000900
Evan Chenga8e29892007-01-19 07:51:42 +0000901 Base = N;
902 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000903 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000904 return true;
905}
906
Bob Wilson665814b2010-11-01 23:40:51 +0000907bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
908 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000909 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000910
911 unsigned Alignment = 0;
912 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
913 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
914 // The maximum alignment is equal to the memory size being referenced.
915 unsigned LSNAlign = LSN->getAlignment();
916 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
917 if (LSNAlign > MemSize && MemSize > 1)
918 Alignment = MemSize;
919 } else {
920 // All other uses of addrmode6 are for intrinsics. For now just record
921 // the raw alignment value; it will be refined later based on the legal
922 // alignment operands for the intrinsic.
923 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
924 }
925
926 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000927 return true;
928}
929
Bob Wilsonda525062011-02-25 06:42:42 +0000930bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
931 SDValue &Offset) {
932 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
933 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
934 if (AM != ISD::POST_INC)
935 return false;
936 Offset = N;
937 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
938 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
939 Offset = CurDAG->getRegister(0, MVT::i32);
940 }
941 return true;
942}
943
Chris Lattner52a261b2010-09-21 20:31:19 +0000944bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000945 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000946 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
947 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000948 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000949 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
950 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000951 return true;
952 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000953
Evan Chenga8e29892007-01-19 07:51:42 +0000954 return false;
955}
956
Bill Wendlingf4caf692010-12-14 03:36:38 +0000957
958//===----------------------------------------------------------------------===//
959// Thumb Addressing Modes
960//===----------------------------------------------------------------------===//
961
Chris Lattner52a261b2010-09-21 20:31:19 +0000962bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000963 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000964 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000965 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000966 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000967 return false;
968
969 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000970 return true;
971 }
972
Evan Chenga8e29892007-01-19 07:51:42 +0000973 Base = N.getOperand(0);
974 Offset = N.getOperand(1);
975 return true;
976}
977
Evan Cheng79d43262007-01-24 02:21:22 +0000978bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000979ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
980 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000981 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000982 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000983 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000984 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000985
Evan Cheng012f2d92007-01-24 08:53:17 +0000986 if (N.getOpcode() == ARMISD::Wrapper &&
987 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
988 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000989 }
990
Chris Lattner0a9481f2011-02-13 22:25:43 +0000991 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000992 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000993
Evan Chengad0e4652007-02-06 00:22:06 +0000994 // Thumb does not have [sp, r] address mode.
995 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
996 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
997 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000998 (RHSR && RHSR->getReg() == ARM::SP))
999 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001000
Daniel Dunbarec91d522011-01-19 15:12:16 +00001001 // FIXME: Why do we explicitly check for a match here and then return false?
1002 // Presumably to allow something else to match, but shouldn't this be
1003 // documented?
1004 int RHSC;
1005 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1006 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001007
1008 Base = N.getOperand(0);
1009 Offset = N.getOperand(1);
1010 return true;
1011}
1012
1013bool
1014ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1015 SDValue &Base,
1016 SDValue &Offset) {
1017 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1018}
1019
1020bool
1021ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1022 SDValue &Base,
1023 SDValue &Offset) {
1024 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1025}
1026
1027bool
1028ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1029 SDValue &Base,
1030 SDValue &Offset) {
1031 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1032}
1033
1034bool
1035ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1036 SDValue &Base, SDValue &OffImm) {
1037 if (Scale == 4) {
1038 SDValue TmpBase, TmpOffImm;
1039 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1040 return false; // We want to select tLDRspi / tSTRspi instead.
1041
1042 if (N.getOpcode() == ARMISD::Wrapper &&
1043 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1044 return false; // We want to select tLDRpci instead.
1045 }
1046
Chris Lattner0a9481f2011-02-13 22:25:43 +00001047 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001048 if (N.getOpcode() == ARMISD::Wrapper &&
1049 !(Subtarget->useMovt() &&
1050 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1051 Base = N.getOperand(0);
1052 } else {
1053 Base = N;
1054 }
1055
Owen Anderson825b72b2009-08-11 20:47:22 +00001056 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001057 return true;
1058 }
1059
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001060 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1061 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1062 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1063 (RHSR && RHSR->getReg() == ARM::SP)) {
1064 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1065 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1066 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1067 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1068
1069 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1070 if (LHSC != 0 || RHSC != 0) return false;
1071
1072 Base = N;
1073 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1074 return true;
1075 }
1076
Evan Chenga8e29892007-01-19 07:51:42 +00001077 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001078 int RHSC;
1079 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1080 Base = N.getOperand(0);
1081 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1082 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001083 }
1084
Evan Chengc38f2bc2007-01-23 22:59:13 +00001085 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001086 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001087 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001088}
1089
Bill Wendlingf4caf692010-12-14 03:36:38 +00001090bool
1091ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1092 SDValue &OffImm) {
1093 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001094}
1095
Bill Wendlingf4caf692010-12-14 03:36:38 +00001096bool
1097ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1098 SDValue &OffImm) {
1099 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001100}
1101
Bill Wendlingf4caf692010-12-14 03:36:38 +00001102bool
1103ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1104 SDValue &OffImm) {
1105 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001106}
1107
Chris Lattner52a261b2010-09-21 20:31:19 +00001108bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1109 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001110 if (N.getOpcode() == ISD::FrameIndex) {
1111 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1112 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001113 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001114 return true;
1115 }
Evan Cheng79d43262007-01-24 02:21:22 +00001116
Chris Lattner0a9481f2011-02-13 22:25:43 +00001117 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001118 return false;
1119
1120 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001121 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1122 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001123 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001124 int RHSC;
1125 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1126 Base = N.getOperand(0);
1127 if (Base.getOpcode() == ISD::FrameIndex) {
1128 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1129 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001130 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001131 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1132 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001133 }
1134 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001135
Evan Chenga8e29892007-01-19 07:51:42 +00001136 return false;
1137}
1138
Bill Wendlingf4caf692010-12-14 03:36:38 +00001139
1140//===----------------------------------------------------------------------===//
1141// Thumb 2 Addressing Modes
1142//===----------------------------------------------------------------------===//
1143
1144
Chris Lattner52a261b2010-09-21 20:31:19 +00001145bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001146 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001147 if (DisableShifterOp)
1148 return false;
1149
Evan Chengee04a6d2011-07-20 23:34:39 +00001150 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001151
1152 // Don't match base register only case. That is matched to a separate
1153 // lower complexity pattern with explicit register operand.
1154 if (ShOpcVal == ARM_AM::no_shift) return false;
1155
1156 BaseReg = N.getOperand(0);
1157 unsigned ShImmVal = 0;
1158 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1159 ShImmVal = RHS->getZExtValue() & 31;
1160 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1161 return true;
1162 }
1163
1164 return false;
1165}
1166
Chris Lattner52a261b2010-09-21 20:31:19 +00001167bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001168 SDValue &Base, SDValue &OffImm) {
1169 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001170
Evan Cheng3a214252009-08-11 08:52:18 +00001171 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001172 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1173 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001174 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001175 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001176 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1177 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001178 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001179 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001180 }
Owen Anderson099e5552011-03-18 19:46:58 +00001181
Chris Lattner0a9481f2011-02-13 22:25:43 +00001182 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001183 !(Subtarget->useMovt() &&
1184 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001185 Base = N.getOperand(0);
1186 if (Base.getOpcode() == ISD::TargetConstantPool)
1187 return false; // We want to select t2LDRpci instead.
1188 } else
1189 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001190 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001191 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001192 }
Evan Cheng055b0312009-06-29 07:51:04 +00001193
1194 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001195 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001196 // Let t2LDRi8 handle (R - imm8).
1197 return false;
1198
Evan Cheng055b0312009-06-29 07:51:04 +00001199 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001200 if (N.getOpcode() == ISD::SUB)
1201 RHSC = -RHSC;
1202
1203 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001204 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001205 if (Base.getOpcode() == ISD::FrameIndex) {
1206 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1207 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1208 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001209 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001210 return true;
1211 }
1212 }
1213
Evan Cheng3a214252009-08-11 08:52:18 +00001214 // Base only.
1215 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001216 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001217 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001218}
1219
Chris Lattner52a261b2010-09-21 20:31:19 +00001220bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001221 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001222 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001223 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1224 !CurDAG->isBaseWithConstantOffset(N))
1225 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001226
Chris Lattner0a9481f2011-02-13 22:25:43 +00001227 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1228 int RHSC = (int)RHS->getSExtValue();
1229 if (N.getOpcode() == ISD::SUB)
1230 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001231
Chris Lattner0a9481f2011-02-13 22:25:43 +00001232 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1233 Base = N.getOperand(0);
1234 if (Base.getOpcode() == ISD::FrameIndex) {
1235 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1236 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001237 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001238 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1239 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001240 }
1241 }
1242
1243 return false;
1244}
1245
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001246bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001247 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001248 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001249 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1250 ? cast<LoadSDNode>(Op)->getAddressingMode()
1251 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001252 int RHSC;
1253 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1254 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1255 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1256 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1257 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001258 }
1259
1260 return false;
1261}
1262
Chris Lattner52a261b2010-09-21 20:31:19 +00001263bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001264 SDValue &Base,
1265 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001266 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001267 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001268 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001269
Evan Cheng3a214252009-08-11 08:52:18 +00001270 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1271 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1272 int RHSC = (int)RHS->getZExtValue();
1273 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1274 return false;
1275 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001276 return false;
1277 }
1278
Evan Chengf40deed2010-10-27 23:41:30 +00001279 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1280 // Compute R + (R << [1,2,3]) and reuse it.
1281 Base = N;
1282 return false;
1283 }
1284
Evan Cheng055b0312009-06-29 07:51:04 +00001285 // Look for (R + R) or (R + (R << [1,2,3])).
1286 unsigned ShAmt = 0;
1287 Base = N.getOperand(0);
1288 OffReg = N.getOperand(1);
1289
1290 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001291 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001292 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001293 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001294 if (ShOpcVal == ARM_AM::lsl)
1295 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001296 }
1297
Evan Cheng055b0312009-06-29 07:51:04 +00001298 if (ShOpcVal == ARM_AM::lsl) {
1299 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1300 // it.
1301 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1302 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001303 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1304 OffReg = OffReg.getOperand(0);
1305 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001306 ShAmt = 0;
1307 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001308 }
Evan Cheng055b0312009-06-29 07:51:04 +00001309 } else {
1310 ShOpcVal = ARM_AM::no_shift;
1311 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001312 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001313
Owen Anderson825b72b2009-08-11 20:47:22 +00001314 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001315
1316 return true;
1317}
1318
1319//===--------------------------------------------------------------------===//
1320
Evan Chengee568cf2007-07-05 07:15:27 +00001321/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001322static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001323 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001324}
1325
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001326SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1327 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001328 ISD::MemIndexedMode AM = LD->getAddressingMode();
1329 if (AM == ISD::UNINDEXED)
1330 return NULL;
1331
Owen Andersone50ed302009-08-10 22:56:29 +00001332 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001333 SDValue Offset, AMOpc;
1334 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1335 unsigned Opcode = 0;
1336 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001337 if (LoadedVT == MVT::i32 && isPre &&
1338 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1339 Opcode = ARM::LDR_PRE_IMM;
1340 Match = true;
1341 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001342 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001343 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001344 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001345 } else if (LoadedVT == MVT::i32 &&
1346 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001347 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001348 Match = true;
1349
Owen Anderson825b72b2009-08-11 20:47:22 +00001350 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001351 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001352 Match = true;
1353 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1354 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1355 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001356 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001357 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001358 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001359 Match = true;
1360 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1361 }
1362 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001363 if (isPre &&
1364 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001365 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001366 Opcode = ARM::LDRB_PRE_IMM;
1367 } else if (!isPre &&
1368 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1369 Match = true;
1370 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001371 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1372 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001373 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001374 }
1375 }
1376 }
1377
1378 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001379 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1380 SDValue Chain = LD->getChain();
1381 SDValue Base = LD->getBasePtr();
1382 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1383 CurDAG->getRegister(0, MVT::i32), Chain };
1384 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1385 MVT::Other, Ops, 5);
1386 } else {
1387 SDValue Chain = LD->getChain();
1388 SDValue Base = LD->getBasePtr();
1389 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1390 CurDAG->getRegister(0, MVT::i32), Chain };
1391 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1392 MVT::Other, Ops, 6);
1393 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001394 }
1395
1396 return NULL;
1397}
1398
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001399SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1400 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001401 ISD::MemIndexedMode AM = LD->getAddressingMode();
1402 if (AM == ISD::UNINDEXED)
1403 return NULL;
1404
Owen Andersone50ed302009-08-10 22:56:29 +00001405 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001406 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001407 SDValue Offset;
1408 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1409 unsigned Opcode = 0;
1410 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001411 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001412 switch (LoadedVT.getSimpleVT().SimpleTy) {
1413 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001414 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1415 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001416 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001417 if (isSExtLd)
1418 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1419 else
1420 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001421 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001422 case MVT::i8:
1423 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001424 if (isSExtLd)
1425 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1426 else
1427 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001428 break;
1429 default:
1430 return NULL;
1431 }
1432 Match = true;
1433 }
1434
1435 if (Match) {
1436 SDValue Chain = LD->getChain();
1437 SDValue Base = LD->getBasePtr();
1438 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001439 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001440 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001441 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001442 }
1443
1444 return NULL;
1445}
1446
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001447/// PairSRegs - Form a D register from a pair of S registers.
1448///
1449SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1450 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001451 SDValue RegClass =
1452 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001453 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1454 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001455 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1456 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001457}
1458
Evan Cheng603afbf2010-05-10 17:34:18 +00001459/// PairDRegs - Form a quad register from a pair of D registers.
1460///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001461SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1462 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001463 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001464 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1465 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001466 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1467 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001468}
1469
Evan Cheng7f687192010-05-14 00:21:45 +00001470/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001471///
1472SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1473 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001474 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001475 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1476 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001477 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1478 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001479}
1480
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001481/// QuadSRegs - Form 4 consecutive S registers.
1482///
1483SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1484 SDValue V2, SDValue V3) {
1485 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001486 SDValue RegClass =
1487 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001488 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1489 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1490 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1491 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001492 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1493 V2, SubReg2, V3, SubReg3 };
1494 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001495}
1496
Evan Cheng7f687192010-05-14 00:21:45 +00001497/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001498///
1499SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1500 SDValue V2, SDValue V3) {
1501 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001502 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001503 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1504 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1505 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1506 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001507 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1508 V2, SubReg2, V3, SubReg3 };
1509 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001510}
1511
Evan Cheng8f6de382010-05-16 03:27:48 +00001512/// QuadQRegs - Form 4 consecutive Q registers.
1513///
1514SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1515 SDValue V2, SDValue V3) {
1516 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001517 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001518 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1519 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1520 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1521 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001522 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1523 V2, SubReg2, V3, SubReg3 };
1524 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001525}
1526
Bob Wilson2a6e6162010-09-23 23:42:37 +00001527/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1528/// of a NEON VLD or VST instruction. The supported values depend on the
1529/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001530SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1531 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001532 unsigned NumRegs = NumVecs;
1533 if (!is64BitVector && NumVecs < 3)
1534 NumRegs *= 2;
1535
Bob Wilson665814b2010-11-01 23:40:51 +00001536 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001537 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001538 Alignment = 32;
1539 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1540 Alignment = 16;
1541 else if (Alignment >= 8)
1542 Alignment = 8;
1543 else
1544 Alignment = 0;
1545
1546 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001547}
1548
Bob Wilson1c3ef902011-02-07 17:43:21 +00001549SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001550 unsigned *DOpcodes, unsigned *QOpcodes0,
1551 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001552 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001553 DebugLoc dl = N->getDebugLoc();
1554
Bob Wilson226036e2010-03-20 22:13:40 +00001555 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001556 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1557 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001558 return NULL;
1559
1560 SDValue Chain = N->getOperand(0);
1561 EVT VT = N->getValueType(0);
1562 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001563 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001564
Bob Wilson3e36f132009-10-14 17:28:52 +00001565 unsigned OpcodeIndex;
1566 switch (VT.getSimpleVT().SimpleTy) {
1567 default: llvm_unreachable("unhandled vld type");
1568 // Double-register operations:
1569 case MVT::v8i8: OpcodeIndex = 0; break;
1570 case MVT::v4i16: OpcodeIndex = 1; break;
1571 case MVT::v2f32:
1572 case MVT::v2i32: OpcodeIndex = 2; break;
1573 case MVT::v1i64: OpcodeIndex = 3; break;
1574 // Quad-register operations:
1575 case MVT::v16i8: OpcodeIndex = 0; break;
1576 case MVT::v8i16: OpcodeIndex = 1; break;
1577 case MVT::v4f32:
1578 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001579 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001580 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001581 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001582 }
1583
Bob Wilsonf5721912010-09-03 18:16:02 +00001584 EVT ResTy;
1585 if (NumVecs == 1)
1586 ResTy = VT;
1587 else {
1588 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1589 if (!is64BitVector)
1590 ResTyElts *= 2;
1591 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1592 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001593 std::vector<EVT> ResTys;
1594 ResTys.push_back(ResTy);
1595 if (isUpdating)
1596 ResTys.push_back(MVT::i32);
1597 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001598
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001599 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001600 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001601 SDNode *VLd;
1602 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001603
Bob Wilson1c3ef902011-02-07 17:43:21 +00001604 // Double registers and VLD1/VLD2 quad registers are directly supported.
1605 if (is64BitVector || NumVecs <= 2) {
1606 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1607 QOpcodes0[OpcodeIndex]);
1608 Ops.push_back(MemAddr);
1609 Ops.push_back(Align);
1610 if (isUpdating) {
1611 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1612 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001613 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001614 Ops.push_back(Pred);
1615 Ops.push_back(Reg0);
1616 Ops.push_back(Chain);
1617 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001618
Bob Wilson3e36f132009-10-14 17:28:52 +00001619 } else {
1620 // Otherwise, quad registers are loaded with two separate instructions,
1621 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001622 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001623
Bob Wilson1c3ef902011-02-07 17:43:21 +00001624 // Load the even subregs. This is always an updating load, so that it
1625 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001626 SDValue ImplDef =
1627 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1628 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001629 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1630 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001631 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001632
Bob Wilson24f995d2009-10-14 18:32:29 +00001633 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001634 Ops.push_back(SDValue(VLdA, 1));
1635 Ops.push_back(Align);
1636 if (isUpdating) {
1637 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1638 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1639 "only constant post-increment update allowed for VLD3/4");
1640 (void)Inc;
1641 Ops.push_back(Reg0);
1642 }
1643 Ops.push_back(SDValue(VLdA, 0));
1644 Ops.push_back(Pred);
1645 Ops.push_back(Reg0);
1646 Ops.push_back(Chain);
1647 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1648 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001649 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001650
Evan Chengb58a3402011-04-19 00:04:03 +00001651 // Transfer memoperands.
1652 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1653 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1654 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1655
Bob Wilson1c3ef902011-02-07 17:43:21 +00001656 if (NumVecs == 1)
1657 return VLd;
1658
1659 // Extract out the subregisters.
1660 SDValue SuperReg = SDValue(VLd, 0);
1661 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1662 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1663 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1664 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1665 ReplaceUses(SDValue(N, Vec),
1666 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1667 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1668 if (isUpdating)
1669 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001670 return NULL;
1671}
1672
Bob Wilson1c3ef902011-02-07 17:43:21 +00001673SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001674 unsigned *DOpcodes, unsigned *QOpcodes0,
1675 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001676 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001677 DebugLoc dl = N->getDebugLoc();
1678
Bob Wilson226036e2010-03-20 22:13:40 +00001679 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001680 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1681 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1682 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001683 return NULL;
1684
Evan Chengb58a3402011-04-19 00:04:03 +00001685 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1686 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1687
Bob Wilson24f995d2009-10-14 18:32:29 +00001688 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001689 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001690 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001691 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001692
Bob Wilson24f995d2009-10-14 18:32:29 +00001693 unsigned OpcodeIndex;
1694 switch (VT.getSimpleVT().SimpleTy) {
1695 default: llvm_unreachable("unhandled vst type");
1696 // Double-register operations:
1697 case MVT::v8i8: OpcodeIndex = 0; break;
1698 case MVT::v4i16: OpcodeIndex = 1; break;
1699 case MVT::v2f32:
1700 case MVT::v2i32: OpcodeIndex = 2; break;
1701 case MVT::v1i64: OpcodeIndex = 3; break;
1702 // Quad-register operations:
1703 case MVT::v16i8: OpcodeIndex = 0; break;
1704 case MVT::v8i16: OpcodeIndex = 1; break;
1705 case MVT::v4f32:
1706 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001707 case MVT::v2i64: OpcodeIndex = 3;
1708 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1709 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001710 }
1711
Bob Wilson1c3ef902011-02-07 17:43:21 +00001712 std::vector<EVT> ResTys;
1713 if (isUpdating)
1714 ResTys.push_back(MVT::i32);
1715 ResTys.push_back(MVT::Other);
1716
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001717 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001718 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001719 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001720
Bob Wilson1c3ef902011-02-07 17:43:21 +00001721 // Double registers and VST1/VST2 quad registers are directly supported.
1722 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001723 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001724 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001725 SrcReg = N->getOperand(Vec0Idx);
1726 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001727 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001728 SDValue V0 = N->getOperand(Vec0Idx + 0);
1729 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001730 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001731 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001732 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001733 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001734 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001735 // an undef.
1736 SDValue V3 = (NumVecs == 3)
1737 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001738 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001739 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001740 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001741 } else {
1742 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001743 SDValue Q0 = N->getOperand(Vec0Idx);
1744 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001745 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001746 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001747
1748 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1749 QOpcodes0[OpcodeIndex]);
1750 Ops.push_back(MemAddr);
1751 Ops.push_back(Align);
1752 if (isUpdating) {
1753 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1754 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1755 }
1756 Ops.push_back(SrcReg);
1757 Ops.push_back(Pred);
1758 Ops.push_back(Reg0);
1759 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001760 SDNode *VSt =
1761 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1762
1763 // Transfer memoperands.
1764 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1765
1766 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001767 }
1768
1769 // Otherwise, quad registers are stored with two separate instructions,
1770 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001771
Bob Wilson07f6e802010-06-16 21:34:01 +00001772 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001773 SDValue V0 = N->getOperand(Vec0Idx + 0);
1774 SDValue V1 = N->getOperand(Vec0Idx + 1);
1775 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001776 SDValue V3 = (NumVecs == 3)
1777 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001778 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001779 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001780
Bob Wilson1c3ef902011-02-07 17:43:21 +00001781 // Store the even D registers. This is always an updating store, so that it
1782 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001783 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1784 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1785 MemAddr.getValueType(),
1786 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001787 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001788 Chain = SDValue(VStA, 1);
1789
1790 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001791 Ops.push_back(SDValue(VStA, 0));
1792 Ops.push_back(Align);
1793 if (isUpdating) {
1794 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1795 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1796 "only constant post-increment update allowed for VST3/4");
1797 (void)Inc;
1798 Ops.push_back(Reg0);
1799 }
1800 Ops.push_back(RegSeq);
1801 Ops.push_back(Pred);
1802 Ops.push_back(Reg0);
1803 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001804 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1805 Ops.data(), Ops.size());
1806 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1807 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001808}
1809
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001810SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001811 bool isUpdating, unsigned NumVecs,
1812 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001813 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001814 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001815 DebugLoc dl = N->getDebugLoc();
1816
Bob Wilson226036e2010-03-20 22:13:40 +00001817 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001818 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1819 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1820 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001821 return NULL;
1822
Evan Chengb58a3402011-04-19 00:04:03 +00001823 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1824 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1825
Bob Wilsona7c397c2009-10-14 16:19:03 +00001826 SDValue Chain = N->getOperand(0);
1827 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001828 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1829 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001830 bool is64BitVector = VT.is64BitVector();
1831
Bob Wilson665814b2010-11-01 23:40:51 +00001832 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001833 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001834 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001835 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1836 if (Alignment > NumBytes)
1837 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001838 if (Alignment < 8 && Alignment < NumBytes)
1839 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001840 // Alignment must be a power of two; make sure of that.
1841 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001842 if (Alignment == 1)
1843 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001844 }
Bob Wilson665814b2010-11-01 23:40:51 +00001845 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001846
Bob Wilsona7c397c2009-10-14 16:19:03 +00001847 unsigned OpcodeIndex;
1848 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001849 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001850 // Double-register operations:
1851 case MVT::v8i8: OpcodeIndex = 0; break;
1852 case MVT::v4i16: OpcodeIndex = 1; break;
1853 case MVT::v2f32:
1854 case MVT::v2i32: OpcodeIndex = 2; break;
1855 // Quad-register operations:
1856 case MVT::v8i16: OpcodeIndex = 0; break;
1857 case MVT::v4f32:
1858 case MVT::v4i32: OpcodeIndex = 1; break;
1859 }
1860
Bob Wilson1c3ef902011-02-07 17:43:21 +00001861 std::vector<EVT> ResTys;
1862 if (IsLoad) {
1863 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1864 if (!is64BitVector)
1865 ResTyElts *= 2;
1866 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1867 MVT::i64, ResTyElts));
1868 }
1869 if (isUpdating)
1870 ResTys.push_back(MVT::i32);
1871 ResTys.push_back(MVT::Other);
1872
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001873 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001874 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001875
Bob Wilson1c3ef902011-02-07 17:43:21 +00001876 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001877 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001878 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001879 if (isUpdating) {
1880 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1881 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1882 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001883
Bob Wilson8466fa12010-09-13 23:01:35 +00001884 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001885 SDValue V0 = N->getOperand(Vec0Idx + 0);
1886 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001887 if (NumVecs == 2) {
1888 if (is64BitVector)
1889 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1890 else
1891 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001892 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001893 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001894 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001895 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1896 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001897 if (is64BitVector)
1898 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1899 else
1900 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001901 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001902 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001903 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001904 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001905 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001906 Ops.push_back(Chain);
1907
Bob Wilson1c3ef902011-02-07 17:43:21 +00001908 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1909 QOpcodes[OpcodeIndex]);
1910 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1911 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001912 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001913 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001914 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001915
Bob Wilson8466fa12010-09-13 23:01:35 +00001916 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001917 SuperReg = SDValue(VLdLn, 0);
1918 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1919 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1920 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001921 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1922 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001923 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1924 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1925 if (isUpdating)
1926 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001927 return NULL;
1928}
1929
Bob Wilson1c3ef902011-02-07 17:43:21 +00001930SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1931 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001932 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1933 DebugLoc dl = N->getDebugLoc();
1934
1935 SDValue MemAddr, Align;
1936 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1937 return NULL;
1938
Evan Chengb58a3402011-04-19 00:04:03 +00001939 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1940 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1941
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001942 SDValue Chain = N->getOperand(0);
1943 EVT VT = N->getValueType(0);
1944
1945 unsigned Alignment = 0;
1946 if (NumVecs != 3) {
1947 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1948 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1949 if (Alignment > NumBytes)
1950 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001951 if (Alignment < 8 && Alignment < NumBytes)
1952 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001953 // Alignment must be a power of two; make sure of that.
1954 Alignment = (Alignment & -Alignment);
1955 if (Alignment == 1)
1956 Alignment = 0;
1957 }
1958 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1959
1960 unsigned OpcodeIndex;
1961 switch (VT.getSimpleVT().SimpleTy) {
1962 default: llvm_unreachable("unhandled vld-dup type");
1963 case MVT::v8i8: OpcodeIndex = 0; break;
1964 case MVT::v4i16: OpcodeIndex = 1; break;
1965 case MVT::v2f32:
1966 case MVT::v2i32: OpcodeIndex = 2; break;
1967 }
1968
1969 SDValue Pred = getAL(CurDAG);
1970 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1971 SDValue SuperReg;
1972 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001973 SmallVector<SDValue, 6> Ops;
1974 Ops.push_back(MemAddr);
1975 Ops.push_back(Align);
1976 if (isUpdating) {
1977 SDValue Inc = N->getOperand(2);
1978 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1979 }
1980 Ops.push_back(Pred);
1981 Ops.push_back(Reg0);
1982 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001983
1984 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001985 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001986 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001987 if (isUpdating)
1988 ResTys.push_back(MVT::i32);
1989 ResTys.push_back(MVT::Other);
1990 SDNode *VLdDup =
1991 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001992 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001993 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001994
1995 // Extract the subregisters.
1996 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1997 unsigned SubIdx = ARM::dsub_0;
1998 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1999 ReplaceUses(SDValue(N, Vec),
2000 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002001 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2002 if (isUpdating)
2003 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002004 return NULL;
2005}
2006
Bob Wilson78dfbc32010-07-07 00:08:54 +00002007SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2008 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002009 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2010 DebugLoc dl = N->getDebugLoc();
2011 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002012 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002013
2014 // Form a REG_SEQUENCE to force register allocation.
2015 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002016 SDValue V0 = N->getOperand(FirstTblReg + 0);
2017 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002018 if (NumVecs == 2)
2019 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2020 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002021 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002022 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002023 // an undef.
2024 SDValue V3 = (NumVecs == 3)
2025 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002026 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002027 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2028 }
2029
Bob Wilson78dfbc32010-07-07 00:08:54 +00002030 SmallVector<SDValue, 6> Ops;
2031 if (IsExt)
2032 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002033 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002034 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002035 Ops.push_back(getAL(CurDAG)); // predicate
2036 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002037 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002038}
2039
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002040SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002041 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002042 if (!Subtarget->hasV6T2Ops())
2043 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002044
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002045 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2046 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2047
2048
2049 // For unsigned extracts, check for a shift right and mask
2050 unsigned And_imm = 0;
2051 if (N->getOpcode() == ISD::AND) {
2052 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2053
2054 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2055 if (And_imm & (And_imm + 1))
2056 return NULL;
2057
2058 unsigned Srl_imm = 0;
2059 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2060 Srl_imm)) {
2061 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2062
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002063 // Note: The width operand is encoded as width-1.
2064 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002065 unsigned LSB = Srl_imm;
2066 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2067 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2068 CurDAG->getTargetConstant(LSB, MVT::i32),
2069 CurDAG->getTargetConstant(Width, MVT::i32),
2070 getAL(CurDAG), Reg0 };
2071 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2072 }
2073 }
2074 return NULL;
2075 }
2076
2077 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002078 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002079 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002080 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2081 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002082 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002083 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002084 // Note: The width operand is encoded as width-1.
2085 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002086 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002087 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002088 return NULL;
2089 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002090 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002091 CurDAG->getTargetConstant(LSB, MVT::i32),
2092 CurDAG->getTargetConstant(Width, MVT::i32),
2093 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002094 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002095 }
2096 }
2097 return NULL;
2098}
2099
Evan Cheng9ef48352009-11-20 00:54:03 +00002100SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002101SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002102 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2103 SDValue CPTmp0;
2104 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002105 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002106 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2107 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2108 unsigned Opc = 0;
2109 switch (SOShOp) {
2110 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2111 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2112 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2113 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2114 default:
2115 llvm_unreachable("Unknown so_reg opcode!");
2116 break;
2117 }
2118 SDValue SOShImm =
2119 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2120 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2121 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002122 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002123 }
2124 return 0;
2125}
2126
2127SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002128SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002129 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2130 SDValue CPTmp0;
2131 SDValue CPTmp1;
2132 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002133 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002134 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002135 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2136 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002137 }
2138
2139 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2140 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2141 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2142 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002143 }
2144 return 0;
2145}
2146
2147SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002148SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002149 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002150 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002151 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002152 return 0;
2153
Evan Cheng63f35442010-11-13 02:25:14 +00002154 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002155 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002156 if (is_t2_so_imm(TrueImm)) {
2157 Opc = ARM::t2MOVCCi;
2158 } else if (TrueImm <= 0xffff) {
2159 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002160 } else if (is_t2_so_imm_not(TrueImm)) {
2161 TrueImm = ~TrueImm;
2162 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002163 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002164 // Large immediate.
2165 Opc = ARM::t2MOVCCi32imm;
2166 }
2167
2168 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002169 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002170 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2171 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002172 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002173 }
Evan Cheng63f35442010-11-13 02:25:14 +00002174
Evan Cheng9ef48352009-11-20 00:54:03 +00002175 return 0;
2176}
2177
2178SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002179SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002180 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002181 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2182 if (!T)
2183 return 0;
2184
Evan Cheng63f35442010-11-13 02:25:14 +00002185 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002186 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002187 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002188 if (isSoImm) {
2189 Opc = ARM::MOVCCi;
2190 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2191 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002192 } else if (is_so_imm_not(TrueImm)) {
2193 TrueImm = ~TrueImm;
2194 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002195 } else if (TrueVal.getNode()->hasOneUse() &&
2196 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002197 // Large immediate.
2198 Opc = ARM::MOVCCi32imm;
2199 }
2200
2201 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002202 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002203 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2204 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002205 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002206 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002207
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 return 0;
2209}
2210
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002211SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2212 EVT VT = N->getValueType(0);
2213 SDValue FalseVal = N->getOperand(0);
2214 SDValue TrueVal = N->getOperand(1);
2215 SDValue CC = N->getOperand(2);
2216 SDValue CCR = N->getOperand(3);
2217 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002218 assert(CC.getOpcode() == ISD::Constant);
2219 assert(CCR.getOpcode() == ISD::Register);
2220 ARMCC::CondCodes CCVal =
2221 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002222
2223 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2224 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2225 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2226 // Pattern complexity = 18 cost = 1 size = 0
2227 SDValue CPTmp0;
2228 SDValue CPTmp1;
2229 SDValue CPTmp2;
2230 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002231 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002232 CCVal, CCR, InFlag);
2233 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002234 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002235 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2236 if (Res)
2237 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002238 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002239 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002240 CCVal, CCR, InFlag);
2241 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002242 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002243 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2244 if (Res)
2245 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002246 }
2247
2248 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002249 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002250 // (imm:i32):$cc)
2251 // Emits: (MOVCCi:i32 GPR:i32:$false,
2252 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2253 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002254 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002255 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002256 CCVal, CCR, InFlag);
2257 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002258 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002259 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2260 if (Res)
2261 return Res;
2262 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002263 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002264 CCVal, CCR, InFlag);
2265 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002266 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002267 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2268 if (Res)
2269 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002270 }
2271 }
2272
2273 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2274 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2275 // Pattern complexity = 6 cost = 1 size = 0
2276 //
2277 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2278 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2279 // Pattern complexity = 6 cost = 11 size = 0
2280 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002281 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002282 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2283 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002284 unsigned Opc = 0;
2285 switch (VT.getSimpleVT().SimpleTy) {
2286 default: assert(false && "Illegal conditional move type!");
2287 break;
2288 case MVT::i32:
2289 Opc = Subtarget->isThumb()
2290 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2291 : ARM::MOVCCr;
2292 break;
2293 case MVT::f32:
2294 Opc = ARM::VMOVScc;
2295 break;
2296 case MVT::f64:
2297 Opc = ARM::VMOVDcc;
2298 break;
2299 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002300 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002301}
2302
Evan Chengde8aa4e2010-05-05 18:28:36 +00002303SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2304 // The only time a CONCAT_VECTORS operation can have legal types is when
2305 // two 64-bit vectors are concatenated to a 128-bit vector.
2306 EVT VT = N->getValueType(0);
2307 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2308 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002309 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002310}
2311
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002312SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002313 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002314
Dan Gohmane8be6c62008-07-17 19:10:17 +00002315 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002316 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002317
2318 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002319 default: break;
2320 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002321 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002322 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002323 if (Subtarget->hasThumb2())
2324 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2325 // be done with MOV + MOVT, at worst.
2326 UseCP = 0;
2327 else {
2328 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002329 UseCP = (Val > 255 && // MOV
2330 ~Val > 255 && // MOV + MVN
2331 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002332 } else
2333 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2334 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2335 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2336 }
2337
Evan Chenga8e29892007-01-19 07:51:42 +00002338 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002339 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002340 CurDAG->getTargetConstantPool(ConstantInt::get(
2341 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002342 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002343
2344 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002345 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002346 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002347 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002348 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002349 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002350 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002351 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002352 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002353 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002354 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002355 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002356 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002357 CurDAG->getEntryNode()
2358 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002359 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002360 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002361 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002362 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002363 return NULL;
2364 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002365
Evan Chenga8e29892007-01-19 07:51:42 +00002366 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002367 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002368 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002369 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002370 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002371 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002372 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002373 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002374 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2375 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2376 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002377 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002378 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2379 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002380 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2381 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2382 CurDAG->getRegister(0, MVT::i32) };
2383 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002384 }
Evan Chenga8e29892007-01-19 07:51:42 +00002385 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002386 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002387 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002388 return I;
2389 break;
2390 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002391 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002392 return I;
2393 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002394 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002395 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002396 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002397 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002398 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002399 if (!RHSV) break;
2400 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002401 unsigned ShImm = Log2_32(RHSV-1);
2402 if (ShImm >= 32)
2403 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002404 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002405 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002406 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2407 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002408 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002409 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002410 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002411 } else {
2412 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002413 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002414 }
Evan Chenga8e29892007-01-19 07:51:42 +00002415 }
2416 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002417 unsigned ShImm = Log2_32(RHSV+1);
2418 if (ShImm >= 32)
2419 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002420 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002421 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002422 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2423 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002424 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002425 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2426 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002427 } else {
2428 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002429 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002430 }
Evan Chenga8e29892007-01-19 07:51:42 +00002431 }
2432 }
2433 break;
Evan Cheng20956592009-10-21 08:15:52 +00002434 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002435 // Check for unsigned bitfield extract
2436 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2437 return I;
2438
Evan Cheng20956592009-10-21 08:15:52 +00002439 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2440 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2441 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2442 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2443 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002444 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002445 if (VT != MVT::i32)
2446 break;
2447 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2448 ? ARM::t2MOVTi16
2449 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2450 if (!Opc)
2451 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002452 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002453 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2454 if (!N1C)
2455 break;
2456 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2457 SDValue N2 = N0.getOperand(1);
2458 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2459 if (!N2C)
2460 break;
2461 unsigned N1CVal = N1C->getZExtValue();
2462 unsigned N2CVal = N2C->getZExtValue();
2463 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2464 (N1CVal & 0xffffU) == 0xffffU &&
2465 (N2CVal & 0xffffU) == 0x0U) {
2466 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2467 MVT::i32);
2468 SDValue Ops[] = { N0.getOperand(0), Imm16,
2469 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2470 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2471 }
2472 }
2473 break;
2474 }
Jim Grosbache5165492009-11-09 00:11:35 +00002475 case ARMISD::VMOVRRD:
2476 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002477 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002478 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002479 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002480 if (Subtarget->isThumb1Only())
2481 break;
2482 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002483 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002484 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2485 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002486 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002487 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002488 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002489 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2490 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002491 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2492 ARM::UMULL : ARM::UMULLv5,
2493 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002494 }
Evan Chengee568cf2007-07-05 07:15:27 +00002495 }
Dan Gohman525178c2007-10-08 18:33:35 +00002496 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002497 if (Subtarget->isThumb1Only())
2498 break;
2499 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002500 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002501 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002502 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002503 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002504 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002505 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2506 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002507 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2508 ARM::SMULL : ARM::SMULLv5,
2509 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002510 }
Evan Chengee568cf2007-07-05 07:15:27 +00002511 }
Evan Chenga8e29892007-01-19 07:51:42 +00002512 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002513 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002514 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002515 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002516 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002517 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002518 if (ResNode)
2519 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002520 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002521 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002522 }
Evan Chengee568cf2007-07-05 07:15:27 +00002523 case ARMISD::BRCOND: {
2524 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2525 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2526 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002527
Evan Chengee568cf2007-07-05 07:15:27 +00002528 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2529 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2530 // Pattern complexity = 6 cost = 1 size = 0
2531
David Goodwin5e47a9a2009-06-30 18:04:13 +00002532 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2533 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2534 // Pattern complexity = 6 cost = 1 size = 0
2535
Jim Grosbach764ab522009-08-11 15:33:49 +00002536 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002537 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002538 SDValue Chain = N->getOperand(0);
2539 SDValue N1 = N->getOperand(1);
2540 SDValue N2 = N->getOperand(2);
2541 SDValue N3 = N->getOperand(3);
2542 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002543 assert(N1.getOpcode() == ISD::BasicBlock);
2544 assert(N2.getOpcode() == ISD::Constant);
2545 assert(N3.getOpcode() == ISD::Register);
2546
Dan Gohman475871a2008-07-27 21:46:04 +00002547 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002548 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002549 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002550 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002551 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002552 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002553 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002554 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002555 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002556 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002557 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002558 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002559 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002560 return NULL;
2561 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002562 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002563 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002564 case ARMISD::VZIP: {
2565 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002566 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002567 switch (VT.getSimpleVT().SimpleTy) {
2568 default: return NULL;
2569 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2570 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2571 case MVT::v2f32:
2572 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2573 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2574 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2575 case MVT::v4f32:
2576 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2577 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002578 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002579 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2580 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2581 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002582 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002583 case ARMISD::VUZP: {
2584 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002585 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002586 switch (VT.getSimpleVT().SimpleTy) {
2587 default: return NULL;
2588 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2589 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2590 case MVT::v2f32:
2591 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2592 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2593 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2594 case MVT::v4f32:
2595 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2596 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002597 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002598 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2599 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2600 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002601 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002602 case ARMISD::VTRN: {
2603 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002604 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002605 switch (VT.getSimpleVT().SimpleTy) {
2606 default: return NULL;
2607 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2608 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2609 case MVT::v2f32:
2610 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2611 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2612 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2613 case MVT::v4f32:
2614 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2615 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002616 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002617 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2618 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2619 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002620 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002621 case ARMISD::BUILD_VECTOR: {
2622 EVT VecVT = N->getValueType(0);
2623 EVT EltVT = VecVT.getVectorElementType();
2624 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002625 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002626 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2627 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2628 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002629 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002630 if (NumElts == 2)
2631 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2632 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2633 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2634 N->getOperand(2), N->getOperand(3));
2635 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002636
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002637 case ARMISD::VLD2DUP: {
2638 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2639 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002640 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002641 }
2642
Bob Wilson86c6d802010-11-29 19:35:29 +00002643 case ARMISD::VLD3DUP: {
2644 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2645 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002646 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002647 }
2648
Bob Wilson6c4c9822010-11-30 00:00:35 +00002649 case ARMISD::VLD4DUP: {
2650 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2651 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002652 return SelectVLDDup(N, false, 4, Opcodes);
2653 }
2654
2655 case ARMISD::VLD2DUP_UPD: {
2656 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2657 ARM::VLD2DUPd32Pseudo_UPD };
2658 return SelectVLDDup(N, true, 2, Opcodes);
2659 }
2660
2661 case ARMISD::VLD3DUP_UPD: {
2662 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2663 ARM::VLD3DUPd32Pseudo_UPD };
2664 return SelectVLDDup(N, true, 3, Opcodes);
2665 }
2666
2667 case ARMISD::VLD4DUP_UPD: {
2668 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2669 ARM::VLD4DUPd32Pseudo_UPD };
2670 return SelectVLDDup(N, true, 4, Opcodes);
2671 }
2672
2673 case ARMISD::VLD1_UPD: {
2674 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2675 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2676 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2677 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2678 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2679 }
2680
2681 case ARMISD::VLD2_UPD: {
2682 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2683 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2684 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2685 ARM::VLD2q32Pseudo_UPD };
2686 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2687 }
2688
2689 case ARMISD::VLD3_UPD: {
2690 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2691 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2692 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2693 ARM::VLD3q16Pseudo_UPD,
2694 ARM::VLD3q32Pseudo_UPD };
2695 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2696 ARM::VLD3q16oddPseudo_UPD,
2697 ARM::VLD3q32oddPseudo_UPD };
2698 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2699 }
2700
2701 case ARMISD::VLD4_UPD: {
2702 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2703 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2704 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2705 ARM::VLD4q16Pseudo_UPD,
2706 ARM::VLD4q32Pseudo_UPD };
2707 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2708 ARM::VLD4q16oddPseudo_UPD,
2709 ARM::VLD4q32oddPseudo_UPD };
2710 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2711 }
2712
2713 case ARMISD::VLD2LN_UPD: {
2714 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2715 ARM::VLD2LNd32Pseudo_UPD };
2716 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2717 ARM::VLD2LNq32Pseudo_UPD };
2718 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2719 }
2720
2721 case ARMISD::VLD3LN_UPD: {
2722 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2723 ARM::VLD3LNd32Pseudo_UPD };
2724 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2725 ARM::VLD3LNq32Pseudo_UPD };
2726 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2727 }
2728
2729 case ARMISD::VLD4LN_UPD: {
2730 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2731 ARM::VLD4LNd32Pseudo_UPD };
2732 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2733 ARM::VLD4LNq32Pseudo_UPD };
2734 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2735 }
2736
2737 case ARMISD::VST1_UPD: {
2738 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2739 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2740 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2741 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2742 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2743 }
2744
2745 case ARMISD::VST2_UPD: {
2746 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2747 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2748 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2749 ARM::VST2q32Pseudo_UPD };
2750 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2751 }
2752
2753 case ARMISD::VST3_UPD: {
2754 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2755 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2756 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2757 ARM::VST3q16Pseudo_UPD,
2758 ARM::VST3q32Pseudo_UPD };
2759 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2760 ARM::VST3q16oddPseudo_UPD,
2761 ARM::VST3q32oddPseudo_UPD };
2762 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2763 }
2764
2765 case ARMISD::VST4_UPD: {
2766 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2767 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2768 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2769 ARM::VST4q16Pseudo_UPD,
2770 ARM::VST4q32Pseudo_UPD };
2771 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2772 ARM::VST4q16oddPseudo_UPD,
2773 ARM::VST4q32oddPseudo_UPD };
2774 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2775 }
2776
2777 case ARMISD::VST2LN_UPD: {
2778 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2779 ARM::VST2LNd32Pseudo_UPD };
2780 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2781 ARM::VST2LNq32Pseudo_UPD };
2782 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2783 }
2784
2785 case ARMISD::VST3LN_UPD: {
2786 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2787 ARM::VST3LNd32Pseudo_UPD };
2788 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2789 ARM::VST3LNq32Pseudo_UPD };
2790 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2791 }
2792
2793 case ARMISD::VST4LN_UPD: {
2794 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2795 ARM::VST4LNd32Pseudo_UPD };
2796 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2797 ARM::VST4LNq32Pseudo_UPD };
2798 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002799 }
2800
Bob Wilson31fb12f2009-08-26 17:39:53 +00002801 case ISD::INTRINSIC_VOID:
2802 case ISD::INTRINSIC_W_CHAIN: {
2803 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002804 switch (IntNo) {
2805 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002806 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002807
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002808 case Intrinsic::arm_ldrexd: {
2809 SDValue MemAddr = N->getOperand(2);
2810 DebugLoc dl = N->getDebugLoc();
2811 SDValue Chain = N->getOperand(0);
2812
2813 unsigned NewOpc = ARM::LDREXD;
2814 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2815 NewOpc = ARM::t2LDREXD;
2816
2817 // arm_ldrexd returns a i64 value in {i32, i32}
2818 std::vector<EVT> ResTys;
2819 ResTys.push_back(MVT::i32);
2820 ResTys.push_back(MVT::i32);
2821 ResTys.push_back(MVT::Other);
2822
2823 // place arguments in the right order
2824 SmallVector<SDValue, 7> Ops;
2825 Ops.push_back(MemAddr);
2826 Ops.push_back(getAL(CurDAG));
2827 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2828 Ops.push_back(Chain);
2829 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2830 Ops.size());
2831 // Transfer memoperands.
2832 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2833 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2834 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2835
2836 // Until there's support for specifing explicit register constraints
2837 // like the use of even/odd register pair, hardcode ldrexd to always
2838 // use the pair [R0, R1] to hold the load result.
2839 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2840 SDValue(Ld, 0), SDValue(0,0));
2841 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2842 SDValue(Ld, 1), Chain.getValue(1));
2843
2844 // Remap uses.
2845 SDValue Glue = Chain.getValue(1);
2846 if (!SDValue(N, 0).use_empty()) {
2847 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2848 ARM::R0, MVT::i32, Glue);
2849 Glue = Result.getValue(2);
2850 ReplaceUses(SDValue(N, 0), Result);
2851 }
2852 if (!SDValue(N, 1).use_empty()) {
2853 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2854 ARM::R1, MVT::i32, Glue);
2855 Glue = Result.getValue(2);
2856 ReplaceUses(SDValue(N, 1), Result);
2857 }
2858
2859 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2860 return NULL;
2861 }
2862
2863 case Intrinsic::arm_strexd: {
2864 DebugLoc dl = N->getDebugLoc();
2865 SDValue Chain = N->getOperand(0);
2866 SDValue Val0 = N->getOperand(2);
2867 SDValue Val1 = N->getOperand(3);
2868 SDValue MemAddr = N->getOperand(4);
2869
2870 // Until there's support for specifing explicit register constraints
2871 // like the use of even/odd register pair, hardcode strexd to always
2872 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2873 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2874 SDValue(0, 0));
2875 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2876
2877 SDValue Glue = Chain.getValue(1);
2878 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2879 ARM::R2, MVT::i32, Glue);
2880 Glue = Val0.getValue(1);
2881 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2882 ARM::R3, MVT::i32, Glue);
2883
2884 // Store exclusive double return a i32 value which is the return status
2885 // of the issued store.
2886 std::vector<EVT> ResTys;
2887 ResTys.push_back(MVT::i32);
2888 ResTys.push_back(MVT::Other);
2889
2890 // place arguments in the right order
2891 SmallVector<SDValue, 7> Ops;
2892 Ops.push_back(Val0);
2893 Ops.push_back(Val1);
2894 Ops.push_back(MemAddr);
2895 Ops.push_back(getAL(CurDAG));
2896 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2897 Ops.push_back(Chain);
2898
2899 unsigned NewOpc = ARM::STREXD;
2900 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2901 NewOpc = ARM::t2STREXD;
2902
2903 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2904 Ops.size());
2905 // Transfer memoperands.
2906 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2907 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2908 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2909
2910 return St;
2911 }
2912
Bob Wilson621f1952010-03-23 05:25:43 +00002913 case Intrinsic::arm_neon_vld1: {
2914 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2915 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002916 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2917 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002918 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002919 }
2920
Bob Wilson31fb12f2009-08-26 17:39:53 +00002921 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002922 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2923 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2924 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2925 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002926 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002927 }
2928
2929 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002930 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2931 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2932 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2933 ARM::VLD3q16Pseudo_UPD,
2934 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002935 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2936 ARM::VLD3q16oddPseudo,
2937 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002938 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002939 }
2940
2941 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002942 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2943 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2944 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2945 ARM::VLD4q16Pseudo_UPD,
2946 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002947 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2948 ARM::VLD4q16oddPseudo,
2949 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002950 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002951 }
2952
Bob Wilson243fcc52009-09-01 04:26:28 +00002953 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002954 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2955 ARM::VLD2LNd32Pseudo };
2956 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002957 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002958 }
2959
2960 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002961 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2962 ARM::VLD3LNd32Pseudo };
2963 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002964 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002965 }
2966
2967 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002968 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2969 ARM::VLD4LNd32Pseudo };
2970 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002971 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002972 }
2973
Bob Wilson11d98992010-03-23 06:20:33 +00002974 case Intrinsic::arm_neon_vst1: {
2975 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2976 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002977 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2978 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002979 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002980 }
2981
Bob Wilson31fb12f2009-08-26 17:39:53 +00002982 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002983 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2984 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2985 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2986 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002987 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002988 }
2989
2990 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002991 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2992 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2993 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2994 ARM::VST3q16Pseudo_UPD,
2995 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002996 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2997 ARM::VST3q16oddPseudo,
2998 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002999 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003000 }
3001
3002 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00003003 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00003004 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00003005 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3006 ARM::VST4q16Pseudo_UPD,
3007 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003008 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
3009 ARM::VST4q16oddPseudo,
3010 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003011 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003012 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003013
3014 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003015 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
3016 ARM::VST2LNd32Pseudo };
3017 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003018 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003019 }
3020
3021 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003022 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
3023 ARM::VST3LNd32Pseudo };
3024 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003025 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003026 }
3027
3028 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003029 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3030 ARM::VST4LNd32Pseudo };
3031 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003032 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003033 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003034 }
Bob Wilson429009b2010-05-06 16:05:26 +00003035 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003036 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003037
Bob Wilsond491d6e2010-07-06 23:36:25 +00003038 case ISD::INTRINSIC_WO_CHAIN: {
3039 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3040 switch (IntNo) {
3041 default:
3042 break;
3043
3044 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003045 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003046 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003047 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003048 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003049 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003050
3051 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003052 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003053 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003054 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003055 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003056 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003057 }
3058 break;
3059 }
3060
Bill Wendling69a05a72011-03-14 23:02:38 +00003061 case ARMISD::VTBL1: {
3062 DebugLoc dl = N->getDebugLoc();
3063 EVT VT = N->getValueType(0);
3064 SmallVector<SDValue, 6> Ops;
3065
3066 Ops.push_back(N->getOperand(0));
3067 Ops.push_back(N->getOperand(1));
3068 Ops.push_back(getAL(CurDAG)); // Predicate
3069 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3070 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3071 }
3072 case ARMISD::VTBL2: {
3073 DebugLoc dl = N->getDebugLoc();
3074 EVT VT = N->getValueType(0);
3075
3076 // Form a REG_SEQUENCE to force register allocation.
3077 SDValue V0 = N->getOperand(0);
3078 SDValue V1 = N->getOperand(1);
3079 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3080
3081 SmallVector<SDValue, 6> Ops;
3082 Ops.push_back(RegSeq);
3083 Ops.push_back(N->getOperand(2));
3084 Ops.push_back(getAL(CurDAG)); // Predicate
3085 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3086 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3087 Ops.data(), Ops.size());
3088 }
3089
Bob Wilson429009b2010-05-06 16:05:26 +00003090 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003091 return SelectConcatVector(N);
3092 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003093
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003094 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003095}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003096
Bob Wilson224c2442009-05-19 05:53:42 +00003097bool ARMDAGToDAGISel::
3098SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3099 std::vector<SDValue> &OutOps) {
3100 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003101 // Require the address to be in a register. That is safe for all ARM
3102 // variants and it is hard to do anything much smarter without knowing
3103 // how the operand is used.
3104 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003105 return false;
3106}
3107
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003108/// createARMISelDag - This pass converts a legalized DAG into a
3109/// ARM-specific DAG, ready for instruction scheduling.
3110///
Bob Wilson522ce972009-09-28 14:30:20 +00003111FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3112 CodeGenOpt::Level OptLevel) {
3113 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003114}