blob: 467b08224c127e431d52fd7b3fc7bca82429006d [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000107 }
108
Jim Grosbach3e556122010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach82891622010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
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,
Owen Anderson099e5552011-03-18 19:46:58 +0000377 SDValue &Opc,
378 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000379 if (DisableShifterOp)
380 return false;
381
Evan Chengee04a6d2011-07-20 23:34:39 +0000382 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000383
384 // Don't match base register only case. That is matched to a separate
385 // lower complexity pattern with explicit register operand.
386 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000387
Evan Cheng055b0312009-06-29 07:51:04 +0000388 BaseReg = N.getOperand(0);
389 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000390 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
391 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000392 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000393 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
394 MVT::i32);
395 return true;
396}
397
Owen Anderson92a20222011-07-21 18:54:16 +0000398bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
399 SDValue &BaseReg,
400 SDValue &ShReg,
401 SDValue &Opc,
402 bool CheckProfitability) {
403 if (DisableShifterOp)
404 return false;
405
406 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
407
408 // Don't match base register only case. That is matched to a separate
409 // lower complexity pattern with explicit register operand.
410 if (ShOpcVal == ARM_AM::no_shift) return false;
411
412 BaseReg = N.getOperand(0);
413 unsigned ShImmVal = 0;
414 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
415 if (RHS) return false;
416
417 ShReg = N.getOperand(1);
418 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
419 return false;
420 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
421 MVT::i32);
422 return true;
423}
424
425
Jim Grosbach3e556122010-10-26 22:37:02 +0000426bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
427 SDValue &Base,
428 SDValue &OffImm) {
429 // Match simple R + imm12 operands.
430
431 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000432 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
433 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000434 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000435 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000436 int FI = cast<FrameIndexSDNode>(N)->getIndex();
437 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
438 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
439 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000440 }
Owen Anderson099e5552011-03-18 19:46:58 +0000441
Chris Lattner0a9481f2011-02-13 22:25:43 +0000442 if (N.getOpcode() == ARMISD::Wrapper &&
443 !(Subtarget->useMovt() &&
444 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000445 Base = N.getOperand(0);
446 } else
447 Base = N;
448 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
449 return true;
450 }
451
452 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
453 int RHSC = (int)RHS->getZExtValue();
454 if (N.getOpcode() == ISD::SUB)
455 RHSC = -RHSC;
456
457 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
458 Base = N.getOperand(0);
459 if (Base.getOpcode() == ISD::FrameIndex) {
460 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
461 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
462 }
463 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
464 return true;
465 }
466 }
467
468 // Base only.
469 Base = N;
470 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
471 return true;
472}
473
474
475
476bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
477 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000478 if (N.getOpcode() == ISD::MUL &&
479 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000480 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
481 // X * [3,5,9] -> X + X * [2,4,8] etc.
482 int RHSC = (int)RHS->getZExtValue();
483 if (RHSC & 1) {
484 RHSC = RHSC & ~1;
485 ARM_AM::AddrOpc AddSub = ARM_AM::add;
486 if (RHSC < 0) {
487 AddSub = ARM_AM::sub;
488 RHSC = - RHSC;
489 }
490 if (isPowerOf2_32(RHSC)) {
491 unsigned ShAmt = Log2_32(RHSC);
492 Base = Offset = N.getOperand(0);
493 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
494 ARM_AM::lsl),
495 MVT::i32);
496 return true;
497 }
498 }
499 }
500 }
501
Chris Lattner0a9481f2011-02-13 22:25:43 +0000502 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
503 // ISD::OR that is equivalent to an ISD::ADD.
504 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000505 return false;
506
507 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000508 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000509 int RHSC;
510 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
511 -0x1000+1, 0x1000, RHSC)) // 12 bits.
512 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000513 }
514
Evan Chengf40deed2010-10-27 23:41:30 +0000515 if (Subtarget->isCortexA9() && !N.hasOneUse())
516 // Compute R +/- (R << N) and reuse it.
517 return false;
518
Jim Grosbach3e556122010-10-26 22:37:02 +0000519 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000520 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000521 ARM_AM::ShiftOpc ShOpcVal =
522 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000523 unsigned ShAmt = 0;
524
525 Base = N.getOperand(0);
526 Offset = N.getOperand(1);
527
528 if (ShOpcVal != ARM_AM::no_shift) {
529 // Check to see if the RHS of the shift is a constant, if not, we can't fold
530 // it.
531 if (ConstantSDNode *Sh =
532 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
533 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000534 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
535 Offset = N.getOperand(1).getOperand(0);
536 else {
537 ShAmt = 0;
538 ShOpcVal = ARM_AM::no_shift;
539 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000540 } else {
541 ShOpcVal = ARM_AM::no_shift;
542 }
543 }
544
545 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000546 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000547 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000548 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000549 if (ShOpcVal != ARM_AM::no_shift) {
550 // Check to see if the RHS of the shift is a constant, if not, we can't
551 // fold it.
552 if (ConstantSDNode *Sh =
553 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
554 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000555 if (!Subtarget->isCortexA9() ||
556 (N.hasOneUse() &&
557 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
558 Offset = N.getOperand(0).getOperand(0);
559 Base = N.getOperand(1);
560 } else {
561 ShAmt = 0;
562 ShOpcVal = ARM_AM::no_shift;
563 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000564 } else {
565 ShOpcVal = ARM_AM::no_shift;
566 }
567 }
568 }
569
570 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
571 MVT::i32);
572 return true;
573}
574
575
576
577
578//-----
579
Jim Grosbach82891622010-09-29 19:03:54 +0000580AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
581 SDValue &Base,
582 SDValue &Offset,
583 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000584 if (N.getOpcode() == ISD::MUL &&
585 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000586 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
587 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000588 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000589 if (RHSC & 1) {
590 RHSC = RHSC & ~1;
591 ARM_AM::AddrOpc AddSub = ARM_AM::add;
592 if (RHSC < 0) {
593 AddSub = ARM_AM::sub;
594 RHSC = - RHSC;
595 }
596 if (isPowerOf2_32(RHSC)) {
597 unsigned ShAmt = Log2_32(RHSC);
598 Base = Offset = N.getOperand(0);
599 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
600 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000601 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000602 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000603 }
604 }
605 }
606 }
607
Chris Lattner0a9481f2011-02-13 22:25:43 +0000608 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
609 // ISD::OR that is equivalent to an ADD.
610 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000611 Base = N;
612 if (N.getOpcode() == ISD::FrameIndex) {
613 int FI = cast<FrameIndexSDNode>(N)->getIndex();
614 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000615 } else if (N.getOpcode() == ARMISD::Wrapper &&
616 !(Subtarget->useMovt() &&
617 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000618 Base = N.getOperand(0);
619 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000620 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000621 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
622 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000623 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000624 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000625 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000626
Evan Chenga8e29892007-01-19 07:51:42 +0000627 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000628 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000629 int RHSC;
630 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
631 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
632 Base = N.getOperand(0);
633 if (Base.getOpcode() == ISD::FrameIndex) {
634 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
635 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000636 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000637 Offset = CurDAG->getRegister(0, MVT::i32);
638
639 ARM_AM::AddrOpc AddSub = ARM_AM::add;
640 if (RHSC < 0) {
641 AddSub = ARM_AM::sub;
642 RHSC = - RHSC;
643 }
644 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
645 ARM_AM::no_shift),
646 MVT::i32);
647 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000648 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000649 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000650
Evan Chengf40deed2010-10-27 23:41:30 +0000651 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
652 // Compute R +/- (R << N) and reuse it.
653 Base = N;
654 Offset = CurDAG->getRegister(0, MVT::i32);
655 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
656 ARM_AM::no_shift),
657 MVT::i32);
658 return AM2_BASE;
659 }
660
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000661 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000662 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000663 ARM_AM::ShiftOpc ShOpcVal =
664 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000665 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000666
Evan Chenga8e29892007-01-19 07:51:42 +0000667 Base = N.getOperand(0);
668 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 if (ShOpcVal != ARM_AM::no_shift) {
671 // Check to see if the RHS of the shift is a constant, if not, we can't fold
672 // it.
673 if (ConstantSDNode *Sh =
674 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000675 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000676 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
677 Offset = N.getOperand(1).getOperand(0);
678 else {
679 ShAmt = 0;
680 ShOpcVal = ARM_AM::no_shift;
681 }
Evan Chenga8e29892007-01-19 07:51:42 +0000682 } else {
683 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000684 }
685 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000686
Evan Chenga8e29892007-01-19 07:51:42 +0000687 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000688 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000689 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000690 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000691 if (ShOpcVal != ARM_AM::no_shift) {
692 // Check to see if the RHS of the shift is a constant, if not, we can't
693 // fold it.
694 if (ConstantSDNode *Sh =
695 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000696 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000697 if (!Subtarget->isCortexA9() ||
698 (N.hasOneUse() &&
699 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
700 Offset = N.getOperand(0).getOperand(0);
701 Base = N.getOperand(1);
702 } else {
703 ShAmt = 0;
704 ShOpcVal = ARM_AM::no_shift;
705 }
Evan Chenga8e29892007-01-19 07:51:42 +0000706 } else {
707 ShOpcVal = ARM_AM::no_shift;
708 }
709 }
710 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000711
Evan Chenga8e29892007-01-19 07:51:42 +0000712 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000713 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000714 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000715}
716
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000717bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000718 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000719 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000720 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
721 ? cast<LoadSDNode>(Op)->getAddressingMode()
722 : cast<StoreSDNode>(Op)->getAddressingMode();
723 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
724 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000725 int Val;
726 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
727 Offset = CurDAG->getRegister(0, MVT::i32);
728 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
729 ARM_AM::no_shift),
730 MVT::i32);
731 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000732 }
733
734 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000735 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000736 unsigned ShAmt = 0;
737 if (ShOpcVal != ARM_AM::no_shift) {
738 // Check to see if the RHS of the shift is a constant, if not, we can't fold
739 // it.
740 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000741 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000742 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
743 Offset = N.getOperand(0);
744 else {
745 ShAmt = 0;
746 ShOpcVal = ARM_AM::no_shift;
747 }
Evan Chenga8e29892007-01-19 07:51:42 +0000748 } else {
749 ShOpcVal = ARM_AM::no_shift;
750 }
751 }
752
753 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000754 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000755 return true;
756}
757
Evan Chenga8e29892007-01-19 07:51:42 +0000758
Chris Lattner52a261b2010-09-21 20:31:19 +0000759bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000760 SDValue &Base, SDValue &Offset,
761 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000762 if (N.getOpcode() == ISD::SUB) {
763 // X - C is canonicalize to X + -C, no need to handle it here.
764 Base = N.getOperand(0);
765 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000766 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000767 return true;
768 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000769
Chris Lattner0a9481f2011-02-13 22:25:43 +0000770 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000771 Base = N;
772 if (N.getOpcode() == ISD::FrameIndex) {
773 int FI = cast<FrameIndexSDNode>(N)->getIndex();
774 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
775 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000776 Offset = CurDAG->getRegister(0, MVT::i32);
777 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000778 return true;
779 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000780
Evan Chenga8e29892007-01-19 07:51:42 +0000781 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000782 int RHSC;
783 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
784 -256 + 1, 256, RHSC)) { // 8 bits.
785 Base = N.getOperand(0);
786 if (Base.getOpcode() == ISD::FrameIndex) {
787 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
788 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000789 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000790 Offset = CurDAG->getRegister(0, MVT::i32);
791
792 ARM_AM::AddrOpc AddSub = ARM_AM::add;
793 if (RHSC < 0) {
794 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000795 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000796 }
797 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
798 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000799 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000800
Evan Chenga8e29892007-01-19 07:51:42 +0000801 Base = N.getOperand(0);
802 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000804 return true;
805}
806
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000807bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000808 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000809 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000810 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
811 ? cast<LoadSDNode>(Op)->getAddressingMode()
812 : cast<StoreSDNode>(Op)->getAddressingMode();
813 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
814 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000815 int Val;
816 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
817 Offset = CurDAG->getRegister(0, MVT::i32);
818 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
819 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000820 }
821
822 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000823 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000824 return true;
825}
826
Jim Grosbach3ab56582010-10-21 19:38:40 +0000827bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000828 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000829 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000830 Base = N;
831 if (N.getOpcode() == ISD::FrameIndex) {
832 int FI = cast<FrameIndexSDNode>(N)->getIndex();
833 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000834 } else if (N.getOpcode() == ARMISD::Wrapper &&
835 !(Subtarget->useMovt() &&
836 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000837 Base = N.getOperand(0);
838 }
839 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000840 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000841 return true;
842 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000843
Evan Chenga8e29892007-01-19 07:51:42 +0000844 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000845 int RHSC;
846 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
847 -256 + 1, 256, RHSC)) {
848 Base = N.getOperand(0);
849 if (Base.getOpcode() == ISD::FrameIndex) {
850 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
851 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000852 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000853
854 ARM_AM::AddrOpc AddSub = ARM_AM::add;
855 if (RHSC < 0) {
856 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000857 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000858 }
859 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
860 MVT::i32);
861 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000862 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000863
Evan Chenga8e29892007-01-19 07:51:42 +0000864 Base = N;
865 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000866 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000867 return true;
868}
869
Bob Wilson665814b2010-11-01 23:40:51 +0000870bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
871 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000872 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000873
874 unsigned Alignment = 0;
875 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
876 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
877 // The maximum alignment is equal to the memory size being referenced.
878 unsigned LSNAlign = LSN->getAlignment();
879 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
880 if (LSNAlign > MemSize && MemSize > 1)
881 Alignment = MemSize;
882 } else {
883 // All other uses of addrmode6 are for intrinsics. For now just record
884 // the raw alignment value; it will be refined later based on the legal
885 // alignment operands for the intrinsic.
886 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
887 }
888
889 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000890 return true;
891}
892
Bob Wilsonda525062011-02-25 06:42:42 +0000893bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
894 SDValue &Offset) {
895 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
896 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
897 if (AM != ISD::POST_INC)
898 return false;
899 Offset = N;
900 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
901 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
902 Offset = CurDAG->getRegister(0, MVT::i32);
903 }
904 return true;
905}
906
Chris Lattner52a261b2010-09-21 20:31:19 +0000907bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000908 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000909 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
910 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000911 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000912 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
913 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000914 return true;
915 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000916
Evan Chenga8e29892007-01-19 07:51:42 +0000917 return false;
918}
919
Bill Wendlingf4caf692010-12-14 03:36:38 +0000920
921//===----------------------------------------------------------------------===//
922// Thumb Addressing Modes
923//===----------------------------------------------------------------------===//
924
Chris Lattner52a261b2010-09-21 20:31:19 +0000925bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000926 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000927 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000928 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000929 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000930 return false;
931
932 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000933 return true;
934 }
935
Evan Chenga8e29892007-01-19 07:51:42 +0000936 Base = N.getOperand(0);
937 Offset = N.getOperand(1);
938 return true;
939}
940
Evan Cheng79d43262007-01-24 02:21:22 +0000941bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000942ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
943 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000944 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000945 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000946 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000947 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000948
Evan Cheng012f2d92007-01-24 08:53:17 +0000949 if (N.getOpcode() == ARMISD::Wrapper &&
950 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
951 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000952 }
953
Chris Lattner0a9481f2011-02-13 22:25:43 +0000954 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000955 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000956
Evan Chengad0e4652007-02-06 00:22:06 +0000957 // Thumb does not have [sp, r] address mode.
958 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
959 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
960 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000961 (RHSR && RHSR->getReg() == ARM::SP))
962 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000963
Daniel Dunbarec91d522011-01-19 15:12:16 +0000964 // FIXME: Why do we explicitly check for a match here and then return false?
965 // Presumably to allow something else to match, but shouldn't this be
966 // documented?
967 int RHSC;
968 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
969 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000970
971 Base = N.getOperand(0);
972 Offset = N.getOperand(1);
973 return true;
974}
975
976bool
977ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
978 SDValue &Base,
979 SDValue &Offset) {
980 return SelectThumbAddrModeRI(N, Base, Offset, 1);
981}
982
983bool
984ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
985 SDValue &Base,
986 SDValue &Offset) {
987 return SelectThumbAddrModeRI(N, Base, Offset, 2);
988}
989
990bool
991ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
992 SDValue &Base,
993 SDValue &Offset) {
994 return SelectThumbAddrModeRI(N, Base, Offset, 4);
995}
996
997bool
998ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
999 SDValue &Base, SDValue &OffImm) {
1000 if (Scale == 4) {
1001 SDValue TmpBase, TmpOffImm;
1002 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1003 return false; // We want to select tLDRspi / tSTRspi instead.
1004
1005 if (N.getOpcode() == ARMISD::Wrapper &&
1006 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1007 return false; // We want to select tLDRpci instead.
1008 }
1009
Chris Lattner0a9481f2011-02-13 22:25:43 +00001010 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001011 if (N.getOpcode() == ARMISD::Wrapper &&
1012 !(Subtarget->useMovt() &&
1013 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1014 Base = N.getOperand(0);
1015 } else {
1016 Base = N;
1017 }
1018
Owen Anderson825b72b2009-08-11 20:47:22 +00001019 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001020 return true;
1021 }
1022
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001023 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1024 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1025 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1026 (RHSR && RHSR->getReg() == ARM::SP)) {
1027 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1028 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1029 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1030 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1031
1032 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1033 if (LHSC != 0 || RHSC != 0) return false;
1034
1035 Base = N;
1036 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1037 return true;
1038 }
1039
Evan Chenga8e29892007-01-19 07:51:42 +00001040 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001041 int RHSC;
1042 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1043 Base = N.getOperand(0);
1044 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1045 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001046 }
1047
Evan Chengc38f2bc2007-01-23 22:59:13 +00001048 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001049 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001050 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001051}
1052
Bill Wendlingf4caf692010-12-14 03:36:38 +00001053bool
1054ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1055 SDValue &OffImm) {
1056 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001057}
1058
Bill Wendlingf4caf692010-12-14 03:36:38 +00001059bool
1060ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1061 SDValue &OffImm) {
1062 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001063}
1064
Bill Wendlingf4caf692010-12-14 03:36:38 +00001065bool
1066ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1067 SDValue &OffImm) {
1068 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001069}
1070
Chris Lattner52a261b2010-09-21 20:31:19 +00001071bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1072 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001073 if (N.getOpcode() == ISD::FrameIndex) {
1074 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1075 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001076 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001077 return true;
1078 }
Evan Cheng79d43262007-01-24 02:21:22 +00001079
Chris Lattner0a9481f2011-02-13 22:25:43 +00001080 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001081 return false;
1082
1083 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001084 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1085 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001086 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001087 int RHSC;
1088 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1089 Base = N.getOperand(0);
1090 if (Base.getOpcode() == ISD::FrameIndex) {
1091 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1092 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001093 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001094 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1095 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001096 }
1097 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001098
Evan Chenga8e29892007-01-19 07:51:42 +00001099 return false;
1100}
1101
Bill Wendlingf4caf692010-12-14 03:36:38 +00001102
1103//===----------------------------------------------------------------------===//
1104// Thumb 2 Addressing Modes
1105//===----------------------------------------------------------------------===//
1106
1107
Chris Lattner52a261b2010-09-21 20:31:19 +00001108bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001109 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001110 if (DisableShifterOp)
1111 return false;
1112
Evan Chengee04a6d2011-07-20 23:34:39 +00001113 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001114
1115 // Don't match base register only case. That is matched to a separate
1116 // lower complexity pattern with explicit register operand.
1117 if (ShOpcVal == ARM_AM::no_shift) return false;
1118
1119 BaseReg = N.getOperand(0);
1120 unsigned ShImmVal = 0;
1121 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1122 ShImmVal = RHS->getZExtValue() & 31;
1123 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1124 return true;
1125 }
1126
1127 return false;
1128}
1129
Chris Lattner52a261b2010-09-21 20:31:19 +00001130bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001131 SDValue &Base, SDValue &OffImm) {
1132 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001133
Evan Cheng3a214252009-08-11 08:52:18 +00001134 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001135 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1136 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001137 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001138 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001139 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1140 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001141 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001142 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001143 }
Owen Anderson099e5552011-03-18 19:46:58 +00001144
Chris Lattner0a9481f2011-02-13 22:25:43 +00001145 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001146 !(Subtarget->useMovt() &&
1147 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001148 Base = N.getOperand(0);
1149 if (Base.getOpcode() == ISD::TargetConstantPool)
1150 return false; // We want to select t2LDRpci instead.
1151 } else
1152 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001153 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001154 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001155 }
Evan Cheng055b0312009-06-29 07:51:04 +00001156
1157 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001158 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001159 // Let t2LDRi8 handle (R - imm8).
1160 return false;
1161
Evan Cheng055b0312009-06-29 07:51:04 +00001162 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001163 if (N.getOpcode() == ISD::SUB)
1164 RHSC = -RHSC;
1165
1166 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001167 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001168 if (Base.getOpcode() == ISD::FrameIndex) {
1169 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1170 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1171 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001172 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001173 return true;
1174 }
1175 }
1176
Evan Cheng3a214252009-08-11 08:52:18 +00001177 // Base only.
1178 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001179 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001180 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001181}
1182
Chris Lattner52a261b2010-09-21 20:31:19 +00001183bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001184 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001185 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001186 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1187 !CurDAG->isBaseWithConstantOffset(N))
1188 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001189
Chris Lattner0a9481f2011-02-13 22:25:43 +00001190 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1191 int RHSC = (int)RHS->getSExtValue();
1192 if (N.getOpcode() == ISD::SUB)
1193 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001194
Chris Lattner0a9481f2011-02-13 22:25:43 +00001195 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1196 Base = N.getOperand(0);
1197 if (Base.getOpcode() == ISD::FrameIndex) {
1198 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1199 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001200 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001201 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1202 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001203 }
1204 }
1205
1206 return false;
1207}
1208
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001209bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001210 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001211 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001212 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1213 ? cast<LoadSDNode>(Op)->getAddressingMode()
1214 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001215 int RHSC;
1216 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1217 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1218 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1219 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1220 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001221 }
1222
1223 return false;
1224}
1225
Chris Lattner52a261b2010-09-21 20:31:19 +00001226bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001227 SDValue &Base,
1228 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001229 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001230 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001231 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001232
Evan Cheng3a214252009-08-11 08:52:18 +00001233 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1234 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1235 int RHSC = (int)RHS->getZExtValue();
1236 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1237 return false;
1238 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001239 return false;
1240 }
1241
Evan Chengf40deed2010-10-27 23:41:30 +00001242 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1243 // Compute R + (R << [1,2,3]) and reuse it.
1244 Base = N;
1245 return false;
1246 }
1247
Evan Cheng055b0312009-06-29 07:51:04 +00001248 // Look for (R + R) or (R + (R << [1,2,3])).
1249 unsigned ShAmt = 0;
1250 Base = N.getOperand(0);
1251 OffReg = N.getOperand(1);
1252
1253 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001254 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001255 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001256 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001257 if (ShOpcVal == ARM_AM::lsl)
1258 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001259 }
1260
Evan Cheng055b0312009-06-29 07:51:04 +00001261 if (ShOpcVal == ARM_AM::lsl) {
1262 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1263 // it.
1264 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1265 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001266 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1267 OffReg = OffReg.getOperand(0);
1268 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001269 ShAmt = 0;
1270 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001271 }
Evan Cheng055b0312009-06-29 07:51:04 +00001272 } else {
1273 ShOpcVal = ARM_AM::no_shift;
1274 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001275 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001276
Owen Anderson825b72b2009-08-11 20:47:22 +00001277 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001278
1279 return true;
1280}
1281
1282//===--------------------------------------------------------------------===//
1283
Evan Chengee568cf2007-07-05 07:15:27 +00001284/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001285static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001286 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001287}
1288
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001289SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1290 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001291 ISD::MemIndexedMode AM = LD->getAddressingMode();
1292 if (AM == ISD::UNINDEXED)
1293 return NULL;
1294
Owen Andersone50ed302009-08-10 22:56:29 +00001295 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001296 SDValue Offset, AMOpc;
1297 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1298 unsigned Opcode = 0;
1299 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001300 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001301 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001302 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1303 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001304 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001305 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001306 Match = true;
1307 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1308 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1309 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001310 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001311 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001312 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001313 Match = true;
1314 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1315 }
1316 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001317 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001318 Match = true;
1319 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1320 }
1321 }
1322 }
1323
1324 if (Match) {
1325 SDValue Chain = LD->getChain();
1326 SDValue Base = LD->getBasePtr();
1327 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001329 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001330 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001331 }
1332
1333 return NULL;
1334}
1335
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001336SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1337 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001338 ISD::MemIndexedMode AM = LD->getAddressingMode();
1339 if (AM == ISD::UNINDEXED)
1340 return NULL;
1341
Owen Andersone50ed302009-08-10 22:56:29 +00001342 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001343 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001344 SDValue Offset;
1345 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1346 unsigned Opcode = 0;
1347 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001348 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001349 switch (LoadedVT.getSimpleVT().SimpleTy) {
1350 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001351 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1352 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001353 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001354 if (isSExtLd)
1355 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1356 else
1357 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001358 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001359 case MVT::i8:
1360 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001361 if (isSExtLd)
1362 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1363 else
1364 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001365 break;
1366 default:
1367 return NULL;
1368 }
1369 Match = true;
1370 }
1371
1372 if (Match) {
1373 SDValue Chain = LD->getChain();
1374 SDValue Base = LD->getBasePtr();
1375 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001376 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001377 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001378 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001379 }
1380
1381 return NULL;
1382}
1383
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001384/// PairSRegs - Form a D register from a pair of S registers.
1385///
1386SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1387 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001388 SDValue RegClass =
1389 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001390 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1391 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001392 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1393 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001394}
1395
Evan Cheng603afbf2010-05-10 17:34:18 +00001396/// PairDRegs - Form a quad register from a pair of D registers.
1397///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001398SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1399 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001400 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001401 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1402 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001403 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1404 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001405}
1406
Evan Cheng7f687192010-05-14 00:21:45 +00001407/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001408///
1409SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1410 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001411 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001412 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1413 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001414 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1415 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001416}
1417
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001418/// QuadSRegs - Form 4 consecutive S registers.
1419///
1420SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1421 SDValue V2, SDValue V3) {
1422 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001423 SDValue RegClass =
1424 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001425 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1426 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1427 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1428 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001429 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1430 V2, SubReg2, V3, SubReg3 };
1431 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001432}
1433
Evan Cheng7f687192010-05-14 00:21:45 +00001434/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001435///
1436SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1437 SDValue V2, SDValue V3) {
1438 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001439 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001440 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1441 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1442 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1443 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001444 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1445 V2, SubReg2, V3, SubReg3 };
1446 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001447}
1448
Evan Cheng8f6de382010-05-16 03:27:48 +00001449/// QuadQRegs - Form 4 consecutive Q registers.
1450///
1451SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1452 SDValue V2, SDValue V3) {
1453 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001454 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001455 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1456 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1457 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1458 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001459 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1460 V2, SubReg2, V3, SubReg3 };
1461 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001462}
1463
Bob Wilson2a6e6162010-09-23 23:42:37 +00001464/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1465/// of a NEON VLD or VST instruction. The supported values depend on the
1466/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001467SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1468 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001469 unsigned NumRegs = NumVecs;
1470 if (!is64BitVector && NumVecs < 3)
1471 NumRegs *= 2;
1472
Bob Wilson665814b2010-11-01 23:40:51 +00001473 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001474 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001475 Alignment = 32;
1476 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1477 Alignment = 16;
1478 else if (Alignment >= 8)
1479 Alignment = 8;
1480 else
1481 Alignment = 0;
1482
1483 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001484}
1485
Bob Wilson1c3ef902011-02-07 17:43:21 +00001486SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001487 unsigned *DOpcodes, unsigned *QOpcodes0,
1488 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001489 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001490 DebugLoc dl = N->getDebugLoc();
1491
Bob Wilson226036e2010-03-20 22:13:40 +00001492 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001493 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1494 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001495 return NULL;
1496
1497 SDValue Chain = N->getOperand(0);
1498 EVT VT = N->getValueType(0);
1499 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001500 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001501
Bob Wilson3e36f132009-10-14 17:28:52 +00001502 unsigned OpcodeIndex;
1503 switch (VT.getSimpleVT().SimpleTy) {
1504 default: llvm_unreachable("unhandled vld type");
1505 // Double-register operations:
1506 case MVT::v8i8: OpcodeIndex = 0; break;
1507 case MVT::v4i16: OpcodeIndex = 1; break;
1508 case MVT::v2f32:
1509 case MVT::v2i32: OpcodeIndex = 2; break;
1510 case MVT::v1i64: OpcodeIndex = 3; break;
1511 // Quad-register operations:
1512 case MVT::v16i8: OpcodeIndex = 0; break;
1513 case MVT::v8i16: OpcodeIndex = 1; break;
1514 case MVT::v4f32:
1515 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001516 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001517 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001518 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001519 }
1520
Bob Wilsonf5721912010-09-03 18:16:02 +00001521 EVT ResTy;
1522 if (NumVecs == 1)
1523 ResTy = VT;
1524 else {
1525 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1526 if (!is64BitVector)
1527 ResTyElts *= 2;
1528 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1529 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001530 std::vector<EVT> ResTys;
1531 ResTys.push_back(ResTy);
1532 if (isUpdating)
1533 ResTys.push_back(MVT::i32);
1534 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001535
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001536 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001537 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001538 SDNode *VLd;
1539 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001540
Bob Wilson1c3ef902011-02-07 17:43:21 +00001541 // Double registers and VLD1/VLD2 quad registers are directly supported.
1542 if (is64BitVector || NumVecs <= 2) {
1543 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1544 QOpcodes0[OpcodeIndex]);
1545 Ops.push_back(MemAddr);
1546 Ops.push_back(Align);
1547 if (isUpdating) {
1548 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1549 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001550 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001551 Ops.push_back(Pred);
1552 Ops.push_back(Reg0);
1553 Ops.push_back(Chain);
1554 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001555
Bob Wilson3e36f132009-10-14 17:28:52 +00001556 } else {
1557 // Otherwise, quad registers are loaded with two separate instructions,
1558 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001559 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001560
Bob Wilson1c3ef902011-02-07 17:43:21 +00001561 // Load the even subregs. This is always an updating load, so that it
1562 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001563 SDValue ImplDef =
1564 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1565 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001566 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1567 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001568 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001569
Bob Wilson24f995d2009-10-14 18:32:29 +00001570 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001571 Ops.push_back(SDValue(VLdA, 1));
1572 Ops.push_back(Align);
1573 if (isUpdating) {
1574 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1575 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1576 "only constant post-increment update allowed for VLD3/4");
1577 (void)Inc;
1578 Ops.push_back(Reg0);
1579 }
1580 Ops.push_back(SDValue(VLdA, 0));
1581 Ops.push_back(Pred);
1582 Ops.push_back(Reg0);
1583 Ops.push_back(Chain);
1584 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1585 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001586 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001587
Evan Chengb58a3402011-04-19 00:04:03 +00001588 // Transfer memoperands.
1589 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1590 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1591 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1592
Bob Wilson1c3ef902011-02-07 17:43:21 +00001593 if (NumVecs == 1)
1594 return VLd;
1595
1596 // Extract out the subregisters.
1597 SDValue SuperReg = SDValue(VLd, 0);
1598 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1599 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1600 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1601 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1602 ReplaceUses(SDValue(N, Vec),
1603 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1604 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1605 if (isUpdating)
1606 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001607 return NULL;
1608}
1609
Bob Wilson1c3ef902011-02-07 17:43:21 +00001610SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001611 unsigned *DOpcodes, unsigned *QOpcodes0,
1612 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001613 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001614 DebugLoc dl = N->getDebugLoc();
1615
Bob Wilson226036e2010-03-20 22:13:40 +00001616 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001617 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1618 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1619 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001620 return NULL;
1621
Evan Chengb58a3402011-04-19 00:04:03 +00001622 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1623 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1624
Bob Wilson24f995d2009-10-14 18:32:29 +00001625 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001626 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001627 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001628 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001629
Bob Wilson24f995d2009-10-14 18:32:29 +00001630 unsigned OpcodeIndex;
1631 switch (VT.getSimpleVT().SimpleTy) {
1632 default: llvm_unreachable("unhandled vst type");
1633 // Double-register operations:
1634 case MVT::v8i8: OpcodeIndex = 0; break;
1635 case MVT::v4i16: OpcodeIndex = 1; break;
1636 case MVT::v2f32:
1637 case MVT::v2i32: OpcodeIndex = 2; break;
1638 case MVT::v1i64: OpcodeIndex = 3; break;
1639 // Quad-register operations:
1640 case MVT::v16i8: OpcodeIndex = 0; break;
1641 case MVT::v8i16: OpcodeIndex = 1; break;
1642 case MVT::v4f32:
1643 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001644 case MVT::v2i64: OpcodeIndex = 3;
1645 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1646 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001647 }
1648
Bob Wilson1c3ef902011-02-07 17:43:21 +00001649 std::vector<EVT> ResTys;
1650 if (isUpdating)
1651 ResTys.push_back(MVT::i32);
1652 ResTys.push_back(MVT::Other);
1653
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001654 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001655 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001656 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001657
Bob Wilson1c3ef902011-02-07 17:43:21 +00001658 // Double registers and VST1/VST2 quad registers are directly supported.
1659 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001660 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001661 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001662 SrcReg = N->getOperand(Vec0Idx);
1663 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001664 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001665 SDValue V0 = N->getOperand(Vec0Idx + 0);
1666 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001667 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001668 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001669 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001670 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001671 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001672 // an undef.
1673 SDValue V3 = (NumVecs == 3)
1674 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001675 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001676 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001677 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001678 } else {
1679 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001680 SDValue Q0 = N->getOperand(Vec0Idx);
1681 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001682 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001683 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001684
1685 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1686 QOpcodes0[OpcodeIndex]);
1687 Ops.push_back(MemAddr);
1688 Ops.push_back(Align);
1689 if (isUpdating) {
1690 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1691 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1692 }
1693 Ops.push_back(SrcReg);
1694 Ops.push_back(Pred);
1695 Ops.push_back(Reg0);
1696 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001697 SDNode *VSt =
1698 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1699
1700 // Transfer memoperands.
1701 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1702
1703 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001704 }
1705
1706 // Otherwise, quad registers are stored with two separate instructions,
1707 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001708
Bob Wilson07f6e802010-06-16 21:34:01 +00001709 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001710 SDValue V0 = N->getOperand(Vec0Idx + 0);
1711 SDValue V1 = N->getOperand(Vec0Idx + 1);
1712 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001713 SDValue V3 = (NumVecs == 3)
1714 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001715 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001716 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001717
Bob Wilson1c3ef902011-02-07 17:43:21 +00001718 // Store the even D registers. This is always an updating store, so that it
1719 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001720 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1721 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1722 MemAddr.getValueType(),
1723 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001724 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001725 Chain = SDValue(VStA, 1);
1726
1727 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001728 Ops.push_back(SDValue(VStA, 0));
1729 Ops.push_back(Align);
1730 if (isUpdating) {
1731 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1732 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1733 "only constant post-increment update allowed for VST3/4");
1734 (void)Inc;
1735 Ops.push_back(Reg0);
1736 }
1737 Ops.push_back(RegSeq);
1738 Ops.push_back(Pred);
1739 Ops.push_back(Reg0);
1740 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001741 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1742 Ops.data(), Ops.size());
1743 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1744 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001745}
1746
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001747SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001748 bool isUpdating, unsigned NumVecs,
1749 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001750 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001751 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001752 DebugLoc dl = N->getDebugLoc();
1753
Bob Wilson226036e2010-03-20 22:13:40 +00001754 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001755 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1756 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1757 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001758 return NULL;
1759
Evan Chengb58a3402011-04-19 00:04:03 +00001760 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1761 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1762
Bob Wilsona7c397c2009-10-14 16:19:03 +00001763 SDValue Chain = N->getOperand(0);
1764 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001765 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1766 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001767 bool is64BitVector = VT.is64BitVector();
1768
Bob Wilson665814b2010-11-01 23:40:51 +00001769 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001770 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001771 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001772 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1773 if (Alignment > NumBytes)
1774 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001775 if (Alignment < 8 && Alignment < NumBytes)
1776 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001777 // Alignment must be a power of two; make sure of that.
1778 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001779 if (Alignment == 1)
1780 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001781 }
Bob Wilson665814b2010-11-01 23:40:51 +00001782 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001783
Bob Wilsona7c397c2009-10-14 16:19:03 +00001784 unsigned OpcodeIndex;
1785 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001786 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001787 // Double-register operations:
1788 case MVT::v8i8: OpcodeIndex = 0; break;
1789 case MVT::v4i16: OpcodeIndex = 1; break;
1790 case MVT::v2f32:
1791 case MVT::v2i32: OpcodeIndex = 2; break;
1792 // Quad-register operations:
1793 case MVT::v8i16: OpcodeIndex = 0; break;
1794 case MVT::v4f32:
1795 case MVT::v4i32: OpcodeIndex = 1; break;
1796 }
1797
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798 std::vector<EVT> ResTys;
1799 if (IsLoad) {
1800 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1801 if (!is64BitVector)
1802 ResTyElts *= 2;
1803 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1804 MVT::i64, ResTyElts));
1805 }
1806 if (isUpdating)
1807 ResTys.push_back(MVT::i32);
1808 ResTys.push_back(MVT::Other);
1809
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001810 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001811 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001812
Bob Wilson1c3ef902011-02-07 17:43:21 +00001813 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001815 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001816 if (isUpdating) {
1817 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1818 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1819 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001820
Bob Wilson8466fa12010-09-13 23:01:35 +00001821 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001822 SDValue V0 = N->getOperand(Vec0Idx + 0);
1823 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001824 if (NumVecs == 2) {
1825 if (is64BitVector)
1826 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1827 else
1828 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001829 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001830 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001831 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001832 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1833 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001834 if (is64BitVector)
1835 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1836 else
1837 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001838 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001839 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001840 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001841 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001842 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001843 Ops.push_back(Chain);
1844
Bob Wilson1c3ef902011-02-07 17:43:21 +00001845 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1846 QOpcodes[OpcodeIndex]);
1847 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1848 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001849 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001850 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001851 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001852
Bob Wilson8466fa12010-09-13 23:01:35 +00001853 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001854 SuperReg = SDValue(VLdLn, 0);
1855 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1856 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1857 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001858 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1859 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001860 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1861 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1862 if (isUpdating)
1863 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001864 return NULL;
1865}
1866
Bob Wilson1c3ef902011-02-07 17:43:21 +00001867SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1868 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001869 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1870 DebugLoc dl = N->getDebugLoc();
1871
1872 SDValue MemAddr, Align;
1873 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1874 return NULL;
1875
Evan Chengb58a3402011-04-19 00:04:03 +00001876 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1877 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1878
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001879 SDValue Chain = N->getOperand(0);
1880 EVT VT = N->getValueType(0);
1881
1882 unsigned Alignment = 0;
1883 if (NumVecs != 3) {
1884 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1885 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1886 if (Alignment > NumBytes)
1887 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001888 if (Alignment < 8 && Alignment < NumBytes)
1889 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001890 // Alignment must be a power of two; make sure of that.
1891 Alignment = (Alignment & -Alignment);
1892 if (Alignment == 1)
1893 Alignment = 0;
1894 }
1895 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1896
1897 unsigned OpcodeIndex;
1898 switch (VT.getSimpleVT().SimpleTy) {
1899 default: llvm_unreachable("unhandled vld-dup type");
1900 case MVT::v8i8: OpcodeIndex = 0; break;
1901 case MVT::v4i16: OpcodeIndex = 1; break;
1902 case MVT::v2f32:
1903 case MVT::v2i32: OpcodeIndex = 2; break;
1904 }
1905
1906 SDValue Pred = getAL(CurDAG);
1907 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1908 SDValue SuperReg;
1909 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001910 SmallVector<SDValue, 6> Ops;
1911 Ops.push_back(MemAddr);
1912 Ops.push_back(Align);
1913 if (isUpdating) {
1914 SDValue Inc = N->getOperand(2);
1915 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1916 }
1917 Ops.push_back(Pred);
1918 Ops.push_back(Reg0);
1919 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001920
1921 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001922 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001923 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001924 if (isUpdating)
1925 ResTys.push_back(MVT::i32);
1926 ResTys.push_back(MVT::Other);
1927 SDNode *VLdDup =
1928 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001929 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001930 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001931
1932 // Extract the subregisters.
1933 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1934 unsigned SubIdx = ARM::dsub_0;
1935 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1936 ReplaceUses(SDValue(N, Vec),
1937 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001938 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1939 if (isUpdating)
1940 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001941 return NULL;
1942}
1943
Bob Wilson78dfbc32010-07-07 00:08:54 +00001944SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1945 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001946 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1947 DebugLoc dl = N->getDebugLoc();
1948 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001949 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001950
1951 // Form a REG_SEQUENCE to force register allocation.
1952 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001953 SDValue V0 = N->getOperand(FirstTblReg + 0);
1954 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001955 if (NumVecs == 2)
1956 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1957 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001958 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001959 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001960 // an undef.
1961 SDValue V3 = (NumVecs == 3)
1962 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001963 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001964 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1965 }
1966
Bob Wilson78dfbc32010-07-07 00:08:54 +00001967 SmallVector<SDValue, 6> Ops;
1968 if (IsExt)
1969 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001970 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001971 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001972 Ops.push_back(getAL(CurDAG)); // predicate
1973 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001974 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001975}
1976
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001977SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001978 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001979 if (!Subtarget->hasV6T2Ops())
1980 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001981
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001982 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1983 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1984
1985
1986 // For unsigned extracts, check for a shift right and mask
1987 unsigned And_imm = 0;
1988 if (N->getOpcode() == ISD::AND) {
1989 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1990
1991 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1992 if (And_imm & (And_imm + 1))
1993 return NULL;
1994
1995 unsigned Srl_imm = 0;
1996 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1997 Srl_imm)) {
1998 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1999
2000 unsigned Width = CountTrailingOnes_32(And_imm);
2001 unsigned LSB = Srl_imm;
2002 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2003 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2004 CurDAG->getTargetConstant(LSB, MVT::i32),
2005 CurDAG->getTargetConstant(Width, MVT::i32),
2006 getAL(CurDAG), Reg0 };
2007 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2008 }
2009 }
2010 return NULL;
2011 }
2012
2013 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002014 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002015 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002016 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2017 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002018 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002019 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2020 unsigned Width = 32 - Srl_imm;
2021 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002022 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002023 return NULL;
2024 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002025 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002026 CurDAG->getTargetConstant(LSB, MVT::i32),
2027 CurDAG->getTargetConstant(Width, MVT::i32),
2028 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002029 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002030 }
2031 }
2032 return NULL;
2033}
2034
Evan Cheng9ef48352009-11-20 00:54:03 +00002035SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002036SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002037 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2038 SDValue CPTmp0;
2039 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002040 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002041 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2042 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2043 unsigned Opc = 0;
2044 switch (SOShOp) {
2045 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2046 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2047 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2048 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2049 default:
2050 llvm_unreachable("Unknown so_reg opcode!");
2051 break;
2052 }
2053 SDValue SOShImm =
2054 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2055 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2056 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002057 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002058 }
2059 return 0;
2060}
2061
2062SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002063SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002064 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2065 SDValue CPTmp0;
2066 SDValue CPTmp1;
2067 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002068 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002069 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2070 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Owen Anderson92a20222011-07-21 18:54:16 +00002071 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 7);
2072 }
2073
2074 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2075 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2076 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2077 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 }
2079 return 0;
2080}
2081
2082SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002083SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002084 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002085 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002086 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002087 return 0;
2088
Evan Cheng63f35442010-11-13 02:25:14 +00002089 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002090 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002091 if (is_t2_so_imm(TrueImm)) {
2092 Opc = ARM::t2MOVCCi;
2093 } else if (TrueImm <= 0xffff) {
2094 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002095 } else if (is_t2_so_imm_not(TrueImm)) {
2096 TrueImm = ~TrueImm;
2097 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002098 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002099 // Large immediate.
2100 Opc = ARM::t2MOVCCi32imm;
2101 }
2102
2103 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002104 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002105 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2106 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002107 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002108 }
Evan Cheng63f35442010-11-13 02:25:14 +00002109
Evan Cheng9ef48352009-11-20 00:54:03 +00002110 return 0;
2111}
2112
2113SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002114SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002115 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002116 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2117 if (!T)
2118 return 0;
2119
Evan Cheng63f35442010-11-13 02:25:14 +00002120 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002121 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002122 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002123 if (isSoImm) {
2124 Opc = ARM::MOVCCi;
2125 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2126 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002127 } else if (is_so_imm_not(TrueImm)) {
2128 TrueImm = ~TrueImm;
2129 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002130 } else if (TrueVal.getNode()->hasOneUse() &&
2131 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002132 // Large immediate.
2133 Opc = ARM::MOVCCi32imm;
2134 }
2135
2136 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002137 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002138 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2139 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002140 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002141 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002142
Evan Cheng9ef48352009-11-20 00:54:03 +00002143 return 0;
2144}
2145
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002146SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2147 EVT VT = N->getValueType(0);
2148 SDValue FalseVal = N->getOperand(0);
2149 SDValue TrueVal = N->getOperand(1);
2150 SDValue CC = N->getOperand(2);
2151 SDValue CCR = N->getOperand(3);
2152 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002153 assert(CC.getOpcode() == ISD::Constant);
2154 assert(CCR.getOpcode() == ISD::Register);
2155 ARMCC::CondCodes CCVal =
2156 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002157
2158 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2159 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2160 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2161 // Pattern complexity = 18 cost = 1 size = 0
2162 SDValue CPTmp0;
2163 SDValue CPTmp1;
2164 SDValue CPTmp2;
2165 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002166 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002167 CCVal, CCR, InFlag);
2168 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002169 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002170 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2171 if (Res)
2172 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002173 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002174 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002175 CCVal, CCR, InFlag);
2176 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002177 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002178 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2179 if (Res)
2180 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002181 }
2182
2183 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002184 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002185 // (imm:i32):$cc)
2186 // Emits: (MOVCCi:i32 GPR:i32:$false,
2187 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2188 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002189 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002190 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002191 CCVal, CCR, InFlag);
2192 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002193 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002194 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2195 if (Res)
2196 return Res;
2197 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002198 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002199 CCVal, CCR, InFlag);
2200 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002201 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002202 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2203 if (Res)
2204 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002205 }
2206 }
2207
2208 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2209 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2210 // Pattern complexity = 6 cost = 1 size = 0
2211 //
2212 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2213 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2214 // Pattern complexity = 6 cost = 11 size = 0
2215 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002216 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002217 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2218 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002219 unsigned Opc = 0;
2220 switch (VT.getSimpleVT().SimpleTy) {
2221 default: assert(false && "Illegal conditional move type!");
2222 break;
2223 case MVT::i32:
2224 Opc = Subtarget->isThumb()
2225 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2226 : ARM::MOVCCr;
2227 break;
2228 case MVT::f32:
2229 Opc = ARM::VMOVScc;
2230 break;
2231 case MVT::f64:
2232 Opc = ARM::VMOVDcc;
2233 break;
2234 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002235 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002236}
2237
Evan Chengde8aa4e2010-05-05 18:28:36 +00002238SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2239 // The only time a CONCAT_VECTORS operation can have legal types is when
2240 // two 64-bit vectors are concatenated to a 128-bit vector.
2241 EVT VT = N->getValueType(0);
2242 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2243 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002244 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002245}
2246
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002247SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002248 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002249
Dan Gohmane8be6c62008-07-17 19:10:17 +00002250 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002251 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002252
2253 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002254 default: break;
2255 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002256 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002257 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002258 if (Subtarget->hasThumb2())
2259 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2260 // be done with MOV + MOVT, at worst.
2261 UseCP = 0;
2262 else {
2263 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002264 UseCP = (Val > 255 && // MOV
2265 ~Val > 255 && // MOV + MVN
2266 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002267 } else
2268 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2269 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2270 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2271 }
2272
Evan Chenga8e29892007-01-19 07:51:42 +00002273 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002274 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002275 CurDAG->getTargetConstantPool(ConstantInt::get(
2276 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002277 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002278
2279 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002280 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002281 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002282 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002283 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002284 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002285 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002286 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002287 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002288 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002289 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002290 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002291 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002292 CurDAG->getEntryNode()
2293 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002294 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002295 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002296 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002297 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002298 return NULL;
2299 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002300
Evan Chenga8e29892007-01-19 07:51:42 +00002301 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002302 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002303 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002304 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002305 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002306 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002307 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002308 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002309 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2310 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002311 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002312 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2313 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002314 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2315 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2316 CurDAG->getRegister(0, MVT::i32) };
2317 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002318 }
Evan Chenga8e29892007-01-19 07:51:42 +00002319 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002320 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002321 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002322 return I;
2323 break;
2324 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002325 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002326 return I;
2327 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002328 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002329 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002330 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002331 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002332 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002333 if (!RHSV) break;
2334 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002335 unsigned ShImm = Log2_32(RHSV-1);
2336 if (ShImm >= 32)
2337 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002338 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002339 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002340 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2341 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002342 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002343 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002344 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002345 } else {
2346 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002347 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002348 }
Evan Chenga8e29892007-01-19 07:51:42 +00002349 }
2350 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002351 unsigned ShImm = Log2_32(RHSV+1);
2352 if (ShImm >= 32)
2353 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002354 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002355 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002356 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2357 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002358 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002359 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2360 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002361 } else {
2362 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002363 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002364 }
Evan Chenga8e29892007-01-19 07:51:42 +00002365 }
2366 }
2367 break;
Evan Cheng20956592009-10-21 08:15:52 +00002368 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002369 // Check for unsigned bitfield extract
2370 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2371 return I;
2372
Evan Cheng20956592009-10-21 08:15:52 +00002373 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2374 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2375 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2376 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2377 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002378 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002379 if (VT != MVT::i32)
2380 break;
2381 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2382 ? ARM::t2MOVTi16
2383 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2384 if (!Opc)
2385 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002386 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002387 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2388 if (!N1C)
2389 break;
2390 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2391 SDValue N2 = N0.getOperand(1);
2392 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2393 if (!N2C)
2394 break;
2395 unsigned N1CVal = N1C->getZExtValue();
2396 unsigned N2CVal = N2C->getZExtValue();
2397 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2398 (N1CVal & 0xffffU) == 0xffffU &&
2399 (N2CVal & 0xffffU) == 0x0U) {
2400 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2401 MVT::i32);
2402 SDValue Ops[] = { N0.getOperand(0), Imm16,
2403 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2404 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2405 }
2406 }
2407 break;
2408 }
Jim Grosbache5165492009-11-09 00:11:35 +00002409 case ARMISD::VMOVRRD:
2410 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002411 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002412 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002413 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002414 if (Subtarget->isThumb1Only())
2415 break;
2416 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002417 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002418 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2419 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002420 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002421 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002422 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002423 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2424 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002425 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2426 ARM::UMULL : ARM::UMULLv5,
2427 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002428 }
Evan Chengee568cf2007-07-05 07:15:27 +00002429 }
Dan Gohman525178c2007-10-08 18:33:35 +00002430 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002431 if (Subtarget->isThumb1Only())
2432 break;
2433 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002434 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002435 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002436 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002437 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002438 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002439 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2440 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002441 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2442 ARM::SMULL : ARM::SMULLv5,
2443 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002444 }
Evan Chengee568cf2007-07-05 07:15:27 +00002445 }
Evan Chenga8e29892007-01-19 07:51:42 +00002446 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002447 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002448 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002449 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002450 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002451 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002452 if (ResNode)
2453 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002454 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002455 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002456 }
Evan Chengee568cf2007-07-05 07:15:27 +00002457 case ARMISD::BRCOND: {
2458 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2459 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2460 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002461
Evan Chengee568cf2007-07-05 07:15:27 +00002462 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2463 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2464 // Pattern complexity = 6 cost = 1 size = 0
2465
David Goodwin5e47a9a2009-06-30 18:04:13 +00002466 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2467 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2468 // Pattern complexity = 6 cost = 1 size = 0
2469
Jim Grosbach764ab522009-08-11 15:33:49 +00002470 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002471 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002472 SDValue Chain = N->getOperand(0);
2473 SDValue N1 = N->getOperand(1);
2474 SDValue N2 = N->getOperand(2);
2475 SDValue N3 = N->getOperand(3);
2476 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002477 assert(N1.getOpcode() == ISD::BasicBlock);
2478 assert(N2.getOpcode() == ISD::Constant);
2479 assert(N3.getOpcode() == ISD::Register);
2480
Dan Gohman475871a2008-07-27 21:46:04 +00002481 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002482 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002483 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002484 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002485 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002486 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002487 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002488 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002489 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002490 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002491 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002492 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002493 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002494 return NULL;
2495 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002496 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002497 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002498 case ARMISD::VZIP: {
2499 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002500 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002501 switch (VT.getSimpleVT().SimpleTy) {
2502 default: return NULL;
2503 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2504 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2505 case MVT::v2f32:
2506 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2507 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2508 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2509 case MVT::v4f32:
2510 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2511 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002512 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002513 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2514 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2515 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002516 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002517 case ARMISD::VUZP: {
2518 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002519 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002520 switch (VT.getSimpleVT().SimpleTy) {
2521 default: return NULL;
2522 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2523 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2524 case MVT::v2f32:
2525 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2526 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2527 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2528 case MVT::v4f32:
2529 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2530 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002531 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002532 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2533 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2534 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002535 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002536 case ARMISD::VTRN: {
2537 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002538 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002539 switch (VT.getSimpleVT().SimpleTy) {
2540 default: return NULL;
2541 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2542 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2543 case MVT::v2f32:
2544 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2545 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2546 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2547 case MVT::v4f32:
2548 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2549 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002550 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002551 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2552 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2553 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002554 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002555 case ARMISD::BUILD_VECTOR: {
2556 EVT VecVT = N->getValueType(0);
2557 EVT EltVT = VecVT.getVectorElementType();
2558 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002559 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002560 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2561 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2562 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002563 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002564 if (NumElts == 2)
2565 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2566 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2567 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2568 N->getOperand(2), N->getOperand(3));
2569 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002570
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002571 case ARMISD::VLD2DUP: {
2572 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2573 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002574 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002575 }
2576
Bob Wilson86c6d802010-11-29 19:35:29 +00002577 case ARMISD::VLD3DUP: {
2578 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2579 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002580 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002581 }
2582
Bob Wilson6c4c9822010-11-30 00:00:35 +00002583 case ARMISD::VLD4DUP: {
2584 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2585 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002586 return SelectVLDDup(N, false, 4, Opcodes);
2587 }
2588
2589 case ARMISD::VLD2DUP_UPD: {
2590 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2591 ARM::VLD2DUPd32Pseudo_UPD };
2592 return SelectVLDDup(N, true, 2, Opcodes);
2593 }
2594
2595 case ARMISD::VLD3DUP_UPD: {
2596 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2597 ARM::VLD3DUPd32Pseudo_UPD };
2598 return SelectVLDDup(N, true, 3, Opcodes);
2599 }
2600
2601 case ARMISD::VLD4DUP_UPD: {
2602 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2603 ARM::VLD4DUPd32Pseudo_UPD };
2604 return SelectVLDDup(N, true, 4, Opcodes);
2605 }
2606
2607 case ARMISD::VLD1_UPD: {
2608 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2609 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2610 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2611 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2612 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2613 }
2614
2615 case ARMISD::VLD2_UPD: {
2616 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2617 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2618 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2619 ARM::VLD2q32Pseudo_UPD };
2620 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2621 }
2622
2623 case ARMISD::VLD3_UPD: {
2624 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2625 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2626 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2627 ARM::VLD3q16Pseudo_UPD,
2628 ARM::VLD3q32Pseudo_UPD };
2629 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2630 ARM::VLD3q16oddPseudo_UPD,
2631 ARM::VLD3q32oddPseudo_UPD };
2632 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2633 }
2634
2635 case ARMISD::VLD4_UPD: {
2636 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2637 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2638 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2639 ARM::VLD4q16Pseudo_UPD,
2640 ARM::VLD4q32Pseudo_UPD };
2641 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2642 ARM::VLD4q16oddPseudo_UPD,
2643 ARM::VLD4q32oddPseudo_UPD };
2644 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2645 }
2646
2647 case ARMISD::VLD2LN_UPD: {
2648 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2649 ARM::VLD2LNd32Pseudo_UPD };
2650 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2651 ARM::VLD2LNq32Pseudo_UPD };
2652 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2653 }
2654
2655 case ARMISD::VLD3LN_UPD: {
2656 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2657 ARM::VLD3LNd32Pseudo_UPD };
2658 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2659 ARM::VLD3LNq32Pseudo_UPD };
2660 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2661 }
2662
2663 case ARMISD::VLD4LN_UPD: {
2664 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2665 ARM::VLD4LNd32Pseudo_UPD };
2666 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2667 ARM::VLD4LNq32Pseudo_UPD };
2668 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2669 }
2670
2671 case ARMISD::VST1_UPD: {
2672 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2673 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2674 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2675 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2676 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2677 }
2678
2679 case ARMISD::VST2_UPD: {
2680 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2681 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2682 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2683 ARM::VST2q32Pseudo_UPD };
2684 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2685 }
2686
2687 case ARMISD::VST3_UPD: {
2688 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2689 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2690 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2691 ARM::VST3q16Pseudo_UPD,
2692 ARM::VST3q32Pseudo_UPD };
2693 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2694 ARM::VST3q16oddPseudo_UPD,
2695 ARM::VST3q32oddPseudo_UPD };
2696 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2697 }
2698
2699 case ARMISD::VST4_UPD: {
2700 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2701 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2702 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2703 ARM::VST4q16Pseudo_UPD,
2704 ARM::VST4q32Pseudo_UPD };
2705 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2706 ARM::VST4q16oddPseudo_UPD,
2707 ARM::VST4q32oddPseudo_UPD };
2708 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2709 }
2710
2711 case ARMISD::VST2LN_UPD: {
2712 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2713 ARM::VST2LNd32Pseudo_UPD };
2714 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2715 ARM::VST2LNq32Pseudo_UPD };
2716 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2717 }
2718
2719 case ARMISD::VST3LN_UPD: {
2720 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2721 ARM::VST3LNd32Pseudo_UPD };
2722 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2723 ARM::VST3LNq32Pseudo_UPD };
2724 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2725 }
2726
2727 case ARMISD::VST4LN_UPD: {
2728 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2729 ARM::VST4LNd32Pseudo_UPD };
2730 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2731 ARM::VST4LNq32Pseudo_UPD };
2732 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002733 }
2734
Bob Wilson31fb12f2009-08-26 17:39:53 +00002735 case ISD::INTRINSIC_VOID:
2736 case ISD::INTRINSIC_W_CHAIN: {
2737 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002738 switch (IntNo) {
2739 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002740 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002741
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002742 case Intrinsic::arm_ldrexd: {
2743 SDValue MemAddr = N->getOperand(2);
2744 DebugLoc dl = N->getDebugLoc();
2745 SDValue Chain = N->getOperand(0);
2746
2747 unsigned NewOpc = ARM::LDREXD;
2748 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2749 NewOpc = ARM::t2LDREXD;
2750
2751 // arm_ldrexd returns a i64 value in {i32, i32}
2752 std::vector<EVT> ResTys;
2753 ResTys.push_back(MVT::i32);
2754 ResTys.push_back(MVT::i32);
2755 ResTys.push_back(MVT::Other);
2756
2757 // place arguments in the right order
2758 SmallVector<SDValue, 7> Ops;
2759 Ops.push_back(MemAddr);
2760 Ops.push_back(getAL(CurDAG));
2761 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2762 Ops.push_back(Chain);
2763 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2764 Ops.size());
2765 // Transfer memoperands.
2766 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2767 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2768 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2769
2770 // Until there's support for specifing explicit register constraints
2771 // like the use of even/odd register pair, hardcode ldrexd to always
2772 // use the pair [R0, R1] to hold the load result.
2773 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2774 SDValue(Ld, 0), SDValue(0,0));
2775 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2776 SDValue(Ld, 1), Chain.getValue(1));
2777
2778 // Remap uses.
2779 SDValue Glue = Chain.getValue(1);
2780 if (!SDValue(N, 0).use_empty()) {
2781 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2782 ARM::R0, MVT::i32, Glue);
2783 Glue = Result.getValue(2);
2784 ReplaceUses(SDValue(N, 0), Result);
2785 }
2786 if (!SDValue(N, 1).use_empty()) {
2787 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2788 ARM::R1, MVT::i32, Glue);
2789 Glue = Result.getValue(2);
2790 ReplaceUses(SDValue(N, 1), Result);
2791 }
2792
2793 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2794 return NULL;
2795 }
2796
2797 case Intrinsic::arm_strexd: {
2798 DebugLoc dl = N->getDebugLoc();
2799 SDValue Chain = N->getOperand(0);
2800 SDValue Val0 = N->getOperand(2);
2801 SDValue Val1 = N->getOperand(3);
2802 SDValue MemAddr = N->getOperand(4);
2803
2804 // Until there's support for specifing explicit register constraints
2805 // like the use of even/odd register pair, hardcode strexd to always
2806 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2807 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2808 SDValue(0, 0));
2809 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2810
2811 SDValue Glue = Chain.getValue(1);
2812 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2813 ARM::R2, MVT::i32, Glue);
2814 Glue = Val0.getValue(1);
2815 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2816 ARM::R3, MVT::i32, Glue);
2817
2818 // Store exclusive double return a i32 value which is the return status
2819 // of the issued store.
2820 std::vector<EVT> ResTys;
2821 ResTys.push_back(MVT::i32);
2822 ResTys.push_back(MVT::Other);
2823
2824 // place arguments in the right order
2825 SmallVector<SDValue, 7> Ops;
2826 Ops.push_back(Val0);
2827 Ops.push_back(Val1);
2828 Ops.push_back(MemAddr);
2829 Ops.push_back(getAL(CurDAG));
2830 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2831 Ops.push_back(Chain);
2832
2833 unsigned NewOpc = ARM::STREXD;
2834 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2835 NewOpc = ARM::t2STREXD;
2836
2837 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2838 Ops.size());
2839 // Transfer memoperands.
2840 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2841 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2842 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2843
2844 return St;
2845 }
2846
Bob Wilson621f1952010-03-23 05:25:43 +00002847 case Intrinsic::arm_neon_vld1: {
2848 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2849 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002850 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2851 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002852 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002853 }
2854
Bob Wilson31fb12f2009-08-26 17:39:53 +00002855 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002856 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2857 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2858 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2859 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002860 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002861 }
2862
2863 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002864 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2865 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2866 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2867 ARM::VLD3q16Pseudo_UPD,
2868 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002869 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2870 ARM::VLD3q16oddPseudo,
2871 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002872 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002873 }
2874
2875 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002876 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2877 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2878 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2879 ARM::VLD4q16Pseudo_UPD,
2880 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002881 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2882 ARM::VLD4q16oddPseudo,
2883 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002884 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002885 }
2886
Bob Wilson243fcc52009-09-01 04:26:28 +00002887 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002888 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2889 ARM::VLD2LNd32Pseudo };
2890 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002891 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002892 }
2893
2894 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002895 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2896 ARM::VLD3LNd32Pseudo };
2897 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002898 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002899 }
2900
2901 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002902 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2903 ARM::VLD4LNd32Pseudo };
2904 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002905 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002906 }
2907
Bob Wilson11d98992010-03-23 06:20:33 +00002908 case Intrinsic::arm_neon_vst1: {
2909 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2910 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002911 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2912 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002913 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002914 }
2915
Bob Wilson31fb12f2009-08-26 17:39:53 +00002916 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002917 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2918 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2919 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2920 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002921 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002922 }
2923
2924 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002925 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2926 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2927 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2928 ARM::VST3q16Pseudo_UPD,
2929 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002930 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2931 ARM::VST3q16oddPseudo,
2932 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002933 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002934 }
2935
2936 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002937 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002938 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002939 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2940 ARM::VST4q16Pseudo_UPD,
2941 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002942 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2943 ARM::VST4q16oddPseudo,
2944 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002945 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002946 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002947
2948 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002949 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2950 ARM::VST2LNd32Pseudo };
2951 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002952 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002953 }
2954
2955 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002956 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2957 ARM::VST3LNd32Pseudo };
2958 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002959 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002960 }
2961
2962 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002963 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2964 ARM::VST4LNd32Pseudo };
2965 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002966 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002967 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002968 }
Bob Wilson429009b2010-05-06 16:05:26 +00002969 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002970 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002971
Bob Wilsond491d6e2010-07-06 23:36:25 +00002972 case ISD::INTRINSIC_WO_CHAIN: {
2973 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2974 switch (IntNo) {
2975 default:
2976 break;
2977
2978 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002979 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002980 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002981 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002982 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002983 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002984
2985 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002986 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002987 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002988 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002989 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002990 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002991 }
2992 break;
2993 }
2994
Bill Wendling69a05a72011-03-14 23:02:38 +00002995 case ARMISD::VTBL1: {
2996 DebugLoc dl = N->getDebugLoc();
2997 EVT VT = N->getValueType(0);
2998 SmallVector<SDValue, 6> Ops;
2999
3000 Ops.push_back(N->getOperand(0));
3001 Ops.push_back(N->getOperand(1));
3002 Ops.push_back(getAL(CurDAG)); // Predicate
3003 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3004 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3005 }
3006 case ARMISD::VTBL2: {
3007 DebugLoc dl = N->getDebugLoc();
3008 EVT VT = N->getValueType(0);
3009
3010 // Form a REG_SEQUENCE to force register allocation.
3011 SDValue V0 = N->getOperand(0);
3012 SDValue V1 = N->getOperand(1);
3013 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3014
3015 SmallVector<SDValue, 6> Ops;
3016 Ops.push_back(RegSeq);
3017 Ops.push_back(N->getOperand(2));
3018 Ops.push_back(getAL(CurDAG)); // Predicate
3019 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3020 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3021 Ops.data(), Ops.size());
3022 }
3023
Bob Wilson429009b2010-05-06 16:05:26 +00003024 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003025 return SelectConcatVector(N);
3026 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003027
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003028 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003029}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003030
Bob Wilson224c2442009-05-19 05:53:42 +00003031bool ARMDAGToDAGISel::
3032SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3033 std::vector<SDValue> &OutOps) {
3034 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003035 // Require the address to be in a register. That is safe for all ARM
3036 // variants and it is hard to do anything much smarter without knowing
3037 // how the operand is used.
3038 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003039 return false;
3040}
3041
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003042/// createARMISelDag - This pass converts a legalized DAG into a
3043/// ARM-specific DAG, ready for instruction scheduling.
3044///
Bob Wilson522ce972009-09-28 14:30:20 +00003045FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3046 CodeGenOpt::Level OptLevel) {
3047 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003048}