blob: 74d877a27fca33e80f3a2b0aad0b9caf8eedf27b [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);
Chris Lattner52a261b2010-09-21 20:31:19 +0000136 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000137 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000138 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000139 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000140 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000141 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000142 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000143 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000144
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000145 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000146
Bill Wendlingf4caf692010-12-14 03:36:38 +0000147 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000148 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000149 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
150 unsigned Scale);
151 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
152 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
153 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
154 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
155 SDValue &OffImm);
156 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
157 SDValue &OffImm);
158 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
159 SDValue &OffImm);
160 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
161 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000162 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000163
Bill Wendlingf4caf692010-12-14 03:36:38 +0000164 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000166 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000167 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
168 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000169 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000170 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000171 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000172 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000173 SDValue &OffReg, SDValue &ShImm);
174
Evan Cheng875a6ac2010-11-12 22:42:47 +0000175 inline bool is_so_imm(unsigned Imm) const {
176 return ARM_AM::getSOImmVal(Imm) != -1;
177 }
178
179 inline bool is_so_imm_not(unsigned Imm) const {
180 return ARM_AM::getSOImmVal(~Imm) != -1;
181 }
182
183 inline bool is_t2_so_imm(unsigned Imm) const {
184 return ARM_AM::getT2SOImmVal(Imm) != -1;
185 }
186
187 inline bool is_t2_so_imm_not(unsigned Imm) const {
188 return ARM_AM::getT2SOImmVal(~Imm) != -1;
189 }
190
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000191 // Include the pieces autogenerated from the target description.
192#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000193
194private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000195 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
196 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000197 SDNode *SelectARMIndexedLoad(SDNode *N);
198 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000199
Bob Wilson621f1952010-03-23 05:25:43 +0000200 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
201 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000202 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000203 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000204 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
205 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000206 unsigned *QOpcodes0, unsigned *QOpcodes1);
207
Bob Wilson24f995d2009-10-14 18:32:29 +0000208 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000209 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000210 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000211 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000212 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
213 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000214 unsigned *QOpcodes0, unsigned *QOpcodes1);
215
Bob Wilson96493442009-10-14 16:46:45 +0000216 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000217 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000218 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000219 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
220 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000221 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000222
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000223 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
224 /// should be 2, 3 or 4. The opcode array specifies the instructions used
225 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000226 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
227 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000228
Bob Wilson78dfbc32010-07-07 00:08:54 +0000229 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
230 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
231 /// generated to force the table registers to be consecutive.
232 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000233
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000234 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000235 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000236
Evan Cheng07ba9062009-11-19 21:45:22 +0000237 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000238 SDNode *SelectCMOVOp(SDNode *N);
239 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000240 ARMCC::CondCodes CCVal, SDValue CCR,
241 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000242 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000243 ARMCC::CondCodes CCVal, SDValue CCR,
244 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000245 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000248 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000251
Evan Chengde8aa4e2010-05-05 18:28:36 +0000252 SDNode *SelectConcatVector(SDNode *N);
253
Evan Chengaf4550f2009-07-02 01:23:32 +0000254 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
255 /// inline asm expressions.
256 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
257 char ConstraintCode,
258 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000259
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000260 // Form pairs of consecutive S, D, or Q registers.
261 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000262 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000263 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
264
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000265 // Form sequences of 4 consecutive S, D, or Q registers.
266 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000267 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000268 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000269
270 // Get the alignment operand for a NEON VLD or VST instruction.
271 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000272};
Evan Chenga8e29892007-01-19 07:51:42 +0000273}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000274
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000275/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
276/// operand. If so Imm will receive the 32-bit value.
277static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
278 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
279 Imm = cast<ConstantSDNode>(N)->getZExtValue();
280 return true;
281 }
282 return false;
283}
284
285// isInt32Immediate - This method tests to see if a constant operand.
286// If so Imm will receive the 32 bit value.
287static bool isInt32Immediate(SDValue N, unsigned &Imm) {
288 return isInt32Immediate(N.getNode(), Imm);
289}
290
291// isOpcWithIntImmediate - This method tests to see if the node is a specific
292// opcode and that it has a immediate integer right operand.
293// If so Imm will receive the 32 bit value.
294static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
295 return N->getOpcode() == Opc &&
296 isInt32Immediate(N->getOperand(1).getNode(), Imm);
297}
298
Daniel Dunbarec91d522011-01-19 15:12:16 +0000299/// \brief Check whether a particular node is a constant value representable as
300/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
301///
302/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
303static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
304 int RangeMin, int RangeMax,
305 int &ScaledConstant) {
306 assert(Scale && "Invalid scale!");
307
308 // Check that this is a constant.
309 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
310 if (!C)
311 return false;
312
313 ScaledConstant = (int) C->getZExtValue();
314 if ((ScaledConstant % Scale) != 0)
315 return false;
316
317 ScaledConstant /= Scale;
318 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
319}
320
Evan Cheng48575f62010-12-05 22:04:16 +0000321/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
322/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
323/// least on current ARM implementations) which should be avoidded.
324bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
325 if (OptLevel == CodeGenOpt::None)
326 return true;
327
328 if (!CheckVMLxHazard)
329 return true;
330
331 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
332 return true;
333
334 if (!N->hasOneUse())
335 return false;
336
337 SDNode *Use = *N->use_begin();
338 if (Use->getOpcode() == ISD::CopyToReg)
339 return true;
340 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000341 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
342 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000343 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000344 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000345 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
346 return true;
347 // vmlx feeding into another vmlx. We actually want to unfold
348 // the use later in the MLxExpansion pass. e.g.
349 // vmla
350 // vmla (stall 8 cycles)
351 //
352 // vmul (5 cycles)
353 // vadd (5 cycles)
354 // vmla
355 // This adds up to about 18 - 19 cycles.
356 //
357 // vmla
358 // vmul (stall 4 cycles)
359 // vadd adds up to about 14 cycles.
360 return TII->isFpMLxInstruction(Opcode);
361 }
362
363 return false;
364}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000365
Evan Chengf40deed2010-10-27 23:41:30 +0000366bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
367 ARM_AM::ShiftOpc ShOpcVal,
368 unsigned ShAmt) {
369 if (!Subtarget->isCortexA9())
370 return true;
371 if (Shift.hasOneUse())
372 return true;
373 // R << 2 is free.
374 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
375}
376
Owen Anderson92a20222011-07-21 18:54:16 +0000377bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000378 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000379 SDValue &Opc,
380 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000381 if (DisableShifterOp)
382 return false;
383
Evan Chengee04a6d2011-07-20 23:34:39 +0000384 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000385
386 // Don't match base register only case. That is matched to a separate
387 // lower complexity pattern with explicit register operand.
388 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000389
Evan Cheng055b0312009-06-29 07:51:04 +0000390 BaseReg = N.getOperand(0);
391 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000392 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
393 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000394 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000395 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
396 MVT::i32);
397 return true;
398}
399
Owen Anderson92a20222011-07-21 18:54:16 +0000400bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
401 SDValue &BaseReg,
402 SDValue &ShReg,
403 SDValue &Opc,
404 bool CheckProfitability) {
405 if (DisableShifterOp)
406 return false;
407
408 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
409
410 // Don't match base register only case. That is matched to a separate
411 // lower complexity pattern with explicit register operand.
412 if (ShOpcVal == ARM_AM::no_shift) return false;
413
414 BaseReg = N.getOperand(0);
415 unsigned ShImmVal = 0;
416 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
417 if (RHS) return false;
418
419 ShReg = N.getOperand(1);
420 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
421 return false;
422 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
423 MVT::i32);
424 return true;
425}
426
427
Jim Grosbach3e556122010-10-26 22:37:02 +0000428bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
429 SDValue &Base,
430 SDValue &OffImm) {
431 // Match simple R + imm12 operands.
432
433 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000434 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
435 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000436 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000437 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000438 int FI = cast<FrameIndexSDNode>(N)->getIndex();
439 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
440 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
441 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000442 }
Owen Anderson099e5552011-03-18 19:46:58 +0000443
Chris Lattner0a9481f2011-02-13 22:25:43 +0000444 if (N.getOpcode() == ARMISD::Wrapper &&
445 !(Subtarget->useMovt() &&
446 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000447 Base = N.getOperand(0);
448 } else
449 Base = N;
450 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
451 return true;
452 }
453
454 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
455 int RHSC = (int)RHS->getZExtValue();
456 if (N.getOpcode() == ISD::SUB)
457 RHSC = -RHSC;
458
459 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
460 Base = N.getOperand(0);
461 if (Base.getOpcode() == ISD::FrameIndex) {
462 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
463 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
464 }
465 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
466 return true;
467 }
468 }
469
470 // Base only.
471 Base = N;
472 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
473 return true;
474}
475
476
477
478bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
479 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000480 if (N.getOpcode() == ISD::MUL &&
481 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000482 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
483 // X * [3,5,9] -> X + X * [2,4,8] etc.
484 int RHSC = (int)RHS->getZExtValue();
485 if (RHSC & 1) {
486 RHSC = RHSC & ~1;
487 ARM_AM::AddrOpc AddSub = ARM_AM::add;
488 if (RHSC < 0) {
489 AddSub = ARM_AM::sub;
490 RHSC = - RHSC;
491 }
492 if (isPowerOf2_32(RHSC)) {
493 unsigned ShAmt = Log2_32(RHSC);
494 Base = Offset = N.getOperand(0);
495 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
496 ARM_AM::lsl),
497 MVT::i32);
498 return true;
499 }
500 }
501 }
502 }
503
Chris Lattner0a9481f2011-02-13 22:25:43 +0000504 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
505 // ISD::OR that is equivalent to an ISD::ADD.
506 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000507 return false;
508
509 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000510 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000511 int RHSC;
512 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
513 -0x1000+1, 0x1000, RHSC)) // 12 bits.
514 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000515 }
516
Evan Chengf40deed2010-10-27 23:41:30 +0000517 if (Subtarget->isCortexA9() && !N.hasOneUse())
518 // Compute R +/- (R << N) and reuse it.
519 return false;
520
Jim Grosbach3e556122010-10-26 22:37:02 +0000521 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000522 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000523 ARM_AM::ShiftOpc ShOpcVal =
524 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000525 unsigned ShAmt = 0;
526
527 Base = N.getOperand(0);
528 Offset = N.getOperand(1);
529
530 if (ShOpcVal != ARM_AM::no_shift) {
531 // Check to see if the RHS of the shift is a constant, if not, we can't fold
532 // it.
533 if (ConstantSDNode *Sh =
534 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
535 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000536 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
537 Offset = N.getOperand(1).getOperand(0);
538 else {
539 ShAmt = 0;
540 ShOpcVal = ARM_AM::no_shift;
541 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000542 } else {
543 ShOpcVal = ARM_AM::no_shift;
544 }
545 }
546
547 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000548 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000549 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000550 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000551 if (ShOpcVal != ARM_AM::no_shift) {
552 // Check to see if the RHS of the shift is a constant, if not, we can't
553 // fold it.
554 if (ConstantSDNode *Sh =
555 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
556 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000557 if (!Subtarget->isCortexA9() ||
558 (N.hasOneUse() &&
559 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
560 Offset = N.getOperand(0).getOperand(0);
561 Base = N.getOperand(1);
562 } else {
563 ShAmt = 0;
564 ShOpcVal = ARM_AM::no_shift;
565 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000566 } else {
567 ShOpcVal = ARM_AM::no_shift;
568 }
569 }
570 }
571
572 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
573 MVT::i32);
574 return true;
575}
576
577
578
579
580//-----
581
Jim Grosbach82891622010-09-29 19:03:54 +0000582AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
583 SDValue &Base,
584 SDValue &Offset,
585 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000586 if (N.getOpcode() == ISD::MUL &&
587 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000588 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
589 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000590 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000591 if (RHSC & 1) {
592 RHSC = RHSC & ~1;
593 ARM_AM::AddrOpc AddSub = ARM_AM::add;
594 if (RHSC < 0) {
595 AddSub = ARM_AM::sub;
596 RHSC = - RHSC;
597 }
598 if (isPowerOf2_32(RHSC)) {
599 unsigned ShAmt = Log2_32(RHSC);
600 Base = Offset = N.getOperand(0);
601 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
602 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000604 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000605 }
606 }
607 }
608 }
609
Chris Lattner0a9481f2011-02-13 22:25:43 +0000610 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
611 // ISD::OR that is equivalent to an ADD.
612 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000613 Base = N;
614 if (N.getOpcode() == ISD::FrameIndex) {
615 int FI = cast<FrameIndexSDNode>(N)->getIndex();
616 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000617 } else if (N.getOpcode() == ARMISD::Wrapper &&
618 !(Subtarget->useMovt() &&
619 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000620 Base = N.getOperand(0);
621 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000622 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000623 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
624 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000626 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000627 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000628
Evan Chenga8e29892007-01-19 07:51:42 +0000629 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000630 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000631 int RHSC;
632 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
633 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
634 Base = N.getOperand(0);
635 if (Base.getOpcode() == ISD::FrameIndex) {
636 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
637 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000638 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000639 Offset = CurDAG->getRegister(0, MVT::i32);
640
641 ARM_AM::AddrOpc AddSub = ARM_AM::add;
642 if (RHSC < 0) {
643 AddSub = ARM_AM::sub;
644 RHSC = - RHSC;
645 }
646 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
647 ARM_AM::no_shift),
648 MVT::i32);
649 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000650 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000651 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000652
Evan Chengf40deed2010-10-27 23:41:30 +0000653 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
654 // Compute R +/- (R << N) and reuse it.
655 Base = N;
656 Offset = CurDAG->getRegister(0, MVT::i32);
657 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
658 ARM_AM::no_shift),
659 MVT::i32);
660 return AM2_BASE;
661 }
662
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000663 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000664 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000665 ARM_AM::ShiftOpc ShOpcVal =
666 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000667 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000668
Evan Chenga8e29892007-01-19 07:51:42 +0000669 Base = N.getOperand(0);
670 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000671
Evan Chenga8e29892007-01-19 07:51:42 +0000672 if (ShOpcVal != ARM_AM::no_shift) {
673 // Check to see if the RHS of the shift is a constant, if not, we can't fold
674 // it.
675 if (ConstantSDNode *Sh =
676 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000677 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000678 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
679 Offset = N.getOperand(1).getOperand(0);
680 else {
681 ShAmt = 0;
682 ShOpcVal = ARM_AM::no_shift;
683 }
Evan Chenga8e29892007-01-19 07:51:42 +0000684 } else {
685 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000686 }
687 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000688
Evan Chenga8e29892007-01-19 07:51:42 +0000689 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000690 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000691 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000692 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000693 if (ShOpcVal != ARM_AM::no_shift) {
694 // Check to see if the RHS of the shift is a constant, if not, we can't
695 // fold it.
696 if (ConstantSDNode *Sh =
697 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000698 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000699 if (!Subtarget->isCortexA9() ||
700 (N.hasOneUse() &&
701 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
702 Offset = N.getOperand(0).getOperand(0);
703 Base = N.getOperand(1);
704 } else {
705 ShAmt = 0;
706 ShOpcVal = ARM_AM::no_shift;
707 }
Evan Chenga8e29892007-01-19 07:51:42 +0000708 } else {
709 ShOpcVal = ARM_AM::no_shift;
710 }
711 }
712 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000713
Evan Chenga8e29892007-01-19 07:51:42 +0000714 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000715 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000716 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000717}
718
Owen Anderson793e7962011-07-26 20:54:26 +0000719bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000720 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000721 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000722 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
723 ? cast<LoadSDNode>(Op)->getAddressingMode()
724 : cast<StoreSDNode>(Op)->getAddressingMode();
725 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
726 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000727 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000728 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
729 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000730
731 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000732 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000733 unsigned ShAmt = 0;
734 if (ShOpcVal != ARM_AM::no_shift) {
735 // Check to see if the RHS of the shift is a constant, if not, we can't fold
736 // it.
737 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000738 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000739 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
740 Offset = N.getOperand(0);
741 else {
742 ShAmt = 0;
743 ShOpcVal = ARM_AM::no_shift;
744 }
Evan Chenga8e29892007-01-19 07:51:42 +0000745 } else {
746 ShOpcVal = ARM_AM::no_shift;
747 }
748 }
749
750 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000751 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000752 return true;
753}
754
Owen Anderson793e7962011-07-26 20:54:26 +0000755bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
756 SDValue &Offset, SDValue &Opc) {
757 unsigned Opcode = Op->getOpcode();
758 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
759 ? cast<LoadSDNode>(Op)->getAddressingMode()
760 : cast<StoreSDNode>(Op)->getAddressingMode();
761 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
762 ? ARM_AM::add : ARM_AM::sub;
763 int Val;
764 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
765 Offset = CurDAG->getRegister(0, MVT::i32);
766 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
767 ARM_AM::no_shift),
768 MVT::i32);
769 return true;
770 }
771
772 return false;
773}
774
775
776
Evan Chenga8e29892007-01-19 07:51:42 +0000777
Chris Lattner52a261b2010-09-21 20:31:19 +0000778bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000779 SDValue &Base, SDValue &Offset,
780 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000781 if (N.getOpcode() == ISD::SUB) {
782 // X - C is canonicalize to X + -C, no need to handle it here.
783 Base = N.getOperand(0);
784 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000785 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000786 return true;
787 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000788
Chris Lattner0a9481f2011-02-13 22:25:43 +0000789 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000790 Base = N;
791 if (N.getOpcode() == ISD::FrameIndex) {
792 int FI = cast<FrameIndexSDNode>(N)->getIndex();
793 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
794 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000795 Offset = CurDAG->getRegister(0, MVT::i32);
796 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000797 return true;
798 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000799
Evan Chenga8e29892007-01-19 07:51:42 +0000800 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000801 int RHSC;
802 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
803 -256 + 1, 256, RHSC)) { // 8 bits.
804 Base = N.getOperand(0);
805 if (Base.getOpcode() == ISD::FrameIndex) {
806 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
807 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000808 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000809 Offset = CurDAG->getRegister(0, MVT::i32);
810
811 ARM_AM::AddrOpc AddSub = ARM_AM::add;
812 if (RHSC < 0) {
813 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000814 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000815 }
816 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
817 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000818 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000819
Evan Chenga8e29892007-01-19 07:51:42 +0000820 Base = N.getOperand(0);
821 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000822 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000823 return true;
824}
825
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000826bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000827 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000828 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000829 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
830 ? cast<LoadSDNode>(Op)->getAddressingMode()
831 : cast<StoreSDNode>(Op)->getAddressingMode();
832 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
833 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000834 int Val;
835 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
836 Offset = CurDAG->getRegister(0, MVT::i32);
837 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
838 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000839 }
840
841 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000842 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000843 return true;
844}
845
Jim Grosbach3ab56582010-10-21 19:38:40 +0000846bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000847 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000848 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000849 Base = N;
850 if (N.getOpcode() == ISD::FrameIndex) {
851 int FI = cast<FrameIndexSDNode>(N)->getIndex();
852 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000853 } else if (N.getOpcode() == ARMISD::Wrapper &&
854 !(Subtarget->useMovt() &&
855 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000856 Base = N.getOperand(0);
857 }
858 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000859 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000860 return true;
861 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000862
Evan Chenga8e29892007-01-19 07:51:42 +0000863 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000864 int RHSC;
865 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
866 -256 + 1, 256, RHSC)) {
867 Base = N.getOperand(0);
868 if (Base.getOpcode() == ISD::FrameIndex) {
869 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
870 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000871 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000872
873 ARM_AM::AddrOpc AddSub = ARM_AM::add;
874 if (RHSC < 0) {
875 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000876 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000877 }
878 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
879 MVT::i32);
880 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000881 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000882
Evan Chenga8e29892007-01-19 07:51:42 +0000883 Base = N;
884 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000885 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000886 return true;
887}
888
Bob Wilson665814b2010-11-01 23:40:51 +0000889bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
890 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000891 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000892
893 unsigned Alignment = 0;
894 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
895 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
896 // The maximum alignment is equal to the memory size being referenced.
897 unsigned LSNAlign = LSN->getAlignment();
898 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
899 if (LSNAlign > MemSize && MemSize > 1)
900 Alignment = MemSize;
901 } else {
902 // All other uses of addrmode6 are for intrinsics. For now just record
903 // the raw alignment value; it will be refined later based on the legal
904 // alignment operands for the intrinsic.
905 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
906 }
907
908 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000909 return true;
910}
911
Bob Wilsonda525062011-02-25 06:42:42 +0000912bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
913 SDValue &Offset) {
914 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
915 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
916 if (AM != ISD::POST_INC)
917 return false;
918 Offset = N;
919 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
920 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
921 Offset = CurDAG->getRegister(0, MVT::i32);
922 }
923 return true;
924}
925
Chris Lattner52a261b2010-09-21 20:31:19 +0000926bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000927 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000928 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
929 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000930 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000931 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
932 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000933 return true;
934 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000935
Evan Chenga8e29892007-01-19 07:51:42 +0000936 return false;
937}
938
Bill Wendlingf4caf692010-12-14 03:36:38 +0000939
940//===----------------------------------------------------------------------===//
941// Thumb Addressing Modes
942//===----------------------------------------------------------------------===//
943
Chris Lattner52a261b2010-09-21 20:31:19 +0000944bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000945 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000946 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000947 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000948 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000949 return false;
950
951 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000952 return true;
953 }
954
Evan Chenga8e29892007-01-19 07:51:42 +0000955 Base = N.getOperand(0);
956 Offset = N.getOperand(1);
957 return true;
958}
959
Evan Cheng79d43262007-01-24 02:21:22 +0000960bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000961ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
962 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000963 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000964 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000965 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000966 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000967
Evan Cheng012f2d92007-01-24 08:53:17 +0000968 if (N.getOpcode() == ARMISD::Wrapper &&
969 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
970 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000971 }
972
Chris Lattner0a9481f2011-02-13 22:25:43 +0000973 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000974 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000975
Evan Chengad0e4652007-02-06 00:22:06 +0000976 // Thumb does not have [sp, r] address mode.
977 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
978 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
979 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000980 (RHSR && RHSR->getReg() == ARM::SP))
981 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000982
Daniel Dunbarec91d522011-01-19 15:12:16 +0000983 // FIXME: Why do we explicitly check for a match here and then return false?
984 // Presumably to allow something else to match, but shouldn't this be
985 // documented?
986 int RHSC;
987 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
988 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000989
990 Base = N.getOperand(0);
991 Offset = N.getOperand(1);
992 return true;
993}
994
995bool
996ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
997 SDValue &Base,
998 SDValue &Offset) {
999 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1000}
1001
1002bool
1003ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1004 SDValue &Base,
1005 SDValue &Offset) {
1006 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1007}
1008
1009bool
1010ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1011 SDValue &Base,
1012 SDValue &Offset) {
1013 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1014}
1015
1016bool
1017ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1018 SDValue &Base, SDValue &OffImm) {
1019 if (Scale == 4) {
1020 SDValue TmpBase, TmpOffImm;
1021 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1022 return false; // We want to select tLDRspi / tSTRspi instead.
1023
1024 if (N.getOpcode() == ARMISD::Wrapper &&
1025 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1026 return false; // We want to select tLDRpci instead.
1027 }
1028
Chris Lattner0a9481f2011-02-13 22:25:43 +00001029 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001030 if (N.getOpcode() == ARMISD::Wrapper &&
1031 !(Subtarget->useMovt() &&
1032 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1033 Base = N.getOperand(0);
1034 } else {
1035 Base = N;
1036 }
1037
Owen Anderson825b72b2009-08-11 20:47:22 +00001038 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001039 return true;
1040 }
1041
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001042 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1043 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1044 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1045 (RHSR && RHSR->getReg() == ARM::SP)) {
1046 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1047 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1048 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1049 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1050
1051 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1052 if (LHSC != 0 || RHSC != 0) return false;
1053
1054 Base = N;
1055 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1056 return true;
1057 }
1058
Evan Chenga8e29892007-01-19 07:51:42 +00001059 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001060 int RHSC;
1061 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1062 Base = N.getOperand(0);
1063 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1064 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001065 }
1066
Evan Chengc38f2bc2007-01-23 22:59:13 +00001067 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001068 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001069 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001070}
1071
Bill Wendlingf4caf692010-12-14 03:36:38 +00001072bool
1073ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1074 SDValue &OffImm) {
1075 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001076}
1077
Bill Wendlingf4caf692010-12-14 03:36:38 +00001078bool
1079ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1080 SDValue &OffImm) {
1081 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001082}
1083
Bill Wendlingf4caf692010-12-14 03:36:38 +00001084bool
1085ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1086 SDValue &OffImm) {
1087 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001088}
1089
Chris Lattner52a261b2010-09-21 20:31:19 +00001090bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1091 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001092 if (N.getOpcode() == ISD::FrameIndex) {
1093 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1094 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001095 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001096 return true;
1097 }
Evan Cheng79d43262007-01-24 02:21:22 +00001098
Chris Lattner0a9481f2011-02-13 22:25:43 +00001099 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001100 return false;
1101
1102 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001103 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1104 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001105 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001106 int RHSC;
1107 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1108 Base = N.getOperand(0);
1109 if (Base.getOpcode() == ISD::FrameIndex) {
1110 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1111 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001112 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001113 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1114 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001115 }
1116 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001117
Evan Chenga8e29892007-01-19 07:51:42 +00001118 return false;
1119}
1120
Bill Wendlingf4caf692010-12-14 03:36:38 +00001121
1122//===----------------------------------------------------------------------===//
1123// Thumb 2 Addressing Modes
1124//===----------------------------------------------------------------------===//
1125
1126
Chris Lattner52a261b2010-09-21 20:31:19 +00001127bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001128 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001129 if (DisableShifterOp)
1130 return false;
1131
Evan Chengee04a6d2011-07-20 23:34:39 +00001132 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001133
1134 // Don't match base register only case. That is matched to a separate
1135 // lower complexity pattern with explicit register operand.
1136 if (ShOpcVal == ARM_AM::no_shift) return false;
1137
1138 BaseReg = N.getOperand(0);
1139 unsigned ShImmVal = 0;
1140 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1141 ShImmVal = RHS->getZExtValue() & 31;
1142 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1143 return true;
1144 }
1145
1146 return false;
1147}
1148
Chris Lattner52a261b2010-09-21 20:31:19 +00001149bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001150 SDValue &Base, SDValue &OffImm) {
1151 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001152
Evan Cheng3a214252009-08-11 08:52:18 +00001153 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001154 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1155 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001156 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001157 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001158 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1159 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001160 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001161 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001162 }
Owen Anderson099e5552011-03-18 19:46:58 +00001163
Chris Lattner0a9481f2011-02-13 22:25:43 +00001164 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001165 !(Subtarget->useMovt() &&
1166 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001167 Base = N.getOperand(0);
1168 if (Base.getOpcode() == ISD::TargetConstantPool)
1169 return false; // We want to select t2LDRpci instead.
1170 } else
1171 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001172 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001173 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001174 }
Evan Cheng055b0312009-06-29 07:51:04 +00001175
1176 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001177 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001178 // Let t2LDRi8 handle (R - imm8).
1179 return false;
1180
Evan Cheng055b0312009-06-29 07:51:04 +00001181 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001182 if (N.getOpcode() == ISD::SUB)
1183 RHSC = -RHSC;
1184
1185 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001186 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001187 if (Base.getOpcode() == ISD::FrameIndex) {
1188 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1189 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1190 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001191 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001192 return true;
1193 }
1194 }
1195
Evan Cheng3a214252009-08-11 08:52:18 +00001196 // Base only.
1197 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001198 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001199 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001200}
1201
Chris Lattner52a261b2010-09-21 20:31:19 +00001202bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001203 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001204 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001205 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1206 !CurDAG->isBaseWithConstantOffset(N))
1207 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001208
Chris Lattner0a9481f2011-02-13 22:25:43 +00001209 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1210 int RHSC = (int)RHS->getSExtValue();
1211 if (N.getOpcode() == ISD::SUB)
1212 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001213
Chris Lattner0a9481f2011-02-13 22:25:43 +00001214 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1215 Base = N.getOperand(0);
1216 if (Base.getOpcode() == ISD::FrameIndex) {
1217 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1218 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001219 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001220 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1221 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001222 }
1223 }
1224
1225 return false;
1226}
1227
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001228bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001229 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001230 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001231 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1232 ? cast<LoadSDNode>(Op)->getAddressingMode()
1233 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001234 int RHSC;
1235 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1236 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1237 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1238 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1239 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001240 }
1241
1242 return false;
1243}
1244
Chris Lattner52a261b2010-09-21 20:31:19 +00001245bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001246 SDValue &Base,
1247 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001248 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001249 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001250 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001251
Evan Cheng3a214252009-08-11 08:52:18 +00001252 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1253 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1254 int RHSC = (int)RHS->getZExtValue();
1255 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1256 return false;
1257 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001258 return false;
1259 }
1260
Evan Chengf40deed2010-10-27 23:41:30 +00001261 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1262 // Compute R + (R << [1,2,3]) and reuse it.
1263 Base = N;
1264 return false;
1265 }
1266
Evan Cheng055b0312009-06-29 07:51:04 +00001267 // Look for (R + R) or (R + (R << [1,2,3])).
1268 unsigned ShAmt = 0;
1269 Base = N.getOperand(0);
1270 OffReg = N.getOperand(1);
1271
1272 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001273 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001274 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001275 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001276 if (ShOpcVal == ARM_AM::lsl)
1277 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001278 }
1279
Evan Cheng055b0312009-06-29 07:51:04 +00001280 if (ShOpcVal == ARM_AM::lsl) {
1281 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1282 // it.
1283 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1284 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001285 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1286 OffReg = OffReg.getOperand(0);
1287 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001288 ShAmt = 0;
1289 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001290 }
Evan Cheng055b0312009-06-29 07:51:04 +00001291 } else {
1292 ShOpcVal = ARM_AM::no_shift;
1293 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001294 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001295
Owen Anderson825b72b2009-08-11 20:47:22 +00001296 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001297
1298 return true;
1299}
1300
1301//===--------------------------------------------------------------------===//
1302
Evan Chengee568cf2007-07-05 07:15:27 +00001303/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001304static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001305 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001306}
1307
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001308SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1309 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001310 ISD::MemIndexedMode AM = LD->getAddressingMode();
1311 if (AM == ISD::UNINDEXED)
1312 return NULL;
1313
Owen Andersone50ed302009-08-10 22:56:29 +00001314 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001315 SDValue Offset, AMOpc;
1316 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1317 unsigned Opcode = 0;
1318 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001319 if (LoadedVT == MVT::i32 &&
Owen Anderson793e7962011-07-26 20:54:26 +00001320 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1321 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001322 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001323 } else if (LoadedVT == MVT::i32 &&
1324 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1325 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST_REG;
1326 Match = true;
1327
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001329 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001330 Match = true;
1331 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1332 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1333 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001334 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001335 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001336 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001337 Match = true;
1338 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1339 }
1340 } else {
Owen Anderson793e7962011-07-26 20:54:26 +00001341 if (SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001342 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001343 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST_IMM;
1344 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1345 Match = true;
1346 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001347 }
1348 }
1349 }
1350
1351 if (Match) {
1352 SDValue Chain = LD->getChain();
1353 SDValue Base = LD->getBasePtr();
1354 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001355 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001356 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001357 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001358 }
1359
1360 return NULL;
1361}
1362
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001363SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1364 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001365 ISD::MemIndexedMode AM = LD->getAddressingMode();
1366 if (AM == ISD::UNINDEXED)
1367 return NULL;
1368
Owen Andersone50ed302009-08-10 22:56:29 +00001369 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001370 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001371 SDValue Offset;
1372 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1373 unsigned Opcode = 0;
1374 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001375 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001376 switch (LoadedVT.getSimpleVT().SimpleTy) {
1377 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001378 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1379 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001380 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001381 if (isSExtLd)
1382 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1383 else
1384 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001385 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001386 case MVT::i8:
1387 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001388 if (isSExtLd)
1389 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1390 else
1391 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001392 break;
1393 default:
1394 return NULL;
1395 }
1396 Match = true;
1397 }
1398
1399 if (Match) {
1400 SDValue Chain = LD->getChain();
1401 SDValue Base = LD->getBasePtr();
1402 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001403 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001404 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001405 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001406 }
1407
1408 return NULL;
1409}
1410
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001411/// PairSRegs - Form a D register from a pair of S registers.
1412///
1413SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1414 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001415 SDValue RegClass =
1416 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001417 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1418 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001419 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1420 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001421}
1422
Evan Cheng603afbf2010-05-10 17:34:18 +00001423/// PairDRegs - Form a quad register from a pair of D registers.
1424///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001425SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1426 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001427 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001428 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1429 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001430 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1431 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001432}
1433
Evan Cheng7f687192010-05-14 00:21:45 +00001434/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001435///
1436SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1437 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001438 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001439 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1440 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001441 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1442 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001443}
1444
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001445/// QuadSRegs - Form 4 consecutive S registers.
1446///
1447SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1448 SDValue V2, SDValue V3) {
1449 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001450 SDValue RegClass =
1451 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001452 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1453 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1454 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1455 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001456 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1457 V2, SubReg2, V3, SubReg3 };
1458 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001459}
1460
Evan Cheng7f687192010-05-14 00:21:45 +00001461/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001462///
1463SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1464 SDValue V2, SDValue V3) {
1465 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001466 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001467 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1468 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1469 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1470 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001471 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1472 V2, SubReg2, V3, SubReg3 };
1473 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001474}
1475
Evan Cheng8f6de382010-05-16 03:27:48 +00001476/// QuadQRegs - Form 4 consecutive Q registers.
1477///
1478SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1479 SDValue V2, SDValue V3) {
1480 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001481 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001482 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1483 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1484 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1485 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001486 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1487 V2, SubReg2, V3, SubReg3 };
1488 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001489}
1490
Bob Wilson2a6e6162010-09-23 23:42:37 +00001491/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1492/// of a NEON VLD or VST instruction. The supported values depend on the
1493/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001494SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1495 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001496 unsigned NumRegs = NumVecs;
1497 if (!is64BitVector && NumVecs < 3)
1498 NumRegs *= 2;
1499
Bob Wilson665814b2010-11-01 23:40:51 +00001500 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001501 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001502 Alignment = 32;
1503 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1504 Alignment = 16;
1505 else if (Alignment >= 8)
1506 Alignment = 8;
1507 else
1508 Alignment = 0;
1509
1510 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001511}
1512
Bob Wilson1c3ef902011-02-07 17:43:21 +00001513SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001514 unsigned *DOpcodes, unsigned *QOpcodes0,
1515 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001516 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001517 DebugLoc dl = N->getDebugLoc();
1518
Bob Wilson226036e2010-03-20 22:13:40 +00001519 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001520 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1521 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001522 return NULL;
1523
1524 SDValue Chain = N->getOperand(0);
1525 EVT VT = N->getValueType(0);
1526 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001527 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001528
Bob Wilson3e36f132009-10-14 17:28:52 +00001529 unsigned OpcodeIndex;
1530 switch (VT.getSimpleVT().SimpleTy) {
1531 default: llvm_unreachable("unhandled vld type");
1532 // Double-register operations:
1533 case MVT::v8i8: OpcodeIndex = 0; break;
1534 case MVT::v4i16: OpcodeIndex = 1; break;
1535 case MVT::v2f32:
1536 case MVT::v2i32: OpcodeIndex = 2; break;
1537 case MVT::v1i64: OpcodeIndex = 3; break;
1538 // Quad-register operations:
1539 case MVT::v16i8: OpcodeIndex = 0; break;
1540 case MVT::v8i16: OpcodeIndex = 1; break;
1541 case MVT::v4f32:
1542 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001543 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001544 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001545 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001546 }
1547
Bob Wilsonf5721912010-09-03 18:16:02 +00001548 EVT ResTy;
1549 if (NumVecs == 1)
1550 ResTy = VT;
1551 else {
1552 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1553 if (!is64BitVector)
1554 ResTyElts *= 2;
1555 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1556 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001557 std::vector<EVT> ResTys;
1558 ResTys.push_back(ResTy);
1559 if (isUpdating)
1560 ResTys.push_back(MVT::i32);
1561 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001562
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001563 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001564 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001565 SDNode *VLd;
1566 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001567
Bob Wilson1c3ef902011-02-07 17:43:21 +00001568 // Double registers and VLD1/VLD2 quad registers are directly supported.
1569 if (is64BitVector || NumVecs <= 2) {
1570 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1571 QOpcodes0[OpcodeIndex]);
1572 Ops.push_back(MemAddr);
1573 Ops.push_back(Align);
1574 if (isUpdating) {
1575 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1576 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001577 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001578 Ops.push_back(Pred);
1579 Ops.push_back(Reg0);
1580 Ops.push_back(Chain);
1581 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001582
Bob Wilson3e36f132009-10-14 17:28:52 +00001583 } else {
1584 // Otherwise, quad registers are loaded with two separate instructions,
1585 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001586 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001587
Bob Wilson1c3ef902011-02-07 17:43:21 +00001588 // Load the even subregs. This is always an updating load, so that it
1589 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001590 SDValue ImplDef =
1591 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1592 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001593 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1594 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001595 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001596
Bob Wilson24f995d2009-10-14 18:32:29 +00001597 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001598 Ops.push_back(SDValue(VLdA, 1));
1599 Ops.push_back(Align);
1600 if (isUpdating) {
1601 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1602 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1603 "only constant post-increment update allowed for VLD3/4");
1604 (void)Inc;
1605 Ops.push_back(Reg0);
1606 }
1607 Ops.push_back(SDValue(VLdA, 0));
1608 Ops.push_back(Pred);
1609 Ops.push_back(Reg0);
1610 Ops.push_back(Chain);
1611 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1612 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001613 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001614
Evan Chengb58a3402011-04-19 00:04:03 +00001615 // Transfer memoperands.
1616 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1617 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1618 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1619
Bob Wilson1c3ef902011-02-07 17:43:21 +00001620 if (NumVecs == 1)
1621 return VLd;
1622
1623 // Extract out the subregisters.
1624 SDValue SuperReg = SDValue(VLd, 0);
1625 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1626 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1627 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1628 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1629 ReplaceUses(SDValue(N, Vec),
1630 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1631 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1632 if (isUpdating)
1633 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001634 return NULL;
1635}
1636
Bob Wilson1c3ef902011-02-07 17:43:21 +00001637SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001638 unsigned *DOpcodes, unsigned *QOpcodes0,
1639 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001640 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001641 DebugLoc dl = N->getDebugLoc();
1642
Bob Wilson226036e2010-03-20 22:13:40 +00001643 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001644 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1645 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1646 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001647 return NULL;
1648
Evan Chengb58a3402011-04-19 00:04:03 +00001649 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1650 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1651
Bob Wilson24f995d2009-10-14 18:32:29 +00001652 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001653 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001654 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001655 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001656
Bob Wilson24f995d2009-10-14 18:32:29 +00001657 unsigned OpcodeIndex;
1658 switch (VT.getSimpleVT().SimpleTy) {
1659 default: llvm_unreachable("unhandled vst type");
1660 // Double-register operations:
1661 case MVT::v8i8: OpcodeIndex = 0; break;
1662 case MVT::v4i16: OpcodeIndex = 1; break;
1663 case MVT::v2f32:
1664 case MVT::v2i32: OpcodeIndex = 2; break;
1665 case MVT::v1i64: OpcodeIndex = 3; break;
1666 // Quad-register operations:
1667 case MVT::v16i8: OpcodeIndex = 0; break;
1668 case MVT::v8i16: OpcodeIndex = 1; break;
1669 case MVT::v4f32:
1670 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001671 case MVT::v2i64: OpcodeIndex = 3;
1672 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1673 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001674 }
1675
Bob Wilson1c3ef902011-02-07 17:43:21 +00001676 std::vector<EVT> ResTys;
1677 if (isUpdating)
1678 ResTys.push_back(MVT::i32);
1679 ResTys.push_back(MVT::Other);
1680
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001681 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001682 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001683 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001684
Bob Wilson1c3ef902011-02-07 17:43:21 +00001685 // Double registers and VST1/VST2 quad registers are directly supported.
1686 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001687 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001688 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001689 SrcReg = N->getOperand(Vec0Idx);
1690 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001691 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001692 SDValue V0 = N->getOperand(Vec0Idx + 0);
1693 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001694 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001695 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001696 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001697 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001698 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001699 // an undef.
1700 SDValue V3 = (NumVecs == 3)
1701 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001702 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001703 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001704 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001705 } else {
1706 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001707 SDValue Q0 = N->getOperand(Vec0Idx);
1708 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001709 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001710 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001711
1712 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1713 QOpcodes0[OpcodeIndex]);
1714 Ops.push_back(MemAddr);
1715 Ops.push_back(Align);
1716 if (isUpdating) {
1717 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1718 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1719 }
1720 Ops.push_back(SrcReg);
1721 Ops.push_back(Pred);
1722 Ops.push_back(Reg0);
1723 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001724 SDNode *VSt =
1725 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1726
1727 // Transfer memoperands.
1728 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1729
1730 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001731 }
1732
1733 // Otherwise, quad registers are stored with two separate instructions,
1734 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001735
Bob Wilson07f6e802010-06-16 21:34:01 +00001736 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001737 SDValue V0 = N->getOperand(Vec0Idx + 0);
1738 SDValue V1 = N->getOperand(Vec0Idx + 1);
1739 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001740 SDValue V3 = (NumVecs == 3)
1741 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001742 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001743 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001744
Bob Wilson1c3ef902011-02-07 17:43:21 +00001745 // Store the even D registers. This is always an updating store, so that it
1746 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001747 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1748 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1749 MemAddr.getValueType(),
1750 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001751 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001752 Chain = SDValue(VStA, 1);
1753
1754 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001755 Ops.push_back(SDValue(VStA, 0));
1756 Ops.push_back(Align);
1757 if (isUpdating) {
1758 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1759 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1760 "only constant post-increment update allowed for VST3/4");
1761 (void)Inc;
1762 Ops.push_back(Reg0);
1763 }
1764 Ops.push_back(RegSeq);
1765 Ops.push_back(Pred);
1766 Ops.push_back(Reg0);
1767 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001768 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1769 Ops.data(), Ops.size());
1770 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1771 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001772}
1773
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001774SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001775 bool isUpdating, unsigned NumVecs,
1776 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001777 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001778 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001779 DebugLoc dl = N->getDebugLoc();
1780
Bob Wilson226036e2010-03-20 22:13:40 +00001781 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001782 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1783 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1784 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001785 return NULL;
1786
Evan Chengb58a3402011-04-19 00:04:03 +00001787 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1788 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1789
Bob Wilsona7c397c2009-10-14 16:19:03 +00001790 SDValue Chain = N->getOperand(0);
1791 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001792 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1793 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001794 bool is64BitVector = VT.is64BitVector();
1795
Bob Wilson665814b2010-11-01 23:40:51 +00001796 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001797 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001798 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001799 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1800 if (Alignment > NumBytes)
1801 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001802 if (Alignment < 8 && Alignment < NumBytes)
1803 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001804 // Alignment must be a power of two; make sure of that.
1805 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001806 if (Alignment == 1)
1807 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001808 }
Bob Wilson665814b2010-11-01 23:40:51 +00001809 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001810
Bob Wilsona7c397c2009-10-14 16:19:03 +00001811 unsigned OpcodeIndex;
1812 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001813 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 // Double-register operations:
1815 case MVT::v8i8: OpcodeIndex = 0; break;
1816 case MVT::v4i16: OpcodeIndex = 1; break;
1817 case MVT::v2f32:
1818 case MVT::v2i32: OpcodeIndex = 2; break;
1819 // Quad-register operations:
1820 case MVT::v8i16: OpcodeIndex = 0; break;
1821 case MVT::v4f32:
1822 case MVT::v4i32: OpcodeIndex = 1; break;
1823 }
1824
Bob Wilson1c3ef902011-02-07 17:43:21 +00001825 std::vector<EVT> ResTys;
1826 if (IsLoad) {
1827 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1828 if (!is64BitVector)
1829 ResTyElts *= 2;
1830 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1831 MVT::i64, ResTyElts));
1832 }
1833 if (isUpdating)
1834 ResTys.push_back(MVT::i32);
1835 ResTys.push_back(MVT::Other);
1836
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001837 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001838 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001839
Bob Wilson1c3ef902011-02-07 17:43:21 +00001840 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001841 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001842 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001843 if (isUpdating) {
1844 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1845 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1846 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001847
Bob Wilson8466fa12010-09-13 23:01:35 +00001848 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001849 SDValue V0 = N->getOperand(Vec0Idx + 0);
1850 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001851 if (NumVecs == 2) {
1852 if (is64BitVector)
1853 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1854 else
1855 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001856 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001857 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001858 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001859 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1860 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001861 if (is64BitVector)
1862 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1863 else
1864 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001865 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001866 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001867 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001868 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001869 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001870 Ops.push_back(Chain);
1871
Bob Wilson1c3ef902011-02-07 17:43:21 +00001872 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1873 QOpcodes[OpcodeIndex]);
1874 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1875 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001876 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001877 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001878 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001879
Bob Wilson8466fa12010-09-13 23:01:35 +00001880 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001881 SuperReg = SDValue(VLdLn, 0);
1882 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1883 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1884 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001885 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1886 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001887 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1888 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1889 if (isUpdating)
1890 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001891 return NULL;
1892}
1893
Bob Wilson1c3ef902011-02-07 17:43:21 +00001894SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1895 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001896 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1897 DebugLoc dl = N->getDebugLoc();
1898
1899 SDValue MemAddr, Align;
1900 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1901 return NULL;
1902
Evan Chengb58a3402011-04-19 00:04:03 +00001903 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1904 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1905
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001906 SDValue Chain = N->getOperand(0);
1907 EVT VT = N->getValueType(0);
1908
1909 unsigned Alignment = 0;
1910 if (NumVecs != 3) {
1911 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1912 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1913 if (Alignment > NumBytes)
1914 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001915 if (Alignment < 8 && Alignment < NumBytes)
1916 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001917 // Alignment must be a power of two; make sure of that.
1918 Alignment = (Alignment & -Alignment);
1919 if (Alignment == 1)
1920 Alignment = 0;
1921 }
1922 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1923
1924 unsigned OpcodeIndex;
1925 switch (VT.getSimpleVT().SimpleTy) {
1926 default: llvm_unreachable("unhandled vld-dup type");
1927 case MVT::v8i8: OpcodeIndex = 0; break;
1928 case MVT::v4i16: OpcodeIndex = 1; break;
1929 case MVT::v2f32:
1930 case MVT::v2i32: OpcodeIndex = 2; break;
1931 }
1932
1933 SDValue Pred = getAL(CurDAG);
1934 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1935 SDValue SuperReg;
1936 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001937 SmallVector<SDValue, 6> Ops;
1938 Ops.push_back(MemAddr);
1939 Ops.push_back(Align);
1940 if (isUpdating) {
1941 SDValue Inc = N->getOperand(2);
1942 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1943 }
1944 Ops.push_back(Pred);
1945 Ops.push_back(Reg0);
1946 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001947
1948 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001949 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001950 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001951 if (isUpdating)
1952 ResTys.push_back(MVT::i32);
1953 ResTys.push_back(MVT::Other);
1954 SDNode *VLdDup =
1955 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001956 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001957 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001958
1959 // Extract the subregisters.
1960 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1961 unsigned SubIdx = ARM::dsub_0;
1962 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1963 ReplaceUses(SDValue(N, Vec),
1964 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001965 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1966 if (isUpdating)
1967 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001968 return NULL;
1969}
1970
Bob Wilson78dfbc32010-07-07 00:08:54 +00001971SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1972 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001973 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1974 DebugLoc dl = N->getDebugLoc();
1975 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001976 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001977
1978 // Form a REG_SEQUENCE to force register allocation.
1979 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001980 SDValue V0 = N->getOperand(FirstTblReg + 0);
1981 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001982 if (NumVecs == 2)
1983 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1984 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001985 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001986 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001987 // an undef.
1988 SDValue V3 = (NumVecs == 3)
1989 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001990 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001991 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1992 }
1993
Bob Wilson78dfbc32010-07-07 00:08:54 +00001994 SmallVector<SDValue, 6> Ops;
1995 if (IsExt)
1996 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001997 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001998 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001999 Ops.push_back(getAL(CurDAG)); // predicate
2000 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002001 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002002}
2003
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002004SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002005 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002006 if (!Subtarget->hasV6T2Ops())
2007 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002008
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002009 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2010 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2011
2012
2013 // For unsigned extracts, check for a shift right and mask
2014 unsigned And_imm = 0;
2015 if (N->getOpcode() == ISD::AND) {
2016 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2017
2018 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2019 if (And_imm & (And_imm + 1))
2020 return NULL;
2021
2022 unsigned Srl_imm = 0;
2023 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2024 Srl_imm)) {
2025 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2026
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002027 // Note: The width operand is encoded as width-1.
2028 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002029 unsigned LSB = Srl_imm;
2030 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2031 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2032 CurDAG->getTargetConstant(LSB, MVT::i32),
2033 CurDAG->getTargetConstant(Width, MVT::i32),
2034 getAL(CurDAG), Reg0 };
2035 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2036 }
2037 }
2038 return NULL;
2039 }
2040
2041 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002042 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002043 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002044 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2045 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002047 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002048 // Note: The width operand is encoded as width-1.
2049 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002050 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002051 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002052 return NULL;
2053 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002054 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002055 CurDAG->getTargetConstant(LSB, MVT::i32),
2056 CurDAG->getTargetConstant(Width, MVT::i32),
2057 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002058 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002059 }
2060 }
2061 return NULL;
2062}
2063
Evan Cheng9ef48352009-11-20 00:54:03 +00002064SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002065SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002066 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2067 SDValue CPTmp0;
2068 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002069 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2071 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2072 unsigned Opc = 0;
2073 switch (SOShOp) {
2074 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2075 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2076 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2077 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2078 default:
2079 llvm_unreachable("Unknown so_reg opcode!");
2080 break;
2081 }
2082 SDValue SOShImm =
2083 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2084 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2085 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002086 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002087 }
2088 return 0;
2089}
2090
2091SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002092SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002093 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2094 SDValue CPTmp0;
2095 SDValue CPTmp1;
2096 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002097 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002098 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002099 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2100 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002101 }
2102
2103 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2104 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2105 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2106 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002107 }
2108 return 0;
2109}
2110
2111SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002112SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002113 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002114 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002115 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002116 return 0;
2117
Evan Cheng63f35442010-11-13 02:25:14 +00002118 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002119 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002120 if (is_t2_so_imm(TrueImm)) {
2121 Opc = ARM::t2MOVCCi;
2122 } else if (TrueImm <= 0xffff) {
2123 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002124 } else if (is_t2_so_imm_not(TrueImm)) {
2125 TrueImm = ~TrueImm;
2126 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002127 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002128 // Large immediate.
2129 Opc = ARM::t2MOVCCi32imm;
2130 }
2131
2132 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002133 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002134 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2135 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002136 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002137 }
Evan Cheng63f35442010-11-13 02:25:14 +00002138
Evan Cheng9ef48352009-11-20 00:54:03 +00002139 return 0;
2140}
2141
2142SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002143SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002144 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002145 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2146 if (!T)
2147 return 0;
2148
Evan Cheng63f35442010-11-13 02:25:14 +00002149 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002150 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002151 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002152 if (isSoImm) {
2153 Opc = ARM::MOVCCi;
2154 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2155 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002156 } else if (is_so_imm_not(TrueImm)) {
2157 TrueImm = ~TrueImm;
2158 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002159 } else if (TrueVal.getNode()->hasOneUse() &&
2160 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002161 // Large immediate.
2162 Opc = ARM::MOVCCi32imm;
2163 }
2164
2165 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002166 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002167 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2168 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002169 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002170 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002171
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 return 0;
2173}
2174
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002175SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2176 EVT VT = N->getValueType(0);
2177 SDValue FalseVal = N->getOperand(0);
2178 SDValue TrueVal = N->getOperand(1);
2179 SDValue CC = N->getOperand(2);
2180 SDValue CCR = N->getOperand(3);
2181 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002182 assert(CC.getOpcode() == ISD::Constant);
2183 assert(CCR.getOpcode() == ISD::Register);
2184 ARMCC::CondCodes CCVal =
2185 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002186
2187 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2188 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2189 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2190 // Pattern complexity = 18 cost = 1 size = 0
2191 SDValue CPTmp0;
2192 SDValue CPTmp1;
2193 SDValue CPTmp2;
2194 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002195 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002196 CCVal, CCR, InFlag);
2197 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002198 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002199 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2200 if (Res)
2201 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002202 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002203 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002204 CCVal, CCR, InFlag);
2205 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002206 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002207 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2208 if (Res)
2209 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002210 }
2211
2212 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002213 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002214 // (imm:i32):$cc)
2215 // Emits: (MOVCCi:i32 GPR:i32:$false,
2216 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2217 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002218 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002219 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002220 CCVal, CCR, InFlag);
2221 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002222 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002223 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2224 if (Res)
2225 return Res;
2226 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002227 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002228 CCVal, CCR, InFlag);
2229 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002230 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002231 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2232 if (Res)
2233 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002234 }
2235 }
2236
2237 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2238 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2239 // Pattern complexity = 6 cost = 1 size = 0
2240 //
2241 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2242 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2243 // Pattern complexity = 6 cost = 11 size = 0
2244 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002245 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002246 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2247 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002248 unsigned Opc = 0;
2249 switch (VT.getSimpleVT().SimpleTy) {
2250 default: assert(false && "Illegal conditional move type!");
2251 break;
2252 case MVT::i32:
2253 Opc = Subtarget->isThumb()
2254 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2255 : ARM::MOVCCr;
2256 break;
2257 case MVT::f32:
2258 Opc = ARM::VMOVScc;
2259 break;
2260 case MVT::f64:
2261 Opc = ARM::VMOVDcc;
2262 break;
2263 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002264 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002265}
2266
Evan Chengde8aa4e2010-05-05 18:28:36 +00002267SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2268 // The only time a CONCAT_VECTORS operation can have legal types is when
2269 // two 64-bit vectors are concatenated to a 128-bit vector.
2270 EVT VT = N->getValueType(0);
2271 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2272 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002273 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002274}
2275
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002276SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002277 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002278
Dan Gohmane8be6c62008-07-17 19:10:17 +00002279 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002280 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002281
2282 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002283 default: break;
2284 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002285 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002286 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002287 if (Subtarget->hasThumb2())
2288 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2289 // be done with MOV + MOVT, at worst.
2290 UseCP = 0;
2291 else {
2292 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002293 UseCP = (Val > 255 && // MOV
2294 ~Val > 255 && // MOV + MVN
2295 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002296 } else
2297 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2298 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2299 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2300 }
2301
Evan Chenga8e29892007-01-19 07:51:42 +00002302 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002303 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002304 CurDAG->getTargetConstantPool(ConstantInt::get(
2305 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002306 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002307
2308 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002309 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002310 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002311 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002312 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002313 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002314 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002315 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002316 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002317 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002318 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002319 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002320 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002321 CurDAG->getEntryNode()
2322 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002323 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002324 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002325 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002326 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002327 return NULL;
2328 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002329
Evan Chenga8e29892007-01-19 07:51:42 +00002330 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002331 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002332 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002333 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002334 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002335 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002336 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002337 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002338 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2339 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002340 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002341 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2342 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002343 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2344 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2345 CurDAG->getRegister(0, MVT::i32) };
2346 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002347 }
Evan Chenga8e29892007-01-19 07:51:42 +00002348 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002349 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002350 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002351 return I;
2352 break;
2353 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002354 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002355 return I;
2356 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002357 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002358 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002359 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002360 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002361 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002362 if (!RHSV) break;
2363 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002364 unsigned ShImm = Log2_32(RHSV-1);
2365 if (ShImm >= 32)
2366 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002367 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002368 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002369 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2370 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002371 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002372 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002373 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002374 } else {
2375 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002376 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002377 }
Evan Chenga8e29892007-01-19 07:51:42 +00002378 }
2379 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002380 unsigned ShImm = Log2_32(RHSV+1);
2381 if (ShImm >= 32)
2382 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002383 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002384 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002385 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2386 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002387 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002388 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2389 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002390 } else {
2391 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002392 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002393 }
Evan Chenga8e29892007-01-19 07:51:42 +00002394 }
2395 }
2396 break;
Evan Cheng20956592009-10-21 08:15:52 +00002397 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002398 // Check for unsigned bitfield extract
2399 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2400 return I;
2401
Evan Cheng20956592009-10-21 08:15:52 +00002402 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2403 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2404 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2405 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2406 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002407 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002408 if (VT != MVT::i32)
2409 break;
2410 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2411 ? ARM::t2MOVTi16
2412 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2413 if (!Opc)
2414 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002415 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002416 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2417 if (!N1C)
2418 break;
2419 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2420 SDValue N2 = N0.getOperand(1);
2421 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2422 if (!N2C)
2423 break;
2424 unsigned N1CVal = N1C->getZExtValue();
2425 unsigned N2CVal = N2C->getZExtValue();
2426 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2427 (N1CVal & 0xffffU) == 0xffffU &&
2428 (N2CVal & 0xffffU) == 0x0U) {
2429 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2430 MVT::i32);
2431 SDValue Ops[] = { N0.getOperand(0), Imm16,
2432 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2433 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2434 }
2435 }
2436 break;
2437 }
Jim Grosbache5165492009-11-09 00:11:35 +00002438 case ARMISD::VMOVRRD:
2439 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002440 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002441 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002442 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002443 if (Subtarget->isThumb1Only())
2444 break;
2445 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002446 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002447 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2448 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002449 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002450 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002451 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002452 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2453 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002454 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2455 ARM::UMULL : ARM::UMULLv5,
2456 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002457 }
Evan Chengee568cf2007-07-05 07:15:27 +00002458 }
Dan Gohman525178c2007-10-08 18:33:35 +00002459 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002460 if (Subtarget->isThumb1Only())
2461 break;
2462 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002463 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002464 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002465 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002466 } else {
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),
2469 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002470 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2471 ARM::SMULL : ARM::SMULLv5,
2472 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002473 }
Evan Chengee568cf2007-07-05 07:15:27 +00002474 }
Evan Chenga8e29892007-01-19 07:51:42 +00002475 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002476 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002477 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002478 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002479 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002480 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002481 if (ResNode)
2482 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002483 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002484 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002485 }
Evan Chengee568cf2007-07-05 07:15:27 +00002486 case ARMISD::BRCOND: {
2487 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2488 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2489 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002490
Evan Chengee568cf2007-07-05 07:15:27 +00002491 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2492 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2493 // Pattern complexity = 6 cost = 1 size = 0
2494
David Goodwin5e47a9a2009-06-30 18:04:13 +00002495 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2496 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2497 // Pattern complexity = 6 cost = 1 size = 0
2498
Jim Grosbach764ab522009-08-11 15:33:49 +00002499 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002500 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002501 SDValue Chain = N->getOperand(0);
2502 SDValue N1 = N->getOperand(1);
2503 SDValue N2 = N->getOperand(2);
2504 SDValue N3 = N->getOperand(3);
2505 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002506 assert(N1.getOpcode() == ISD::BasicBlock);
2507 assert(N2.getOpcode() == ISD::Constant);
2508 assert(N3.getOpcode() == ISD::Register);
2509
Dan Gohman475871a2008-07-27 21:46:04 +00002510 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002511 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002512 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002513 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002514 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002515 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002516 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002517 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002518 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002519 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002520 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002521 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002522 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002523 return NULL;
2524 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002525 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002526 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002527 case ARMISD::VZIP: {
2528 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002529 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002530 switch (VT.getSimpleVT().SimpleTy) {
2531 default: return NULL;
2532 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2533 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2534 case MVT::v2f32:
2535 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2536 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2537 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2538 case MVT::v4f32:
2539 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2540 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002541 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002542 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2543 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2544 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002545 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002546 case ARMISD::VUZP: {
2547 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002548 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002549 switch (VT.getSimpleVT().SimpleTy) {
2550 default: return NULL;
2551 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2552 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2553 case MVT::v2f32:
2554 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2555 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2556 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2557 case MVT::v4f32:
2558 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2559 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002560 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002561 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2562 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2563 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002564 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002565 case ARMISD::VTRN: {
2566 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002567 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002568 switch (VT.getSimpleVT().SimpleTy) {
2569 default: return NULL;
2570 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2571 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2572 case MVT::v2f32:
2573 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2574 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2575 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2576 case MVT::v4f32:
2577 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2578 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002579 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002580 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2581 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2582 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002583 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002584 case ARMISD::BUILD_VECTOR: {
2585 EVT VecVT = N->getValueType(0);
2586 EVT EltVT = VecVT.getVectorElementType();
2587 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002588 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002589 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2590 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2591 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002592 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002593 if (NumElts == 2)
2594 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2595 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2596 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2597 N->getOperand(2), N->getOperand(3));
2598 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002599
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002600 case ARMISD::VLD2DUP: {
2601 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2602 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002603 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002604 }
2605
Bob Wilson86c6d802010-11-29 19:35:29 +00002606 case ARMISD::VLD3DUP: {
2607 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2608 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002609 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002610 }
2611
Bob Wilson6c4c9822010-11-30 00:00:35 +00002612 case ARMISD::VLD4DUP: {
2613 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2614 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002615 return SelectVLDDup(N, false, 4, Opcodes);
2616 }
2617
2618 case ARMISD::VLD2DUP_UPD: {
2619 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2620 ARM::VLD2DUPd32Pseudo_UPD };
2621 return SelectVLDDup(N, true, 2, Opcodes);
2622 }
2623
2624 case ARMISD::VLD3DUP_UPD: {
2625 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2626 ARM::VLD3DUPd32Pseudo_UPD };
2627 return SelectVLDDup(N, true, 3, Opcodes);
2628 }
2629
2630 case ARMISD::VLD4DUP_UPD: {
2631 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2632 ARM::VLD4DUPd32Pseudo_UPD };
2633 return SelectVLDDup(N, true, 4, Opcodes);
2634 }
2635
2636 case ARMISD::VLD1_UPD: {
2637 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2638 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2639 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2640 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2641 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2642 }
2643
2644 case ARMISD::VLD2_UPD: {
2645 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2646 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2647 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2648 ARM::VLD2q32Pseudo_UPD };
2649 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2650 }
2651
2652 case ARMISD::VLD3_UPD: {
2653 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2654 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2655 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2656 ARM::VLD3q16Pseudo_UPD,
2657 ARM::VLD3q32Pseudo_UPD };
2658 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2659 ARM::VLD3q16oddPseudo_UPD,
2660 ARM::VLD3q32oddPseudo_UPD };
2661 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2662 }
2663
2664 case ARMISD::VLD4_UPD: {
2665 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2666 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2667 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2668 ARM::VLD4q16Pseudo_UPD,
2669 ARM::VLD4q32Pseudo_UPD };
2670 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2671 ARM::VLD4q16oddPseudo_UPD,
2672 ARM::VLD4q32oddPseudo_UPD };
2673 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2674 }
2675
2676 case ARMISD::VLD2LN_UPD: {
2677 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2678 ARM::VLD2LNd32Pseudo_UPD };
2679 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2680 ARM::VLD2LNq32Pseudo_UPD };
2681 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2682 }
2683
2684 case ARMISD::VLD3LN_UPD: {
2685 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2686 ARM::VLD3LNd32Pseudo_UPD };
2687 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2688 ARM::VLD3LNq32Pseudo_UPD };
2689 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2690 }
2691
2692 case ARMISD::VLD4LN_UPD: {
2693 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2694 ARM::VLD4LNd32Pseudo_UPD };
2695 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2696 ARM::VLD4LNq32Pseudo_UPD };
2697 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2698 }
2699
2700 case ARMISD::VST1_UPD: {
2701 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2702 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2703 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2704 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2705 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2706 }
2707
2708 case ARMISD::VST2_UPD: {
2709 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2710 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2711 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2712 ARM::VST2q32Pseudo_UPD };
2713 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2714 }
2715
2716 case ARMISD::VST3_UPD: {
2717 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2718 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2719 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2720 ARM::VST3q16Pseudo_UPD,
2721 ARM::VST3q32Pseudo_UPD };
2722 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2723 ARM::VST3q16oddPseudo_UPD,
2724 ARM::VST3q32oddPseudo_UPD };
2725 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2726 }
2727
2728 case ARMISD::VST4_UPD: {
2729 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2730 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2731 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2732 ARM::VST4q16Pseudo_UPD,
2733 ARM::VST4q32Pseudo_UPD };
2734 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2735 ARM::VST4q16oddPseudo_UPD,
2736 ARM::VST4q32oddPseudo_UPD };
2737 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2738 }
2739
2740 case ARMISD::VST2LN_UPD: {
2741 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2742 ARM::VST2LNd32Pseudo_UPD };
2743 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2744 ARM::VST2LNq32Pseudo_UPD };
2745 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2746 }
2747
2748 case ARMISD::VST3LN_UPD: {
2749 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2750 ARM::VST3LNd32Pseudo_UPD };
2751 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2752 ARM::VST3LNq32Pseudo_UPD };
2753 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2754 }
2755
2756 case ARMISD::VST4LN_UPD: {
2757 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2758 ARM::VST4LNd32Pseudo_UPD };
2759 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2760 ARM::VST4LNq32Pseudo_UPD };
2761 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002762 }
2763
Bob Wilson31fb12f2009-08-26 17:39:53 +00002764 case ISD::INTRINSIC_VOID:
2765 case ISD::INTRINSIC_W_CHAIN: {
2766 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002767 switch (IntNo) {
2768 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002769 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002770
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002771 case Intrinsic::arm_ldrexd: {
2772 SDValue MemAddr = N->getOperand(2);
2773 DebugLoc dl = N->getDebugLoc();
2774 SDValue Chain = N->getOperand(0);
2775
2776 unsigned NewOpc = ARM::LDREXD;
2777 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2778 NewOpc = ARM::t2LDREXD;
2779
2780 // arm_ldrexd returns a i64 value in {i32, i32}
2781 std::vector<EVT> ResTys;
2782 ResTys.push_back(MVT::i32);
2783 ResTys.push_back(MVT::i32);
2784 ResTys.push_back(MVT::Other);
2785
2786 // place arguments in the right order
2787 SmallVector<SDValue, 7> Ops;
2788 Ops.push_back(MemAddr);
2789 Ops.push_back(getAL(CurDAG));
2790 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2791 Ops.push_back(Chain);
2792 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2793 Ops.size());
2794 // Transfer memoperands.
2795 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2796 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2797 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2798
2799 // Until there's support for specifing explicit register constraints
2800 // like the use of even/odd register pair, hardcode ldrexd to always
2801 // use the pair [R0, R1] to hold the load result.
2802 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2803 SDValue(Ld, 0), SDValue(0,0));
2804 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2805 SDValue(Ld, 1), Chain.getValue(1));
2806
2807 // Remap uses.
2808 SDValue Glue = Chain.getValue(1);
2809 if (!SDValue(N, 0).use_empty()) {
2810 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2811 ARM::R0, MVT::i32, Glue);
2812 Glue = Result.getValue(2);
2813 ReplaceUses(SDValue(N, 0), Result);
2814 }
2815 if (!SDValue(N, 1).use_empty()) {
2816 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2817 ARM::R1, MVT::i32, Glue);
2818 Glue = Result.getValue(2);
2819 ReplaceUses(SDValue(N, 1), Result);
2820 }
2821
2822 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2823 return NULL;
2824 }
2825
2826 case Intrinsic::arm_strexd: {
2827 DebugLoc dl = N->getDebugLoc();
2828 SDValue Chain = N->getOperand(0);
2829 SDValue Val0 = N->getOperand(2);
2830 SDValue Val1 = N->getOperand(3);
2831 SDValue MemAddr = N->getOperand(4);
2832
2833 // Until there's support for specifing explicit register constraints
2834 // like the use of even/odd register pair, hardcode strexd to always
2835 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2836 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2837 SDValue(0, 0));
2838 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2839
2840 SDValue Glue = Chain.getValue(1);
2841 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2842 ARM::R2, MVT::i32, Glue);
2843 Glue = Val0.getValue(1);
2844 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2845 ARM::R3, MVT::i32, Glue);
2846
2847 // Store exclusive double return a i32 value which is the return status
2848 // of the issued store.
2849 std::vector<EVT> ResTys;
2850 ResTys.push_back(MVT::i32);
2851 ResTys.push_back(MVT::Other);
2852
2853 // place arguments in the right order
2854 SmallVector<SDValue, 7> Ops;
2855 Ops.push_back(Val0);
2856 Ops.push_back(Val1);
2857 Ops.push_back(MemAddr);
2858 Ops.push_back(getAL(CurDAG));
2859 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2860 Ops.push_back(Chain);
2861
2862 unsigned NewOpc = ARM::STREXD;
2863 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2864 NewOpc = ARM::t2STREXD;
2865
2866 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2867 Ops.size());
2868 // Transfer memoperands.
2869 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2870 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2871 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2872
2873 return St;
2874 }
2875
Bob Wilson621f1952010-03-23 05:25:43 +00002876 case Intrinsic::arm_neon_vld1: {
2877 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2878 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002879 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2880 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002881 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002882 }
2883
Bob Wilson31fb12f2009-08-26 17:39:53 +00002884 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002885 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2886 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2887 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2888 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002889 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002890 }
2891
2892 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002893 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2894 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2895 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2896 ARM::VLD3q16Pseudo_UPD,
2897 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002898 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2899 ARM::VLD3q16oddPseudo,
2900 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002901 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002902 }
2903
2904 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002905 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2906 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2907 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2908 ARM::VLD4q16Pseudo_UPD,
2909 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002910 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2911 ARM::VLD4q16oddPseudo,
2912 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002913 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002914 }
2915
Bob Wilson243fcc52009-09-01 04:26:28 +00002916 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002917 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2918 ARM::VLD2LNd32Pseudo };
2919 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002920 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002921 }
2922
2923 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002924 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2925 ARM::VLD3LNd32Pseudo };
2926 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002927 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002928 }
2929
2930 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002931 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2932 ARM::VLD4LNd32Pseudo };
2933 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002934 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002935 }
2936
Bob Wilson11d98992010-03-23 06:20:33 +00002937 case Intrinsic::arm_neon_vst1: {
2938 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2939 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002940 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2941 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002942 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002943 }
2944
Bob Wilson31fb12f2009-08-26 17:39:53 +00002945 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002946 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2947 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2948 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2949 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002950 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002951 }
2952
2953 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002954 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2955 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2956 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2957 ARM::VST3q16Pseudo_UPD,
2958 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002959 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2960 ARM::VST3q16oddPseudo,
2961 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002962 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002963 }
2964
2965 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002966 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002967 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002968 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2969 ARM::VST4q16Pseudo_UPD,
2970 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002971 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2972 ARM::VST4q16oddPseudo,
2973 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002974 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002975 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002976
2977 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002978 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2979 ARM::VST2LNd32Pseudo };
2980 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002981 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002982 }
2983
2984 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002985 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2986 ARM::VST3LNd32Pseudo };
2987 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002988 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002989 }
2990
2991 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002992 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2993 ARM::VST4LNd32Pseudo };
2994 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002995 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002996 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002997 }
Bob Wilson429009b2010-05-06 16:05:26 +00002998 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002999 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003000
Bob Wilsond491d6e2010-07-06 23:36:25 +00003001 case ISD::INTRINSIC_WO_CHAIN: {
3002 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3003 switch (IntNo) {
3004 default:
3005 break;
3006
3007 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003008 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003009 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003010 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003011 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003012 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003013
3014 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003015 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003016 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003017 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003018 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003019 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003020 }
3021 break;
3022 }
3023
Bill Wendling69a05a72011-03-14 23:02:38 +00003024 case ARMISD::VTBL1: {
3025 DebugLoc dl = N->getDebugLoc();
3026 EVT VT = N->getValueType(0);
3027 SmallVector<SDValue, 6> Ops;
3028
3029 Ops.push_back(N->getOperand(0));
3030 Ops.push_back(N->getOperand(1));
3031 Ops.push_back(getAL(CurDAG)); // Predicate
3032 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3033 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3034 }
3035 case ARMISD::VTBL2: {
3036 DebugLoc dl = N->getDebugLoc();
3037 EVT VT = N->getValueType(0);
3038
3039 // Form a REG_SEQUENCE to force register allocation.
3040 SDValue V0 = N->getOperand(0);
3041 SDValue V1 = N->getOperand(1);
3042 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3043
3044 SmallVector<SDValue, 6> Ops;
3045 Ops.push_back(RegSeq);
3046 Ops.push_back(N->getOperand(2));
3047 Ops.push_back(getAL(CurDAG)); // Predicate
3048 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3049 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3050 Ops.data(), Ops.size());
3051 }
3052
Bob Wilson429009b2010-05-06 16:05:26 +00003053 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003054 return SelectConcatVector(N);
3055 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003056
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003057 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003058}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003059
Bob Wilson224c2442009-05-19 05:53:42 +00003060bool ARMDAGToDAGISel::
3061SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3062 std::vector<SDValue> &OutOps) {
3063 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003064 // Require the address to be in a register. That is safe for all ARM
3065 // variants and it is hard to do anything much smarter without knowing
3066 // how the operand is used.
3067 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003068 return false;
3069}
3070
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003071/// createARMISelDag - This pass converts a legalized DAG into a
3072/// ARM-specific DAG, ready for instruction scheduling.
3073///
Bob Wilson522ce972009-09-28 14:30:20 +00003074FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3075 CodeGenOpt::Level OptLevel) {
3076 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003077}