blob: 7e4450fced20d9c1f46ca2fc4175f44282086d20 [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)) {
1324 Opcode = isPre ? ARM::LDR_PRE : 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)) {
1328 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST_REG;
1329 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 Anderson793e7962011-07-26 20:54:26 +00001346 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST_IMM;
1347 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1348 Match = true;
1349 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001350 }
1351 }
1352 }
1353
1354 if (Match) {
1355 SDValue Chain = LD->getChain();
1356 SDValue Base = LD->getBasePtr();
1357 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001358 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001359 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001360 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001361 }
1362
1363 return NULL;
1364}
1365
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001366SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1367 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001368 ISD::MemIndexedMode AM = LD->getAddressingMode();
1369 if (AM == ISD::UNINDEXED)
1370 return NULL;
1371
Owen Andersone50ed302009-08-10 22:56:29 +00001372 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001373 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001374 SDValue Offset;
1375 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1376 unsigned Opcode = 0;
1377 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001378 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001379 switch (LoadedVT.getSimpleVT().SimpleTy) {
1380 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001381 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1382 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001383 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001384 if (isSExtLd)
1385 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1386 else
1387 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001388 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001389 case MVT::i8:
1390 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001391 if (isSExtLd)
1392 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1393 else
1394 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001395 break;
1396 default:
1397 return NULL;
1398 }
1399 Match = true;
1400 }
1401
1402 if (Match) {
1403 SDValue Chain = LD->getChain();
1404 SDValue Base = LD->getBasePtr();
1405 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001406 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001407 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001408 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001409 }
1410
1411 return NULL;
1412}
1413
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001414/// PairSRegs - Form a D register from a pair of S registers.
1415///
1416SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1417 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001418 SDValue RegClass =
1419 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001420 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1421 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001422 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1423 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001424}
1425
Evan Cheng603afbf2010-05-10 17:34:18 +00001426/// PairDRegs - Form a quad register from a pair of D registers.
1427///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001428SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1429 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001430 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001431 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1432 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001433 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1434 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001435}
1436
Evan Cheng7f687192010-05-14 00:21:45 +00001437/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001438///
1439SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1440 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001441 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001442 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1443 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001444 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1445 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001446}
1447
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001448/// QuadSRegs - Form 4 consecutive S registers.
1449///
1450SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1451 SDValue V2, SDValue V3) {
1452 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001453 SDValue RegClass =
1454 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001455 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1456 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1457 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1458 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001459 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1460 V2, SubReg2, V3, SubReg3 };
1461 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001462}
1463
Evan Cheng7f687192010-05-14 00:21:45 +00001464/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001465///
1466SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1467 SDValue V2, SDValue V3) {
1468 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001469 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001470 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1471 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1472 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1473 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001474 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1475 V2, SubReg2, V3, SubReg3 };
1476 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001477}
1478
Evan Cheng8f6de382010-05-16 03:27:48 +00001479/// QuadQRegs - Form 4 consecutive Q registers.
1480///
1481SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1482 SDValue V2, SDValue V3) {
1483 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001484 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001485 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1486 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1487 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1488 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001489 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1490 V2, SubReg2, V3, SubReg3 };
1491 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001492}
1493
Bob Wilson2a6e6162010-09-23 23:42:37 +00001494/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1495/// of a NEON VLD or VST instruction. The supported values depend on the
1496/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001497SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1498 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001499 unsigned NumRegs = NumVecs;
1500 if (!is64BitVector && NumVecs < 3)
1501 NumRegs *= 2;
1502
Bob Wilson665814b2010-11-01 23:40:51 +00001503 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001504 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001505 Alignment = 32;
1506 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1507 Alignment = 16;
1508 else if (Alignment >= 8)
1509 Alignment = 8;
1510 else
1511 Alignment = 0;
1512
1513 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001514}
1515
Bob Wilson1c3ef902011-02-07 17:43:21 +00001516SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001517 unsigned *DOpcodes, unsigned *QOpcodes0,
1518 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001519 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001520 DebugLoc dl = N->getDebugLoc();
1521
Bob Wilson226036e2010-03-20 22:13:40 +00001522 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001523 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1524 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001525 return NULL;
1526
1527 SDValue Chain = N->getOperand(0);
1528 EVT VT = N->getValueType(0);
1529 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001530 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001531
Bob Wilson3e36f132009-10-14 17:28:52 +00001532 unsigned OpcodeIndex;
1533 switch (VT.getSimpleVT().SimpleTy) {
1534 default: llvm_unreachable("unhandled vld type");
1535 // Double-register operations:
1536 case MVT::v8i8: OpcodeIndex = 0; break;
1537 case MVT::v4i16: OpcodeIndex = 1; break;
1538 case MVT::v2f32:
1539 case MVT::v2i32: OpcodeIndex = 2; break;
1540 case MVT::v1i64: OpcodeIndex = 3; break;
1541 // Quad-register operations:
1542 case MVT::v16i8: OpcodeIndex = 0; break;
1543 case MVT::v8i16: OpcodeIndex = 1; break;
1544 case MVT::v4f32:
1545 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001546 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001547 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001548 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001549 }
1550
Bob Wilsonf5721912010-09-03 18:16:02 +00001551 EVT ResTy;
1552 if (NumVecs == 1)
1553 ResTy = VT;
1554 else {
1555 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1556 if (!is64BitVector)
1557 ResTyElts *= 2;
1558 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1559 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001560 std::vector<EVT> ResTys;
1561 ResTys.push_back(ResTy);
1562 if (isUpdating)
1563 ResTys.push_back(MVT::i32);
1564 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001565
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001566 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001567 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001568 SDNode *VLd;
1569 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001570
Bob Wilson1c3ef902011-02-07 17:43:21 +00001571 // Double registers and VLD1/VLD2 quad registers are directly supported.
1572 if (is64BitVector || NumVecs <= 2) {
1573 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1574 QOpcodes0[OpcodeIndex]);
1575 Ops.push_back(MemAddr);
1576 Ops.push_back(Align);
1577 if (isUpdating) {
1578 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1579 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001580 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001581 Ops.push_back(Pred);
1582 Ops.push_back(Reg0);
1583 Ops.push_back(Chain);
1584 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001585
Bob Wilson3e36f132009-10-14 17:28:52 +00001586 } else {
1587 // Otherwise, quad registers are loaded with two separate instructions,
1588 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001589 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001590
Bob Wilson1c3ef902011-02-07 17:43:21 +00001591 // Load the even subregs. This is always an updating load, so that it
1592 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001593 SDValue ImplDef =
1594 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1595 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001596 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1597 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001598 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001599
Bob Wilson24f995d2009-10-14 18:32:29 +00001600 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001601 Ops.push_back(SDValue(VLdA, 1));
1602 Ops.push_back(Align);
1603 if (isUpdating) {
1604 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1605 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1606 "only constant post-increment update allowed for VLD3/4");
1607 (void)Inc;
1608 Ops.push_back(Reg0);
1609 }
1610 Ops.push_back(SDValue(VLdA, 0));
1611 Ops.push_back(Pred);
1612 Ops.push_back(Reg0);
1613 Ops.push_back(Chain);
1614 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1615 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001616 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001617
Evan Chengb58a3402011-04-19 00:04:03 +00001618 // Transfer memoperands.
1619 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1620 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1621 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1622
Bob Wilson1c3ef902011-02-07 17:43:21 +00001623 if (NumVecs == 1)
1624 return VLd;
1625
1626 // Extract out the subregisters.
1627 SDValue SuperReg = SDValue(VLd, 0);
1628 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1629 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1630 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1631 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1632 ReplaceUses(SDValue(N, Vec),
1633 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1634 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1635 if (isUpdating)
1636 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001637 return NULL;
1638}
1639
Bob Wilson1c3ef902011-02-07 17:43:21 +00001640SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001641 unsigned *DOpcodes, unsigned *QOpcodes0,
1642 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001643 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001644 DebugLoc dl = N->getDebugLoc();
1645
Bob Wilson226036e2010-03-20 22:13:40 +00001646 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001647 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1648 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1649 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001650 return NULL;
1651
Evan Chengb58a3402011-04-19 00:04:03 +00001652 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1653 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1654
Bob Wilson24f995d2009-10-14 18:32:29 +00001655 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001656 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001657 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001658 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001659
Bob Wilson24f995d2009-10-14 18:32:29 +00001660 unsigned OpcodeIndex;
1661 switch (VT.getSimpleVT().SimpleTy) {
1662 default: llvm_unreachable("unhandled vst type");
1663 // Double-register operations:
1664 case MVT::v8i8: OpcodeIndex = 0; break;
1665 case MVT::v4i16: OpcodeIndex = 1; break;
1666 case MVT::v2f32:
1667 case MVT::v2i32: OpcodeIndex = 2; break;
1668 case MVT::v1i64: OpcodeIndex = 3; break;
1669 // Quad-register operations:
1670 case MVT::v16i8: OpcodeIndex = 0; break;
1671 case MVT::v8i16: OpcodeIndex = 1; break;
1672 case MVT::v4f32:
1673 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001674 case MVT::v2i64: OpcodeIndex = 3;
1675 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1676 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001677 }
1678
Bob Wilson1c3ef902011-02-07 17:43:21 +00001679 std::vector<EVT> ResTys;
1680 if (isUpdating)
1681 ResTys.push_back(MVT::i32);
1682 ResTys.push_back(MVT::Other);
1683
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001684 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001685 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001686 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001687
Bob Wilson1c3ef902011-02-07 17:43:21 +00001688 // Double registers and VST1/VST2 quad registers are directly supported.
1689 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001690 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001691 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001692 SrcReg = N->getOperand(Vec0Idx);
1693 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001694 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001695 SDValue V0 = N->getOperand(Vec0Idx + 0);
1696 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001697 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001698 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001699 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001700 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001701 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001702 // an undef.
1703 SDValue V3 = (NumVecs == 3)
1704 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001705 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001706 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001707 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001708 } else {
1709 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001710 SDValue Q0 = N->getOperand(Vec0Idx);
1711 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001712 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001713 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001714
1715 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1716 QOpcodes0[OpcodeIndex]);
1717 Ops.push_back(MemAddr);
1718 Ops.push_back(Align);
1719 if (isUpdating) {
1720 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1721 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1722 }
1723 Ops.push_back(SrcReg);
1724 Ops.push_back(Pred);
1725 Ops.push_back(Reg0);
1726 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001727 SDNode *VSt =
1728 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1729
1730 // Transfer memoperands.
1731 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1732
1733 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001734 }
1735
1736 // Otherwise, quad registers are stored with two separate instructions,
1737 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001738
Bob Wilson07f6e802010-06-16 21:34:01 +00001739 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001740 SDValue V0 = N->getOperand(Vec0Idx + 0);
1741 SDValue V1 = N->getOperand(Vec0Idx + 1);
1742 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001743 SDValue V3 = (NumVecs == 3)
1744 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001745 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001746 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001747
Bob Wilson1c3ef902011-02-07 17:43:21 +00001748 // Store the even D registers. This is always an updating store, so that it
1749 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001750 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1751 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1752 MemAddr.getValueType(),
1753 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001754 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001755 Chain = SDValue(VStA, 1);
1756
1757 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001758 Ops.push_back(SDValue(VStA, 0));
1759 Ops.push_back(Align);
1760 if (isUpdating) {
1761 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1762 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1763 "only constant post-increment update allowed for VST3/4");
1764 (void)Inc;
1765 Ops.push_back(Reg0);
1766 }
1767 Ops.push_back(RegSeq);
1768 Ops.push_back(Pred);
1769 Ops.push_back(Reg0);
1770 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001771 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1772 Ops.data(), Ops.size());
1773 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1774 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001775}
1776
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001777SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001778 bool isUpdating, unsigned NumVecs,
1779 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001780 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001781 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001782 DebugLoc dl = N->getDebugLoc();
1783
Bob Wilson226036e2010-03-20 22:13:40 +00001784 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001785 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1786 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1787 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001788 return NULL;
1789
Evan Chengb58a3402011-04-19 00:04:03 +00001790 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1791 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1792
Bob Wilsona7c397c2009-10-14 16:19:03 +00001793 SDValue Chain = N->getOperand(0);
1794 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001795 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1796 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001797 bool is64BitVector = VT.is64BitVector();
1798
Bob Wilson665814b2010-11-01 23:40:51 +00001799 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001800 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001801 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001802 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1803 if (Alignment > NumBytes)
1804 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001805 if (Alignment < 8 && Alignment < NumBytes)
1806 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001807 // Alignment must be a power of two; make sure of that.
1808 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001809 if (Alignment == 1)
1810 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001811 }
Bob Wilson665814b2010-11-01 23:40:51 +00001812 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001813
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 unsigned OpcodeIndex;
1815 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001816 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001817 // Double-register operations:
1818 case MVT::v8i8: OpcodeIndex = 0; break;
1819 case MVT::v4i16: OpcodeIndex = 1; break;
1820 case MVT::v2f32:
1821 case MVT::v2i32: OpcodeIndex = 2; break;
1822 // Quad-register operations:
1823 case MVT::v8i16: OpcodeIndex = 0; break;
1824 case MVT::v4f32:
1825 case MVT::v4i32: OpcodeIndex = 1; break;
1826 }
1827
Bob Wilson1c3ef902011-02-07 17:43:21 +00001828 std::vector<EVT> ResTys;
1829 if (IsLoad) {
1830 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1831 if (!is64BitVector)
1832 ResTyElts *= 2;
1833 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1834 MVT::i64, ResTyElts));
1835 }
1836 if (isUpdating)
1837 ResTys.push_back(MVT::i32);
1838 ResTys.push_back(MVT::Other);
1839
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001840 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001841 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001842
Bob Wilson1c3ef902011-02-07 17:43:21 +00001843 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001844 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001845 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001846 if (isUpdating) {
1847 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1848 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1849 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001850
Bob Wilson8466fa12010-09-13 23:01:35 +00001851 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001852 SDValue V0 = N->getOperand(Vec0Idx + 0);
1853 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001854 if (NumVecs == 2) {
1855 if (is64BitVector)
1856 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1857 else
1858 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001859 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001860 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001861 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001862 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1863 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001864 if (is64BitVector)
1865 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1866 else
1867 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001868 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001869 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001870 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001871 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001872 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001873 Ops.push_back(Chain);
1874
Bob Wilson1c3ef902011-02-07 17:43:21 +00001875 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1876 QOpcodes[OpcodeIndex]);
1877 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1878 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001879 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001880 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001881 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001882
Bob Wilson8466fa12010-09-13 23:01:35 +00001883 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 SuperReg = SDValue(VLdLn, 0);
1885 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1886 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1887 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001888 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1889 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001890 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1891 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1892 if (isUpdating)
1893 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001894 return NULL;
1895}
1896
Bob Wilson1c3ef902011-02-07 17:43:21 +00001897SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1898 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001899 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1900 DebugLoc dl = N->getDebugLoc();
1901
1902 SDValue MemAddr, Align;
1903 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1904 return NULL;
1905
Evan Chengb58a3402011-04-19 00:04:03 +00001906 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1907 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1908
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001909 SDValue Chain = N->getOperand(0);
1910 EVT VT = N->getValueType(0);
1911
1912 unsigned Alignment = 0;
1913 if (NumVecs != 3) {
1914 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1915 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1916 if (Alignment > NumBytes)
1917 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001918 if (Alignment < 8 && Alignment < NumBytes)
1919 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001920 // Alignment must be a power of two; make sure of that.
1921 Alignment = (Alignment & -Alignment);
1922 if (Alignment == 1)
1923 Alignment = 0;
1924 }
1925 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1926
1927 unsigned OpcodeIndex;
1928 switch (VT.getSimpleVT().SimpleTy) {
1929 default: llvm_unreachable("unhandled vld-dup type");
1930 case MVT::v8i8: OpcodeIndex = 0; break;
1931 case MVT::v4i16: OpcodeIndex = 1; break;
1932 case MVT::v2f32:
1933 case MVT::v2i32: OpcodeIndex = 2; break;
1934 }
1935
1936 SDValue Pred = getAL(CurDAG);
1937 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1938 SDValue SuperReg;
1939 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001940 SmallVector<SDValue, 6> Ops;
1941 Ops.push_back(MemAddr);
1942 Ops.push_back(Align);
1943 if (isUpdating) {
1944 SDValue Inc = N->getOperand(2);
1945 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1946 }
1947 Ops.push_back(Pred);
1948 Ops.push_back(Reg0);
1949 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001950
1951 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001952 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001953 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001954 if (isUpdating)
1955 ResTys.push_back(MVT::i32);
1956 ResTys.push_back(MVT::Other);
1957 SDNode *VLdDup =
1958 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001959 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001960 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001961
1962 // Extract the subregisters.
1963 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1964 unsigned SubIdx = ARM::dsub_0;
1965 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1966 ReplaceUses(SDValue(N, Vec),
1967 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001968 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1969 if (isUpdating)
1970 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001971 return NULL;
1972}
1973
Bob Wilson78dfbc32010-07-07 00:08:54 +00001974SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1975 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001976 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1977 DebugLoc dl = N->getDebugLoc();
1978 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001979 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001980
1981 // Form a REG_SEQUENCE to force register allocation.
1982 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001983 SDValue V0 = N->getOperand(FirstTblReg + 0);
1984 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001985 if (NumVecs == 2)
1986 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1987 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001988 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001989 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001990 // an undef.
1991 SDValue V3 = (NumVecs == 3)
1992 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001993 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001994 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1995 }
1996
Bob Wilson78dfbc32010-07-07 00:08:54 +00001997 SmallVector<SDValue, 6> Ops;
1998 if (IsExt)
1999 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002000 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002001 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002002 Ops.push_back(getAL(CurDAG)); // predicate
2003 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002004 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002005}
2006
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002007SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002008 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002009 if (!Subtarget->hasV6T2Ops())
2010 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002011
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002012 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2013 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2014
2015
2016 // For unsigned extracts, check for a shift right and mask
2017 unsigned And_imm = 0;
2018 if (N->getOpcode() == ISD::AND) {
2019 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2020
2021 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2022 if (And_imm & (And_imm + 1))
2023 return NULL;
2024
2025 unsigned Srl_imm = 0;
2026 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2027 Srl_imm)) {
2028 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2029
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002030 // Note: The width operand is encoded as width-1.
2031 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002032 unsigned LSB = Srl_imm;
2033 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2034 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2035 CurDAG->getTargetConstant(LSB, MVT::i32),
2036 CurDAG->getTargetConstant(Width, MVT::i32),
2037 getAL(CurDAG), Reg0 };
2038 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2039 }
2040 }
2041 return NULL;
2042 }
2043
2044 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002045 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002047 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2048 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002049 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002050 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002051 // Note: The width operand is encoded as width-1.
2052 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002053 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002054 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002055 return NULL;
2056 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002057 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002058 CurDAG->getTargetConstant(LSB, MVT::i32),
2059 CurDAG->getTargetConstant(Width, MVT::i32),
2060 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002061 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002062 }
2063 }
2064 return NULL;
2065}
2066
Evan Cheng9ef48352009-11-20 00:54:03 +00002067SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002068SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002069 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2070 SDValue CPTmp0;
2071 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002072 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002073 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2074 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2075 unsigned Opc = 0;
2076 switch (SOShOp) {
2077 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2078 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2079 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2080 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2081 default:
2082 llvm_unreachable("Unknown so_reg opcode!");
2083 break;
2084 }
2085 SDValue SOShImm =
2086 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2087 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2088 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002089 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002090 }
2091 return 0;
2092}
2093
2094SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002095SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002096 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2097 SDValue CPTmp0;
2098 SDValue CPTmp1;
2099 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002100 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002101 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002102 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2103 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002104 }
2105
2106 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2107 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2108 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2109 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002110 }
2111 return 0;
2112}
2113
2114SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002115SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002116 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002117 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002118 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002119 return 0;
2120
Evan Cheng63f35442010-11-13 02:25:14 +00002121 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002122 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002123 if (is_t2_so_imm(TrueImm)) {
2124 Opc = ARM::t2MOVCCi;
2125 } else if (TrueImm <= 0xffff) {
2126 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002127 } else if (is_t2_so_imm_not(TrueImm)) {
2128 TrueImm = ~TrueImm;
2129 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002130 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002131 // Large immediate.
2132 Opc = ARM::t2MOVCCi32imm;
2133 }
2134
2135 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002136 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002137 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2138 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002139 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002140 }
Evan Cheng63f35442010-11-13 02:25:14 +00002141
Evan Cheng9ef48352009-11-20 00:54:03 +00002142 return 0;
2143}
2144
2145SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002146SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002147 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002148 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2149 if (!T)
2150 return 0;
2151
Evan Cheng63f35442010-11-13 02:25:14 +00002152 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002153 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002154 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002155 if (isSoImm) {
2156 Opc = ARM::MOVCCi;
2157 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2158 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002159 } else if (is_so_imm_not(TrueImm)) {
2160 TrueImm = ~TrueImm;
2161 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002162 } else if (TrueVal.getNode()->hasOneUse() &&
2163 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002164 // Large immediate.
2165 Opc = ARM::MOVCCi32imm;
2166 }
2167
2168 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002169 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002170 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2171 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002172 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002173 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002174
Evan Cheng9ef48352009-11-20 00:54:03 +00002175 return 0;
2176}
2177
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002178SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2179 EVT VT = N->getValueType(0);
2180 SDValue FalseVal = N->getOperand(0);
2181 SDValue TrueVal = N->getOperand(1);
2182 SDValue CC = N->getOperand(2);
2183 SDValue CCR = N->getOperand(3);
2184 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002185 assert(CC.getOpcode() == ISD::Constant);
2186 assert(CCR.getOpcode() == ISD::Register);
2187 ARMCC::CondCodes CCVal =
2188 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002189
2190 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2191 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2192 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2193 // Pattern complexity = 18 cost = 1 size = 0
2194 SDValue CPTmp0;
2195 SDValue CPTmp1;
2196 SDValue CPTmp2;
2197 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002198 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002199 CCVal, CCR, InFlag);
2200 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002201 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002202 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2203 if (Res)
2204 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002205 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002206 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002207 CCVal, CCR, InFlag);
2208 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002209 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002210 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2211 if (Res)
2212 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002213 }
2214
2215 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002216 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002217 // (imm:i32):$cc)
2218 // Emits: (MOVCCi:i32 GPR:i32:$false,
2219 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2220 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002221 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002222 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002223 CCVal, CCR, InFlag);
2224 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002225 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002226 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2227 if (Res)
2228 return Res;
2229 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002230 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002231 CCVal, CCR, InFlag);
2232 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002233 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002234 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2235 if (Res)
2236 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002237 }
2238 }
2239
2240 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2241 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2242 // Pattern complexity = 6 cost = 1 size = 0
2243 //
2244 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2245 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2246 // Pattern complexity = 6 cost = 11 size = 0
2247 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002248 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002249 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2250 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002251 unsigned Opc = 0;
2252 switch (VT.getSimpleVT().SimpleTy) {
2253 default: assert(false && "Illegal conditional move type!");
2254 break;
2255 case MVT::i32:
2256 Opc = Subtarget->isThumb()
2257 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2258 : ARM::MOVCCr;
2259 break;
2260 case MVT::f32:
2261 Opc = ARM::VMOVScc;
2262 break;
2263 case MVT::f64:
2264 Opc = ARM::VMOVDcc;
2265 break;
2266 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002267 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002268}
2269
Evan Chengde8aa4e2010-05-05 18:28:36 +00002270SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2271 // The only time a CONCAT_VECTORS operation can have legal types is when
2272 // two 64-bit vectors are concatenated to a 128-bit vector.
2273 EVT VT = N->getValueType(0);
2274 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2275 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002276 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002277}
2278
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002279SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002280 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002281
Dan Gohmane8be6c62008-07-17 19:10:17 +00002282 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002283 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002284
2285 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002286 default: break;
2287 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002288 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002289 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002290 if (Subtarget->hasThumb2())
2291 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2292 // be done with MOV + MOVT, at worst.
2293 UseCP = 0;
2294 else {
2295 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002296 UseCP = (Val > 255 && // MOV
2297 ~Val > 255 && // MOV + MVN
2298 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002299 } else
2300 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2301 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2302 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2303 }
2304
Evan Chenga8e29892007-01-19 07:51:42 +00002305 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002306 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002307 CurDAG->getTargetConstantPool(ConstantInt::get(
2308 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002309 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002310
2311 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002312 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002313 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002314 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002315 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002316 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002317 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002318 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002319 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002320 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002321 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002322 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002323 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002324 CurDAG->getEntryNode()
2325 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002326 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002327 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002328 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002329 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002330 return NULL;
2331 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002332
Evan Chenga8e29892007-01-19 07:51:42 +00002333 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002334 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002335 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002336 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002337 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002338 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002339 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002340 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002341 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2342 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2343 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002344 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002345 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2346 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002347 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2348 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2349 CurDAG->getRegister(0, MVT::i32) };
2350 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002351 }
Evan Chenga8e29892007-01-19 07:51:42 +00002352 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002353 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002354 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002355 return I;
2356 break;
2357 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002358 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002359 return I;
2360 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002361 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002362 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002363 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002364 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002365 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002366 if (!RHSV) break;
2367 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002368 unsigned ShImm = Log2_32(RHSV-1);
2369 if (ShImm >= 32)
2370 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002371 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002372 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002373 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2374 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002375 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002376 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002377 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002378 } else {
2379 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002380 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002381 }
Evan Chenga8e29892007-01-19 07:51:42 +00002382 }
2383 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002384 unsigned ShImm = Log2_32(RHSV+1);
2385 if (ShImm >= 32)
2386 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002387 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002388 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002389 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2390 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002391 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002392 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2393 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002394 } else {
2395 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002396 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002397 }
Evan Chenga8e29892007-01-19 07:51:42 +00002398 }
2399 }
2400 break;
Evan Cheng20956592009-10-21 08:15:52 +00002401 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002402 // Check for unsigned bitfield extract
2403 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2404 return I;
2405
Evan Cheng20956592009-10-21 08:15:52 +00002406 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2407 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2408 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2409 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2410 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002411 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002412 if (VT != MVT::i32)
2413 break;
2414 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2415 ? ARM::t2MOVTi16
2416 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2417 if (!Opc)
2418 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002419 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002420 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2421 if (!N1C)
2422 break;
2423 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2424 SDValue N2 = N0.getOperand(1);
2425 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2426 if (!N2C)
2427 break;
2428 unsigned N1CVal = N1C->getZExtValue();
2429 unsigned N2CVal = N2C->getZExtValue();
2430 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2431 (N1CVal & 0xffffU) == 0xffffU &&
2432 (N2CVal & 0xffffU) == 0x0U) {
2433 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2434 MVT::i32);
2435 SDValue Ops[] = { N0.getOperand(0), Imm16,
2436 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2437 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2438 }
2439 }
2440 break;
2441 }
Jim Grosbache5165492009-11-09 00:11:35 +00002442 case ARMISD::VMOVRRD:
2443 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002444 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002445 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002446 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002447 if (Subtarget->isThumb1Only())
2448 break;
2449 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002450 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002451 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2452 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002453 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002454 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002455 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002456 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2457 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002458 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2459 ARM::UMULL : ARM::UMULLv5,
2460 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002461 }
Evan Chengee568cf2007-07-05 07:15:27 +00002462 }
Dan Gohman525178c2007-10-08 18:33:35 +00002463 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002464 if (Subtarget->isThumb1Only())
2465 break;
2466 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002467 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002468 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002469 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002470 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002471 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002472 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2473 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002474 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2475 ARM::SMULL : ARM::SMULLv5,
2476 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002477 }
Evan Chengee568cf2007-07-05 07:15:27 +00002478 }
Evan Chenga8e29892007-01-19 07:51:42 +00002479 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002480 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002481 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002482 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002483 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002484 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002485 if (ResNode)
2486 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002487 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002488 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002489 }
Evan Chengee568cf2007-07-05 07:15:27 +00002490 case ARMISD::BRCOND: {
2491 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2492 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2493 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002494
Evan Chengee568cf2007-07-05 07:15:27 +00002495 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2496 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2497 // Pattern complexity = 6 cost = 1 size = 0
2498
David Goodwin5e47a9a2009-06-30 18:04:13 +00002499 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2500 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2501 // Pattern complexity = 6 cost = 1 size = 0
2502
Jim Grosbach764ab522009-08-11 15:33:49 +00002503 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002504 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002505 SDValue Chain = N->getOperand(0);
2506 SDValue N1 = N->getOperand(1);
2507 SDValue N2 = N->getOperand(2);
2508 SDValue N3 = N->getOperand(3);
2509 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002510 assert(N1.getOpcode() == ISD::BasicBlock);
2511 assert(N2.getOpcode() == ISD::Constant);
2512 assert(N3.getOpcode() == ISD::Register);
2513
Dan Gohman475871a2008-07-27 21:46:04 +00002514 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002515 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002516 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002517 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002518 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002519 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002520 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002521 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002522 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002523 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002524 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002525 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002526 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002527 return NULL;
2528 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002529 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002530 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002531 case ARMISD::VZIP: {
2532 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002533 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002534 switch (VT.getSimpleVT().SimpleTy) {
2535 default: return NULL;
2536 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2537 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2538 case MVT::v2f32:
2539 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2540 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2541 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2542 case MVT::v4f32:
2543 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2544 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002545 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002546 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2547 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2548 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002549 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002550 case ARMISD::VUZP: {
2551 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002552 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002553 switch (VT.getSimpleVT().SimpleTy) {
2554 default: return NULL;
2555 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2556 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2557 case MVT::v2f32:
2558 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2559 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2560 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2561 case MVT::v4f32:
2562 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2563 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002564 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002565 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2566 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2567 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002568 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002569 case ARMISD::VTRN: {
2570 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002571 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002572 switch (VT.getSimpleVT().SimpleTy) {
2573 default: return NULL;
2574 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2575 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2576 case MVT::v2f32:
2577 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2578 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2579 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2580 case MVT::v4f32:
2581 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2582 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002583 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002584 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2585 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2586 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002587 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002588 case ARMISD::BUILD_VECTOR: {
2589 EVT VecVT = N->getValueType(0);
2590 EVT EltVT = VecVT.getVectorElementType();
2591 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002592 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002593 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2594 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2595 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002596 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002597 if (NumElts == 2)
2598 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2599 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2600 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2601 N->getOperand(2), N->getOperand(3));
2602 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002603
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002604 case ARMISD::VLD2DUP: {
2605 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2606 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002607 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002608 }
2609
Bob Wilson86c6d802010-11-29 19:35:29 +00002610 case ARMISD::VLD3DUP: {
2611 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2612 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002613 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002614 }
2615
Bob Wilson6c4c9822010-11-30 00:00:35 +00002616 case ARMISD::VLD4DUP: {
2617 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2618 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002619 return SelectVLDDup(N, false, 4, Opcodes);
2620 }
2621
2622 case ARMISD::VLD2DUP_UPD: {
2623 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2624 ARM::VLD2DUPd32Pseudo_UPD };
2625 return SelectVLDDup(N, true, 2, Opcodes);
2626 }
2627
2628 case ARMISD::VLD3DUP_UPD: {
2629 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2630 ARM::VLD3DUPd32Pseudo_UPD };
2631 return SelectVLDDup(N, true, 3, Opcodes);
2632 }
2633
2634 case ARMISD::VLD4DUP_UPD: {
2635 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2636 ARM::VLD4DUPd32Pseudo_UPD };
2637 return SelectVLDDup(N, true, 4, Opcodes);
2638 }
2639
2640 case ARMISD::VLD1_UPD: {
2641 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2642 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2643 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2644 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2645 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2646 }
2647
2648 case ARMISD::VLD2_UPD: {
2649 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2650 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2651 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2652 ARM::VLD2q32Pseudo_UPD };
2653 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2654 }
2655
2656 case ARMISD::VLD3_UPD: {
2657 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2658 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2659 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2660 ARM::VLD3q16Pseudo_UPD,
2661 ARM::VLD3q32Pseudo_UPD };
2662 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2663 ARM::VLD3q16oddPseudo_UPD,
2664 ARM::VLD3q32oddPseudo_UPD };
2665 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2666 }
2667
2668 case ARMISD::VLD4_UPD: {
2669 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2670 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2671 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2672 ARM::VLD4q16Pseudo_UPD,
2673 ARM::VLD4q32Pseudo_UPD };
2674 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2675 ARM::VLD4q16oddPseudo_UPD,
2676 ARM::VLD4q32oddPseudo_UPD };
2677 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2678 }
2679
2680 case ARMISD::VLD2LN_UPD: {
2681 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2682 ARM::VLD2LNd32Pseudo_UPD };
2683 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2684 ARM::VLD2LNq32Pseudo_UPD };
2685 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2686 }
2687
2688 case ARMISD::VLD3LN_UPD: {
2689 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2690 ARM::VLD3LNd32Pseudo_UPD };
2691 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2692 ARM::VLD3LNq32Pseudo_UPD };
2693 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2694 }
2695
2696 case ARMISD::VLD4LN_UPD: {
2697 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2698 ARM::VLD4LNd32Pseudo_UPD };
2699 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2700 ARM::VLD4LNq32Pseudo_UPD };
2701 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2702 }
2703
2704 case ARMISD::VST1_UPD: {
2705 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2706 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2707 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2708 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2709 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2710 }
2711
2712 case ARMISD::VST2_UPD: {
2713 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2714 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2715 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2716 ARM::VST2q32Pseudo_UPD };
2717 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2718 }
2719
2720 case ARMISD::VST3_UPD: {
2721 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2722 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2723 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2724 ARM::VST3q16Pseudo_UPD,
2725 ARM::VST3q32Pseudo_UPD };
2726 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2727 ARM::VST3q16oddPseudo_UPD,
2728 ARM::VST3q32oddPseudo_UPD };
2729 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2730 }
2731
2732 case ARMISD::VST4_UPD: {
2733 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2734 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2735 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2736 ARM::VST4q16Pseudo_UPD,
2737 ARM::VST4q32Pseudo_UPD };
2738 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2739 ARM::VST4q16oddPseudo_UPD,
2740 ARM::VST4q32oddPseudo_UPD };
2741 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2742 }
2743
2744 case ARMISD::VST2LN_UPD: {
2745 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2746 ARM::VST2LNd32Pseudo_UPD };
2747 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2748 ARM::VST2LNq32Pseudo_UPD };
2749 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2750 }
2751
2752 case ARMISD::VST3LN_UPD: {
2753 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2754 ARM::VST3LNd32Pseudo_UPD };
2755 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2756 ARM::VST3LNq32Pseudo_UPD };
2757 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2758 }
2759
2760 case ARMISD::VST4LN_UPD: {
2761 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2762 ARM::VST4LNd32Pseudo_UPD };
2763 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2764 ARM::VST4LNq32Pseudo_UPD };
2765 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002766 }
2767
Bob Wilson31fb12f2009-08-26 17:39:53 +00002768 case ISD::INTRINSIC_VOID:
2769 case ISD::INTRINSIC_W_CHAIN: {
2770 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002771 switch (IntNo) {
2772 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002773 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002774
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002775 case Intrinsic::arm_ldrexd: {
2776 SDValue MemAddr = N->getOperand(2);
2777 DebugLoc dl = N->getDebugLoc();
2778 SDValue Chain = N->getOperand(0);
2779
2780 unsigned NewOpc = ARM::LDREXD;
2781 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2782 NewOpc = ARM::t2LDREXD;
2783
2784 // arm_ldrexd returns a i64 value in {i32, i32}
2785 std::vector<EVT> ResTys;
2786 ResTys.push_back(MVT::i32);
2787 ResTys.push_back(MVT::i32);
2788 ResTys.push_back(MVT::Other);
2789
2790 // place arguments in the right order
2791 SmallVector<SDValue, 7> Ops;
2792 Ops.push_back(MemAddr);
2793 Ops.push_back(getAL(CurDAG));
2794 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2795 Ops.push_back(Chain);
2796 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2797 Ops.size());
2798 // Transfer memoperands.
2799 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2800 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2801 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2802
2803 // Until there's support for specifing explicit register constraints
2804 // like the use of even/odd register pair, hardcode ldrexd to always
2805 // use the pair [R0, R1] to hold the load result.
2806 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2807 SDValue(Ld, 0), SDValue(0,0));
2808 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2809 SDValue(Ld, 1), Chain.getValue(1));
2810
2811 // Remap uses.
2812 SDValue Glue = Chain.getValue(1);
2813 if (!SDValue(N, 0).use_empty()) {
2814 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2815 ARM::R0, MVT::i32, Glue);
2816 Glue = Result.getValue(2);
2817 ReplaceUses(SDValue(N, 0), Result);
2818 }
2819 if (!SDValue(N, 1).use_empty()) {
2820 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2821 ARM::R1, MVT::i32, Glue);
2822 Glue = Result.getValue(2);
2823 ReplaceUses(SDValue(N, 1), Result);
2824 }
2825
2826 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2827 return NULL;
2828 }
2829
2830 case Intrinsic::arm_strexd: {
2831 DebugLoc dl = N->getDebugLoc();
2832 SDValue Chain = N->getOperand(0);
2833 SDValue Val0 = N->getOperand(2);
2834 SDValue Val1 = N->getOperand(3);
2835 SDValue MemAddr = N->getOperand(4);
2836
2837 // Until there's support for specifing explicit register constraints
2838 // like the use of even/odd register pair, hardcode strexd to always
2839 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2840 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2841 SDValue(0, 0));
2842 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2843
2844 SDValue Glue = Chain.getValue(1);
2845 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2846 ARM::R2, MVT::i32, Glue);
2847 Glue = Val0.getValue(1);
2848 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2849 ARM::R3, MVT::i32, Glue);
2850
2851 // Store exclusive double return a i32 value which is the return status
2852 // of the issued store.
2853 std::vector<EVT> ResTys;
2854 ResTys.push_back(MVT::i32);
2855 ResTys.push_back(MVT::Other);
2856
2857 // place arguments in the right order
2858 SmallVector<SDValue, 7> Ops;
2859 Ops.push_back(Val0);
2860 Ops.push_back(Val1);
2861 Ops.push_back(MemAddr);
2862 Ops.push_back(getAL(CurDAG));
2863 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2864 Ops.push_back(Chain);
2865
2866 unsigned NewOpc = ARM::STREXD;
2867 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2868 NewOpc = ARM::t2STREXD;
2869
2870 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2871 Ops.size());
2872 // Transfer memoperands.
2873 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2874 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2875 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2876
2877 return St;
2878 }
2879
Bob Wilson621f1952010-03-23 05:25:43 +00002880 case Intrinsic::arm_neon_vld1: {
2881 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2882 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002883 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2884 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002885 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002886 }
2887
Bob Wilson31fb12f2009-08-26 17:39:53 +00002888 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002889 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2890 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2891 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2892 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002893 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002894 }
2895
2896 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002897 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2898 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2899 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2900 ARM::VLD3q16Pseudo_UPD,
2901 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002902 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2903 ARM::VLD3q16oddPseudo,
2904 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002905 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002906 }
2907
2908 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002909 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2910 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2911 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2912 ARM::VLD4q16Pseudo_UPD,
2913 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002914 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2915 ARM::VLD4q16oddPseudo,
2916 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002917 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002918 }
2919
Bob Wilson243fcc52009-09-01 04:26:28 +00002920 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002921 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2922 ARM::VLD2LNd32Pseudo };
2923 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002924 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002925 }
2926
2927 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002928 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2929 ARM::VLD3LNd32Pseudo };
2930 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002931 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002932 }
2933
2934 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002935 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2936 ARM::VLD4LNd32Pseudo };
2937 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002938 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002939 }
2940
Bob Wilson11d98992010-03-23 06:20:33 +00002941 case Intrinsic::arm_neon_vst1: {
2942 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2943 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002944 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2945 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002946 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002947 }
2948
Bob Wilson31fb12f2009-08-26 17:39:53 +00002949 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002950 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2951 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2952 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2953 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002954 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002955 }
2956
2957 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002958 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2959 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2960 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2961 ARM::VST3q16Pseudo_UPD,
2962 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002963 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2964 ARM::VST3q16oddPseudo,
2965 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002966 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002967 }
2968
2969 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002970 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002971 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002972 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2973 ARM::VST4q16Pseudo_UPD,
2974 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002975 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2976 ARM::VST4q16oddPseudo,
2977 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002978 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002979 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002980
2981 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002982 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2983 ARM::VST2LNd32Pseudo };
2984 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002985 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002986 }
2987
2988 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002989 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2990 ARM::VST3LNd32Pseudo };
2991 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002992 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002993 }
2994
2995 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002996 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2997 ARM::VST4LNd32Pseudo };
2998 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002999 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003000 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003001 }
Bob Wilson429009b2010-05-06 16:05:26 +00003002 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003003 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003004
Bob Wilsond491d6e2010-07-06 23:36:25 +00003005 case ISD::INTRINSIC_WO_CHAIN: {
3006 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3007 switch (IntNo) {
3008 default:
3009 break;
3010
3011 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003012 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003013 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003014 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003015 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003016 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003017
3018 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003019 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003020 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003021 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003022 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003023 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003024 }
3025 break;
3026 }
3027
Bill Wendling69a05a72011-03-14 23:02:38 +00003028 case ARMISD::VTBL1: {
3029 DebugLoc dl = N->getDebugLoc();
3030 EVT VT = N->getValueType(0);
3031 SmallVector<SDValue, 6> Ops;
3032
3033 Ops.push_back(N->getOperand(0));
3034 Ops.push_back(N->getOperand(1));
3035 Ops.push_back(getAL(CurDAG)); // Predicate
3036 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3037 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3038 }
3039 case ARMISD::VTBL2: {
3040 DebugLoc dl = N->getDebugLoc();
3041 EVT VT = N->getValueType(0);
3042
3043 // Form a REG_SEQUENCE to force register allocation.
3044 SDValue V0 = N->getOperand(0);
3045 SDValue V1 = N->getOperand(1);
3046 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3047
3048 SmallVector<SDValue, 6> Ops;
3049 Ops.push_back(RegSeq);
3050 Ops.push_back(N->getOperand(2));
3051 Ops.push_back(getAL(CurDAG)); // Predicate
3052 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3053 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3054 Ops.data(), Ops.size());
3055 }
3056
Bob Wilson429009b2010-05-06 16:05:26 +00003057 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003058 return SelectConcatVector(N);
3059 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003060
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003061 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003062}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003063
Bob Wilson224c2442009-05-19 05:53:42 +00003064bool ARMDAGToDAGISel::
3065SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3066 std::vector<SDValue> &OutOps) {
3067 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003068 // Require the address to be in a register. That is safe for all ARM
3069 // variants and it is hard to do anything much smarter without knowing
3070 // how the operand is used.
3071 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003072 return false;
3073}
3074
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003075/// createARMISelDag - This pass converts a legalized DAG into a
3076/// ARM-specific DAG, ready for instruction scheduling.
3077///
Bob Wilson522ce972009-09-28 14:30:20 +00003078FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3079 CodeGenOpt::Level OptLevel) {
3080 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003081}