blob: 6a35f05da24a067fac756f2f305f577c8af85e40 [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);
Jim Grosbach19dec202011-08-05 20:35:44 +0000136 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000137 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000138 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000141 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000143 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000144 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000145
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000146 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000147
Bill Wendlingf4caf692010-12-14 03:36:38 +0000148 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000149 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
151 unsigned Scale);
152 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
153 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
154 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
156 SDValue &OffImm);
157 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
158 SDValue &OffImm);
159 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
160 SDValue &OffImm);
161 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
162 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000163 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000164
Bill Wendlingf4caf692010-12-14 03:36:38 +0000165 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000166 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000167 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000168 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
169 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000170 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000171 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000172 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000173 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000174 SDValue &OffReg, SDValue &ShImm);
175
Evan Cheng875a6ac2010-11-12 22:42:47 +0000176 inline bool is_so_imm(unsigned Imm) const {
177 return ARM_AM::getSOImmVal(Imm) != -1;
178 }
179
180 inline bool is_so_imm_not(unsigned Imm) const {
181 return ARM_AM::getSOImmVal(~Imm) != -1;
182 }
183
184 inline bool is_t2_so_imm(unsigned Imm) const {
185 return ARM_AM::getT2SOImmVal(Imm) != -1;
186 }
187
188 inline bool is_t2_so_imm_not(unsigned Imm) const {
189 return ARM_AM::getT2SOImmVal(~Imm) != -1;
190 }
191
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000192 // Include the pieces autogenerated from the target description.
193#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000194
195private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000196 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
197 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000198 SDNode *SelectARMIndexedLoad(SDNode *N);
199 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000200
Bob Wilson621f1952010-03-23 05:25:43 +0000201 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
202 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000203 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000204 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000205 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
206 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000207 unsigned *QOpcodes0, unsigned *QOpcodes1);
208
Bob Wilson24f995d2009-10-14 18:32:29 +0000209 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000210 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000213 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
214 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000215 unsigned *QOpcodes0, unsigned *QOpcodes1);
216
Bob Wilson96493442009-10-14 16:46:45 +0000217 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000218 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000219 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000220 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
221 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000222 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000223
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000224 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
225 /// should be 2, 3 or 4. The opcode array specifies the instructions used
226 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000227 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
228 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000229
Bob Wilson78dfbc32010-07-07 00:08:54 +0000230 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
231 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
232 /// generated to force the table registers to be consecutive.
233 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000234
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000235 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000236 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000237
Evan Cheng07ba9062009-11-19 21:45:22 +0000238 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000239 SDNode *SelectCMOVOp(SDNode *N);
240 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000241 ARMCC::CondCodes CCVal, SDValue CCR,
242 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000243 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000244 ARMCC::CondCodes CCVal, SDValue CCR,
245 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000246 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000247 ARMCC::CondCodes CCVal, SDValue CCR,
248 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000249 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000250 ARMCC::CondCodes CCVal, SDValue CCR,
251 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000252
Evan Chengde8aa4e2010-05-05 18:28:36 +0000253 SDNode *SelectConcatVector(SDNode *N);
254
Evan Chengaf4550f2009-07-02 01:23:32 +0000255 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
256 /// inline asm expressions.
257 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
258 char ConstraintCode,
259 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000260
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000261 // Form pairs of consecutive S, D, or Q registers.
262 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000263 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000264 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
265
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000266 // Form sequences of 4 consecutive S, D, or Q registers.
267 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000268 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000269 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000270
271 // Get the alignment operand for a NEON VLD or VST instruction.
272 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000273};
Evan Chenga8e29892007-01-19 07:51:42 +0000274}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000275
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000276/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
277/// operand. If so Imm will receive the 32-bit value.
278static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
279 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
280 Imm = cast<ConstantSDNode>(N)->getZExtValue();
281 return true;
282 }
283 return false;
284}
285
286// isInt32Immediate - This method tests to see if a constant operand.
287// If so Imm will receive the 32 bit value.
288static bool isInt32Immediate(SDValue N, unsigned &Imm) {
289 return isInt32Immediate(N.getNode(), Imm);
290}
291
292// isOpcWithIntImmediate - This method tests to see if the node is a specific
293// opcode and that it has a immediate integer right operand.
294// If so Imm will receive the 32 bit value.
295static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
296 return N->getOpcode() == Opc &&
297 isInt32Immediate(N->getOperand(1).getNode(), Imm);
298}
299
Daniel Dunbarec91d522011-01-19 15:12:16 +0000300/// \brief Check whether a particular node is a constant value representable as
301/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
302///
303/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
304static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
305 int RangeMin, int RangeMax,
306 int &ScaledConstant) {
307 assert(Scale && "Invalid scale!");
308
309 // Check that this is a constant.
310 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
311 if (!C)
312 return false;
313
314 ScaledConstant = (int) C->getZExtValue();
315 if ((ScaledConstant % Scale) != 0)
316 return false;
317
318 ScaledConstant /= Scale;
319 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
320}
321
Evan Cheng48575f62010-12-05 22:04:16 +0000322/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
323/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
324/// least on current ARM implementations) which should be avoidded.
325bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
326 if (OptLevel == CodeGenOpt::None)
327 return true;
328
329 if (!CheckVMLxHazard)
330 return true;
331
332 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
333 return true;
334
335 if (!N->hasOneUse())
336 return false;
337
338 SDNode *Use = *N->use_begin();
339 if (Use->getOpcode() == ISD::CopyToReg)
340 return true;
341 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000342 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
343 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000344 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000345 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000346 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
347 return true;
348 // vmlx feeding into another vmlx. We actually want to unfold
349 // the use later in the MLxExpansion pass. e.g.
350 // vmla
351 // vmla (stall 8 cycles)
352 //
353 // vmul (5 cycles)
354 // vadd (5 cycles)
355 // vmla
356 // This adds up to about 18 - 19 cycles.
357 //
358 // vmla
359 // vmul (stall 4 cycles)
360 // vadd adds up to about 14 cycles.
361 return TII->isFpMLxInstruction(Opcode);
362 }
363
364 return false;
365}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000366
Evan Chengf40deed2010-10-27 23:41:30 +0000367bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
368 ARM_AM::ShiftOpc ShOpcVal,
369 unsigned ShAmt) {
370 if (!Subtarget->isCortexA9())
371 return true;
372 if (Shift.hasOneUse())
373 return true;
374 // R << 2 is free.
375 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
376}
377
Owen Anderson92a20222011-07-21 18:54:16 +0000378bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000379 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000380 SDValue &Opc,
381 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000382 if (DisableShifterOp)
383 return false;
384
Evan Chengee04a6d2011-07-20 23:34:39 +0000385 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000386
387 // Don't match base register only case. That is matched to a separate
388 // lower complexity pattern with explicit register operand.
389 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000390
Evan Cheng055b0312009-06-29 07:51:04 +0000391 BaseReg = N.getOperand(0);
392 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000393 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
394 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000395 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000396 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
397 MVT::i32);
398 return true;
399}
400
Owen Anderson92a20222011-07-21 18:54:16 +0000401bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
402 SDValue &BaseReg,
403 SDValue &ShReg,
404 SDValue &Opc,
405 bool CheckProfitability) {
406 if (DisableShifterOp)
407 return false;
408
409 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
410
411 // Don't match base register only case. That is matched to a separate
412 // lower complexity pattern with explicit register operand.
413 if (ShOpcVal == ARM_AM::no_shift) return false;
414
415 BaseReg = N.getOperand(0);
416 unsigned ShImmVal = 0;
417 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
418 if (RHS) return false;
419
420 ShReg = N.getOperand(1);
421 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
422 return false;
423 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
424 MVT::i32);
425 return true;
426}
427
428
Jim Grosbach3e556122010-10-26 22:37:02 +0000429bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
430 SDValue &Base,
431 SDValue &OffImm) {
432 // Match simple R + imm12 operands.
433
434 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000435 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
436 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000437 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000438 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000439 int FI = cast<FrameIndexSDNode>(N)->getIndex();
440 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
441 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
442 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000443 }
Owen Anderson099e5552011-03-18 19:46:58 +0000444
Chris Lattner0a9481f2011-02-13 22:25:43 +0000445 if (N.getOpcode() == ARMISD::Wrapper &&
446 !(Subtarget->useMovt() &&
447 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000448 Base = N.getOperand(0);
449 } else
450 Base = N;
451 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
452 return true;
453 }
454
455 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
456 int RHSC = (int)RHS->getZExtValue();
457 if (N.getOpcode() == ISD::SUB)
458 RHSC = -RHSC;
459
460 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
461 Base = N.getOperand(0);
462 if (Base.getOpcode() == ISD::FrameIndex) {
463 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
464 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
465 }
466 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
467 return true;
468 }
469 }
470
471 // Base only.
472 Base = N;
473 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
474 return true;
475}
476
477
478
479bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
480 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000481 if (N.getOpcode() == ISD::MUL &&
482 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000483 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
484 // X * [3,5,9] -> X + X * [2,4,8] etc.
485 int RHSC = (int)RHS->getZExtValue();
486 if (RHSC & 1) {
487 RHSC = RHSC & ~1;
488 ARM_AM::AddrOpc AddSub = ARM_AM::add;
489 if (RHSC < 0) {
490 AddSub = ARM_AM::sub;
491 RHSC = - RHSC;
492 }
493 if (isPowerOf2_32(RHSC)) {
494 unsigned ShAmt = Log2_32(RHSC);
495 Base = Offset = N.getOperand(0);
496 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
497 ARM_AM::lsl),
498 MVT::i32);
499 return true;
500 }
501 }
502 }
503 }
504
Chris Lattner0a9481f2011-02-13 22:25:43 +0000505 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
506 // ISD::OR that is equivalent to an ISD::ADD.
507 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000508 return false;
509
510 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000511 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000512 int RHSC;
513 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
514 -0x1000+1, 0x1000, RHSC)) // 12 bits.
515 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000516 }
517
Evan Chengf40deed2010-10-27 23:41:30 +0000518 if (Subtarget->isCortexA9() && !N.hasOneUse())
519 // Compute R +/- (R << N) and reuse it.
520 return false;
521
Jim Grosbach3e556122010-10-26 22:37:02 +0000522 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000523 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000524 ARM_AM::ShiftOpc ShOpcVal =
525 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000526 unsigned ShAmt = 0;
527
528 Base = N.getOperand(0);
529 Offset = N.getOperand(1);
530
531 if (ShOpcVal != ARM_AM::no_shift) {
532 // Check to see if the RHS of the shift is a constant, if not, we can't fold
533 // it.
534 if (ConstantSDNode *Sh =
535 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
536 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000537 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
538 Offset = N.getOperand(1).getOperand(0);
539 else {
540 ShAmt = 0;
541 ShOpcVal = ARM_AM::no_shift;
542 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000543 } else {
544 ShOpcVal = ARM_AM::no_shift;
545 }
546 }
547
548 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000549 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000550 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000551 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000552 if (ShOpcVal != ARM_AM::no_shift) {
553 // Check to see if the RHS of the shift is a constant, if not, we can't
554 // fold it.
555 if (ConstantSDNode *Sh =
556 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
557 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000558 if (!Subtarget->isCortexA9() ||
559 (N.hasOneUse() &&
560 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
561 Offset = N.getOperand(0).getOperand(0);
562 Base = N.getOperand(1);
563 } else {
564 ShAmt = 0;
565 ShOpcVal = ARM_AM::no_shift;
566 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000567 } else {
568 ShOpcVal = ARM_AM::no_shift;
569 }
570 }
571 }
572
573 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
574 MVT::i32);
575 return true;
576}
577
578
579
580
581//-----
582
Jim Grosbach82891622010-09-29 19:03:54 +0000583AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
584 SDValue &Base,
585 SDValue &Offset,
586 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000587 if (N.getOpcode() == ISD::MUL &&
588 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000589 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
590 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000591 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000592 if (RHSC & 1) {
593 RHSC = RHSC & ~1;
594 ARM_AM::AddrOpc AddSub = ARM_AM::add;
595 if (RHSC < 0) {
596 AddSub = ARM_AM::sub;
597 RHSC = - RHSC;
598 }
599 if (isPowerOf2_32(RHSC)) {
600 unsigned ShAmt = Log2_32(RHSC);
601 Base = Offset = N.getOperand(0);
602 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
603 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000605 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000606 }
607 }
608 }
609 }
610
Chris Lattner0a9481f2011-02-13 22:25:43 +0000611 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
612 // ISD::OR that is equivalent to an ADD.
613 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000614 Base = N;
615 if (N.getOpcode() == ISD::FrameIndex) {
616 int FI = cast<FrameIndexSDNode>(N)->getIndex();
617 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000618 } else if (N.getOpcode() == ARMISD::Wrapper &&
619 !(Subtarget->useMovt() &&
620 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000621 Base = N.getOperand(0);
622 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000623 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000624 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
625 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000627 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000628 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000629
Evan Chenga8e29892007-01-19 07:51:42 +0000630 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000631 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000632 int RHSC;
633 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
634 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
635 Base = N.getOperand(0);
636 if (Base.getOpcode() == ISD::FrameIndex) {
637 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
638 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000639 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000640 Offset = CurDAG->getRegister(0, MVT::i32);
641
642 ARM_AM::AddrOpc AddSub = ARM_AM::add;
643 if (RHSC < 0) {
644 AddSub = ARM_AM::sub;
645 RHSC = - RHSC;
646 }
647 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
648 ARM_AM::no_shift),
649 MVT::i32);
650 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000651 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000652 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000653
Evan Chengf40deed2010-10-27 23:41:30 +0000654 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
655 // Compute R +/- (R << N) and reuse it.
656 Base = N;
657 Offset = CurDAG->getRegister(0, MVT::i32);
658 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
659 ARM_AM::no_shift),
660 MVT::i32);
661 return AM2_BASE;
662 }
663
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000664 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000665 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000666 ARM_AM::ShiftOpc ShOpcVal =
667 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000668 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 Base = N.getOperand(0);
671 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000672
Evan Chenga8e29892007-01-19 07:51:42 +0000673 if (ShOpcVal != ARM_AM::no_shift) {
674 // Check to see if the RHS of the shift is a constant, if not, we can't fold
675 // it.
676 if (ConstantSDNode *Sh =
677 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000678 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000679 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
680 Offset = N.getOperand(1).getOperand(0);
681 else {
682 ShAmt = 0;
683 ShOpcVal = ARM_AM::no_shift;
684 }
Evan Chenga8e29892007-01-19 07:51:42 +0000685 } else {
686 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000687 }
688 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000689
Evan Chenga8e29892007-01-19 07:51:42 +0000690 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000691 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000692 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000693 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000694 if (ShOpcVal != ARM_AM::no_shift) {
695 // Check to see if the RHS of the shift is a constant, if not, we can't
696 // fold it.
697 if (ConstantSDNode *Sh =
698 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000699 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000700 if (!Subtarget->isCortexA9() ||
701 (N.hasOneUse() &&
702 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
703 Offset = N.getOperand(0).getOperand(0);
704 Base = N.getOperand(1);
705 } else {
706 ShAmt = 0;
707 ShOpcVal = ARM_AM::no_shift;
708 }
Evan Chenga8e29892007-01-19 07:51:42 +0000709 } else {
710 ShOpcVal = ARM_AM::no_shift;
711 }
712 }
713 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000714
Evan Chenga8e29892007-01-19 07:51:42 +0000715 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000716 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000717 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000718}
719
Owen Anderson793e7962011-07-26 20:54:26 +0000720bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000721 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000722 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000723 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
724 ? cast<LoadSDNode>(Op)->getAddressingMode()
725 : cast<StoreSDNode>(Op)->getAddressingMode();
726 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
727 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000728 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000729 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
730 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000731
732 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000733 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000734 unsigned ShAmt = 0;
735 if (ShOpcVal != ARM_AM::no_shift) {
736 // Check to see if the RHS of the shift is a constant, if not, we can't fold
737 // it.
738 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000739 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000740 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
741 Offset = N.getOperand(0);
742 else {
743 ShAmt = 0;
744 ShOpcVal = ARM_AM::no_shift;
745 }
Evan Chenga8e29892007-01-19 07:51:42 +0000746 } else {
747 ShOpcVal = ARM_AM::no_shift;
748 }
749 }
750
751 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000752 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000753 return true;
754}
755
Owen Anderson793e7962011-07-26 20:54:26 +0000756bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
757 SDValue &Offset, SDValue &Opc) {
758 unsigned Opcode = Op->getOpcode();
759 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
760 ? cast<LoadSDNode>(Op)->getAddressingMode()
761 : cast<StoreSDNode>(Op)->getAddressingMode();
762 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
763 ? ARM_AM::add : ARM_AM::sub;
764 int Val;
765 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
766 Offset = CurDAG->getRegister(0, MVT::i32);
767 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
768 ARM_AM::no_shift),
769 MVT::i32);
770 return true;
771 }
772
773 return false;
774}
775
Jim Grosbach19dec202011-08-05 20:35:44 +0000776bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
777 Base = N;
778 return true;
779}
Evan Chenga8e29892007-01-19 07:51:42 +0000780
Chris Lattner52a261b2010-09-21 20:31:19 +0000781bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000782 SDValue &Base, SDValue &Offset,
783 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000784 if (N.getOpcode() == ISD::SUB) {
785 // X - C is canonicalize to X + -C, no need to handle it here.
786 Base = N.getOperand(0);
787 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000788 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000789 return true;
790 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000791
Chris Lattner0a9481f2011-02-13 22:25:43 +0000792 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000793 Base = N;
794 if (N.getOpcode() == ISD::FrameIndex) {
795 int FI = cast<FrameIndexSDNode>(N)->getIndex();
796 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
797 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000798 Offset = CurDAG->getRegister(0, MVT::i32);
799 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000800 return true;
801 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000802
Evan Chenga8e29892007-01-19 07:51:42 +0000803 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000804 int RHSC;
805 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
806 -256 + 1, 256, RHSC)) { // 8 bits.
807 Base = N.getOperand(0);
808 if (Base.getOpcode() == ISD::FrameIndex) {
809 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
810 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000811 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000812 Offset = CurDAG->getRegister(0, MVT::i32);
813
814 ARM_AM::AddrOpc AddSub = ARM_AM::add;
815 if (RHSC < 0) {
816 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000817 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000818 }
819 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
820 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000821 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000822
Evan Chenga8e29892007-01-19 07:51:42 +0000823 Base = N.getOperand(0);
824 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000825 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000826 return true;
827}
828
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000829bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000830 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000831 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000832 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
833 ? cast<LoadSDNode>(Op)->getAddressingMode()
834 : cast<StoreSDNode>(Op)->getAddressingMode();
835 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
836 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000837 int Val;
838 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
839 Offset = CurDAG->getRegister(0, MVT::i32);
840 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
841 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000842 }
843
844 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000846 return true;
847}
848
Jim Grosbach3ab56582010-10-21 19:38:40 +0000849bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000850 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000851 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000852 Base = N;
853 if (N.getOpcode() == ISD::FrameIndex) {
854 int FI = cast<FrameIndexSDNode>(N)->getIndex();
855 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000856 } else if (N.getOpcode() == ARMISD::Wrapper &&
857 !(Subtarget->useMovt() &&
858 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000859 Base = N.getOperand(0);
860 }
861 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000863 return true;
864 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000865
Evan Chenga8e29892007-01-19 07:51:42 +0000866 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000867 int RHSC;
868 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
869 -256 + 1, 256, RHSC)) {
870 Base = N.getOperand(0);
871 if (Base.getOpcode() == ISD::FrameIndex) {
872 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
873 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000874 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000875
876 ARM_AM::AddrOpc AddSub = ARM_AM::add;
877 if (RHSC < 0) {
878 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000879 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000880 }
881 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
882 MVT::i32);
883 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000884 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000885
Evan Chenga8e29892007-01-19 07:51:42 +0000886 Base = N;
887 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000888 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000889 return true;
890}
891
Bob Wilson665814b2010-11-01 23:40:51 +0000892bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
893 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000894 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000895
896 unsigned Alignment = 0;
897 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
898 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
899 // The maximum alignment is equal to the memory size being referenced.
900 unsigned LSNAlign = LSN->getAlignment();
901 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
902 if (LSNAlign > MemSize && MemSize > 1)
903 Alignment = MemSize;
904 } else {
905 // All other uses of addrmode6 are for intrinsics. For now just record
906 // the raw alignment value; it will be refined later based on the legal
907 // alignment operands for the intrinsic.
908 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
909 }
910
911 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000912 return true;
913}
914
Bob Wilsonda525062011-02-25 06:42:42 +0000915bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
916 SDValue &Offset) {
917 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
918 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
919 if (AM != ISD::POST_INC)
920 return false;
921 Offset = N;
922 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
923 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
924 Offset = CurDAG->getRegister(0, MVT::i32);
925 }
926 return true;
927}
928
Chris Lattner52a261b2010-09-21 20:31:19 +0000929bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000930 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000931 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
932 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000933 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000934 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
935 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000936 return true;
937 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000938
Evan Chenga8e29892007-01-19 07:51:42 +0000939 return false;
940}
941
Bill Wendlingf4caf692010-12-14 03:36:38 +0000942
943//===----------------------------------------------------------------------===//
944// Thumb Addressing Modes
945//===----------------------------------------------------------------------===//
946
Chris Lattner52a261b2010-09-21 20:31:19 +0000947bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000948 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000949 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000950 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000951 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000952 return false;
953
954 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000955 return true;
956 }
957
Evan Chenga8e29892007-01-19 07:51:42 +0000958 Base = N.getOperand(0);
959 Offset = N.getOperand(1);
960 return true;
961}
962
Evan Cheng79d43262007-01-24 02:21:22 +0000963bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000964ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
965 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000966 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000967 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000968 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000969 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000970
Evan Cheng012f2d92007-01-24 08:53:17 +0000971 if (N.getOpcode() == ARMISD::Wrapper &&
972 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
973 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000974 }
975
Chris Lattner0a9481f2011-02-13 22:25:43 +0000976 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000977 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000978
Evan Chengad0e4652007-02-06 00:22:06 +0000979 // Thumb does not have [sp, r] address mode.
980 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
981 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
982 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000983 (RHSR && RHSR->getReg() == ARM::SP))
984 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000985
Daniel Dunbarec91d522011-01-19 15:12:16 +0000986 // FIXME: Why do we explicitly check for a match here and then return false?
987 // Presumably to allow something else to match, but shouldn't this be
988 // documented?
989 int RHSC;
990 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
991 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000992
993 Base = N.getOperand(0);
994 Offset = N.getOperand(1);
995 return true;
996}
997
998bool
999ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1000 SDValue &Base,
1001 SDValue &Offset) {
1002 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1003}
1004
1005bool
1006ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1007 SDValue &Base,
1008 SDValue &Offset) {
1009 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1010}
1011
1012bool
1013ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1014 SDValue &Base,
1015 SDValue &Offset) {
1016 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1017}
1018
1019bool
1020ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1021 SDValue &Base, SDValue &OffImm) {
1022 if (Scale == 4) {
1023 SDValue TmpBase, TmpOffImm;
1024 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1025 return false; // We want to select tLDRspi / tSTRspi instead.
1026
1027 if (N.getOpcode() == ARMISD::Wrapper &&
1028 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1029 return false; // We want to select tLDRpci instead.
1030 }
1031
Chris Lattner0a9481f2011-02-13 22:25:43 +00001032 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001033 if (N.getOpcode() == ARMISD::Wrapper &&
1034 !(Subtarget->useMovt() &&
1035 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1036 Base = N.getOperand(0);
1037 } else {
1038 Base = N;
1039 }
1040
Owen Anderson825b72b2009-08-11 20:47:22 +00001041 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001042 return true;
1043 }
1044
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001045 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1046 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1047 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1048 (RHSR && RHSR->getReg() == ARM::SP)) {
1049 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1050 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1051 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1052 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1053
1054 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1055 if (LHSC != 0 || RHSC != 0) return false;
1056
1057 Base = N;
1058 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1059 return true;
1060 }
1061
Evan Chenga8e29892007-01-19 07:51:42 +00001062 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001063 int RHSC;
1064 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1065 Base = N.getOperand(0);
1066 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1067 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001068 }
1069
Evan Chengc38f2bc2007-01-23 22:59:13 +00001070 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001071 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001072 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001073}
1074
Bill Wendlingf4caf692010-12-14 03:36:38 +00001075bool
1076ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1077 SDValue &OffImm) {
1078 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001079}
1080
Bill Wendlingf4caf692010-12-14 03:36:38 +00001081bool
1082ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1083 SDValue &OffImm) {
1084 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001085}
1086
Bill Wendlingf4caf692010-12-14 03:36:38 +00001087bool
1088ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1089 SDValue &OffImm) {
1090 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001091}
1092
Chris Lattner52a261b2010-09-21 20:31:19 +00001093bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1094 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001095 if (N.getOpcode() == ISD::FrameIndex) {
1096 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1097 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001098 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001099 return true;
1100 }
Evan Cheng79d43262007-01-24 02:21:22 +00001101
Chris Lattner0a9481f2011-02-13 22:25:43 +00001102 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001103 return false;
1104
1105 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001106 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1107 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001108 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001109 int RHSC;
1110 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1111 Base = N.getOperand(0);
1112 if (Base.getOpcode() == ISD::FrameIndex) {
1113 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1114 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001115 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001116 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1117 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001118 }
1119 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001120
Evan Chenga8e29892007-01-19 07:51:42 +00001121 return false;
1122}
1123
Bill Wendlingf4caf692010-12-14 03:36:38 +00001124
1125//===----------------------------------------------------------------------===//
1126// Thumb 2 Addressing Modes
1127//===----------------------------------------------------------------------===//
1128
1129
Chris Lattner52a261b2010-09-21 20:31:19 +00001130bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001131 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001132 if (DisableShifterOp)
1133 return false;
1134
Evan Chengee04a6d2011-07-20 23:34:39 +00001135 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001136
1137 // Don't match base register only case. That is matched to a separate
1138 // lower complexity pattern with explicit register operand.
1139 if (ShOpcVal == ARM_AM::no_shift) return false;
1140
1141 BaseReg = N.getOperand(0);
1142 unsigned ShImmVal = 0;
1143 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1144 ShImmVal = RHS->getZExtValue() & 31;
1145 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1146 return true;
1147 }
1148
1149 return false;
1150}
1151
Chris Lattner52a261b2010-09-21 20:31:19 +00001152bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001153 SDValue &Base, SDValue &OffImm) {
1154 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001155
Evan Cheng3a214252009-08-11 08:52:18 +00001156 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001157 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1158 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001159 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001160 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001161 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1162 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001163 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001164 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001165 }
Owen Anderson099e5552011-03-18 19:46:58 +00001166
Chris Lattner0a9481f2011-02-13 22:25:43 +00001167 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001168 !(Subtarget->useMovt() &&
1169 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001170 Base = N.getOperand(0);
1171 if (Base.getOpcode() == ISD::TargetConstantPool)
1172 return false; // We want to select t2LDRpci instead.
1173 } else
1174 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001175 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001176 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001177 }
Evan Cheng055b0312009-06-29 07:51:04 +00001178
1179 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001180 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001181 // Let t2LDRi8 handle (R - imm8).
1182 return false;
1183
Evan Cheng055b0312009-06-29 07:51:04 +00001184 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001185 if (N.getOpcode() == ISD::SUB)
1186 RHSC = -RHSC;
1187
1188 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001189 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001190 if (Base.getOpcode() == ISD::FrameIndex) {
1191 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1192 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1193 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001194 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001195 return true;
1196 }
1197 }
1198
Evan Cheng3a214252009-08-11 08:52:18 +00001199 // Base only.
1200 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001201 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001202 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001203}
1204
Chris Lattner52a261b2010-09-21 20:31:19 +00001205bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001206 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001207 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001208 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1209 !CurDAG->isBaseWithConstantOffset(N))
1210 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001211
Chris Lattner0a9481f2011-02-13 22:25:43 +00001212 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1213 int RHSC = (int)RHS->getSExtValue();
1214 if (N.getOpcode() == ISD::SUB)
1215 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001216
Chris Lattner0a9481f2011-02-13 22:25:43 +00001217 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1218 Base = N.getOperand(0);
1219 if (Base.getOpcode() == ISD::FrameIndex) {
1220 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1221 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001222 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001223 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1224 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001225 }
1226 }
1227
1228 return false;
1229}
1230
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001231bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001232 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001233 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001234 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1235 ? cast<LoadSDNode>(Op)->getAddressingMode()
1236 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001237 int RHSC;
1238 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1239 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1240 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1241 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1242 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001243 }
1244
1245 return false;
1246}
1247
Chris Lattner52a261b2010-09-21 20:31:19 +00001248bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001249 SDValue &Base,
1250 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001251 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001252 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001253 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001254
Evan Cheng3a214252009-08-11 08:52:18 +00001255 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1256 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1257 int RHSC = (int)RHS->getZExtValue();
1258 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1259 return false;
1260 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001261 return false;
1262 }
1263
Evan Chengf40deed2010-10-27 23:41:30 +00001264 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1265 // Compute R + (R << [1,2,3]) and reuse it.
1266 Base = N;
1267 return false;
1268 }
1269
Evan Cheng055b0312009-06-29 07:51:04 +00001270 // Look for (R + R) or (R + (R << [1,2,3])).
1271 unsigned ShAmt = 0;
1272 Base = N.getOperand(0);
1273 OffReg = N.getOperand(1);
1274
1275 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001276 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001277 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001278 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001279 if (ShOpcVal == ARM_AM::lsl)
1280 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001281 }
1282
Evan Cheng055b0312009-06-29 07:51:04 +00001283 if (ShOpcVal == ARM_AM::lsl) {
1284 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1285 // it.
1286 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1287 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001288 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1289 OffReg = OffReg.getOperand(0);
1290 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001291 ShAmt = 0;
1292 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001293 }
Evan Cheng055b0312009-06-29 07:51:04 +00001294 } else {
1295 ShOpcVal = ARM_AM::no_shift;
1296 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001297 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001298
Owen Anderson825b72b2009-08-11 20:47:22 +00001299 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001300
1301 return true;
1302}
1303
1304//===--------------------------------------------------------------------===//
1305
Evan Chengee568cf2007-07-05 07:15:27 +00001306/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001307static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001308 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001309}
1310
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001311SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1312 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001313 ISD::MemIndexedMode AM = LD->getAddressingMode();
1314 if (AM == ISD::UNINDEXED)
1315 return NULL;
1316
Owen Andersone50ed302009-08-10 22:56:29 +00001317 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001318 SDValue Offset, AMOpc;
1319 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1320 unsigned Opcode = 0;
1321 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001322 if (LoadedVT == MVT::i32 &&
Owen Anderson793e7962011-07-26 20:54:26 +00001323 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001324 Opcode = isPre ? ARM::LDR_PRE_IMM : ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001325 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001326 } else if (LoadedVT == MVT::i32 &&
1327 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001328 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001329 Match = true;
1330
Owen Anderson825b72b2009-08-11 20:47:22 +00001331 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001332 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001333 Match = true;
1334 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1335 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1336 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001337 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001338 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001339 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001340 Match = true;
1341 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1342 }
1343 } else {
Owen Anderson793e7962011-07-26 20:54:26 +00001344 if (SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001345 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001346 Opcode = isPre ? ARM::LDRB_PRE_IMM : ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001347 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1348 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001349 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001350 }
1351 }
1352 }
1353
1354 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001355 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1356 SDValue Chain = LD->getChain();
1357 SDValue Base = LD->getBasePtr();
1358 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1359 CurDAG->getRegister(0, MVT::i32), Chain };
1360 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1361 MVT::Other, Ops, 5);
1362 } else {
1363 SDValue Chain = LD->getChain();
1364 SDValue Base = LD->getBasePtr();
1365 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1366 CurDAG->getRegister(0, MVT::i32), Chain };
1367 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1368 MVT::Other, Ops, 6);
1369 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001370 }
1371
1372 return NULL;
1373}
1374
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001375SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1376 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001377 ISD::MemIndexedMode AM = LD->getAddressingMode();
1378 if (AM == ISD::UNINDEXED)
1379 return NULL;
1380
Owen Andersone50ed302009-08-10 22:56:29 +00001381 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001382 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001383 SDValue Offset;
1384 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1385 unsigned Opcode = 0;
1386 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001387 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001388 switch (LoadedVT.getSimpleVT().SimpleTy) {
1389 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001390 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1391 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001392 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001393 if (isSExtLd)
1394 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1395 else
1396 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001397 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001398 case MVT::i8:
1399 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001400 if (isSExtLd)
1401 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1402 else
1403 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001404 break;
1405 default:
1406 return NULL;
1407 }
1408 Match = true;
1409 }
1410
1411 if (Match) {
1412 SDValue Chain = LD->getChain();
1413 SDValue Base = LD->getBasePtr();
1414 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001415 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001416 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001417 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001418 }
1419
1420 return NULL;
1421}
1422
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001423/// PairSRegs - Form a D register from a pair of S registers.
1424///
1425SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1426 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001427 SDValue RegClass =
1428 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001429 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1430 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001431 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1432 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001433}
1434
Evan Cheng603afbf2010-05-10 17:34:18 +00001435/// PairDRegs - Form a quad register from a pair of D registers.
1436///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001437SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1438 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001439 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001440 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1441 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001442 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1443 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001444}
1445
Evan Cheng7f687192010-05-14 00:21:45 +00001446/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001447///
1448SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1449 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001450 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001451 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1452 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001453 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1454 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001455}
1456
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001457/// QuadSRegs - Form 4 consecutive S registers.
1458///
1459SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1460 SDValue V2, SDValue V3) {
1461 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001462 SDValue RegClass =
1463 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001464 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1465 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1466 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1467 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001468 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1469 V2, SubReg2, V3, SubReg3 };
1470 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001471}
1472
Evan Cheng7f687192010-05-14 00:21:45 +00001473/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001474///
1475SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1476 SDValue V2, SDValue V3) {
1477 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001478 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001479 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1480 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1481 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1482 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001483 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1484 V2, SubReg2, V3, SubReg3 };
1485 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001486}
1487
Evan Cheng8f6de382010-05-16 03:27:48 +00001488/// QuadQRegs - Form 4 consecutive Q registers.
1489///
1490SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1491 SDValue V2, SDValue V3) {
1492 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001493 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001494 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1495 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1496 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1497 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001498 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1499 V2, SubReg2, V3, SubReg3 };
1500 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001501}
1502
Bob Wilson2a6e6162010-09-23 23:42:37 +00001503/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1504/// of a NEON VLD or VST instruction. The supported values depend on the
1505/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001506SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1507 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001508 unsigned NumRegs = NumVecs;
1509 if (!is64BitVector && NumVecs < 3)
1510 NumRegs *= 2;
1511
Bob Wilson665814b2010-11-01 23:40:51 +00001512 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001513 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001514 Alignment = 32;
1515 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1516 Alignment = 16;
1517 else if (Alignment >= 8)
1518 Alignment = 8;
1519 else
1520 Alignment = 0;
1521
1522 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001523}
1524
Bob Wilson1c3ef902011-02-07 17:43:21 +00001525SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001526 unsigned *DOpcodes, unsigned *QOpcodes0,
1527 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001528 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001529 DebugLoc dl = N->getDebugLoc();
1530
Bob Wilson226036e2010-03-20 22:13:40 +00001531 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001532 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1533 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001534 return NULL;
1535
1536 SDValue Chain = N->getOperand(0);
1537 EVT VT = N->getValueType(0);
1538 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001539 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001540
Bob Wilson3e36f132009-10-14 17:28:52 +00001541 unsigned OpcodeIndex;
1542 switch (VT.getSimpleVT().SimpleTy) {
1543 default: llvm_unreachable("unhandled vld type");
1544 // Double-register operations:
1545 case MVT::v8i8: OpcodeIndex = 0; break;
1546 case MVT::v4i16: OpcodeIndex = 1; break;
1547 case MVT::v2f32:
1548 case MVT::v2i32: OpcodeIndex = 2; break;
1549 case MVT::v1i64: OpcodeIndex = 3; break;
1550 // Quad-register operations:
1551 case MVT::v16i8: OpcodeIndex = 0; break;
1552 case MVT::v8i16: OpcodeIndex = 1; break;
1553 case MVT::v4f32:
1554 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001555 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001556 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001557 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001558 }
1559
Bob Wilsonf5721912010-09-03 18:16:02 +00001560 EVT ResTy;
1561 if (NumVecs == 1)
1562 ResTy = VT;
1563 else {
1564 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1565 if (!is64BitVector)
1566 ResTyElts *= 2;
1567 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1568 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001569 std::vector<EVT> ResTys;
1570 ResTys.push_back(ResTy);
1571 if (isUpdating)
1572 ResTys.push_back(MVT::i32);
1573 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001574
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001575 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001576 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001577 SDNode *VLd;
1578 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001579
Bob Wilson1c3ef902011-02-07 17:43:21 +00001580 // Double registers and VLD1/VLD2 quad registers are directly supported.
1581 if (is64BitVector || NumVecs <= 2) {
1582 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1583 QOpcodes0[OpcodeIndex]);
1584 Ops.push_back(MemAddr);
1585 Ops.push_back(Align);
1586 if (isUpdating) {
1587 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1588 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001589 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001590 Ops.push_back(Pred);
1591 Ops.push_back(Reg0);
1592 Ops.push_back(Chain);
1593 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001594
Bob Wilson3e36f132009-10-14 17:28:52 +00001595 } else {
1596 // Otherwise, quad registers are loaded with two separate instructions,
1597 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001598 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001599
Bob Wilson1c3ef902011-02-07 17:43:21 +00001600 // Load the even subregs. This is always an updating load, so that it
1601 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001602 SDValue ImplDef =
1603 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1604 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001605 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1606 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001607 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001608
Bob Wilson24f995d2009-10-14 18:32:29 +00001609 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001610 Ops.push_back(SDValue(VLdA, 1));
1611 Ops.push_back(Align);
1612 if (isUpdating) {
1613 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1614 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1615 "only constant post-increment update allowed for VLD3/4");
1616 (void)Inc;
1617 Ops.push_back(Reg0);
1618 }
1619 Ops.push_back(SDValue(VLdA, 0));
1620 Ops.push_back(Pred);
1621 Ops.push_back(Reg0);
1622 Ops.push_back(Chain);
1623 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1624 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001625 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001626
Evan Chengb58a3402011-04-19 00:04:03 +00001627 // Transfer memoperands.
1628 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1629 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1630 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1631
Bob Wilson1c3ef902011-02-07 17:43:21 +00001632 if (NumVecs == 1)
1633 return VLd;
1634
1635 // Extract out the subregisters.
1636 SDValue SuperReg = SDValue(VLd, 0);
1637 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1638 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1639 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1640 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1641 ReplaceUses(SDValue(N, Vec),
1642 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1643 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1644 if (isUpdating)
1645 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001646 return NULL;
1647}
1648
Bob Wilson1c3ef902011-02-07 17:43:21 +00001649SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001650 unsigned *DOpcodes, unsigned *QOpcodes0,
1651 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001652 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001653 DebugLoc dl = N->getDebugLoc();
1654
Bob Wilson226036e2010-03-20 22:13:40 +00001655 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001656 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1657 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1658 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001659 return NULL;
1660
Evan Chengb58a3402011-04-19 00:04:03 +00001661 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1662 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1663
Bob Wilson24f995d2009-10-14 18:32:29 +00001664 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001665 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001666 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001667 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001668
Bob Wilson24f995d2009-10-14 18:32:29 +00001669 unsigned OpcodeIndex;
1670 switch (VT.getSimpleVT().SimpleTy) {
1671 default: llvm_unreachable("unhandled vst type");
1672 // Double-register operations:
1673 case MVT::v8i8: OpcodeIndex = 0; break;
1674 case MVT::v4i16: OpcodeIndex = 1; break;
1675 case MVT::v2f32:
1676 case MVT::v2i32: OpcodeIndex = 2; break;
1677 case MVT::v1i64: OpcodeIndex = 3; break;
1678 // Quad-register operations:
1679 case MVT::v16i8: OpcodeIndex = 0; break;
1680 case MVT::v8i16: OpcodeIndex = 1; break;
1681 case MVT::v4f32:
1682 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001683 case MVT::v2i64: OpcodeIndex = 3;
1684 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1685 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001686 }
1687
Bob Wilson1c3ef902011-02-07 17:43:21 +00001688 std::vector<EVT> ResTys;
1689 if (isUpdating)
1690 ResTys.push_back(MVT::i32);
1691 ResTys.push_back(MVT::Other);
1692
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001693 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001694 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001695 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001696
Bob Wilson1c3ef902011-02-07 17:43:21 +00001697 // Double registers and VST1/VST2 quad registers are directly supported.
1698 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001699 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001700 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001701 SrcReg = N->getOperand(Vec0Idx);
1702 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001703 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001704 SDValue V0 = N->getOperand(Vec0Idx + 0);
1705 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001706 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001707 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001708 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001709 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001710 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001711 // an undef.
1712 SDValue V3 = (NumVecs == 3)
1713 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001714 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001715 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001716 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001717 } else {
1718 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001719 SDValue Q0 = N->getOperand(Vec0Idx);
1720 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001721 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001722 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001723
1724 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1725 QOpcodes0[OpcodeIndex]);
1726 Ops.push_back(MemAddr);
1727 Ops.push_back(Align);
1728 if (isUpdating) {
1729 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1730 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1731 }
1732 Ops.push_back(SrcReg);
1733 Ops.push_back(Pred);
1734 Ops.push_back(Reg0);
1735 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001736 SDNode *VSt =
1737 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1738
1739 // Transfer memoperands.
1740 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1741
1742 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001743 }
1744
1745 // Otherwise, quad registers are stored with two separate instructions,
1746 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001747
Bob Wilson07f6e802010-06-16 21:34:01 +00001748 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001749 SDValue V0 = N->getOperand(Vec0Idx + 0);
1750 SDValue V1 = N->getOperand(Vec0Idx + 1);
1751 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001752 SDValue V3 = (NumVecs == 3)
1753 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001754 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001755 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001756
Bob Wilson1c3ef902011-02-07 17:43:21 +00001757 // Store the even D registers. This is always an updating store, so that it
1758 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001759 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1760 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1761 MemAddr.getValueType(),
1762 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001763 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001764 Chain = SDValue(VStA, 1);
1765
1766 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001767 Ops.push_back(SDValue(VStA, 0));
1768 Ops.push_back(Align);
1769 if (isUpdating) {
1770 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1771 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1772 "only constant post-increment update allowed for VST3/4");
1773 (void)Inc;
1774 Ops.push_back(Reg0);
1775 }
1776 Ops.push_back(RegSeq);
1777 Ops.push_back(Pred);
1778 Ops.push_back(Reg0);
1779 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001780 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1781 Ops.data(), Ops.size());
1782 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1783 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001784}
1785
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001786SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001787 bool isUpdating, unsigned NumVecs,
1788 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001789 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001790 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001791 DebugLoc dl = N->getDebugLoc();
1792
Bob Wilson226036e2010-03-20 22:13:40 +00001793 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001794 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1795 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1796 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001797 return NULL;
1798
Evan Chengb58a3402011-04-19 00:04:03 +00001799 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1800 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1801
Bob Wilsona7c397c2009-10-14 16:19:03 +00001802 SDValue Chain = N->getOperand(0);
1803 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001804 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1805 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001806 bool is64BitVector = VT.is64BitVector();
1807
Bob Wilson665814b2010-11-01 23:40:51 +00001808 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001809 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001810 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001811 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1812 if (Alignment > NumBytes)
1813 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001814 if (Alignment < 8 && Alignment < NumBytes)
1815 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001816 // Alignment must be a power of two; make sure of that.
1817 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001818 if (Alignment == 1)
1819 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001820 }
Bob Wilson665814b2010-11-01 23:40:51 +00001821 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001822
Bob Wilsona7c397c2009-10-14 16:19:03 +00001823 unsigned OpcodeIndex;
1824 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001825 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001826 // Double-register operations:
1827 case MVT::v8i8: OpcodeIndex = 0; break;
1828 case MVT::v4i16: OpcodeIndex = 1; break;
1829 case MVT::v2f32:
1830 case MVT::v2i32: OpcodeIndex = 2; break;
1831 // Quad-register operations:
1832 case MVT::v8i16: OpcodeIndex = 0; break;
1833 case MVT::v4f32:
1834 case MVT::v4i32: OpcodeIndex = 1; break;
1835 }
1836
Bob Wilson1c3ef902011-02-07 17:43:21 +00001837 std::vector<EVT> ResTys;
1838 if (IsLoad) {
1839 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1840 if (!is64BitVector)
1841 ResTyElts *= 2;
1842 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1843 MVT::i64, ResTyElts));
1844 }
1845 if (isUpdating)
1846 ResTys.push_back(MVT::i32);
1847 ResTys.push_back(MVT::Other);
1848
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001849 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001850 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001851
Bob Wilson1c3ef902011-02-07 17:43:21 +00001852 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001853 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001854 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001855 if (isUpdating) {
1856 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1857 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1858 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001859
Bob Wilson8466fa12010-09-13 23:01:35 +00001860 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001861 SDValue V0 = N->getOperand(Vec0Idx + 0);
1862 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001863 if (NumVecs == 2) {
1864 if (is64BitVector)
1865 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1866 else
1867 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001868 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001869 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001870 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001871 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1872 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001873 if (is64BitVector)
1874 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1875 else
1876 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001877 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001878 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001879 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001880 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001881 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001882 Ops.push_back(Chain);
1883
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1885 QOpcodes[OpcodeIndex]);
1886 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1887 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001888 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001889 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001890 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001891
Bob Wilson8466fa12010-09-13 23:01:35 +00001892 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001893 SuperReg = SDValue(VLdLn, 0);
1894 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1895 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1896 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001897 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1898 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001899 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1900 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1901 if (isUpdating)
1902 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001903 return NULL;
1904}
1905
Bob Wilson1c3ef902011-02-07 17:43:21 +00001906SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1907 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001908 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1909 DebugLoc dl = N->getDebugLoc();
1910
1911 SDValue MemAddr, Align;
1912 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1913 return NULL;
1914
Evan Chengb58a3402011-04-19 00:04:03 +00001915 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1916 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1917
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001918 SDValue Chain = N->getOperand(0);
1919 EVT VT = N->getValueType(0);
1920
1921 unsigned Alignment = 0;
1922 if (NumVecs != 3) {
1923 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1924 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1925 if (Alignment > NumBytes)
1926 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001927 if (Alignment < 8 && Alignment < NumBytes)
1928 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001929 // Alignment must be a power of two; make sure of that.
1930 Alignment = (Alignment & -Alignment);
1931 if (Alignment == 1)
1932 Alignment = 0;
1933 }
1934 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1935
1936 unsigned OpcodeIndex;
1937 switch (VT.getSimpleVT().SimpleTy) {
1938 default: llvm_unreachable("unhandled vld-dup type");
1939 case MVT::v8i8: OpcodeIndex = 0; break;
1940 case MVT::v4i16: OpcodeIndex = 1; break;
1941 case MVT::v2f32:
1942 case MVT::v2i32: OpcodeIndex = 2; break;
1943 }
1944
1945 SDValue Pred = getAL(CurDAG);
1946 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1947 SDValue SuperReg;
1948 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001949 SmallVector<SDValue, 6> Ops;
1950 Ops.push_back(MemAddr);
1951 Ops.push_back(Align);
1952 if (isUpdating) {
1953 SDValue Inc = N->getOperand(2);
1954 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1955 }
1956 Ops.push_back(Pred);
1957 Ops.push_back(Reg0);
1958 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001959
1960 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001961 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001962 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001963 if (isUpdating)
1964 ResTys.push_back(MVT::i32);
1965 ResTys.push_back(MVT::Other);
1966 SDNode *VLdDup =
1967 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001968 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001969 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001970
1971 // Extract the subregisters.
1972 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1973 unsigned SubIdx = ARM::dsub_0;
1974 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1975 ReplaceUses(SDValue(N, Vec),
1976 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001977 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1978 if (isUpdating)
1979 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001980 return NULL;
1981}
1982
Bob Wilson78dfbc32010-07-07 00:08:54 +00001983SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1984 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001985 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1986 DebugLoc dl = N->getDebugLoc();
1987 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001988 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001989
1990 // Form a REG_SEQUENCE to force register allocation.
1991 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001992 SDValue V0 = N->getOperand(FirstTblReg + 0);
1993 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001994 if (NumVecs == 2)
1995 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1996 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001997 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001998 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001999 // an undef.
2000 SDValue V3 = (NumVecs == 3)
2001 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002002 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002003 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2004 }
2005
Bob Wilson78dfbc32010-07-07 00:08:54 +00002006 SmallVector<SDValue, 6> Ops;
2007 if (IsExt)
2008 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002009 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002010 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002011 Ops.push_back(getAL(CurDAG)); // predicate
2012 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002013 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002014}
2015
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002016SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002017 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002018 if (!Subtarget->hasV6T2Ops())
2019 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002020
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002021 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2022 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2023
2024
2025 // For unsigned extracts, check for a shift right and mask
2026 unsigned And_imm = 0;
2027 if (N->getOpcode() == ISD::AND) {
2028 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2029
2030 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2031 if (And_imm & (And_imm + 1))
2032 return NULL;
2033
2034 unsigned Srl_imm = 0;
2035 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2036 Srl_imm)) {
2037 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2038
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002039 // Note: The width operand is encoded as width-1.
2040 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002041 unsigned LSB = Srl_imm;
2042 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2043 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2044 CurDAG->getTargetConstant(LSB, MVT::i32),
2045 CurDAG->getTargetConstant(Width, MVT::i32),
2046 getAL(CurDAG), Reg0 };
2047 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2048 }
2049 }
2050 return NULL;
2051 }
2052
2053 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002054 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002055 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002056 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2057 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002058 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002059 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002060 // Note: The width operand is encoded as width-1.
2061 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002062 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002063 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002064 return NULL;
2065 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002066 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002067 CurDAG->getTargetConstant(LSB, MVT::i32),
2068 CurDAG->getTargetConstant(Width, MVT::i32),
2069 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002070 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002071 }
2072 }
2073 return NULL;
2074}
2075
Evan Cheng9ef48352009-11-20 00:54:03 +00002076SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002077SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2079 SDValue CPTmp0;
2080 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002081 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002082 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2083 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2084 unsigned Opc = 0;
2085 switch (SOShOp) {
2086 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2087 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2088 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2089 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2090 default:
2091 llvm_unreachable("Unknown so_reg opcode!");
2092 break;
2093 }
2094 SDValue SOShImm =
2095 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2096 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2097 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002098 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002099 }
2100 return 0;
2101}
2102
2103SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002104SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002105 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2106 SDValue CPTmp0;
2107 SDValue CPTmp1;
2108 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002109 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002110 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002111 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2112 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002113 }
2114
2115 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2116 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2117 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2118 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002119 }
2120 return 0;
2121}
2122
2123SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002124SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002125 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002126 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002127 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002128 return 0;
2129
Evan Cheng63f35442010-11-13 02:25:14 +00002130 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002131 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002132 if (is_t2_so_imm(TrueImm)) {
2133 Opc = ARM::t2MOVCCi;
2134 } else if (TrueImm <= 0xffff) {
2135 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002136 } else if (is_t2_so_imm_not(TrueImm)) {
2137 TrueImm = ~TrueImm;
2138 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002139 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002140 // Large immediate.
2141 Opc = ARM::t2MOVCCi32imm;
2142 }
2143
2144 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002145 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002146 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2147 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002148 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002149 }
Evan Cheng63f35442010-11-13 02:25:14 +00002150
Evan Cheng9ef48352009-11-20 00:54:03 +00002151 return 0;
2152}
2153
2154SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002155SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002156 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002157 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2158 if (!T)
2159 return 0;
2160
Evan Cheng63f35442010-11-13 02:25:14 +00002161 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002162 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002163 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002164 if (isSoImm) {
2165 Opc = ARM::MOVCCi;
2166 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2167 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002168 } else if (is_so_imm_not(TrueImm)) {
2169 TrueImm = ~TrueImm;
2170 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002171 } else if (TrueVal.getNode()->hasOneUse() &&
2172 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002173 // Large immediate.
2174 Opc = ARM::MOVCCi32imm;
2175 }
2176
2177 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002178 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002179 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2180 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002181 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002182 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002183
Evan Cheng9ef48352009-11-20 00:54:03 +00002184 return 0;
2185}
2186
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002187SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2188 EVT VT = N->getValueType(0);
2189 SDValue FalseVal = N->getOperand(0);
2190 SDValue TrueVal = N->getOperand(1);
2191 SDValue CC = N->getOperand(2);
2192 SDValue CCR = N->getOperand(3);
2193 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002194 assert(CC.getOpcode() == ISD::Constant);
2195 assert(CCR.getOpcode() == ISD::Register);
2196 ARMCC::CondCodes CCVal =
2197 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002198
2199 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2200 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2201 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2202 // Pattern complexity = 18 cost = 1 size = 0
2203 SDValue CPTmp0;
2204 SDValue CPTmp1;
2205 SDValue CPTmp2;
2206 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002207 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 CCVal, CCR, InFlag);
2209 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002210 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002211 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2212 if (Res)
2213 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002214 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002215 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002216 CCVal, CCR, InFlag);
2217 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002218 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002219 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2220 if (Res)
2221 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002222 }
2223
2224 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002225 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002226 // (imm:i32):$cc)
2227 // Emits: (MOVCCi:i32 GPR:i32:$false,
2228 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2229 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002230 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002231 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002232 CCVal, CCR, InFlag);
2233 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002234 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002235 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2236 if (Res)
2237 return Res;
2238 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002239 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002240 CCVal, CCR, InFlag);
2241 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002242 Res = SelectARMCMOVImmOp(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
2249 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2250 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2251 // Pattern complexity = 6 cost = 1 size = 0
2252 //
2253 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2254 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2255 // Pattern complexity = 6 cost = 11 size = 0
2256 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002257 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002258 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2259 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002260 unsigned Opc = 0;
2261 switch (VT.getSimpleVT().SimpleTy) {
2262 default: assert(false && "Illegal conditional move type!");
2263 break;
2264 case MVT::i32:
2265 Opc = Subtarget->isThumb()
2266 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2267 : ARM::MOVCCr;
2268 break;
2269 case MVT::f32:
2270 Opc = ARM::VMOVScc;
2271 break;
2272 case MVT::f64:
2273 Opc = ARM::VMOVDcc;
2274 break;
2275 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002276 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002277}
2278
Evan Chengde8aa4e2010-05-05 18:28:36 +00002279SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2280 // The only time a CONCAT_VECTORS operation can have legal types is when
2281 // two 64-bit vectors are concatenated to a 128-bit vector.
2282 EVT VT = N->getValueType(0);
2283 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2284 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002285 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002286}
2287
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002288SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002289 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002290
Dan Gohmane8be6c62008-07-17 19:10:17 +00002291 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002292 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002293
2294 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002295 default: break;
2296 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002297 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002298 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002299 if (Subtarget->hasThumb2())
2300 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2301 // be done with MOV + MOVT, at worst.
2302 UseCP = 0;
2303 else {
2304 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002305 UseCP = (Val > 255 && // MOV
2306 ~Val > 255 && // MOV + MVN
2307 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002308 } else
2309 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2310 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2311 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2312 }
2313
Evan Chenga8e29892007-01-19 07:51:42 +00002314 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002315 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002316 CurDAG->getTargetConstantPool(ConstantInt::get(
2317 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002318 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002319
2320 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002321 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002322 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002323 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002324 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002325 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002326 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002327 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002328 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002329 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002330 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002331 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002332 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002333 CurDAG->getEntryNode()
2334 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002335 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002336 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002337 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002338 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002339 return NULL;
2340 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002341
Evan Chenga8e29892007-01-19 07:51:42 +00002342 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002343 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002344 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002345 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002346 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002347 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002348 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002349 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002350 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2351 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2352 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002353 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002354 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2355 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002356 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2357 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2358 CurDAG->getRegister(0, MVT::i32) };
2359 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002360 }
Evan Chenga8e29892007-01-19 07:51:42 +00002361 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002362 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002363 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002364 return I;
2365 break;
2366 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002367 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002368 return I;
2369 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002370 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002371 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002372 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002373 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002374 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002375 if (!RHSV) break;
2376 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002377 unsigned ShImm = Log2_32(RHSV-1);
2378 if (ShImm >= 32)
2379 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002380 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002381 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002382 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2383 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002384 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002385 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002386 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002387 } else {
2388 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002389 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002390 }
Evan Chenga8e29892007-01-19 07:51:42 +00002391 }
2392 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002393 unsigned ShImm = Log2_32(RHSV+1);
2394 if (ShImm >= 32)
2395 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002396 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002397 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002398 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2399 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002400 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002401 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2402 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002403 } else {
2404 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002405 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002406 }
Evan Chenga8e29892007-01-19 07:51:42 +00002407 }
2408 }
2409 break;
Evan Cheng20956592009-10-21 08:15:52 +00002410 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002411 // Check for unsigned bitfield extract
2412 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2413 return I;
2414
Evan Cheng20956592009-10-21 08:15:52 +00002415 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2416 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2417 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2418 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2419 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002420 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002421 if (VT != MVT::i32)
2422 break;
2423 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2424 ? ARM::t2MOVTi16
2425 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2426 if (!Opc)
2427 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002428 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002429 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2430 if (!N1C)
2431 break;
2432 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2433 SDValue N2 = N0.getOperand(1);
2434 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2435 if (!N2C)
2436 break;
2437 unsigned N1CVal = N1C->getZExtValue();
2438 unsigned N2CVal = N2C->getZExtValue();
2439 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2440 (N1CVal & 0xffffU) == 0xffffU &&
2441 (N2CVal & 0xffffU) == 0x0U) {
2442 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2443 MVT::i32);
2444 SDValue Ops[] = { N0.getOperand(0), Imm16,
2445 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2446 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2447 }
2448 }
2449 break;
2450 }
Jim Grosbache5165492009-11-09 00:11:35 +00002451 case ARMISD::VMOVRRD:
2452 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002453 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002454 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002455 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002456 if (Subtarget->isThumb1Only())
2457 break;
2458 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002459 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002460 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2461 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002462 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002463 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002464 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002465 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2466 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002467 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2468 ARM::UMULL : ARM::UMULLv5,
2469 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002470 }
Evan Chengee568cf2007-07-05 07:15:27 +00002471 }
Dan Gohman525178c2007-10-08 18:33:35 +00002472 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002473 if (Subtarget->isThumb1Only())
2474 break;
2475 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002476 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002477 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002478 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002479 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002480 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002481 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2482 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002483 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2484 ARM::SMULL : ARM::SMULLv5,
2485 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002486 }
Evan Chengee568cf2007-07-05 07:15:27 +00002487 }
Evan Chenga8e29892007-01-19 07:51:42 +00002488 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002489 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002490 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002491 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002492 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002493 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002494 if (ResNode)
2495 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002496 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002497 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002498 }
Evan Chengee568cf2007-07-05 07:15:27 +00002499 case ARMISD::BRCOND: {
2500 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2501 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2502 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002503
Evan Chengee568cf2007-07-05 07:15:27 +00002504 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2505 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2506 // Pattern complexity = 6 cost = 1 size = 0
2507
David Goodwin5e47a9a2009-06-30 18:04:13 +00002508 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2509 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2510 // Pattern complexity = 6 cost = 1 size = 0
2511
Jim Grosbach764ab522009-08-11 15:33:49 +00002512 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002513 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002514 SDValue Chain = N->getOperand(0);
2515 SDValue N1 = N->getOperand(1);
2516 SDValue N2 = N->getOperand(2);
2517 SDValue N3 = N->getOperand(3);
2518 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002519 assert(N1.getOpcode() == ISD::BasicBlock);
2520 assert(N2.getOpcode() == ISD::Constant);
2521 assert(N3.getOpcode() == ISD::Register);
2522
Dan Gohman475871a2008-07-27 21:46:04 +00002523 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002524 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002525 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002526 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002527 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002528 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002529 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002530 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002531 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002532 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002533 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002534 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002535 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002536 return NULL;
2537 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002538 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002539 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002540 case ARMISD::VZIP: {
2541 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002542 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002543 switch (VT.getSimpleVT().SimpleTy) {
2544 default: return NULL;
2545 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2546 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2547 case MVT::v2f32:
2548 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2549 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2550 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2551 case MVT::v4f32:
2552 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2553 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002554 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002555 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2556 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2557 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002558 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002559 case ARMISD::VUZP: {
2560 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002561 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002562 switch (VT.getSimpleVT().SimpleTy) {
2563 default: return NULL;
2564 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2565 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2566 case MVT::v2f32:
2567 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2568 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2569 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2570 case MVT::v4f32:
2571 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2572 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002573 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002574 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2575 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2576 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002577 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002578 case ARMISD::VTRN: {
2579 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002580 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002581 switch (VT.getSimpleVT().SimpleTy) {
2582 default: return NULL;
2583 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2584 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2585 case MVT::v2f32:
2586 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2587 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2588 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2589 case MVT::v4f32:
2590 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2591 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002592 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002593 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2594 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2595 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002596 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002597 case ARMISD::BUILD_VECTOR: {
2598 EVT VecVT = N->getValueType(0);
2599 EVT EltVT = VecVT.getVectorElementType();
2600 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002601 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002602 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2603 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2604 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002605 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002606 if (NumElts == 2)
2607 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2608 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2609 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2610 N->getOperand(2), N->getOperand(3));
2611 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002612
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002613 case ARMISD::VLD2DUP: {
2614 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2615 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002616 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002617 }
2618
Bob Wilson86c6d802010-11-29 19:35:29 +00002619 case ARMISD::VLD3DUP: {
2620 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2621 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002622 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002623 }
2624
Bob Wilson6c4c9822010-11-30 00:00:35 +00002625 case ARMISD::VLD4DUP: {
2626 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2627 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002628 return SelectVLDDup(N, false, 4, Opcodes);
2629 }
2630
2631 case ARMISD::VLD2DUP_UPD: {
2632 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2633 ARM::VLD2DUPd32Pseudo_UPD };
2634 return SelectVLDDup(N, true, 2, Opcodes);
2635 }
2636
2637 case ARMISD::VLD3DUP_UPD: {
2638 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2639 ARM::VLD3DUPd32Pseudo_UPD };
2640 return SelectVLDDup(N, true, 3, Opcodes);
2641 }
2642
2643 case ARMISD::VLD4DUP_UPD: {
2644 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2645 ARM::VLD4DUPd32Pseudo_UPD };
2646 return SelectVLDDup(N, true, 4, Opcodes);
2647 }
2648
2649 case ARMISD::VLD1_UPD: {
2650 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2651 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2652 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2653 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2654 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2655 }
2656
2657 case ARMISD::VLD2_UPD: {
2658 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2659 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2660 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2661 ARM::VLD2q32Pseudo_UPD };
2662 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2663 }
2664
2665 case ARMISD::VLD3_UPD: {
2666 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2667 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2668 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2669 ARM::VLD3q16Pseudo_UPD,
2670 ARM::VLD3q32Pseudo_UPD };
2671 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2672 ARM::VLD3q16oddPseudo_UPD,
2673 ARM::VLD3q32oddPseudo_UPD };
2674 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2675 }
2676
2677 case ARMISD::VLD4_UPD: {
2678 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2679 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2680 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2681 ARM::VLD4q16Pseudo_UPD,
2682 ARM::VLD4q32Pseudo_UPD };
2683 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2684 ARM::VLD4q16oddPseudo_UPD,
2685 ARM::VLD4q32oddPseudo_UPD };
2686 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2687 }
2688
2689 case ARMISD::VLD2LN_UPD: {
2690 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2691 ARM::VLD2LNd32Pseudo_UPD };
2692 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2693 ARM::VLD2LNq32Pseudo_UPD };
2694 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2695 }
2696
2697 case ARMISD::VLD3LN_UPD: {
2698 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2699 ARM::VLD3LNd32Pseudo_UPD };
2700 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2701 ARM::VLD3LNq32Pseudo_UPD };
2702 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2703 }
2704
2705 case ARMISD::VLD4LN_UPD: {
2706 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2707 ARM::VLD4LNd32Pseudo_UPD };
2708 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2709 ARM::VLD4LNq32Pseudo_UPD };
2710 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2711 }
2712
2713 case ARMISD::VST1_UPD: {
2714 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2715 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2716 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2717 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2718 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2719 }
2720
2721 case ARMISD::VST2_UPD: {
2722 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2723 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2724 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2725 ARM::VST2q32Pseudo_UPD };
2726 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2727 }
2728
2729 case ARMISD::VST3_UPD: {
2730 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2731 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2732 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2733 ARM::VST3q16Pseudo_UPD,
2734 ARM::VST3q32Pseudo_UPD };
2735 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2736 ARM::VST3q16oddPseudo_UPD,
2737 ARM::VST3q32oddPseudo_UPD };
2738 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2739 }
2740
2741 case ARMISD::VST4_UPD: {
2742 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2743 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2744 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2745 ARM::VST4q16Pseudo_UPD,
2746 ARM::VST4q32Pseudo_UPD };
2747 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2748 ARM::VST4q16oddPseudo_UPD,
2749 ARM::VST4q32oddPseudo_UPD };
2750 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2751 }
2752
2753 case ARMISD::VST2LN_UPD: {
2754 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2755 ARM::VST2LNd32Pseudo_UPD };
2756 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2757 ARM::VST2LNq32Pseudo_UPD };
2758 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2759 }
2760
2761 case ARMISD::VST3LN_UPD: {
2762 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2763 ARM::VST3LNd32Pseudo_UPD };
2764 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2765 ARM::VST3LNq32Pseudo_UPD };
2766 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2767 }
2768
2769 case ARMISD::VST4LN_UPD: {
2770 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2771 ARM::VST4LNd32Pseudo_UPD };
2772 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2773 ARM::VST4LNq32Pseudo_UPD };
2774 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002775 }
2776
Bob Wilson31fb12f2009-08-26 17:39:53 +00002777 case ISD::INTRINSIC_VOID:
2778 case ISD::INTRINSIC_W_CHAIN: {
2779 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002780 switch (IntNo) {
2781 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002782 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002783
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002784 case Intrinsic::arm_ldrexd: {
2785 SDValue MemAddr = N->getOperand(2);
2786 DebugLoc dl = N->getDebugLoc();
2787 SDValue Chain = N->getOperand(0);
2788
2789 unsigned NewOpc = ARM::LDREXD;
2790 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2791 NewOpc = ARM::t2LDREXD;
2792
2793 // arm_ldrexd returns a i64 value in {i32, i32}
2794 std::vector<EVT> ResTys;
2795 ResTys.push_back(MVT::i32);
2796 ResTys.push_back(MVT::i32);
2797 ResTys.push_back(MVT::Other);
2798
2799 // place arguments in the right order
2800 SmallVector<SDValue, 7> Ops;
2801 Ops.push_back(MemAddr);
2802 Ops.push_back(getAL(CurDAG));
2803 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2804 Ops.push_back(Chain);
2805 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2806 Ops.size());
2807 // Transfer memoperands.
2808 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2809 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2810 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2811
2812 // Until there's support for specifing explicit register constraints
2813 // like the use of even/odd register pair, hardcode ldrexd to always
2814 // use the pair [R0, R1] to hold the load result.
2815 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2816 SDValue(Ld, 0), SDValue(0,0));
2817 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2818 SDValue(Ld, 1), Chain.getValue(1));
2819
2820 // Remap uses.
2821 SDValue Glue = Chain.getValue(1);
2822 if (!SDValue(N, 0).use_empty()) {
2823 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2824 ARM::R0, MVT::i32, Glue);
2825 Glue = Result.getValue(2);
2826 ReplaceUses(SDValue(N, 0), Result);
2827 }
2828 if (!SDValue(N, 1).use_empty()) {
2829 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2830 ARM::R1, MVT::i32, Glue);
2831 Glue = Result.getValue(2);
2832 ReplaceUses(SDValue(N, 1), Result);
2833 }
2834
2835 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2836 return NULL;
2837 }
2838
2839 case Intrinsic::arm_strexd: {
2840 DebugLoc dl = N->getDebugLoc();
2841 SDValue Chain = N->getOperand(0);
2842 SDValue Val0 = N->getOperand(2);
2843 SDValue Val1 = N->getOperand(3);
2844 SDValue MemAddr = N->getOperand(4);
2845
2846 // Until there's support for specifing explicit register constraints
2847 // like the use of even/odd register pair, hardcode strexd to always
2848 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2849 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2850 SDValue(0, 0));
2851 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2852
2853 SDValue Glue = Chain.getValue(1);
2854 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2855 ARM::R2, MVT::i32, Glue);
2856 Glue = Val0.getValue(1);
2857 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2858 ARM::R3, MVT::i32, Glue);
2859
2860 // Store exclusive double return a i32 value which is the return status
2861 // of the issued store.
2862 std::vector<EVT> ResTys;
2863 ResTys.push_back(MVT::i32);
2864 ResTys.push_back(MVT::Other);
2865
2866 // place arguments in the right order
2867 SmallVector<SDValue, 7> Ops;
2868 Ops.push_back(Val0);
2869 Ops.push_back(Val1);
2870 Ops.push_back(MemAddr);
2871 Ops.push_back(getAL(CurDAG));
2872 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2873 Ops.push_back(Chain);
2874
2875 unsigned NewOpc = ARM::STREXD;
2876 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2877 NewOpc = ARM::t2STREXD;
2878
2879 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2880 Ops.size());
2881 // Transfer memoperands.
2882 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2883 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2884 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2885
2886 return St;
2887 }
2888
Bob Wilson621f1952010-03-23 05:25:43 +00002889 case Intrinsic::arm_neon_vld1: {
2890 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2891 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002892 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2893 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002894 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002895 }
2896
Bob Wilson31fb12f2009-08-26 17:39:53 +00002897 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002898 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2899 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2900 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2901 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002902 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002903 }
2904
2905 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002906 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2907 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2908 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2909 ARM::VLD3q16Pseudo_UPD,
2910 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002911 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2912 ARM::VLD3q16oddPseudo,
2913 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002914 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002915 }
2916
2917 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002918 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2919 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2920 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2921 ARM::VLD4q16Pseudo_UPD,
2922 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002923 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2924 ARM::VLD4q16oddPseudo,
2925 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002926 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002927 }
2928
Bob Wilson243fcc52009-09-01 04:26:28 +00002929 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002930 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2931 ARM::VLD2LNd32Pseudo };
2932 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002933 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002934 }
2935
2936 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002937 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2938 ARM::VLD3LNd32Pseudo };
2939 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002940 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002941 }
2942
2943 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002944 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2945 ARM::VLD4LNd32Pseudo };
2946 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002947 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002948 }
2949
Bob Wilson11d98992010-03-23 06:20:33 +00002950 case Intrinsic::arm_neon_vst1: {
2951 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2952 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002953 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2954 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002955 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002956 }
2957
Bob Wilson31fb12f2009-08-26 17:39:53 +00002958 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002959 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2960 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2961 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2962 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002963 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002964 }
2965
2966 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002967 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2968 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2969 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2970 ARM::VST3q16Pseudo_UPD,
2971 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002972 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2973 ARM::VST3q16oddPseudo,
2974 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002975 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002976 }
2977
2978 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002979 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002980 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002981 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2982 ARM::VST4q16Pseudo_UPD,
2983 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002984 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2985 ARM::VST4q16oddPseudo,
2986 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002987 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002988 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002989
2990 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002991 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2992 ARM::VST2LNd32Pseudo };
2993 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002994 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002995 }
2996
2997 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002998 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2999 ARM::VST3LNd32Pseudo };
3000 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003001 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003002 }
3003
3004 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003005 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3006 ARM::VST4LNd32Pseudo };
3007 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003008 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003009 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003010 }
Bob Wilson429009b2010-05-06 16:05:26 +00003011 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003012 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003013
Bob Wilsond491d6e2010-07-06 23:36:25 +00003014 case ISD::INTRINSIC_WO_CHAIN: {
3015 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3016 switch (IntNo) {
3017 default:
3018 break;
3019
3020 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003021 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003022 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003023 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003024 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003025 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003026
3027 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003028 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003029 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003030 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003031 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003032 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003033 }
3034 break;
3035 }
3036
Bill Wendling69a05a72011-03-14 23:02:38 +00003037 case ARMISD::VTBL1: {
3038 DebugLoc dl = N->getDebugLoc();
3039 EVT VT = N->getValueType(0);
3040 SmallVector<SDValue, 6> Ops;
3041
3042 Ops.push_back(N->getOperand(0));
3043 Ops.push_back(N->getOperand(1));
3044 Ops.push_back(getAL(CurDAG)); // Predicate
3045 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3046 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3047 }
3048 case ARMISD::VTBL2: {
3049 DebugLoc dl = N->getDebugLoc();
3050 EVT VT = N->getValueType(0);
3051
3052 // Form a REG_SEQUENCE to force register allocation.
3053 SDValue V0 = N->getOperand(0);
3054 SDValue V1 = N->getOperand(1);
3055 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3056
3057 SmallVector<SDValue, 6> Ops;
3058 Ops.push_back(RegSeq);
3059 Ops.push_back(N->getOperand(2));
3060 Ops.push_back(getAL(CurDAG)); // Predicate
3061 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3062 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3063 Ops.data(), Ops.size());
3064 }
3065
Bob Wilson429009b2010-05-06 16:05:26 +00003066 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003067 return SelectConcatVector(N);
3068 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003069
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003070 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003071}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003072
Bob Wilson224c2442009-05-19 05:53:42 +00003073bool ARMDAGToDAGISel::
3074SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3075 std::vector<SDValue> &OutOps) {
3076 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003077 // Require the address to be in a register. That is safe for all ARM
3078 // variants and it is hard to do anything much smarter without knowing
3079 // how the operand is used.
3080 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003081 return false;
3082}
3083
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003084/// createARMISelDag - This pass converts a legalized DAG into a
3085/// ARM-specific DAG, ready for instruction scheduling.
3086///
Bob Wilson522ce972009-09-28 14:30:20 +00003087FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3088 CodeGenOpt::Level OptLevel) {
3089 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003090}