blob: ea30597cd9ae57ba21a4eb28c74800996723fd98 [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 Anderson099e5552011-03-18 19:46:58 +000097 SDValue &B, SDValue &C,
98 bool CheckProfitability = true);
Evan Chengf40deed2010-10-27 23:41:30 +000099 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +0000100 SDValue &B, SDValue &C) {
101 // Don't apply the profitability check
Owen Anderson92a20222011-07-21 18:54:16 +0000102 if (SelectImmShifterOperand(N, A, B, C, false))
103 return true;
104 else if (SelectRegShifterOperand(N, A, B, C, false))
105 return true;
106 return 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
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000133 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000136 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000137 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000138 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000139 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000140 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000141 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000142
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000143 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000144
Bill Wendlingf4caf692010-12-14 03:36:38 +0000145 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000146 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000147 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
148 unsigned Scale);
149 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
150 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
151 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
152 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
153 SDValue &OffImm);
154 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
155 SDValue &OffImm);
156 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
157 SDValue &OffImm);
158 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
159 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000160 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000161
Bill Wendlingf4caf692010-12-14 03:36:38 +0000162 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000163 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000164 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
166 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000167 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000168 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000169 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000171 SDValue &OffReg, SDValue &ShImm);
172
Evan Cheng875a6ac2010-11-12 22:42:47 +0000173 inline bool is_so_imm(unsigned Imm) const {
174 return ARM_AM::getSOImmVal(Imm) != -1;
175 }
176
177 inline bool is_so_imm_not(unsigned Imm) const {
178 return ARM_AM::getSOImmVal(~Imm) != -1;
179 }
180
181 inline bool is_t2_so_imm(unsigned Imm) const {
182 return ARM_AM::getT2SOImmVal(Imm) != -1;
183 }
184
185 inline bool is_t2_so_imm_not(unsigned Imm) const {
186 return ARM_AM::getT2SOImmVal(~Imm) != -1;
187 }
188
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000189 // Include the pieces autogenerated from the target description.
190#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000191
192private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000193 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
194 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000195 SDNode *SelectARMIndexedLoad(SDNode *N);
196 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000197
Bob Wilson621f1952010-03-23 05:25:43 +0000198 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
199 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000200 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000201 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000202 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
203 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000204 unsigned *QOpcodes0, unsigned *QOpcodes1);
205
Bob Wilson24f995d2009-10-14 18:32:29 +0000206 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000207 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000208 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000209 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000210 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
211 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000212 unsigned *QOpcodes0, unsigned *QOpcodes1);
213
Bob Wilson96493442009-10-14 16:46:45 +0000214 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000215 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000216 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000217 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
218 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000219 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000220
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000221 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
222 /// should be 2, 3 or 4. The opcode array specifies the instructions used
223 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000224 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
225 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000226
Bob Wilson78dfbc32010-07-07 00:08:54 +0000227 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
228 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
229 /// generated to force the table registers to be consecutive.
230 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000231
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000232 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000233 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000234
Evan Cheng07ba9062009-11-19 21:45:22 +0000235 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000236 SDNode *SelectCMOVOp(SDNode *N);
237 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000238 ARMCC::CondCodes CCVal, SDValue CCR,
239 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000240 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000241 ARMCC::CondCodes CCVal, SDValue CCR,
242 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000243 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000244 ARMCC::CondCodes CCVal, SDValue CCR,
245 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000246 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000247 ARMCC::CondCodes CCVal, SDValue CCR,
248 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000249
Evan Chengde8aa4e2010-05-05 18:28:36 +0000250 SDNode *SelectConcatVector(SDNode *N);
251
Evan Chengaf4550f2009-07-02 01:23:32 +0000252 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
253 /// inline asm expressions.
254 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
255 char ConstraintCode,
256 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000257
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000258 // Form pairs of consecutive S, D, or Q registers.
259 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000260 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000261 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
262
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000263 // Form sequences of 4 consecutive S, D, or Q registers.
264 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000265 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000266 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000267
268 // Get the alignment operand for a NEON VLD or VST instruction.
269 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000270};
Evan Chenga8e29892007-01-19 07:51:42 +0000271}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000272
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000273/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
274/// operand. If so Imm will receive the 32-bit value.
275static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
276 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
277 Imm = cast<ConstantSDNode>(N)->getZExtValue();
278 return true;
279 }
280 return false;
281}
282
283// isInt32Immediate - This method tests to see if a constant operand.
284// If so Imm will receive the 32 bit value.
285static bool isInt32Immediate(SDValue N, unsigned &Imm) {
286 return isInt32Immediate(N.getNode(), Imm);
287}
288
289// isOpcWithIntImmediate - This method tests to see if the node is a specific
290// opcode and that it has a immediate integer right operand.
291// If so Imm will receive the 32 bit value.
292static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
293 return N->getOpcode() == Opc &&
294 isInt32Immediate(N->getOperand(1).getNode(), Imm);
295}
296
Daniel Dunbarec91d522011-01-19 15:12:16 +0000297/// \brief Check whether a particular node is a constant value representable as
298/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
299///
300/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
301static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
302 int RangeMin, int RangeMax,
303 int &ScaledConstant) {
304 assert(Scale && "Invalid scale!");
305
306 // Check that this is a constant.
307 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
308 if (!C)
309 return false;
310
311 ScaledConstant = (int) C->getZExtValue();
312 if ((ScaledConstant % Scale) != 0)
313 return false;
314
315 ScaledConstant /= Scale;
316 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
317}
318
Evan Cheng48575f62010-12-05 22:04:16 +0000319/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
320/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
321/// least on current ARM implementations) which should be avoidded.
322bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
323 if (OptLevel == CodeGenOpt::None)
324 return true;
325
326 if (!CheckVMLxHazard)
327 return true;
328
329 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
330 return true;
331
332 if (!N->hasOneUse())
333 return false;
334
335 SDNode *Use = *N->use_begin();
336 if (Use->getOpcode() == ISD::CopyToReg)
337 return true;
338 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000339 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
340 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000341 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000342 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000343 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
344 return true;
345 // vmlx feeding into another vmlx. We actually want to unfold
346 // the use later in the MLxExpansion pass. e.g.
347 // vmla
348 // vmla (stall 8 cycles)
349 //
350 // vmul (5 cycles)
351 // vadd (5 cycles)
352 // vmla
353 // This adds up to about 18 - 19 cycles.
354 //
355 // vmla
356 // vmul (stall 4 cycles)
357 // vadd adds up to about 14 cycles.
358 return TII->isFpMLxInstruction(Opcode);
359 }
360
361 return false;
362}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000363
Evan Chengf40deed2010-10-27 23:41:30 +0000364bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
365 ARM_AM::ShiftOpc ShOpcVal,
366 unsigned ShAmt) {
367 if (!Subtarget->isCortexA9())
368 return true;
369 if (Shift.hasOneUse())
370 return true;
371 // R << 2 is free.
372 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
373}
374
Owen Anderson92a20222011-07-21 18:54:16 +0000375bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000376 SDValue &BaseReg,
377 SDValue &ShReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000378 SDValue &Opc,
379 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000380 if (DisableShifterOp)
381 return false;
382
Evan Chengee04a6d2011-07-20 23:34:39 +0000383 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000384
385 // Don't match base register only case. That is matched to a separate
386 // lower complexity pattern with explicit register operand.
387 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000388
Evan Cheng055b0312009-06-29 07:51:04 +0000389 BaseReg = N.getOperand(0);
390 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000391 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
392 if (!RHS) return false;
393 ShReg = CurDAG->getRegister(0, MVT::i32);
394 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
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000719bool ARMDAGToDAGISel::SelectAddrMode2Offset(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;
728 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
729 Offset = CurDAG->getRegister(0, MVT::i32);
730 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
731 ARM_AM::no_shift),
732 MVT::i32);
733 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000734 }
735
736 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000737 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000738 unsigned ShAmt = 0;
739 if (ShOpcVal != ARM_AM::no_shift) {
740 // Check to see if the RHS of the shift is a constant, if not, we can't fold
741 // it.
742 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000743 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000744 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
745 Offset = N.getOperand(0);
746 else {
747 ShAmt = 0;
748 ShOpcVal = ARM_AM::no_shift;
749 }
Evan Chenga8e29892007-01-19 07:51:42 +0000750 } else {
751 ShOpcVal = ARM_AM::no_shift;
752 }
753 }
754
755 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000757 return true;
758}
759
Evan Chenga8e29892007-01-19 07:51:42 +0000760
Chris Lattner52a261b2010-09-21 20:31:19 +0000761bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000762 SDValue &Base, SDValue &Offset,
763 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000764 if (N.getOpcode() == ISD::SUB) {
765 // X - C is canonicalize to X + -C, no need to handle it here.
766 Base = N.getOperand(0);
767 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000768 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000769 return true;
770 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000771
Chris Lattner0a9481f2011-02-13 22:25:43 +0000772 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000773 Base = N;
774 if (N.getOpcode() == ISD::FrameIndex) {
775 int FI = cast<FrameIndexSDNode>(N)->getIndex();
776 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
777 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000778 Offset = CurDAG->getRegister(0, MVT::i32);
779 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000780 return true;
781 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000782
Evan Chenga8e29892007-01-19 07:51:42 +0000783 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000784 int RHSC;
785 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
786 -256 + 1, 256, RHSC)) { // 8 bits.
787 Base = N.getOperand(0);
788 if (Base.getOpcode() == ISD::FrameIndex) {
789 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
790 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000791 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000792 Offset = CurDAG->getRegister(0, MVT::i32);
793
794 ARM_AM::AddrOpc AddSub = ARM_AM::add;
795 if (RHSC < 0) {
796 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000797 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000798 }
799 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
800 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000801 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000802
Evan Chenga8e29892007-01-19 07:51:42 +0000803 Base = N.getOperand(0);
804 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000805 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000806 return true;
807}
808
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000809bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000810 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000811 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000812 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
813 ? cast<LoadSDNode>(Op)->getAddressingMode()
814 : cast<StoreSDNode>(Op)->getAddressingMode();
815 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
816 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000817 int Val;
818 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
819 Offset = CurDAG->getRegister(0, MVT::i32);
820 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
821 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000822 }
823
824 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000825 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000826 return true;
827}
828
Jim Grosbach3ab56582010-10-21 19:38:40 +0000829bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000830 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000831 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000832 Base = N;
833 if (N.getOpcode() == ISD::FrameIndex) {
834 int FI = cast<FrameIndexSDNode>(N)->getIndex();
835 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000836 } else if (N.getOpcode() == ARMISD::Wrapper &&
837 !(Subtarget->useMovt() &&
838 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000839 Base = N.getOperand(0);
840 }
841 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000842 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000843 return true;
844 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000845
Evan Chenga8e29892007-01-19 07:51:42 +0000846 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000847 int RHSC;
848 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
849 -256 + 1, 256, RHSC)) {
850 Base = N.getOperand(0);
851 if (Base.getOpcode() == ISD::FrameIndex) {
852 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
853 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000854 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000855
856 ARM_AM::AddrOpc AddSub = ARM_AM::add;
857 if (RHSC < 0) {
858 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000859 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000860 }
861 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
862 MVT::i32);
863 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000864 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000865
Evan Chenga8e29892007-01-19 07:51:42 +0000866 Base = N;
867 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000869 return true;
870}
871
Bob Wilson665814b2010-11-01 23:40:51 +0000872bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
873 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000874 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000875
876 unsigned Alignment = 0;
877 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
878 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
879 // The maximum alignment is equal to the memory size being referenced.
880 unsigned LSNAlign = LSN->getAlignment();
881 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
882 if (LSNAlign > MemSize && MemSize > 1)
883 Alignment = MemSize;
884 } else {
885 // All other uses of addrmode6 are for intrinsics. For now just record
886 // the raw alignment value; it will be refined later based on the legal
887 // alignment operands for the intrinsic.
888 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
889 }
890
891 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000892 return true;
893}
894
Bob Wilsonda525062011-02-25 06:42:42 +0000895bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
896 SDValue &Offset) {
897 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
898 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
899 if (AM != ISD::POST_INC)
900 return false;
901 Offset = N;
902 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
903 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
904 Offset = CurDAG->getRegister(0, MVT::i32);
905 }
906 return true;
907}
908
Chris Lattner52a261b2010-09-21 20:31:19 +0000909bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000910 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000911 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
912 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000913 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000914 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
915 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000916 return true;
917 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000918
Evan Chenga8e29892007-01-19 07:51:42 +0000919 return false;
920}
921
Bill Wendlingf4caf692010-12-14 03:36:38 +0000922
923//===----------------------------------------------------------------------===//
924// Thumb Addressing Modes
925//===----------------------------------------------------------------------===//
926
Chris Lattner52a261b2010-09-21 20:31:19 +0000927bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000928 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000929 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000930 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000931 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000932 return false;
933
934 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000935 return true;
936 }
937
Evan Chenga8e29892007-01-19 07:51:42 +0000938 Base = N.getOperand(0);
939 Offset = N.getOperand(1);
940 return true;
941}
942
Evan Cheng79d43262007-01-24 02:21:22 +0000943bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000944ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
945 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000946 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000947 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000948 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000949 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000950
Evan Cheng012f2d92007-01-24 08:53:17 +0000951 if (N.getOpcode() == ARMISD::Wrapper &&
952 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
953 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000954 }
955
Chris Lattner0a9481f2011-02-13 22:25:43 +0000956 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000957 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000958
Evan Chengad0e4652007-02-06 00:22:06 +0000959 // Thumb does not have [sp, r] address mode.
960 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
961 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
962 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000963 (RHSR && RHSR->getReg() == ARM::SP))
964 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000965
Daniel Dunbarec91d522011-01-19 15:12:16 +0000966 // FIXME: Why do we explicitly check for a match here and then return false?
967 // Presumably to allow something else to match, but shouldn't this be
968 // documented?
969 int RHSC;
970 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
971 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000972
973 Base = N.getOperand(0);
974 Offset = N.getOperand(1);
975 return true;
976}
977
978bool
979ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
980 SDValue &Base,
981 SDValue &Offset) {
982 return SelectThumbAddrModeRI(N, Base, Offset, 1);
983}
984
985bool
986ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
987 SDValue &Base,
988 SDValue &Offset) {
989 return SelectThumbAddrModeRI(N, Base, Offset, 2);
990}
991
992bool
993ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
994 SDValue &Base,
995 SDValue &Offset) {
996 return SelectThumbAddrModeRI(N, Base, Offset, 4);
997}
998
999bool
1000ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1001 SDValue &Base, SDValue &OffImm) {
1002 if (Scale == 4) {
1003 SDValue TmpBase, TmpOffImm;
1004 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1005 return false; // We want to select tLDRspi / tSTRspi instead.
1006
1007 if (N.getOpcode() == ARMISD::Wrapper &&
1008 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1009 return false; // We want to select tLDRpci instead.
1010 }
1011
Chris Lattner0a9481f2011-02-13 22:25:43 +00001012 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001013 if (N.getOpcode() == ARMISD::Wrapper &&
1014 !(Subtarget->useMovt() &&
1015 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1016 Base = N.getOperand(0);
1017 } else {
1018 Base = N;
1019 }
1020
Owen Anderson825b72b2009-08-11 20:47:22 +00001021 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001022 return true;
1023 }
1024
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001025 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1026 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1027 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1028 (RHSR && RHSR->getReg() == ARM::SP)) {
1029 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1030 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1031 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1032 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1033
1034 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1035 if (LHSC != 0 || RHSC != 0) return false;
1036
1037 Base = N;
1038 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1039 return true;
1040 }
1041
Evan Chenga8e29892007-01-19 07:51:42 +00001042 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001043 int RHSC;
1044 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1045 Base = N.getOperand(0);
1046 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1047 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001048 }
1049
Evan Chengc38f2bc2007-01-23 22:59:13 +00001050 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001051 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001052 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001053}
1054
Bill Wendlingf4caf692010-12-14 03:36:38 +00001055bool
1056ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1057 SDValue &OffImm) {
1058 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001059}
1060
Bill Wendlingf4caf692010-12-14 03:36:38 +00001061bool
1062ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1063 SDValue &OffImm) {
1064 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001065}
1066
Bill Wendlingf4caf692010-12-14 03:36:38 +00001067bool
1068ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1069 SDValue &OffImm) {
1070 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001071}
1072
Chris Lattner52a261b2010-09-21 20:31:19 +00001073bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1074 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001075 if (N.getOpcode() == ISD::FrameIndex) {
1076 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1077 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001078 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001079 return true;
1080 }
Evan Cheng79d43262007-01-24 02:21:22 +00001081
Chris Lattner0a9481f2011-02-13 22:25:43 +00001082 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001083 return false;
1084
1085 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001086 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1087 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001088 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001089 int RHSC;
1090 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1091 Base = N.getOperand(0);
1092 if (Base.getOpcode() == ISD::FrameIndex) {
1093 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1094 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001095 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001096 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1097 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001098 }
1099 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001100
Evan Chenga8e29892007-01-19 07:51:42 +00001101 return false;
1102}
1103
Bill Wendlingf4caf692010-12-14 03:36:38 +00001104
1105//===----------------------------------------------------------------------===//
1106// Thumb 2 Addressing Modes
1107//===----------------------------------------------------------------------===//
1108
1109
Chris Lattner52a261b2010-09-21 20:31:19 +00001110bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001111 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001112 if (DisableShifterOp)
1113 return false;
1114
Evan Chengee04a6d2011-07-20 23:34:39 +00001115 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001116
1117 // Don't match base register only case. That is matched to a separate
1118 // lower complexity pattern with explicit register operand.
1119 if (ShOpcVal == ARM_AM::no_shift) return false;
1120
1121 BaseReg = N.getOperand(0);
1122 unsigned ShImmVal = 0;
1123 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1124 ShImmVal = RHS->getZExtValue() & 31;
1125 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1126 return true;
1127 }
1128
1129 return false;
1130}
1131
Chris Lattner52a261b2010-09-21 20:31:19 +00001132bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001133 SDValue &Base, SDValue &OffImm) {
1134 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001135
Evan Cheng3a214252009-08-11 08:52:18 +00001136 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001137 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1138 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001139 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001140 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001141 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1142 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001143 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001144 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001145 }
Owen Anderson099e5552011-03-18 19:46:58 +00001146
Chris Lattner0a9481f2011-02-13 22:25:43 +00001147 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001148 !(Subtarget->useMovt() &&
1149 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001150 Base = N.getOperand(0);
1151 if (Base.getOpcode() == ISD::TargetConstantPool)
1152 return false; // We want to select t2LDRpci instead.
1153 } else
1154 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001155 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001156 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001157 }
Evan Cheng055b0312009-06-29 07:51:04 +00001158
1159 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001160 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001161 // Let t2LDRi8 handle (R - imm8).
1162 return false;
1163
Evan Cheng055b0312009-06-29 07:51:04 +00001164 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001165 if (N.getOpcode() == ISD::SUB)
1166 RHSC = -RHSC;
1167
1168 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001169 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001170 if (Base.getOpcode() == ISD::FrameIndex) {
1171 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1172 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1173 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001174 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001175 return true;
1176 }
1177 }
1178
Evan Cheng3a214252009-08-11 08:52:18 +00001179 // Base only.
1180 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001181 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001182 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001183}
1184
Chris Lattner52a261b2010-09-21 20:31:19 +00001185bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001186 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001187 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001188 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1189 !CurDAG->isBaseWithConstantOffset(N))
1190 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001191
Chris Lattner0a9481f2011-02-13 22:25:43 +00001192 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1193 int RHSC = (int)RHS->getSExtValue();
1194 if (N.getOpcode() == ISD::SUB)
1195 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001196
Chris Lattner0a9481f2011-02-13 22:25:43 +00001197 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1198 Base = N.getOperand(0);
1199 if (Base.getOpcode() == ISD::FrameIndex) {
1200 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1201 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001202 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001203 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1204 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001205 }
1206 }
1207
1208 return false;
1209}
1210
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001211bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001212 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001213 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001214 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1215 ? cast<LoadSDNode>(Op)->getAddressingMode()
1216 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001217 int RHSC;
1218 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1219 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1220 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1221 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1222 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001223 }
1224
1225 return false;
1226}
1227
Chris Lattner52a261b2010-09-21 20:31:19 +00001228bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001229 SDValue &Base,
1230 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001231 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001232 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001233 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001234
Evan Cheng3a214252009-08-11 08:52:18 +00001235 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1236 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1237 int RHSC = (int)RHS->getZExtValue();
1238 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1239 return false;
1240 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001241 return false;
1242 }
1243
Evan Chengf40deed2010-10-27 23:41:30 +00001244 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1245 // Compute R + (R << [1,2,3]) and reuse it.
1246 Base = N;
1247 return false;
1248 }
1249
Evan Cheng055b0312009-06-29 07:51:04 +00001250 // Look for (R + R) or (R + (R << [1,2,3])).
1251 unsigned ShAmt = 0;
1252 Base = N.getOperand(0);
1253 OffReg = N.getOperand(1);
1254
1255 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001256 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001257 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001258 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001259 if (ShOpcVal == ARM_AM::lsl)
1260 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001261 }
1262
Evan Cheng055b0312009-06-29 07:51:04 +00001263 if (ShOpcVal == ARM_AM::lsl) {
1264 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1265 // it.
1266 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1267 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001268 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1269 OffReg = OffReg.getOperand(0);
1270 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001271 ShAmt = 0;
1272 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001273 }
Evan Cheng055b0312009-06-29 07:51:04 +00001274 } else {
1275 ShOpcVal = ARM_AM::no_shift;
1276 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001277 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001278
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001280
1281 return true;
1282}
1283
1284//===--------------------------------------------------------------------===//
1285
Evan Chengee568cf2007-07-05 07:15:27 +00001286/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001287static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001288 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001289}
1290
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001291SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1292 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001293 ISD::MemIndexedMode AM = LD->getAddressingMode();
1294 if (AM == ISD::UNINDEXED)
1295 return NULL;
1296
Owen Andersone50ed302009-08-10 22:56:29 +00001297 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001298 SDValue Offset, AMOpc;
1299 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1300 unsigned Opcode = 0;
1301 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001302 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001303 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001304 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1305 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001306 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001307 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001308 Match = true;
1309 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1310 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1311 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001312 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001313 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001314 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001315 Match = true;
1316 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1317 }
1318 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001319 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001320 Match = true;
1321 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1322 }
1323 }
1324 }
1325
1326 if (Match) {
1327 SDValue Chain = LD->getChain();
1328 SDValue Base = LD->getBasePtr();
1329 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001330 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001331 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001332 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001333 }
1334
1335 return NULL;
1336}
1337
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001338SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1339 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001340 ISD::MemIndexedMode AM = LD->getAddressingMode();
1341 if (AM == ISD::UNINDEXED)
1342 return NULL;
1343
Owen Andersone50ed302009-08-10 22:56:29 +00001344 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001345 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001346 SDValue Offset;
1347 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1348 unsigned Opcode = 0;
1349 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001350 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001351 switch (LoadedVT.getSimpleVT().SimpleTy) {
1352 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001353 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1354 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001355 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001356 if (isSExtLd)
1357 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1358 else
1359 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001360 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001361 case MVT::i8:
1362 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001363 if (isSExtLd)
1364 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1365 else
1366 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001367 break;
1368 default:
1369 return NULL;
1370 }
1371 Match = true;
1372 }
1373
1374 if (Match) {
1375 SDValue Chain = LD->getChain();
1376 SDValue Base = LD->getBasePtr();
1377 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001378 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001379 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001380 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001381 }
1382
1383 return NULL;
1384}
1385
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001386/// PairSRegs - Form a D register from a pair of S registers.
1387///
1388SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1389 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001390 SDValue RegClass =
1391 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001392 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1393 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001394 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1395 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001396}
1397
Evan Cheng603afbf2010-05-10 17:34:18 +00001398/// PairDRegs - Form a quad register from a pair of D registers.
1399///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001400SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1401 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001402 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001403 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1404 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001405 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1406 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001407}
1408
Evan Cheng7f687192010-05-14 00:21:45 +00001409/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001410///
1411SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1412 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001413 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001414 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1415 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001416 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1417 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001418}
1419
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001420/// QuadSRegs - Form 4 consecutive S registers.
1421///
1422SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1423 SDValue V2, SDValue V3) {
1424 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001425 SDValue RegClass =
1426 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001427 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1428 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1429 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1430 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001431 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1432 V2, SubReg2, V3, SubReg3 };
1433 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001434}
1435
Evan Cheng7f687192010-05-14 00:21:45 +00001436/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001437///
1438SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1439 SDValue V2, SDValue V3) {
1440 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001441 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001442 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1443 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1444 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1445 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001446 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1447 V2, SubReg2, V3, SubReg3 };
1448 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001449}
1450
Evan Cheng8f6de382010-05-16 03:27:48 +00001451/// QuadQRegs - Form 4 consecutive Q registers.
1452///
1453SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1454 SDValue V2, SDValue V3) {
1455 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001456 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001457 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1458 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1459 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1460 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001461 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1462 V2, SubReg2, V3, SubReg3 };
1463 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001464}
1465
Bob Wilson2a6e6162010-09-23 23:42:37 +00001466/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1467/// of a NEON VLD or VST instruction. The supported values depend on the
1468/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001469SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1470 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001471 unsigned NumRegs = NumVecs;
1472 if (!is64BitVector && NumVecs < 3)
1473 NumRegs *= 2;
1474
Bob Wilson665814b2010-11-01 23:40:51 +00001475 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001476 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001477 Alignment = 32;
1478 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1479 Alignment = 16;
1480 else if (Alignment >= 8)
1481 Alignment = 8;
1482 else
1483 Alignment = 0;
1484
1485 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001486}
1487
Bob Wilson1c3ef902011-02-07 17:43:21 +00001488SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001489 unsigned *DOpcodes, unsigned *QOpcodes0,
1490 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001491 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001492 DebugLoc dl = N->getDebugLoc();
1493
Bob Wilson226036e2010-03-20 22:13:40 +00001494 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001495 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1496 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001497 return NULL;
1498
1499 SDValue Chain = N->getOperand(0);
1500 EVT VT = N->getValueType(0);
1501 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001502 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001503
Bob Wilson3e36f132009-10-14 17:28:52 +00001504 unsigned OpcodeIndex;
1505 switch (VT.getSimpleVT().SimpleTy) {
1506 default: llvm_unreachable("unhandled vld type");
1507 // Double-register operations:
1508 case MVT::v8i8: OpcodeIndex = 0; break;
1509 case MVT::v4i16: OpcodeIndex = 1; break;
1510 case MVT::v2f32:
1511 case MVT::v2i32: OpcodeIndex = 2; break;
1512 case MVT::v1i64: OpcodeIndex = 3; break;
1513 // Quad-register operations:
1514 case MVT::v16i8: OpcodeIndex = 0; break;
1515 case MVT::v8i16: OpcodeIndex = 1; break;
1516 case MVT::v4f32:
1517 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001518 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001519 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001520 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001521 }
1522
Bob Wilsonf5721912010-09-03 18:16:02 +00001523 EVT ResTy;
1524 if (NumVecs == 1)
1525 ResTy = VT;
1526 else {
1527 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1528 if (!is64BitVector)
1529 ResTyElts *= 2;
1530 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1531 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001532 std::vector<EVT> ResTys;
1533 ResTys.push_back(ResTy);
1534 if (isUpdating)
1535 ResTys.push_back(MVT::i32);
1536 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001537
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001538 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001539 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001540 SDNode *VLd;
1541 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001542
Bob Wilson1c3ef902011-02-07 17:43:21 +00001543 // Double registers and VLD1/VLD2 quad registers are directly supported.
1544 if (is64BitVector || NumVecs <= 2) {
1545 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1546 QOpcodes0[OpcodeIndex]);
1547 Ops.push_back(MemAddr);
1548 Ops.push_back(Align);
1549 if (isUpdating) {
1550 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1551 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001552 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001553 Ops.push_back(Pred);
1554 Ops.push_back(Reg0);
1555 Ops.push_back(Chain);
1556 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001557
Bob Wilson3e36f132009-10-14 17:28:52 +00001558 } else {
1559 // Otherwise, quad registers are loaded with two separate instructions,
1560 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001561 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001562
Bob Wilson1c3ef902011-02-07 17:43:21 +00001563 // Load the even subregs. This is always an updating load, so that it
1564 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001565 SDValue ImplDef =
1566 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1567 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001568 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1569 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001570 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001571
Bob Wilson24f995d2009-10-14 18:32:29 +00001572 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001573 Ops.push_back(SDValue(VLdA, 1));
1574 Ops.push_back(Align);
1575 if (isUpdating) {
1576 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1577 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1578 "only constant post-increment update allowed for VLD3/4");
1579 (void)Inc;
1580 Ops.push_back(Reg0);
1581 }
1582 Ops.push_back(SDValue(VLdA, 0));
1583 Ops.push_back(Pred);
1584 Ops.push_back(Reg0);
1585 Ops.push_back(Chain);
1586 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1587 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001588 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001589
Evan Chengb58a3402011-04-19 00:04:03 +00001590 // Transfer memoperands.
1591 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1592 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1593 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1594
Bob Wilson1c3ef902011-02-07 17:43:21 +00001595 if (NumVecs == 1)
1596 return VLd;
1597
1598 // Extract out the subregisters.
1599 SDValue SuperReg = SDValue(VLd, 0);
1600 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1601 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1602 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1603 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1604 ReplaceUses(SDValue(N, Vec),
1605 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1606 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1607 if (isUpdating)
1608 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001609 return NULL;
1610}
1611
Bob Wilson1c3ef902011-02-07 17:43:21 +00001612SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001613 unsigned *DOpcodes, unsigned *QOpcodes0,
1614 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001615 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001616 DebugLoc dl = N->getDebugLoc();
1617
Bob Wilson226036e2010-03-20 22:13:40 +00001618 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001619 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1620 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1621 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001622 return NULL;
1623
Evan Chengb58a3402011-04-19 00:04:03 +00001624 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1625 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1626
Bob Wilson24f995d2009-10-14 18:32:29 +00001627 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001628 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001629 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001630 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001631
Bob Wilson24f995d2009-10-14 18:32:29 +00001632 unsigned OpcodeIndex;
1633 switch (VT.getSimpleVT().SimpleTy) {
1634 default: llvm_unreachable("unhandled vst type");
1635 // Double-register operations:
1636 case MVT::v8i8: OpcodeIndex = 0; break;
1637 case MVT::v4i16: OpcodeIndex = 1; break;
1638 case MVT::v2f32:
1639 case MVT::v2i32: OpcodeIndex = 2; break;
1640 case MVT::v1i64: OpcodeIndex = 3; break;
1641 // Quad-register operations:
1642 case MVT::v16i8: OpcodeIndex = 0; break;
1643 case MVT::v8i16: OpcodeIndex = 1; break;
1644 case MVT::v4f32:
1645 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001646 case MVT::v2i64: OpcodeIndex = 3;
1647 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1648 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001649 }
1650
Bob Wilson1c3ef902011-02-07 17:43:21 +00001651 std::vector<EVT> ResTys;
1652 if (isUpdating)
1653 ResTys.push_back(MVT::i32);
1654 ResTys.push_back(MVT::Other);
1655
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001656 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001657 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001658 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001659
Bob Wilson1c3ef902011-02-07 17:43:21 +00001660 // Double registers and VST1/VST2 quad registers are directly supported.
1661 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001662 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001663 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001664 SrcReg = N->getOperand(Vec0Idx);
1665 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001666 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001667 SDValue V0 = N->getOperand(Vec0Idx + 0);
1668 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001669 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001670 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001671 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001672 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001673 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001674 // an undef.
1675 SDValue V3 = (NumVecs == 3)
1676 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001677 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001678 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001679 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001680 } else {
1681 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001682 SDValue Q0 = N->getOperand(Vec0Idx);
1683 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001684 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001685 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001686
1687 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1688 QOpcodes0[OpcodeIndex]);
1689 Ops.push_back(MemAddr);
1690 Ops.push_back(Align);
1691 if (isUpdating) {
1692 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1693 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1694 }
1695 Ops.push_back(SrcReg);
1696 Ops.push_back(Pred);
1697 Ops.push_back(Reg0);
1698 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001699 SDNode *VSt =
1700 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1701
1702 // Transfer memoperands.
1703 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1704
1705 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001706 }
1707
1708 // Otherwise, quad registers are stored with two separate instructions,
1709 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001710
Bob Wilson07f6e802010-06-16 21:34:01 +00001711 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001712 SDValue V0 = N->getOperand(Vec0Idx + 0);
1713 SDValue V1 = N->getOperand(Vec0Idx + 1);
1714 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001715 SDValue V3 = (NumVecs == 3)
1716 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001717 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001718 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001719
Bob Wilson1c3ef902011-02-07 17:43:21 +00001720 // Store the even D registers. This is always an updating store, so that it
1721 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001722 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1723 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1724 MemAddr.getValueType(),
1725 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001726 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001727 Chain = SDValue(VStA, 1);
1728
1729 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001730 Ops.push_back(SDValue(VStA, 0));
1731 Ops.push_back(Align);
1732 if (isUpdating) {
1733 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1734 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1735 "only constant post-increment update allowed for VST3/4");
1736 (void)Inc;
1737 Ops.push_back(Reg0);
1738 }
1739 Ops.push_back(RegSeq);
1740 Ops.push_back(Pred);
1741 Ops.push_back(Reg0);
1742 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001743 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1744 Ops.data(), Ops.size());
1745 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1746 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001747}
1748
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001749SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001750 bool isUpdating, unsigned NumVecs,
1751 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001752 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001753 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001754 DebugLoc dl = N->getDebugLoc();
1755
Bob Wilson226036e2010-03-20 22:13:40 +00001756 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001757 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1758 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1759 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001760 return NULL;
1761
Evan Chengb58a3402011-04-19 00:04:03 +00001762 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1763 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1764
Bob Wilsona7c397c2009-10-14 16:19:03 +00001765 SDValue Chain = N->getOperand(0);
1766 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001767 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1768 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001769 bool is64BitVector = VT.is64BitVector();
1770
Bob Wilson665814b2010-11-01 23:40:51 +00001771 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001772 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001773 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001774 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1775 if (Alignment > NumBytes)
1776 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001777 if (Alignment < 8 && Alignment < NumBytes)
1778 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001779 // Alignment must be a power of two; make sure of that.
1780 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001781 if (Alignment == 1)
1782 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001783 }
Bob Wilson665814b2010-11-01 23:40:51 +00001784 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001785
Bob Wilsona7c397c2009-10-14 16:19:03 +00001786 unsigned OpcodeIndex;
1787 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001788 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001789 // Double-register operations:
1790 case MVT::v8i8: OpcodeIndex = 0; break;
1791 case MVT::v4i16: OpcodeIndex = 1; break;
1792 case MVT::v2f32:
1793 case MVT::v2i32: OpcodeIndex = 2; break;
1794 // Quad-register operations:
1795 case MVT::v8i16: OpcodeIndex = 0; break;
1796 case MVT::v4f32:
1797 case MVT::v4i32: OpcodeIndex = 1; break;
1798 }
1799
Bob Wilson1c3ef902011-02-07 17:43:21 +00001800 std::vector<EVT> ResTys;
1801 if (IsLoad) {
1802 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1803 if (!is64BitVector)
1804 ResTyElts *= 2;
1805 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1806 MVT::i64, ResTyElts));
1807 }
1808 if (isUpdating)
1809 ResTys.push_back(MVT::i32);
1810 ResTys.push_back(MVT::Other);
1811
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001812 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001813 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001814
Bob Wilson1c3ef902011-02-07 17:43:21 +00001815 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001816 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001817 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001818 if (isUpdating) {
1819 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1820 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1821 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001822
Bob Wilson8466fa12010-09-13 23:01:35 +00001823 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001824 SDValue V0 = N->getOperand(Vec0Idx + 0);
1825 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001826 if (NumVecs == 2) {
1827 if (is64BitVector)
1828 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1829 else
1830 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001831 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001832 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001833 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001834 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1835 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001836 if (is64BitVector)
1837 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1838 else
1839 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001840 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001841 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001842 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001843 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001844 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001845 Ops.push_back(Chain);
1846
Bob Wilson1c3ef902011-02-07 17:43:21 +00001847 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1848 QOpcodes[OpcodeIndex]);
1849 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1850 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001851 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001852 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001853 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001854
Bob Wilson8466fa12010-09-13 23:01:35 +00001855 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001856 SuperReg = SDValue(VLdLn, 0);
1857 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1858 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1859 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001860 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1861 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001862 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1863 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1864 if (isUpdating)
1865 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001866 return NULL;
1867}
1868
Bob Wilson1c3ef902011-02-07 17:43:21 +00001869SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1870 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001871 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1872 DebugLoc dl = N->getDebugLoc();
1873
1874 SDValue MemAddr, Align;
1875 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1876 return NULL;
1877
Evan Chengb58a3402011-04-19 00:04:03 +00001878 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1879 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1880
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001881 SDValue Chain = N->getOperand(0);
1882 EVT VT = N->getValueType(0);
1883
1884 unsigned Alignment = 0;
1885 if (NumVecs != 3) {
1886 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1887 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1888 if (Alignment > NumBytes)
1889 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001890 if (Alignment < 8 && Alignment < NumBytes)
1891 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001892 // Alignment must be a power of two; make sure of that.
1893 Alignment = (Alignment & -Alignment);
1894 if (Alignment == 1)
1895 Alignment = 0;
1896 }
1897 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1898
1899 unsigned OpcodeIndex;
1900 switch (VT.getSimpleVT().SimpleTy) {
1901 default: llvm_unreachable("unhandled vld-dup type");
1902 case MVT::v8i8: OpcodeIndex = 0; break;
1903 case MVT::v4i16: OpcodeIndex = 1; break;
1904 case MVT::v2f32:
1905 case MVT::v2i32: OpcodeIndex = 2; break;
1906 }
1907
1908 SDValue Pred = getAL(CurDAG);
1909 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1910 SDValue SuperReg;
1911 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001912 SmallVector<SDValue, 6> Ops;
1913 Ops.push_back(MemAddr);
1914 Ops.push_back(Align);
1915 if (isUpdating) {
1916 SDValue Inc = N->getOperand(2);
1917 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1918 }
1919 Ops.push_back(Pred);
1920 Ops.push_back(Reg0);
1921 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001922
1923 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001924 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001925 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001926 if (isUpdating)
1927 ResTys.push_back(MVT::i32);
1928 ResTys.push_back(MVT::Other);
1929 SDNode *VLdDup =
1930 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001931 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001932 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001933
1934 // Extract the subregisters.
1935 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1936 unsigned SubIdx = ARM::dsub_0;
1937 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1938 ReplaceUses(SDValue(N, Vec),
1939 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001940 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1941 if (isUpdating)
1942 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001943 return NULL;
1944}
1945
Bob Wilson78dfbc32010-07-07 00:08:54 +00001946SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1947 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001948 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1949 DebugLoc dl = N->getDebugLoc();
1950 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001951 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001952
1953 // Form a REG_SEQUENCE to force register allocation.
1954 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001955 SDValue V0 = N->getOperand(FirstTblReg + 0);
1956 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001957 if (NumVecs == 2)
1958 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1959 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001960 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001961 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001962 // an undef.
1963 SDValue V3 = (NumVecs == 3)
1964 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001965 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001966 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1967 }
1968
Bob Wilson78dfbc32010-07-07 00:08:54 +00001969 SmallVector<SDValue, 6> Ops;
1970 if (IsExt)
1971 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001972 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001973 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001974 Ops.push_back(getAL(CurDAG)); // predicate
1975 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001976 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001977}
1978
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001980 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001981 if (!Subtarget->hasV6T2Ops())
1982 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001983
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001984 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1985 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1986
1987
1988 // For unsigned extracts, check for a shift right and mask
1989 unsigned And_imm = 0;
1990 if (N->getOpcode() == ISD::AND) {
1991 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1992
1993 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1994 if (And_imm & (And_imm + 1))
1995 return NULL;
1996
1997 unsigned Srl_imm = 0;
1998 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1999 Srl_imm)) {
2000 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2001
2002 unsigned Width = CountTrailingOnes_32(And_imm);
2003 unsigned LSB = Srl_imm;
2004 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2005 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2006 CurDAG->getTargetConstant(LSB, MVT::i32),
2007 CurDAG->getTargetConstant(Width, MVT::i32),
2008 getAL(CurDAG), Reg0 };
2009 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2010 }
2011 }
2012 return NULL;
2013 }
2014
2015 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002016 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002017 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002018 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2019 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002020 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002021 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2022 unsigned Width = 32 - Srl_imm;
2023 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002024 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002025 return NULL;
2026 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002027 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002028 CurDAG->getTargetConstant(LSB, MVT::i32),
2029 CurDAG->getTargetConstant(Width, MVT::i32),
2030 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002031 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002032 }
2033 }
2034 return NULL;
2035}
2036
Evan Cheng9ef48352009-11-20 00:54:03 +00002037SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002038SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002039 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2040 SDValue CPTmp0;
2041 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002042 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002043 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2044 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2045 unsigned Opc = 0;
2046 switch (SOShOp) {
2047 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2048 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2049 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2050 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2051 default:
2052 llvm_unreachable("Unknown so_reg opcode!");
2053 break;
2054 }
2055 SDValue SOShImm =
2056 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2057 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2058 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002059 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002060 }
2061 return 0;
2062}
2063
2064SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002065SelectARMCMOVShiftOp(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;
2069 SDValue CPTmp2;
Owen Anderson92a20222011-07-21 18:54:16 +00002070 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002071 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2072 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Owen Anderson92a20222011-07-21 18:54:16 +00002073 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 7);
2074 }
2075
2076 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2077 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2078 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2079 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002080 }
2081 return 0;
2082}
2083
2084SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002085SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002086 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002087 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002088 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002089 return 0;
2090
Evan Cheng63f35442010-11-13 02:25:14 +00002091 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002092 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002093 if (is_t2_so_imm(TrueImm)) {
2094 Opc = ARM::t2MOVCCi;
2095 } else if (TrueImm <= 0xffff) {
2096 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002097 } else if (is_t2_so_imm_not(TrueImm)) {
2098 TrueImm = ~TrueImm;
2099 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002100 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002101 // Large immediate.
2102 Opc = ARM::t2MOVCCi32imm;
2103 }
2104
2105 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002106 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002107 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2108 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002109 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002110 }
Evan Cheng63f35442010-11-13 02:25:14 +00002111
Evan Cheng9ef48352009-11-20 00:54:03 +00002112 return 0;
2113}
2114
2115SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002116SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002117 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002118 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2119 if (!T)
2120 return 0;
2121
Evan Cheng63f35442010-11-13 02:25:14 +00002122 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002123 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002124 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002125 if (isSoImm) {
2126 Opc = ARM::MOVCCi;
2127 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2128 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002129 } else if (is_so_imm_not(TrueImm)) {
2130 TrueImm = ~TrueImm;
2131 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002132 } else if (TrueVal.getNode()->hasOneUse() &&
2133 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002134 // Large immediate.
2135 Opc = ARM::MOVCCi32imm;
2136 }
2137
2138 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002139 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002140 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2141 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002142 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002143 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002144
Evan Cheng9ef48352009-11-20 00:54:03 +00002145 return 0;
2146}
2147
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2149 EVT VT = N->getValueType(0);
2150 SDValue FalseVal = N->getOperand(0);
2151 SDValue TrueVal = N->getOperand(1);
2152 SDValue CC = N->getOperand(2);
2153 SDValue CCR = N->getOperand(3);
2154 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002155 assert(CC.getOpcode() == ISD::Constant);
2156 assert(CCR.getOpcode() == ISD::Register);
2157 ARMCC::CondCodes CCVal =
2158 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002159
2160 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2161 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2162 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2163 // Pattern complexity = 18 cost = 1 size = 0
2164 SDValue CPTmp0;
2165 SDValue CPTmp1;
2166 SDValue CPTmp2;
2167 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002168 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002169 CCVal, CCR, InFlag);
2170 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002171 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2173 if (Res)
2174 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002175 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002176 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002177 CCVal, CCR, InFlag);
2178 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002179 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002180 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2181 if (Res)
2182 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002183 }
2184
2185 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002186 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002187 // (imm:i32):$cc)
2188 // Emits: (MOVCCi:i32 GPR:i32:$false,
2189 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2190 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002191 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002192 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002193 CCVal, CCR, InFlag);
2194 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002195 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002196 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2197 if (Res)
2198 return Res;
2199 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002200 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002201 CCVal, CCR, InFlag);
2202 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002203 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002204 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2205 if (Res)
2206 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002207 }
2208 }
2209
2210 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2211 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2212 // Pattern complexity = 6 cost = 1 size = 0
2213 //
2214 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2215 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2216 // Pattern complexity = 6 cost = 11 size = 0
2217 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002218 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002219 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2220 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002221 unsigned Opc = 0;
2222 switch (VT.getSimpleVT().SimpleTy) {
2223 default: assert(false && "Illegal conditional move type!");
2224 break;
2225 case MVT::i32:
2226 Opc = Subtarget->isThumb()
2227 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2228 : ARM::MOVCCr;
2229 break;
2230 case MVT::f32:
2231 Opc = ARM::VMOVScc;
2232 break;
2233 case MVT::f64:
2234 Opc = ARM::VMOVDcc;
2235 break;
2236 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002237 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002238}
2239
Evan Chengde8aa4e2010-05-05 18:28:36 +00002240SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2241 // The only time a CONCAT_VECTORS operation can have legal types is when
2242 // two 64-bit vectors are concatenated to a 128-bit vector.
2243 EVT VT = N->getValueType(0);
2244 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2245 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002246 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002247}
2248
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002249SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002250 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002251
Dan Gohmane8be6c62008-07-17 19:10:17 +00002252 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002253 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002254
2255 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002256 default: break;
2257 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002258 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002259 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002260 if (Subtarget->hasThumb2())
2261 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2262 // be done with MOV + MOVT, at worst.
2263 UseCP = 0;
2264 else {
2265 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002266 UseCP = (Val > 255 && // MOV
2267 ~Val > 255 && // MOV + MVN
2268 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002269 } else
2270 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2271 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2272 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2273 }
2274
Evan Chenga8e29892007-01-19 07:51:42 +00002275 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002276 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002277 CurDAG->getTargetConstantPool(ConstantInt::get(
2278 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002279 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002280
2281 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002282 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002283 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002284 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002285 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002286 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002287 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002288 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002289 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002290 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002291 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002292 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002293 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002294 CurDAG->getEntryNode()
2295 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002296 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002297 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002298 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002299 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002300 return NULL;
2301 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002302
Evan Chenga8e29892007-01-19 07:51:42 +00002303 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002304 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002305 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002306 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002307 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002308 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002309 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002310 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002311 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2312 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002313 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002314 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2315 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002316 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2317 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2318 CurDAG->getRegister(0, MVT::i32) };
2319 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002320 }
Evan Chenga8e29892007-01-19 07:51:42 +00002321 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002322 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002323 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002324 return I;
2325 break;
2326 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002327 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002328 return I;
2329 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002330 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002331 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002332 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002333 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002334 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002335 if (!RHSV) break;
2336 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002337 unsigned ShImm = Log2_32(RHSV-1);
2338 if (ShImm >= 32)
2339 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002340 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002341 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002342 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2343 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002344 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002345 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002346 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002347 } else {
2348 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002349 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002350 }
Evan Chenga8e29892007-01-19 07:51:42 +00002351 }
2352 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002353 unsigned ShImm = Log2_32(RHSV+1);
2354 if (ShImm >= 32)
2355 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002356 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002357 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002358 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2359 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002360 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002361 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2362 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002363 } else {
2364 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002365 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002366 }
Evan Chenga8e29892007-01-19 07:51:42 +00002367 }
2368 }
2369 break;
Evan Cheng20956592009-10-21 08:15:52 +00002370 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002371 // Check for unsigned bitfield extract
2372 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2373 return I;
2374
Evan Cheng20956592009-10-21 08:15:52 +00002375 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2376 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2377 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2378 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2379 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002380 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002381 if (VT != MVT::i32)
2382 break;
2383 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2384 ? ARM::t2MOVTi16
2385 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2386 if (!Opc)
2387 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002388 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002389 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2390 if (!N1C)
2391 break;
2392 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2393 SDValue N2 = N0.getOperand(1);
2394 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2395 if (!N2C)
2396 break;
2397 unsigned N1CVal = N1C->getZExtValue();
2398 unsigned N2CVal = N2C->getZExtValue();
2399 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2400 (N1CVal & 0xffffU) == 0xffffU &&
2401 (N2CVal & 0xffffU) == 0x0U) {
2402 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2403 MVT::i32);
2404 SDValue Ops[] = { N0.getOperand(0), Imm16,
2405 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2406 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2407 }
2408 }
2409 break;
2410 }
Jim Grosbache5165492009-11-09 00:11:35 +00002411 case ARMISD::VMOVRRD:
2412 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002413 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002414 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002415 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002416 if (Subtarget->isThumb1Only())
2417 break;
2418 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002419 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002420 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2421 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002422 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002423 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002424 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002425 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2426 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002427 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2428 ARM::UMULL : ARM::UMULLv5,
2429 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002430 }
Evan Chengee568cf2007-07-05 07:15:27 +00002431 }
Dan Gohman525178c2007-10-08 18:33:35 +00002432 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002433 if (Subtarget->isThumb1Only())
2434 break;
2435 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002436 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002437 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002438 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002439 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002440 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002441 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2442 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002443 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2444 ARM::SMULL : ARM::SMULLv5,
2445 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002446 }
Evan Chengee568cf2007-07-05 07:15:27 +00002447 }
Evan Chenga8e29892007-01-19 07:51:42 +00002448 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002449 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002450 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002451 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002452 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002453 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002454 if (ResNode)
2455 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002456 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002457 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002458 }
Evan Chengee568cf2007-07-05 07:15:27 +00002459 case ARMISD::BRCOND: {
2460 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2461 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2462 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002463
Evan Chengee568cf2007-07-05 07:15:27 +00002464 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2465 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2466 // Pattern complexity = 6 cost = 1 size = 0
2467
David Goodwin5e47a9a2009-06-30 18:04:13 +00002468 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2469 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2470 // Pattern complexity = 6 cost = 1 size = 0
2471
Jim Grosbach764ab522009-08-11 15:33:49 +00002472 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002473 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002474 SDValue Chain = N->getOperand(0);
2475 SDValue N1 = N->getOperand(1);
2476 SDValue N2 = N->getOperand(2);
2477 SDValue N3 = N->getOperand(3);
2478 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002479 assert(N1.getOpcode() == ISD::BasicBlock);
2480 assert(N2.getOpcode() == ISD::Constant);
2481 assert(N3.getOpcode() == ISD::Register);
2482
Dan Gohman475871a2008-07-27 21:46:04 +00002483 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002484 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002485 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002486 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002487 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002488 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002489 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002490 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002491 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002492 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002493 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002494 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002495 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002496 return NULL;
2497 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002498 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002499 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002500 case ARMISD::VZIP: {
2501 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002502 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002503 switch (VT.getSimpleVT().SimpleTy) {
2504 default: return NULL;
2505 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2506 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2507 case MVT::v2f32:
2508 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2509 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2510 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2511 case MVT::v4f32:
2512 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2513 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002514 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002515 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2516 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2517 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002518 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002519 case ARMISD::VUZP: {
2520 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002521 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002522 switch (VT.getSimpleVT().SimpleTy) {
2523 default: return NULL;
2524 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2525 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2526 case MVT::v2f32:
2527 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2528 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2529 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2530 case MVT::v4f32:
2531 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2532 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002533 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002534 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2535 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2536 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002537 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002538 case ARMISD::VTRN: {
2539 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002540 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002541 switch (VT.getSimpleVT().SimpleTy) {
2542 default: return NULL;
2543 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2544 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2545 case MVT::v2f32:
2546 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2547 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2548 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2549 case MVT::v4f32:
2550 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2551 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002552 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002553 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2554 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2555 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002556 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002557 case ARMISD::BUILD_VECTOR: {
2558 EVT VecVT = N->getValueType(0);
2559 EVT EltVT = VecVT.getVectorElementType();
2560 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002561 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002562 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2563 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2564 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002565 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002566 if (NumElts == 2)
2567 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2568 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2569 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2570 N->getOperand(2), N->getOperand(3));
2571 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002572
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002573 case ARMISD::VLD2DUP: {
2574 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2575 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002576 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002577 }
2578
Bob Wilson86c6d802010-11-29 19:35:29 +00002579 case ARMISD::VLD3DUP: {
2580 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2581 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002582 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002583 }
2584
Bob Wilson6c4c9822010-11-30 00:00:35 +00002585 case ARMISD::VLD4DUP: {
2586 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2587 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002588 return SelectVLDDup(N, false, 4, Opcodes);
2589 }
2590
2591 case ARMISD::VLD2DUP_UPD: {
2592 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2593 ARM::VLD2DUPd32Pseudo_UPD };
2594 return SelectVLDDup(N, true, 2, Opcodes);
2595 }
2596
2597 case ARMISD::VLD3DUP_UPD: {
2598 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2599 ARM::VLD3DUPd32Pseudo_UPD };
2600 return SelectVLDDup(N, true, 3, Opcodes);
2601 }
2602
2603 case ARMISD::VLD4DUP_UPD: {
2604 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2605 ARM::VLD4DUPd32Pseudo_UPD };
2606 return SelectVLDDup(N, true, 4, Opcodes);
2607 }
2608
2609 case ARMISD::VLD1_UPD: {
2610 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2611 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2612 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2613 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2614 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2615 }
2616
2617 case ARMISD::VLD2_UPD: {
2618 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2619 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2620 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2621 ARM::VLD2q32Pseudo_UPD };
2622 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2623 }
2624
2625 case ARMISD::VLD3_UPD: {
2626 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2627 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2628 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2629 ARM::VLD3q16Pseudo_UPD,
2630 ARM::VLD3q32Pseudo_UPD };
2631 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2632 ARM::VLD3q16oddPseudo_UPD,
2633 ARM::VLD3q32oddPseudo_UPD };
2634 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2635 }
2636
2637 case ARMISD::VLD4_UPD: {
2638 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2639 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2640 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2641 ARM::VLD4q16Pseudo_UPD,
2642 ARM::VLD4q32Pseudo_UPD };
2643 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2644 ARM::VLD4q16oddPseudo_UPD,
2645 ARM::VLD4q32oddPseudo_UPD };
2646 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2647 }
2648
2649 case ARMISD::VLD2LN_UPD: {
2650 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2651 ARM::VLD2LNd32Pseudo_UPD };
2652 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2653 ARM::VLD2LNq32Pseudo_UPD };
2654 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2655 }
2656
2657 case ARMISD::VLD3LN_UPD: {
2658 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2659 ARM::VLD3LNd32Pseudo_UPD };
2660 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2661 ARM::VLD3LNq32Pseudo_UPD };
2662 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2663 }
2664
2665 case ARMISD::VLD4LN_UPD: {
2666 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2667 ARM::VLD4LNd32Pseudo_UPD };
2668 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2669 ARM::VLD4LNq32Pseudo_UPD };
2670 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2671 }
2672
2673 case ARMISD::VST1_UPD: {
2674 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2675 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2676 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2677 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2678 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2679 }
2680
2681 case ARMISD::VST2_UPD: {
2682 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2683 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2684 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2685 ARM::VST2q32Pseudo_UPD };
2686 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2687 }
2688
2689 case ARMISD::VST3_UPD: {
2690 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2691 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2692 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2693 ARM::VST3q16Pseudo_UPD,
2694 ARM::VST3q32Pseudo_UPD };
2695 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2696 ARM::VST3q16oddPseudo_UPD,
2697 ARM::VST3q32oddPseudo_UPD };
2698 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2699 }
2700
2701 case ARMISD::VST4_UPD: {
2702 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2703 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2704 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2705 ARM::VST4q16Pseudo_UPD,
2706 ARM::VST4q32Pseudo_UPD };
2707 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2708 ARM::VST4q16oddPseudo_UPD,
2709 ARM::VST4q32oddPseudo_UPD };
2710 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2711 }
2712
2713 case ARMISD::VST2LN_UPD: {
2714 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2715 ARM::VST2LNd32Pseudo_UPD };
2716 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2717 ARM::VST2LNq32Pseudo_UPD };
2718 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2719 }
2720
2721 case ARMISD::VST3LN_UPD: {
2722 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2723 ARM::VST3LNd32Pseudo_UPD };
2724 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2725 ARM::VST3LNq32Pseudo_UPD };
2726 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2727 }
2728
2729 case ARMISD::VST4LN_UPD: {
2730 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2731 ARM::VST4LNd32Pseudo_UPD };
2732 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2733 ARM::VST4LNq32Pseudo_UPD };
2734 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002735 }
2736
Bob Wilson31fb12f2009-08-26 17:39:53 +00002737 case ISD::INTRINSIC_VOID:
2738 case ISD::INTRINSIC_W_CHAIN: {
2739 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002740 switch (IntNo) {
2741 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002742 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002743
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002744 case Intrinsic::arm_ldrexd: {
2745 SDValue MemAddr = N->getOperand(2);
2746 DebugLoc dl = N->getDebugLoc();
2747 SDValue Chain = N->getOperand(0);
2748
2749 unsigned NewOpc = ARM::LDREXD;
2750 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2751 NewOpc = ARM::t2LDREXD;
2752
2753 // arm_ldrexd returns a i64 value in {i32, i32}
2754 std::vector<EVT> ResTys;
2755 ResTys.push_back(MVT::i32);
2756 ResTys.push_back(MVT::i32);
2757 ResTys.push_back(MVT::Other);
2758
2759 // place arguments in the right order
2760 SmallVector<SDValue, 7> Ops;
2761 Ops.push_back(MemAddr);
2762 Ops.push_back(getAL(CurDAG));
2763 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2764 Ops.push_back(Chain);
2765 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2766 Ops.size());
2767 // Transfer memoperands.
2768 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2769 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2770 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2771
2772 // Until there's support for specifing explicit register constraints
2773 // like the use of even/odd register pair, hardcode ldrexd to always
2774 // use the pair [R0, R1] to hold the load result.
2775 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2776 SDValue(Ld, 0), SDValue(0,0));
2777 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2778 SDValue(Ld, 1), Chain.getValue(1));
2779
2780 // Remap uses.
2781 SDValue Glue = Chain.getValue(1);
2782 if (!SDValue(N, 0).use_empty()) {
2783 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2784 ARM::R0, MVT::i32, Glue);
2785 Glue = Result.getValue(2);
2786 ReplaceUses(SDValue(N, 0), Result);
2787 }
2788 if (!SDValue(N, 1).use_empty()) {
2789 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2790 ARM::R1, MVT::i32, Glue);
2791 Glue = Result.getValue(2);
2792 ReplaceUses(SDValue(N, 1), Result);
2793 }
2794
2795 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2796 return NULL;
2797 }
2798
2799 case Intrinsic::arm_strexd: {
2800 DebugLoc dl = N->getDebugLoc();
2801 SDValue Chain = N->getOperand(0);
2802 SDValue Val0 = N->getOperand(2);
2803 SDValue Val1 = N->getOperand(3);
2804 SDValue MemAddr = N->getOperand(4);
2805
2806 // Until there's support for specifing explicit register constraints
2807 // like the use of even/odd register pair, hardcode strexd to always
2808 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2809 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2810 SDValue(0, 0));
2811 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2812
2813 SDValue Glue = Chain.getValue(1);
2814 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2815 ARM::R2, MVT::i32, Glue);
2816 Glue = Val0.getValue(1);
2817 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2818 ARM::R3, MVT::i32, Glue);
2819
2820 // Store exclusive double return a i32 value which is the return status
2821 // of the issued store.
2822 std::vector<EVT> ResTys;
2823 ResTys.push_back(MVT::i32);
2824 ResTys.push_back(MVT::Other);
2825
2826 // place arguments in the right order
2827 SmallVector<SDValue, 7> Ops;
2828 Ops.push_back(Val0);
2829 Ops.push_back(Val1);
2830 Ops.push_back(MemAddr);
2831 Ops.push_back(getAL(CurDAG));
2832 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2833 Ops.push_back(Chain);
2834
2835 unsigned NewOpc = ARM::STREXD;
2836 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2837 NewOpc = ARM::t2STREXD;
2838
2839 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2840 Ops.size());
2841 // Transfer memoperands.
2842 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2843 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2844 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2845
2846 return St;
2847 }
2848
Bob Wilson621f1952010-03-23 05:25:43 +00002849 case Intrinsic::arm_neon_vld1: {
2850 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2851 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002852 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2853 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002854 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002855 }
2856
Bob Wilson31fb12f2009-08-26 17:39:53 +00002857 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002858 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2859 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2860 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2861 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002862 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002863 }
2864
2865 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002866 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2867 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2868 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2869 ARM::VLD3q16Pseudo_UPD,
2870 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002871 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2872 ARM::VLD3q16oddPseudo,
2873 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002874 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002875 }
2876
2877 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002878 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2879 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2880 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2881 ARM::VLD4q16Pseudo_UPD,
2882 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002883 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2884 ARM::VLD4q16oddPseudo,
2885 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002886 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002887 }
2888
Bob Wilson243fcc52009-09-01 04:26:28 +00002889 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002890 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2891 ARM::VLD2LNd32Pseudo };
2892 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002893 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002894 }
2895
2896 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002897 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2898 ARM::VLD3LNd32Pseudo };
2899 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002900 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002901 }
2902
2903 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002904 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2905 ARM::VLD4LNd32Pseudo };
2906 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002907 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002908 }
2909
Bob Wilson11d98992010-03-23 06:20:33 +00002910 case Intrinsic::arm_neon_vst1: {
2911 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2912 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002913 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2914 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002915 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002916 }
2917
Bob Wilson31fb12f2009-08-26 17:39:53 +00002918 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002919 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2920 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2921 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2922 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002923 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002924 }
2925
2926 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002927 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2928 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2929 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2930 ARM::VST3q16Pseudo_UPD,
2931 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002932 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2933 ARM::VST3q16oddPseudo,
2934 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002935 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002936 }
2937
2938 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002939 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002940 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002941 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2942 ARM::VST4q16Pseudo_UPD,
2943 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002944 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2945 ARM::VST4q16oddPseudo,
2946 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002947 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002948 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002949
2950 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002951 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2952 ARM::VST2LNd32Pseudo };
2953 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002954 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002955 }
2956
2957 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002958 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2959 ARM::VST3LNd32Pseudo };
2960 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002961 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002962 }
2963
2964 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002965 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2966 ARM::VST4LNd32Pseudo };
2967 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002968 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002969 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002970 }
Bob Wilson429009b2010-05-06 16:05:26 +00002971 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002972 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002973
Bob Wilsond491d6e2010-07-06 23:36:25 +00002974 case ISD::INTRINSIC_WO_CHAIN: {
2975 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2976 switch (IntNo) {
2977 default:
2978 break;
2979
2980 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002981 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002982 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002983 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002984 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002985 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002986
2987 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002988 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002989 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002990 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002991 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002992 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002993 }
2994 break;
2995 }
2996
Bill Wendling69a05a72011-03-14 23:02:38 +00002997 case ARMISD::VTBL1: {
2998 DebugLoc dl = N->getDebugLoc();
2999 EVT VT = N->getValueType(0);
3000 SmallVector<SDValue, 6> Ops;
3001
3002 Ops.push_back(N->getOperand(0));
3003 Ops.push_back(N->getOperand(1));
3004 Ops.push_back(getAL(CurDAG)); // Predicate
3005 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3006 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3007 }
3008 case ARMISD::VTBL2: {
3009 DebugLoc dl = N->getDebugLoc();
3010 EVT VT = N->getValueType(0);
3011
3012 // Form a REG_SEQUENCE to force register allocation.
3013 SDValue V0 = N->getOperand(0);
3014 SDValue V1 = N->getOperand(1);
3015 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3016
3017 SmallVector<SDValue, 6> Ops;
3018 Ops.push_back(RegSeq);
3019 Ops.push_back(N->getOperand(2));
3020 Ops.push_back(getAL(CurDAG)); // Predicate
3021 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3022 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3023 Ops.data(), Ops.size());
3024 }
3025
Bob Wilson429009b2010-05-06 16:05:26 +00003026 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003027 return SelectConcatVector(N);
3028 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003029
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003030 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003031}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003032
Bob Wilson224c2442009-05-19 05:53:42 +00003033bool ARMDAGToDAGISel::
3034SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3035 std::vector<SDValue> &OutOps) {
3036 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003037 // Require the address to be in a register. That is safe for all ARM
3038 // variants and it is hard to do anything much smarter without knowing
3039 // how the operand is used.
3040 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003041 return false;
3042}
3043
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003044/// createARMISelDag - This pass converts a legalized DAG into a
3045/// ARM-specific DAG, ready for instruction scheduling.
3046///
Bob Wilson522ce972009-09-28 14:30:20 +00003047FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3048 CodeGenOpt::Level OptLevel) {
3049 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003050}