blob: abe5a316a45bd1c2700c429a30a60acaf7df256b [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"
Evan Chenge5ad88e2008-12-10 21:54:21 +000017#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000018#include "ARMTargetMachine.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);
Chris Lattner52a261b2010-09-21 20:31:19 +000093 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000094 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
Evan Chengf40deed2010-10-27 23:41:30 +000096 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000097 SDValue &B, SDValue &C) {
98 // Don't apply the profitability check
99 return SelectShifterOperandReg(N, A, B, C, false);
100 }
101
Jim Grosbach3e556122010-10-26 22:37:02 +0000102 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
103 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
104
Jim Grosbach82891622010-09-29 19:03:54 +0000105 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
106 SDValue &Offset, SDValue &Opc);
107 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
108 SDValue &Opc) {
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
110 }
111
112 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
113 SDValue &Opc) {
114 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
115 }
116
117 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
118 SDValue &Opc) {
119 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000120// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000121 // This always matches one way or another.
122 return true;
123 }
124
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000126 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000127 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000128 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000129 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000130 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000131 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000132 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000133 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000134 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000135
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000136 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000137
Bill Wendlingf4caf692010-12-14 03:36:38 +0000138 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000140 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
141 unsigned Scale);
142 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
143 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
144 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
145 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
146 SDValue &OffImm);
147 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
148 SDValue &OffImm);
149 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
150 SDValue &OffImm);
151 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
152 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000153 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000154
Bill Wendlingf4caf692010-12-14 03:36:38 +0000155 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000156 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000157 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000158 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
159 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000160 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000161 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000162 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000163 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000164 SDValue &OffReg, SDValue &ShImm);
165
Evan Cheng875a6ac2010-11-12 22:42:47 +0000166 inline bool is_so_imm(unsigned Imm) const {
167 return ARM_AM::getSOImmVal(Imm) != -1;
168 }
169
170 inline bool is_so_imm_not(unsigned Imm) const {
171 return ARM_AM::getSOImmVal(~Imm) != -1;
172 }
173
174 inline bool is_t2_so_imm(unsigned Imm) const {
175 return ARM_AM::getT2SOImmVal(Imm) != -1;
176 }
177
178 inline bool is_t2_so_imm_not(unsigned Imm) const {
179 return ARM_AM::getT2SOImmVal(~Imm) != -1;
180 }
181
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000182 // Include the pieces autogenerated from the target description.
183#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000184
185private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000186 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
187 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000188 SDNode *SelectARMIndexedLoad(SDNode *N);
189 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000190
Bob Wilson621f1952010-03-23 05:25:43 +0000191 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
192 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000193 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000194 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000195 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
196 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000197 unsigned *QOpcodes0, unsigned *QOpcodes1);
198
Bob Wilson24f995d2009-10-14 18:32:29 +0000199 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000200 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000201 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000202 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000203 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
204 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000205 unsigned *QOpcodes0, unsigned *QOpcodes1);
206
Bob Wilson96493442009-10-14 16:46:45 +0000207 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000208 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000209 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000210 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
211 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000212 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000213
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000214 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
215 /// should be 2, 3 or 4. The opcode array specifies the instructions used
216 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000217 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
218 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000219
Bob Wilson78dfbc32010-07-07 00:08:54 +0000220 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
221 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
222 /// generated to force the table registers to be consecutive.
223 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000224
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000225 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000226 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000227
Evan Cheng07ba9062009-11-19 21:45:22 +0000228 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000229 SDNode *SelectCMOVOp(SDNode *N);
230 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000231 ARMCC::CondCodes CCVal, SDValue CCR,
232 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000234 ARMCC::CondCodes CCVal, SDValue CCR,
235 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000236 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000237 ARMCC::CondCodes CCVal, SDValue CCR,
238 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000239 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000240 ARMCC::CondCodes CCVal, SDValue CCR,
241 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000242
Evan Chengde8aa4e2010-05-05 18:28:36 +0000243 SDNode *SelectConcatVector(SDNode *N);
244
Evan Chengaf4550f2009-07-02 01:23:32 +0000245 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
246 /// inline asm expressions.
247 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
248 char ConstraintCode,
249 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000250
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000251 // Form pairs of consecutive S, D, or Q registers.
252 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000253 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000254 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
255
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000256 // Form sequences of 4 consecutive S, D, or Q registers.
257 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000258 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000259 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000260
261 // Get the alignment operand for a NEON VLD or VST instruction.
262 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000263};
Evan Chenga8e29892007-01-19 07:51:42 +0000264}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000265
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000266/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
267/// operand. If so Imm will receive the 32-bit value.
268static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
269 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
270 Imm = cast<ConstantSDNode>(N)->getZExtValue();
271 return true;
272 }
273 return false;
274}
275
276// isInt32Immediate - This method tests to see if a constant operand.
277// If so Imm will receive the 32 bit value.
278static bool isInt32Immediate(SDValue N, unsigned &Imm) {
279 return isInt32Immediate(N.getNode(), Imm);
280}
281
282// isOpcWithIntImmediate - This method tests to see if the node is a specific
283// opcode and that it has a immediate integer right operand.
284// If so Imm will receive the 32 bit value.
285static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
286 return N->getOpcode() == Opc &&
287 isInt32Immediate(N->getOperand(1).getNode(), Imm);
288}
289
Daniel Dunbarec91d522011-01-19 15:12:16 +0000290/// \brief Check whether a particular node is a constant value representable as
291/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
292///
293/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
294static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
295 int RangeMin, int RangeMax,
296 int &ScaledConstant) {
297 assert(Scale && "Invalid scale!");
298
299 // Check that this is a constant.
300 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
301 if (!C)
302 return false;
303
304 ScaledConstant = (int) C->getZExtValue();
305 if ((ScaledConstant % Scale) != 0)
306 return false;
307
308 ScaledConstant /= Scale;
309 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
310}
311
Evan Cheng48575f62010-12-05 22:04:16 +0000312/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
313/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
314/// least on current ARM implementations) which should be avoidded.
315bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
316 if (OptLevel == CodeGenOpt::None)
317 return true;
318
319 if (!CheckVMLxHazard)
320 return true;
321
322 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
323 return true;
324
325 if (!N->hasOneUse())
326 return false;
327
328 SDNode *Use = *N->use_begin();
329 if (Use->getOpcode() == ISD::CopyToReg)
330 return true;
331 if (Use->isMachineOpcode()) {
332 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
333 if (TID.mayStore())
334 return true;
335 unsigned Opcode = TID.getOpcode();
336 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
337 return true;
338 // vmlx feeding into another vmlx. We actually want to unfold
339 // the use later in the MLxExpansion pass. e.g.
340 // vmla
341 // vmla (stall 8 cycles)
342 //
343 // vmul (5 cycles)
344 // vadd (5 cycles)
345 // vmla
346 // This adds up to about 18 - 19 cycles.
347 //
348 // vmla
349 // vmul (stall 4 cycles)
350 // vadd adds up to about 14 cycles.
351 return TII->isFpMLxInstruction(Opcode);
352 }
353
354 return false;
355}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000356
Evan Chengf40deed2010-10-27 23:41:30 +0000357bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
358 ARM_AM::ShiftOpc ShOpcVal,
359 unsigned ShAmt) {
360 if (!Subtarget->isCortexA9())
361 return true;
362 if (Shift.hasOneUse())
363 return true;
364 // R << 2 is free.
365 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
366}
367
Chris Lattner52a261b2010-09-21 20:31:19 +0000368bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000369 SDValue &BaseReg,
370 SDValue &ShReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000371 SDValue &Opc,
372 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000373 if (DisableShifterOp)
374 return false;
375
Evan Cheng055b0312009-06-29 07:51:04 +0000376 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
377
378 // Don't match base register only case. That is matched to a separate
379 // lower complexity pattern with explicit register operand.
380 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000381
Evan Cheng055b0312009-06-29 07:51:04 +0000382 BaseReg = N.getOperand(0);
383 unsigned ShImmVal = 0;
384 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000385 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000386 ShImmVal = RHS->getZExtValue() & 31;
387 } else {
388 ShReg = N.getOperand(1);
Owen Anderson099e5552011-03-18 19:46:58 +0000389 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
Evan Chengf40deed2010-10-27 23:41:30 +0000390 return false;
391 }
392 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
393 MVT::i32);
394 return true;
395}
396
Jim Grosbach3e556122010-10-26 22:37:02 +0000397bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
398 SDValue &Base,
399 SDValue &OffImm) {
400 // Match simple R + imm12 operands.
401
402 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000403 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
404 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000405 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000406 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000407 int FI = cast<FrameIndexSDNode>(N)->getIndex();
408 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
409 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
410 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000411 }
Owen Anderson099e5552011-03-18 19:46:58 +0000412
Chris Lattner0a9481f2011-02-13 22:25:43 +0000413 if (N.getOpcode() == ARMISD::Wrapper &&
414 !(Subtarget->useMovt() &&
415 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000416 Base = N.getOperand(0);
417 } else
418 Base = N;
419 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
420 return true;
421 }
422
423 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
424 int RHSC = (int)RHS->getZExtValue();
425 if (N.getOpcode() == ISD::SUB)
426 RHSC = -RHSC;
427
428 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
429 Base = N.getOperand(0);
430 if (Base.getOpcode() == ISD::FrameIndex) {
431 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
432 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
433 }
434 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
435 return true;
436 }
437 }
438
439 // Base only.
440 Base = N;
441 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
442 return true;
443}
444
445
446
447bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
448 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000449 if (N.getOpcode() == ISD::MUL &&
450 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000451 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
452 // X * [3,5,9] -> X + X * [2,4,8] etc.
453 int RHSC = (int)RHS->getZExtValue();
454 if (RHSC & 1) {
455 RHSC = RHSC & ~1;
456 ARM_AM::AddrOpc AddSub = ARM_AM::add;
457 if (RHSC < 0) {
458 AddSub = ARM_AM::sub;
459 RHSC = - RHSC;
460 }
461 if (isPowerOf2_32(RHSC)) {
462 unsigned ShAmt = Log2_32(RHSC);
463 Base = Offset = N.getOperand(0);
464 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
465 ARM_AM::lsl),
466 MVT::i32);
467 return true;
468 }
469 }
470 }
471 }
472
Chris Lattner0a9481f2011-02-13 22:25:43 +0000473 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
474 // ISD::OR that is equivalent to an ISD::ADD.
475 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000476 return false;
477
478 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000479 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000480 int RHSC;
481 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
482 -0x1000+1, 0x1000, RHSC)) // 12 bits.
483 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000484 }
485
Evan Chengf40deed2010-10-27 23:41:30 +0000486 if (Subtarget->isCortexA9() && !N.hasOneUse())
487 // Compute R +/- (R << N) and reuse it.
488 return false;
489
Jim Grosbach3e556122010-10-26 22:37:02 +0000490 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000491 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Jim Grosbach3e556122010-10-26 22:37:02 +0000492 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
493 unsigned ShAmt = 0;
494
495 Base = N.getOperand(0);
496 Offset = N.getOperand(1);
497
498 if (ShOpcVal != ARM_AM::no_shift) {
499 // Check to see if the RHS of the shift is a constant, if not, we can't fold
500 // it.
501 if (ConstantSDNode *Sh =
502 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
503 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000504 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
505 Offset = N.getOperand(1).getOperand(0);
506 else {
507 ShAmt = 0;
508 ShOpcVal = ARM_AM::no_shift;
509 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000510 } else {
511 ShOpcVal = ARM_AM::no_shift;
512 }
513 }
514
515 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000516 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000517 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000518 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
519 if (ShOpcVal != ARM_AM::no_shift) {
520 // Check to see if the RHS of the shift is a constant, if not, we can't
521 // fold it.
522 if (ConstantSDNode *Sh =
523 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
524 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000525 if (!Subtarget->isCortexA9() ||
526 (N.hasOneUse() &&
527 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
528 Offset = N.getOperand(0).getOperand(0);
529 Base = N.getOperand(1);
530 } else {
531 ShAmt = 0;
532 ShOpcVal = ARM_AM::no_shift;
533 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000534 } else {
535 ShOpcVal = ARM_AM::no_shift;
536 }
537 }
538 }
539
540 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
541 MVT::i32);
542 return true;
543}
544
545
546
547
548//-----
549
Jim Grosbach82891622010-09-29 19:03:54 +0000550AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
551 SDValue &Base,
552 SDValue &Offset,
553 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000554 if (N.getOpcode() == ISD::MUL &&
555 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000556 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
557 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000558 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000559 if (RHSC & 1) {
560 RHSC = RHSC & ~1;
561 ARM_AM::AddrOpc AddSub = ARM_AM::add;
562 if (RHSC < 0) {
563 AddSub = ARM_AM::sub;
564 RHSC = - RHSC;
565 }
566 if (isPowerOf2_32(RHSC)) {
567 unsigned ShAmt = Log2_32(RHSC);
568 Base = Offset = N.getOperand(0);
569 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
570 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000571 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000572 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000573 }
574 }
575 }
576 }
577
Chris Lattner0a9481f2011-02-13 22:25:43 +0000578 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
579 // ISD::OR that is equivalent to an ADD.
580 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000581 Base = N;
582 if (N.getOpcode() == ISD::FrameIndex) {
583 int FI = cast<FrameIndexSDNode>(N)->getIndex();
584 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000585 } else if (N.getOpcode() == ARMISD::Wrapper &&
586 !(Subtarget->useMovt() &&
587 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000588 Base = N.getOperand(0);
589 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000591 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
592 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000593 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000594 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000595 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000596
Evan Chenga8e29892007-01-19 07:51:42 +0000597 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000598 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000599 int RHSC;
600 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
601 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
602 Base = N.getOperand(0);
603 if (Base.getOpcode() == ISD::FrameIndex) {
604 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
605 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000606 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000607 Offset = CurDAG->getRegister(0, MVT::i32);
608
609 ARM_AM::AddrOpc AddSub = ARM_AM::add;
610 if (RHSC < 0) {
611 AddSub = ARM_AM::sub;
612 RHSC = - RHSC;
613 }
614 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
615 ARM_AM::no_shift),
616 MVT::i32);
617 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000618 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000619 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000620
Evan Chengf40deed2010-10-27 23:41:30 +0000621 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
622 // Compute R +/- (R << N) and reuse it.
623 Base = N;
624 Offset = CurDAG->getRegister(0, MVT::i32);
625 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
626 ARM_AM::no_shift),
627 MVT::i32);
628 return AM2_BASE;
629 }
630
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000631 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000632 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga8e29892007-01-19 07:51:42 +0000633 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
634 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000635
Evan Chenga8e29892007-01-19 07:51:42 +0000636 Base = N.getOperand(0);
637 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000638
Evan Chenga8e29892007-01-19 07:51:42 +0000639 if (ShOpcVal != ARM_AM::no_shift) {
640 // Check to see if the RHS of the shift is a constant, if not, we can't fold
641 // it.
642 if (ConstantSDNode *Sh =
643 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000644 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000645 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
646 Offset = N.getOperand(1).getOperand(0);
647 else {
648 ShAmt = 0;
649 ShOpcVal = ARM_AM::no_shift;
650 }
Evan Chenga8e29892007-01-19 07:51:42 +0000651 } else {
652 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000653 }
654 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000655
Evan Chenga8e29892007-01-19 07:51:42 +0000656 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000657 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000658 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000659 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
660 if (ShOpcVal != ARM_AM::no_shift) {
661 // Check to see if the RHS of the shift is a constant, if not, we can't
662 // fold it.
663 if (ConstantSDNode *Sh =
664 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000665 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000666 if (!Subtarget->isCortexA9() ||
667 (N.hasOneUse() &&
668 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
669 Offset = N.getOperand(0).getOperand(0);
670 Base = N.getOperand(1);
671 } else {
672 ShAmt = 0;
673 ShOpcVal = ARM_AM::no_shift;
674 }
Evan Chenga8e29892007-01-19 07:51:42 +0000675 } else {
676 ShOpcVal = ARM_AM::no_shift;
677 }
678 }
679 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000680
Evan Chenga8e29892007-01-19 07:51:42 +0000681 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000682 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000683 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000684}
685
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000686bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000687 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000688 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000689 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
690 ? cast<LoadSDNode>(Op)->getAddressingMode()
691 : cast<StoreSDNode>(Op)->getAddressingMode();
692 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
693 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000694 int Val;
695 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
696 Offset = CurDAG->getRegister(0, MVT::i32);
697 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
698 ARM_AM::no_shift),
699 MVT::i32);
700 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000701 }
702
703 Offset = N;
704 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
705 unsigned ShAmt = 0;
706 if (ShOpcVal != ARM_AM::no_shift) {
707 // Check to see if the RHS of the shift is a constant, if not, we can't fold
708 // it.
709 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000710 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000711 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
712 Offset = N.getOperand(0);
713 else {
714 ShAmt = 0;
715 ShOpcVal = ARM_AM::no_shift;
716 }
Evan Chenga8e29892007-01-19 07:51:42 +0000717 } else {
718 ShOpcVal = ARM_AM::no_shift;
719 }
720 }
721
722 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000723 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000724 return true;
725}
726
Evan Chenga8e29892007-01-19 07:51:42 +0000727
Chris Lattner52a261b2010-09-21 20:31:19 +0000728bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000729 SDValue &Base, SDValue &Offset,
730 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000731 if (N.getOpcode() == ISD::SUB) {
732 // X - C is canonicalize to X + -C, no need to handle it here.
733 Base = N.getOperand(0);
734 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000735 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000736 return true;
737 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000738
Chris Lattner0a9481f2011-02-13 22:25:43 +0000739 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000740 Base = N;
741 if (N.getOpcode() == ISD::FrameIndex) {
742 int FI = cast<FrameIndexSDNode>(N)->getIndex();
743 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
744 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000745 Offset = CurDAG->getRegister(0, MVT::i32);
746 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000747 return true;
748 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000749
Evan Chenga8e29892007-01-19 07:51:42 +0000750 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000751 int RHSC;
752 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
753 -256 + 1, 256, RHSC)) { // 8 bits.
754 Base = N.getOperand(0);
755 if (Base.getOpcode() == ISD::FrameIndex) {
756 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
757 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000758 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000759 Offset = CurDAG->getRegister(0, MVT::i32);
760
761 ARM_AM::AddrOpc AddSub = ARM_AM::add;
762 if (RHSC < 0) {
763 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000764 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000765 }
766 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
767 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000768 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000769
Evan Chenga8e29892007-01-19 07:51:42 +0000770 Base = N.getOperand(0);
771 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000772 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000773 return true;
774}
775
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000776bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000777 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000778 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000779 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
780 ? cast<LoadSDNode>(Op)->getAddressingMode()
781 : cast<StoreSDNode>(Op)->getAddressingMode();
782 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
783 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000784 int Val;
785 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
786 Offset = CurDAG->getRegister(0, MVT::i32);
787 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
788 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000789 }
790
791 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000792 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000793 return true;
794}
795
Jim Grosbach3ab56582010-10-21 19:38:40 +0000796bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000797 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000798 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000799 Base = N;
800 if (N.getOpcode() == ISD::FrameIndex) {
801 int FI = cast<FrameIndexSDNode>(N)->getIndex();
802 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000803 } else if (N.getOpcode() == ARMISD::Wrapper &&
804 !(Subtarget->useMovt() &&
805 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000806 Base = N.getOperand(0);
807 }
808 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000809 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000810 return true;
811 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000812
Evan Chenga8e29892007-01-19 07:51:42 +0000813 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000814 int RHSC;
815 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
816 -256 + 1, 256, RHSC)) {
817 Base = N.getOperand(0);
818 if (Base.getOpcode() == ISD::FrameIndex) {
819 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
820 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000821 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000822
823 ARM_AM::AddrOpc AddSub = ARM_AM::add;
824 if (RHSC < 0) {
825 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000826 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000827 }
828 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
829 MVT::i32);
830 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000831 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000832
Evan Chenga8e29892007-01-19 07:51:42 +0000833 Base = N;
834 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000835 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000836 return true;
837}
838
Bob Wilson665814b2010-11-01 23:40:51 +0000839bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
840 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000841 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000842
843 unsigned Alignment = 0;
844 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
845 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
846 // The maximum alignment is equal to the memory size being referenced.
847 unsigned LSNAlign = LSN->getAlignment();
848 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
849 if (LSNAlign > MemSize && MemSize > 1)
850 Alignment = MemSize;
851 } else {
852 // All other uses of addrmode6 are for intrinsics. For now just record
853 // the raw alignment value; it will be refined later based on the legal
854 // alignment operands for the intrinsic.
855 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
856 }
857
858 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000859 return true;
860}
861
Bob Wilsonda525062011-02-25 06:42:42 +0000862bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
863 SDValue &Offset) {
864 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
865 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
866 if (AM != ISD::POST_INC)
867 return false;
868 Offset = N;
869 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
870 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
871 Offset = CurDAG->getRegister(0, MVT::i32);
872 }
873 return true;
874}
875
Chris Lattner52a261b2010-09-21 20:31:19 +0000876bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000877 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000878 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
879 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000880 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000881 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
882 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000883 return true;
884 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000885
Evan Chenga8e29892007-01-19 07:51:42 +0000886 return false;
887}
888
Bill Wendlingf4caf692010-12-14 03:36:38 +0000889
890//===----------------------------------------------------------------------===//
891// Thumb Addressing Modes
892//===----------------------------------------------------------------------===//
893
Chris Lattner52a261b2010-09-21 20:31:19 +0000894bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000895 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000896 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000897 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000898 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000899 return false;
900
901 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000902 return true;
903 }
904
Evan Chenga8e29892007-01-19 07:51:42 +0000905 Base = N.getOperand(0);
906 Offset = N.getOperand(1);
907 return true;
908}
909
Evan Cheng79d43262007-01-24 02:21:22 +0000910bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000911ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
912 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000913 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000914 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000915 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000916 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000917
Evan Cheng012f2d92007-01-24 08:53:17 +0000918 if (N.getOpcode() == ARMISD::Wrapper &&
919 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
920 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000921 }
922
Chris Lattner0a9481f2011-02-13 22:25:43 +0000923 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000924 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000925
Evan Chengad0e4652007-02-06 00:22:06 +0000926 // Thumb does not have [sp, r] address mode.
927 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
928 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
929 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000930 (RHSR && RHSR->getReg() == ARM::SP))
931 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000932
Daniel Dunbarec91d522011-01-19 15:12:16 +0000933 // FIXME: Why do we explicitly check for a match here and then return false?
934 // Presumably to allow something else to match, but shouldn't this be
935 // documented?
936 int RHSC;
937 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
938 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000939
940 Base = N.getOperand(0);
941 Offset = N.getOperand(1);
942 return true;
943}
944
945bool
946ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
947 SDValue &Base,
948 SDValue &Offset) {
949 return SelectThumbAddrModeRI(N, Base, Offset, 1);
950}
951
952bool
953ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
954 SDValue &Base,
955 SDValue &Offset) {
956 return SelectThumbAddrModeRI(N, Base, Offset, 2);
957}
958
959bool
960ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
961 SDValue &Base,
962 SDValue &Offset) {
963 return SelectThumbAddrModeRI(N, Base, Offset, 4);
964}
965
966bool
967ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
968 SDValue &Base, SDValue &OffImm) {
969 if (Scale == 4) {
970 SDValue TmpBase, TmpOffImm;
971 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
972 return false; // We want to select tLDRspi / tSTRspi instead.
973
974 if (N.getOpcode() == ARMISD::Wrapper &&
975 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
976 return false; // We want to select tLDRpci instead.
977 }
978
Chris Lattner0a9481f2011-02-13 22:25:43 +0000979 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000980 if (N.getOpcode() == ARMISD::Wrapper &&
981 !(Subtarget->useMovt() &&
982 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
983 Base = N.getOperand(0);
984 } else {
985 Base = N;
986 }
987
Owen Anderson825b72b2009-08-11 20:47:22 +0000988 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000989 return true;
990 }
991
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000992 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
993 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
994 if ((LHSR && LHSR->getReg() == ARM::SP) ||
995 (RHSR && RHSR->getReg() == ARM::SP)) {
996 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
997 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
998 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
999 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1000
1001 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1002 if (LHSC != 0 || RHSC != 0) return false;
1003
1004 Base = N;
1005 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1006 return true;
1007 }
1008
Evan Chenga8e29892007-01-19 07:51:42 +00001009 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001010 int RHSC;
1011 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1012 Base = N.getOperand(0);
1013 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1014 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001015 }
1016
Evan Chengc38f2bc2007-01-23 22:59:13 +00001017 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001018 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001019 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001020}
1021
Bill Wendlingf4caf692010-12-14 03:36:38 +00001022bool
1023ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1024 SDValue &OffImm) {
1025 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001026}
1027
Bill Wendlingf4caf692010-12-14 03:36:38 +00001028bool
1029ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1030 SDValue &OffImm) {
1031 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001032}
1033
Bill Wendlingf4caf692010-12-14 03:36:38 +00001034bool
1035ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1036 SDValue &OffImm) {
1037 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001038}
1039
Chris Lattner52a261b2010-09-21 20:31:19 +00001040bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1041 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001042 if (N.getOpcode() == ISD::FrameIndex) {
1043 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1044 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001045 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001046 return true;
1047 }
Evan Cheng79d43262007-01-24 02:21:22 +00001048
Chris Lattner0a9481f2011-02-13 22:25:43 +00001049 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001050 return false;
1051
1052 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001053 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1054 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001055 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001056 int RHSC;
1057 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1058 Base = N.getOperand(0);
1059 if (Base.getOpcode() == ISD::FrameIndex) {
1060 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1061 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001062 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001063 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1064 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001065 }
1066 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001067
Evan Chenga8e29892007-01-19 07:51:42 +00001068 return false;
1069}
1070
Bill Wendlingf4caf692010-12-14 03:36:38 +00001071
1072//===----------------------------------------------------------------------===//
1073// Thumb 2 Addressing Modes
1074//===----------------------------------------------------------------------===//
1075
1076
Chris Lattner52a261b2010-09-21 20:31:19 +00001077bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001078 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001079 if (DisableShifterOp)
1080 return false;
1081
Evan Cheng9cb9e672009-06-27 02:26:13 +00001082 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1083
1084 // Don't match base register only case. That is matched to a separate
1085 // lower complexity pattern with explicit register operand.
1086 if (ShOpcVal == ARM_AM::no_shift) return false;
1087
1088 BaseReg = N.getOperand(0);
1089 unsigned ShImmVal = 0;
1090 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1091 ShImmVal = RHS->getZExtValue() & 31;
1092 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1093 return true;
1094 }
1095
1096 return false;
1097}
1098
Chris Lattner52a261b2010-09-21 20:31:19 +00001099bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001100 SDValue &Base, SDValue &OffImm) {
1101 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001102
Evan Cheng3a214252009-08-11 08:52:18 +00001103 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001104 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1105 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001106 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001107 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001108 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1109 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001110 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001111 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001112 }
Owen Anderson099e5552011-03-18 19:46:58 +00001113
Chris Lattner0a9481f2011-02-13 22:25:43 +00001114 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001115 !(Subtarget->useMovt() &&
1116 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001117 Base = N.getOperand(0);
1118 if (Base.getOpcode() == ISD::TargetConstantPool)
1119 return false; // We want to select t2LDRpci instead.
1120 } else
1121 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001122 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001123 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001124 }
Evan Cheng055b0312009-06-29 07:51:04 +00001125
1126 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001127 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001128 // Let t2LDRi8 handle (R - imm8).
1129 return false;
1130
Evan Cheng055b0312009-06-29 07:51:04 +00001131 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001132 if (N.getOpcode() == ISD::SUB)
1133 RHSC = -RHSC;
1134
1135 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001136 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001137 if (Base.getOpcode() == ISD::FrameIndex) {
1138 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1139 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1140 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001141 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001142 return true;
1143 }
1144 }
1145
Evan Cheng3a214252009-08-11 08:52:18 +00001146 // Base only.
1147 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001148 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001149 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001150}
1151
Chris Lattner52a261b2010-09-21 20:31:19 +00001152bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001153 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001154 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001155 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1156 !CurDAG->isBaseWithConstantOffset(N))
1157 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001158
Chris Lattner0a9481f2011-02-13 22:25:43 +00001159 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1160 int RHSC = (int)RHS->getSExtValue();
1161 if (N.getOpcode() == ISD::SUB)
1162 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001163
Chris Lattner0a9481f2011-02-13 22:25:43 +00001164 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1165 Base = N.getOperand(0);
1166 if (Base.getOpcode() == ISD::FrameIndex) {
1167 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1168 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001169 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001170 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1171 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001172 }
1173 }
1174
1175 return false;
1176}
1177
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001178bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001179 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001180 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001181 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1182 ? cast<LoadSDNode>(Op)->getAddressingMode()
1183 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001184 int RHSC;
1185 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1186 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1187 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1188 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1189 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001190 }
1191
1192 return false;
1193}
1194
Chris Lattner52a261b2010-09-21 20:31:19 +00001195bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001196 SDValue &Base,
1197 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001198 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001199 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001200 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001201
Evan Cheng3a214252009-08-11 08:52:18 +00001202 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1203 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1204 int RHSC = (int)RHS->getZExtValue();
1205 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1206 return false;
1207 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001208 return false;
1209 }
1210
Evan Chengf40deed2010-10-27 23:41:30 +00001211 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1212 // Compute R + (R << [1,2,3]) and reuse it.
1213 Base = N;
1214 return false;
1215 }
1216
Evan Cheng055b0312009-06-29 07:51:04 +00001217 // Look for (R + R) or (R + (R << [1,2,3])).
1218 unsigned ShAmt = 0;
1219 Base = N.getOperand(0);
1220 OffReg = N.getOperand(1);
1221
1222 // Swap if it is ((R << c) + R).
1223 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1224 if (ShOpcVal != ARM_AM::lsl) {
1225 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1226 if (ShOpcVal == ARM_AM::lsl)
1227 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001228 }
1229
Evan Cheng055b0312009-06-29 07:51:04 +00001230 if (ShOpcVal == ARM_AM::lsl) {
1231 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1232 // it.
1233 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1234 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001235 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1236 OffReg = OffReg.getOperand(0);
1237 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001238 ShAmt = 0;
1239 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001240 }
Evan Cheng055b0312009-06-29 07:51:04 +00001241 } else {
1242 ShOpcVal = ARM_AM::no_shift;
1243 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001244 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001245
Owen Anderson825b72b2009-08-11 20:47:22 +00001246 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001247
1248 return true;
1249}
1250
1251//===--------------------------------------------------------------------===//
1252
Evan Chengee568cf2007-07-05 07:15:27 +00001253/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001254static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001255 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001256}
1257
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001258SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1259 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001260 ISD::MemIndexedMode AM = LD->getAddressingMode();
1261 if (AM == ISD::UNINDEXED)
1262 return NULL;
1263
Owen Andersone50ed302009-08-10 22:56:29 +00001264 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001265 SDValue Offset, AMOpc;
1266 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1267 unsigned Opcode = 0;
1268 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001269 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001270 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001271 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1272 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001273 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001274 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001275 Match = true;
1276 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1277 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1278 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001280 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001281 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001282 Match = true;
1283 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1284 }
1285 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001286 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001287 Match = true;
1288 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1289 }
1290 }
1291 }
1292
1293 if (Match) {
1294 SDValue Chain = LD->getChain();
1295 SDValue Base = LD->getBasePtr();
1296 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001297 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001298 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001299 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001300 }
1301
1302 return NULL;
1303}
1304
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001305SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1306 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001307 ISD::MemIndexedMode AM = LD->getAddressingMode();
1308 if (AM == ISD::UNINDEXED)
1309 return NULL;
1310
Owen Andersone50ed302009-08-10 22:56:29 +00001311 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001312 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001313 SDValue Offset;
1314 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1315 unsigned Opcode = 0;
1316 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001317 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001318 switch (LoadedVT.getSimpleVT().SimpleTy) {
1319 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001320 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1321 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001322 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001323 if (isSExtLd)
1324 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1325 else
1326 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001327 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 case MVT::i8:
1329 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001330 if (isSExtLd)
1331 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1332 else
1333 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001334 break;
1335 default:
1336 return NULL;
1337 }
1338 Match = true;
1339 }
1340
1341 if (Match) {
1342 SDValue Chain = LD->getChain();
1343 SDValue Base = LD->getBasePtr();
1344 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001345 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001346 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001347 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001348 }
1349
1350 return NULL;
1351}
1352
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001353/// PairSRegs - Form a D register from a pair of S registers.
1354///
1355SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1356 DebugLoc dl = V0.getNode()->getDebugLoc();
1357 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1358 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001359 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1360 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001361}
1362
Evan Cheng603afbf2010-05-10 17:34:18 +00001363/// PairDRegs - Form a quad register from a pair of D registers.
1364///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001365SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1366 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001367 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1368 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001369 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1370 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001371}
1372
Evan Cheng7f687192010-05-14 00:21:45 +00001373/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001374///
1375SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1376 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001377 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1378 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001379 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1380 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1381}
1382
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001383/// QuadSRegs - Form 4 consecutive S registers.
1384///
1385SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1386 SDValue V2, SDValue V3) {
1387 DebugLoc dl = V0.getNode()->getDebugLoc();
1388 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1389 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1390 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1391 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1392 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1393 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1394}
1395
Evan Cheng7f687192010-05-14 00:21:45 +00001396/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001397///
1398SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1399 SDValue V2, SDValue V3) {
1400 DebugLoc dl = V0.getNode()->getDebugLoc();
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);
1403 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1404 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001405 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1406 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1407}
1408
Evan Cheng8f6de382010-05-16 03:27:48 +00001409/// QuadQRegs - Form 4 consecutive Q registers.
1410///
1411SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1412 SDValue V2, SDValue V3) {
1413 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001414 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1415 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1416 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1417 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001418 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1419 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1420}
1421
Bob Wilson2a6e6162010-09-23 23:42:37 +00001422/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1423/// of a NEON VLD or VST instruction. The supported values depend on the
1424/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001425SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1426 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001427 unsigned NumRegs = NumVecs;
1428 if (!is64BitVector && NumVecs < 3)
1429 NumRegs *= 2;
1430
Bob Wilson665814b2010-11-01 23:40:51 +00001431 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001432 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001433 Alignment = 32;
1434 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1435 Alignment = 16;
1436 else if (Alignment >= 8)
1437 Alignment = 8;
1438 else
1439 Alignment = 0;
1440
1441 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001442}
1443
Bob Wilson1c3ef902011-02-07 17:43:21 +00001444SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001445 unsigned *DOpcodes, unsigned *QOpcodes0,
1446 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001447 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001448 DebugLoc dl = N->getDebugLoc();
1449
Bob Wilson226036e2010-03-20 22:13:40 +00001450 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001451 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1452 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001453 return NULL;
1454
1455 SDValue Chain = N->getOperand(0);
1456 EVT VT = N->getValueType(0);
1457 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001458 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001459
Bob Wilson3e36f132009-10-14 17:28:52 +00001460 unsigned OpcodeIndex;
1461 switch (VT.getSimpleVT().SimpleTy) {
1462 default: llvm_unreachable("unhandled vld type");
1463 // Double-register operations:
1464 case MVT::v8i8: OpcodeIndex = 0; break;
1465 case MVT::v4i16: OpcodeIndex = 1; break;
1466 case MVT::v2f32:
1467 case MVT::v2i32: OpcodeIndex = 2; break;
1468 case MVT::v1i64: OpcodeIndex = 3; break;
1469 // Quad-register operations:
1470 case MVT::v16i8: OpcodeIndex = 0; break;
1471 case MVT::v8i16: OpcodeIndex = 1; break;
1472 case MVT::v4f32:
1473 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001474 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001475 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001476 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001477 }
1478
Bob Wilsonf5721912010-09-03 18:16:02 +00001479 EVT ResTy;
1480 if (NumVecs == 1)
1481 ResTy = VT;
1482 else {
1483 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1484 if (!is64BitVector)
1485 ResTyElts *= 2;
1486 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1487 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001488 std::vector<EVT> ResTys;
1489 ResTys.push_back(ResTy);
1490 if (isUpdating)
1491 ResTys.push_back(MVT::i32);
1492 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001493
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001494 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001495 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001496 SDNode *VLd;
1497 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001498
Bob Wilson1c3ef902011-02-07 17:43:21 +00001499 // Double registers and VLD1/VLD2 quad registers are directly supported.
1500 if (is64BitVector || NumVecs <= 2) {
1501 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1502 QOpcodes0[OpcodeIndex]);
1503 Ops.push_back(MemAddr);
1504 Ops.push_back(Align);
1505 if (isUpdating) {
1506 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1507 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001508 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001509 Ops.push_back(Pred);
1510 Ops.push_back(Reg0);
1511 Ops.push_back(Chain);
1512 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001513
Bob Wilson3e36f132009-10-14 17:28:52 +00001514 } else {
1515 // Otherwise, quad registers are loaded with two separate instructions,
1516 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001517 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001518
Bob Wilson1c3ef902011-02-07 17:43:21 +00001519 // Load the even subregs. This is always an updating load, so that it
1520 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001521 SDValue ImplDef =
1522 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1523 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001524 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1525 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001526 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001527
Bob Wilson24f995d2009-10-14 18:32:29 +00001528 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001529 Ops.push_back(SDValue(VLdA, 1));
1530 Ops.push_back(Align);
1531 if (isUpdating) {
1532 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1533 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1534 "only constant post-increment update allowed for VLD3/4");
1535 (void)Inc;
1536 Ops.push_back(Reg0);
1537 }
1538 Ops.push_back(SDValue(VLdA, 0));
1539 Ops.push_back(Pred);
1540 Ops.push_back(Reg0);
1541 Ops.push_back(Chain);
1542 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1543 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001544 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001545
Evan Chengb58a3402011-04-19 00:04:03 +00001546 // Transfer memoperands.
1547 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1548 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1549 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1550
Bob Wilson1c3ef902011-02-07 17:43:21 +00001551 if (NumVecs == 1)
1552 return VLd;
1553
1554 // Extract out the subregisters.
1555 SDValue SuperReg = SDValue(VLd, 0);
1556 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1557 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1558 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1559 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1560 ReplaceUses(SDValue(N, Vec),
1561 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1562 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1563 if (isUpdating)
1564 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001565 return NULL;
1566}
1567
Bob Wilson1c3ef902011-02-07 17:43:21 +00001568SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001569 unsigned *DOpcodes, unsigned *QOpcodes0,
1570 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001571 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001572 DebugLoc dl = N->getDebugLoc();
1573
Bob Wilson226036e2010-03-20 22:13:40 +00001574 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001575 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1576 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1577 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001578 return NULL;
1579
Evan Chengb58a3402011-04-19 00:04:03 +00001580 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1581 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1582
Bob Wilson24f995d2009-10-14 18:32:29 +00001583 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001584 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001585 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001586 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001587
Bob Wilson24f995d2009-10-14 18:32:29 +00001588 unsigned OpcodeIndex;
1589 switch (VT.getSimpleVT().SimpleTy) {
1590 default: llvm_unreachable("unhandled vst type");
1591 // Double-register operations:
1592 case MVT::v8i8: OpcodeIndex = 0; break;
1593 case MVT::v4i16: OpcodeIndex = 1; break;
1594 case MVT::v2f32:
1595 case MVT::v2i32: OpcodeIndex = 2; break;
1596 case MVT::v1i64: OpcodeIndex = 3; break;
1597 // Quad-register operations:
1598 case MVT::v16i8: OpcodeIndex = 0; break;
1599 case MVT::v8i16: OpcodeIndex = 1; break;
1600 case MVT::v4f32:
1601 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001602 case MVT::v2i64: OpcodeIndex = 3;
1603 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1604 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001605 }
1606
Bob Wilson1c3ef902011-02-07 17:43:21 +00001607 std::vector<EVT> ResTys;
1608 if (isUpdating)
1609 ResTys.push_back(MVT::i32);
1610 ResTys.push_back(MVT::Other);
1611
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001612 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001613 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001614 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001615
Bob Wilson1c3ef902011-02-07 17:43:21 +00001616 // Double registers and VST1/VST2 quad registers are directly supported.
1617 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001618 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001619 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001620 SrcReg = N->getOperand(Vec0Idx);
1621 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001622 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001623 SDValue V0 = N->getOperand(Vec0Idx + 0);
1624 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001625 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001626 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001627 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001628 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001629 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001630 // an undef.
1631 SDValue V3 = (NumVecs == 3)
1632 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001633 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001634 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001635 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001636 } else {
1637 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001638 SDValue Q0 = N->getOperand(Vec0Idx);
1639 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001640 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001641 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001642
1643 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1644 QOpcodes0[OpcodeIndex]);
1645 Ops.push_back(MemAddr);
1646 Ops.push_back(Align);
1647 if (isUpdating) {
1648 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1649 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1650 }
1651 Ops.push_back(SrcReg);
1652 Ops.push_back(Pred);
1653 Ops.push_back(Reg0);
1654 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001655 SDNode *VSt =
1656 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1657
1658 // Transfer memoperands.
1659 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1660
1661 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001662 }
1663
1664 // Otherwise, quad registers are stored with two separate instructions,
1665 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001666
Bob Wilson07f6e802010-06-16 21:34:01 +00001667 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001668 SDValue V0 = N->getOperand(Vec0Idx + 0);
1669 SDValue V1 = N->getOperand(Vec0Idx + 1);
1670 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001671 SDValue V3 = (NumVecs == 3)
1672 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001673 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001674 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001675
Bob Wilson1c3ef902011-02-07 17:43:21 +00001676 // Store the even D registers. This is always an updating store, so that it
1677 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001678 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1679 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1680 MemAddr.getValueType(),
1681 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001682 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001683 Chain = SDValue(VStA, 1);
1684
1685 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001686 Ops.push_back(SDValue(VStA, 0));
1687 Ops.push_back(Align);
1688 if (isUpdating) {
1689 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1690 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1691 "only constant post-increment update allowed for VST3/4");
1692 (void)Inc;
1693 Ops.push_back(Reg0);
1694 }
1695 Ops.push_back(RegSeq);
1696 Ops.push_back(Pred);
1697 Ops.push_back(Reg0);
1698 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001699 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1700 Ops.data(), Ops.size());
1701 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1702 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001703}
1704
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001705SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001706 bool isUpdating, unsigned NumVecs,
1707 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001708 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001709 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001710 DebugLoc dl = N->getDebugLoc();
1711
Bob Wilson226036e2010-03-20 22:13:40 +00001712 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001713 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1714 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1715 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001716 return NULL;
1717
Evan Chengb58a3402011-04-19 00:04:03 +00001718 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1719 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1720
Bob Wilsona7c397c2009-10-14 16:19:03 +00001721 SDValue Chain = N->getOperand(0);
1722 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001723 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1724 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001725 bool is64BitVector = VT.is64BitVector();
1726
Bob Wilson665814b2010-11-01 23:40:51 +00001727 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001728 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001729 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001730 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1731 if (Alignment > NumBytes)
1732 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001733 if (Alignment < 8 && Alignment < NumBytes)
1734 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001735 // Alignment must be a power of two; make sure of that.
1736 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001737 if (Alignment == 1)
1738 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001739 }
Bob Wilson665814b2010-11-01 23:40:51 +00001740 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001741
Bob Wilsona7c397c2009-10-14 16:19:03 +00001742 unsigned OpcodeIndex;
1743 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001744 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001745 // Double-register operations:
1746 case MVT::v8i8: OpcodeIndex = 0; break;
1747 case MVT::v4i16: OpcodeIndex = 1; break;
1748 case MVT::v2f32:
1749 case MVT::v2i32: OpcodeIndex = 2; break;
1750 // Quad-register operations:
1751 case MVT::v8i16: OpcodeIndex = 0; break;
1752 case MVT::v4f32:
1753 case MVT::v4i32: OpcodeIndex = 1; break;
1754 }
1755
Bob Wilson1c3ef902011-02-07 17:43:21 +00001756 std::vector<EVT> ResTys;
1757 if (IsLoad) {
1758 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1759 if (!is64BitVector)
1760 ResTyElts *= 2;
1761 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1762 MVT::i64, ResTyElts));
1763 }
1764 if (isUpdating)
1765 ResTys.push_back(MVT::i32);
1766 ResTys.push_back(MVT::Other);
1767
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001768 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001769 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001770
Bob Wilson1c3ef902011-02-07 17:43:21 +00001771 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001772 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001773 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001774 if (isUpdating) {
1775 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1776 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1777 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001778
Bob Wilson8466fa12010-09-13 23:01:35 +00001779 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001780 SDValue V0 = N->getOperand(Vec0Idx + 0);
1781 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001782 if (NumVecs == 2) {
1783 if (is64BitVector)
1784 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1785 else
1786 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001787 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001788 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001789 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1791 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001792 if (is64BitVector)
1793 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1794 else
1795 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001796 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001797 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001798 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001799 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001800 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001801 Ops.push_back(Chain);
1802
Bob Wilson1c3ef902011-02-07 17:43:21 +00001803 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1804 QOpcodes[OpcodeIndex]);
1805 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1806 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001807 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001808 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001809 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001810
Bob Wilson8466fa12010-09-13 23:01:35 +00001811 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001812 SuperReg = SDValue(VLdLn, 0);
1813 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1814 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1815 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001816 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1817 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001818 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1819 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1820 if (isUpdating)
1821 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001822 return NULL;
1823}
1824
Bob Wilson1c3ef902011-02-07 17:43:21 +00001825SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1826 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001827 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1828 DebugLoc dl = N->getDebugLoc();
1829
1830 SDValue MemAddr, Align;
1831 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1832 return NULL;
1833
Evan Chengb58a3402011-04-19 00:04:03 +00001834 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1835 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1836
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001837 SDValue Chain = N->getOperand(0);
1838 EVT VT = N->getValueType(0);
1839
1840 unsigned Alignment = 0;
1841 if (NumVecs != 3) {
1842 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1843 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1844 if (Alignment > NumBytes)
1845 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001846 if (Alignment < 8 && Alignment < NumBytes)
1847 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001848 // Alignment must be a power of two; make sure of that.
1849 Alignment = (Alignment & -Alignment);
1850 if (Alignment == 1)
1851 Alignment = 0;
1852 }
1853 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1854
1855 unsigned OpcodeIndex;
1856 switch (VT.getSimpleVT().SimpleTy) {
1857 default: llvm_unreachable("unhandled vld-dup type");
1858 case MVT::v8i8: OpcodeIndex = 0; break;
1859 case MVT::v4i16: OpcodeIndex = 1; break;
1860 case MVT::v2f32:
1861 case MVT::v2i32: OpcodeIndex = 2; break;
1862 }
1863
1864 SDValue Pred = getAL(CurDAG);
1865 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1866 SDValue SuperReg;
1867 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001868 SmallVector<SDValue, 6> Ops;
1869 Ops.push_back(MemAddr);
1870 Ops.push_back(Align);
1871 if (isUpdating) {
1872 SDValue Inc = N->getOperand(2);
1873 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1874 }
1875 Ops.push_back(Pred);
1876 Ops.push_back(Reg0);
1877 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001878
1879 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001880 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001881 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001882 if (isUpdating)
1883 ResTys.push_back(MVT::i32);
1884 ResTys.push_back(MVT::Other);
1885 SDNode *VLdDup =
1886 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001887 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001888 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001889
1890 // Extract the subregisters.
1891 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1892 unsigned SubIdx = ARM::dsub_0;
1893 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1894 ReplaceUses(SDValue(N, Vec),
1895 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001896 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1897 if (isUpdating)
1898 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001899 return NULL;
1900}
1901
Bob Wilson78dfbc32010-07-07 00:08:54 +00001902SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1903 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001904 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1905 DebugLoc dl = N->getDebugLoc();
1906 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001907 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001908
1909 // Form a REG_SEQUENCE to force register allocation.
1910 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001911 SDValue V0 = N->getOperand(FirstTblReg + 0);
1912 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001913 if (NumVecs == 2)
1914 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1915 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001916 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001917 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001918 // an undef.
1919 SDValue V3 = (NumVecs == 3)
1920 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001921 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001922 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1923 }
1924
Bob Wilson78dfbc32010-07-07 00:08:54 +00001925 SmallVector<SDValue, 6> Ops;
1926 if (IsExt)
1927 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001928 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001929 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001930 Ops.push_back(getAL(CurDAG)); // predicate
1931 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001932 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001933}
1934
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001935SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001936 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001937 if (!Subtarget->hasV6T2Ops())
1938 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001939
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001940 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1941 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1942
1943
1944 // For unsigned extracts, check for a shift right and mask
1945 unsigned And_imm = 0;
1946 if (N->getOpcode() == ISD::AND) {
1947 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1948
1949 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1950 if (And_imm & (And_imm + 1))
1951 return NULL;
1952
1953 unsigned Srl_imm = 0;
1954 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1955 Srl_imm)) {
1956 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1957
1958 unsigned Width = CountTrailingOnes_32(And_imm);
1959 unsigned LSB = Srl_imm;
1960 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1961 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1962 CurDAG->getTargetConstant(LSB, MVT::i32),
1963 CurDAG->getTargetConstant(Width, MVT::i32),
1964 getAL(CurDAG), Reg0 };
1965 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1966 }
1967 }
1968 return NULL;
1969 }
1970
1971 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001972 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001973 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001974 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1975 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001977 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1978 unsigned Width = 32 - Srl_imm;
1979 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001980 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001981 return NULL;
1982 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001984 CurDAG->getTargetConstant(LSB, MVT::i32),
1985 CurDAG->getTargetConstant(Width, MVT::i32),
1986 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001987 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001988 }
1989 }
1990 return NULL;
1991}
1992
Evan Cheng9ef48352009-11-20 00:54:03 +00001993SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001994SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001995 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1996 SDValue CPTmp0;
1997 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001998 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001999 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2000 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2001 unsigned Opc = 0;
2002 switch (SOShOp) {
2003 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2004 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2005 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2006 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2007 default:
2008 llvm_unreachable("Unknown so_reg opcode!");
2009 break;
2010 }
2011 SDValue SOShImm =
2012 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2013 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2014 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002015 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002016 }
2017 return 0;
2018}
2019
2020SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002021SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002022 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2023 SDValue CPTmp0;
2024 SDValue CPTmp1;
2025 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002026 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002027 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2028 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002029 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002030 }
2031 return 0;
2032}
2033
2034SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002035SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002036 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002037 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002038 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002039 return 0;
2040
Evan Cheng63f35442010-11-13 02:25:14 +00002041 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002042 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002043 if (is_t2_so_imm(TrueImm)) {
2044 Opc = ARM::t2MOVCCi;
2045 } else if (TrueImm <= 0xffff) {
2046 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002047 } else if (is_t2_so_imm_not(TrueImm)) {
2048 TrueImm = ~TrueImm;
2049 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002050 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002051 // Large immediate.
2052 Opc = ARM::t2MOVCCi32imm;
2053 }
2054
2055 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002056 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002057 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2058 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002059 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002060 }
Evan Cheng63f35442010-11-13 02:25:14 +00002061
Evan Cheng9ef48352009-11-20 00:54:03 +00002062 return 0;
2063}
2064
2065SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002066SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002067 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002068 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2069 if (!T)
2070 return 0;
2071
Evan Cheng63f35442010-11-13 02:25:14 +00002072 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002073 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002074 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002075 if (isSoImm) {
2076 Opc = ARM::MOVCCi;
2077 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2078 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002079 } else if (is_so_imm_not(TrueImm)) {
2080 TrueImm = ~TrueImm;
2081 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002082 } else if (TrueVal.getNode()->hasOneUse() &&
2083 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002084 // Large immediate.
2085 Opc = ARM::MOVCCi32imm;
2086 }
2087
2088 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002089 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002090 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2091 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002092 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002093 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002094
Evan Cheng9ef48352009-11-20 00:54:03 +00002095 return 0;
2096}
2097
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002098SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2099 EVT VT = N->getValueType(0);
2100 SDValue FalseVal = N->getOperand(0);
2101 SDValue TrueVal = N->getOperand(1);
2102 SDValue CC = N->getOperand(2);
2103 SDValue CCR = N->getOperand(3);
2104 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002105 assert(CC.getOpcode() == ISD::Constant);
2106 assert(CCR.getOpcode() == ISD::Register);
2107 ARMCC::CondCodes CCVal =
2108 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002109
2110 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2111 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2112 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2113 // Pattern complexity = 18 cost = 1 size = 0
2114 SDValue CPTmp0;
2115 SDValue CPTmp1;
2116 SDValue CPTmp2;
2117 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002118 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002119 CCVal, CCR, InFlag);
2120 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002121 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002122 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2123 if (Res)
2124 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002125 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002126 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002127 CCVal, CCR, InFlag);
2128 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002129 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002130 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2131 if (Res)
2132 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002133 }
2134
2135 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002136 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002137 // (imm:i32):$cc)
2138 // Emits: (MOVCCi:i32 GPR:i32:$false,
2139 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2140 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002141 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002142 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002143 CCVal, CCR, InFlag);
2144 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002145 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002146 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2147 if (Res)
2148 return Res;
2149 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002150 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002151 CCVal, CCR, InFlag);
2152 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002153 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2155 if (Res)
2156 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002157 }
2158 }
2159
2160 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2161 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2162 // Pattern complexity = 6 cost = 1 size = 0
2163 //
2164 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2165 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2166 // Pattern complexity = 6 cost = 11 size = 0
2167 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002168 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002169 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2170 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002171 unsigned Opc = 0;
2172 switch (VT.getSimpleVT().SimpleTy) {
2173 default: assert(false && "Illegal conditional move type!");
2174 break;
2175 case MVT::i32:
2176 Opc = Subtarget->isThumb()
2177 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2178 : ARM::MOVCCr;
2179 break;
2180 case MVT::f32:
2181 Opc = ARM::VMOVScc;
2182 break;
2183 case MVT::f64:
2184 Opc = ARM::VMOVDcc;
2185 break;
2186 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002187 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002188}
2189
Evan Chengde8aa4e2010-05-05 18:28:36 +00002190SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2191 // The only time a CONCAT_VECTORS operation can have legal types is when
2192 // two 64-bit vectors are concatenated to a 128-bit vector.
2193 EVT VT = N->getValueType(0);
2194 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2195 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002196 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002197}
2198
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002199SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002200 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002201
Dan Gohmane8be6c62008-07-17 19:10:17 +00002202 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002203 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002204
2205 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002206 default: break;
2207 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002208 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002209 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002210 if (Subtarget->hasThumb2())
2211 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2212 // be done with MOV + MOVT, at worst.
2213 UseCP = 0;
2214 else {
2215 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002216 UseCP = (Val > 255 && // MOV
2217 ~Val > 255 && // MOV + MVN
2218 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002219 } else
2220 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2221 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2222 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2223 }
2224
Evan Chenga8e29892007-01-19 07:51:42 +00002225 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002226 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002227 CurDAG->getTargetConstantPool(ConstantInt::get(
2228 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002229 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002230
2231 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002232 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002233 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002234 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002235 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002236 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002237 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002238 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002239 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002240 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002241 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002242 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002243 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002244 CurDAG->getEntryNode()
2245 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002246 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002247 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002248 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002249 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002250 return NULL;
2251 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002252
Evan Chenga8e29892007-01-19 07:51:42 +00002253 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002254 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002255 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002256 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002257 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002258 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002259 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002260 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002261 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2262 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002263 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002264 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2265 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002266 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2267 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2268 CurDAG->getRegister(0, MVT::i32) };
2269 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002270 }
Evan Chenga8e29892007-01-19 07:51:42 +00002271 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002272 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002273 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002274 return I;
2275 break;
2276 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002277 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002278 return I;
2279 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002280 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002281 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002282 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002283 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002284 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002285 if (!RHSV) break;
2286 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002287 unsigned ShImm = Log2_32(RHSV-1);
2288 if (ShImm >= 32)
2289 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002290 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002291 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002292 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2293 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002294 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002295 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002296 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002297 } else {
2298 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002299 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002300 }
Evan Chenga8e29892007-01-19 07:51:42 +00002301 }
2302 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002303 unsigned ShImm = Log2_32(RHSV+1);
2304 if (ShImm >= 32)
2305 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002306 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002307 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002308 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2309 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002310 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002311 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2312 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002313 } else {
2314 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002315 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002316 }
Evan Chenga8e29892007-01-19 07:51:42 +00002317 }
2318 }
2319 break;
Evan Cheng20956592009-10-21 08:15:52 +00002320 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002321 // Check for unsigned bitfield extract
2322 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2323 return I;
2324
Evan Cheng20956592009-10-21 08:15:52 +00002325 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2326 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2327 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2328 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2329 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002330 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002331 if (VT != MVT::i32)
2332 break;
2333 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2334 ? ARM::t2MOVTi16
2335 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2336 if (!Opc)
2337 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002338 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002339 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2340 if (!N1C)
2341 break;
2342 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2343 SDValue N2 = N0.getOperand(1);
2344 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2345 if (!N2C)
2346 break;
2347 unsigned N1CVal = N1C->getZExtValue();
2348 unsigned N2CVal = N2C->getZExtValue();
2349 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2350 (N1CVal & 0xffffU) == 0xffffU &&
2351 (N2CVal & 0xffffU) == 0x0U) {
2352 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2353 MVT::i32);
2354 SDValue Ops[] = { N0.getOperand(0), Imm16,
2355 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2356 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2357 }
2358 }
2359 break;
2360 }
Jim Grosbache5165492009-11-09 00:11:35 +00002361 case ARMISD::VMOVRRD:
2362 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002363 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002364 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002365 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002366 if (Subtarget->isThumb1Only())
2367 break;
2368 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002369 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002370 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2371 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002372 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002373 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002374 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002375 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2376 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002377 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2378 ARM::UMULL : ARM::UMULLv5,
2379 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002380 }
Evan Chengee568cf2007-07-05 07:15:27 +00002381 }
Dan Gohman525178c2007-10-08 18:33:35 +00002382 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002383 if (Subtarget->isThumb1Only())
2384 break;
2385 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002386 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002387 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002388 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002389 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002390 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002391 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2392 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002393 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2394 ARM::SMULL : ARM::SMULLv5,
2395 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002396 }
Evan Chengee568cf2007-07-05 07:15:27 +00002397 }
Evan Chenga8e29892007-01-19 07:51:42 +00002398 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002399 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002400 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002401 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002402 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002403 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002404 if (ResNode)
2405 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002406 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002407 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002408 }
Evan Chengee568cf2007-07-05 07:15:27 +00002409 case ARMISD::BRCOND: {
2410 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2411 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2412 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002413
Evan Chengee568cf2007-07-05 07:15:27 +00002414 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2415 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2416 // Pattern complexity = 6 cost = 1 size = 0
2417
David Goodwin5e47a9a2009-06-30 18:04:13 +00002418 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2419 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2420 // Pattern complexity = 6 cost = 1 size = 0
2421
Jim Grosbach764ab522009-08-11 15:33:49 +00002422 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002423 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002424 SDValue Chain = N->getOperand(0);
2425 SDValue N1 = N->getOperand(1);
2426 SDValue N2 = N->getOperand(2);
2427 SDValue N3 = N->getOperand(3);
2428 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002429 assert(N1.getOpcode() == ISD::BasicBlock);
2430 assert(N2.getOpcode() == ISD::Constant);
2431 assert(N3.getOpcode() == ISD::Register);
2432
Dan Gohman475871a2008-07-27 21:46:04 +00002433 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002434 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002435 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002436 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002437 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002438 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002439 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002440 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002441 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002442 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002443 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002444 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002445 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002446 return NULL;
2447 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002448 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002449 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002450 case ARMISD::VZIP: {
2451 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002452 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002453 switch (VT.getSimpleVT().SimpleTy) {
2454 default: return NULL;
2455 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2456 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2457 case MVT::v2f32:
2458 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2459 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2460 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2461 case MVT::v4f32:
2462 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2463 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002464 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002465 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2466 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2467 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002468 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002469 case ARMISD::VUZP: {
2470 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002471 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002472 switch (VT.getSimpleVT().SimpleTy) {
2473 default: return NULL;
2474 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2475 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2476 case MVT::v2f32:
2477 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2478 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2479 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2480 case MVT::v4f32:
2481 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2482 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002483 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002484 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2485 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2486 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002487 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002488 case ARMISD::VTRN: {
2489 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002490 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002491 switch (VT.getSimpleVT().SimpleTy) {
2492 default: return NULL;
2493 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2494 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2495 case MVT::v2f32:
2496 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2497 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2498 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2499 case MVT::v4f32:
2500 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2501 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002502 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002503 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2504 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2505 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002506 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002507 case ARMISD::BUILD_VECTOR: {
2508 EVT VecVT = N->getValueType(0);
2509 EVT EltVT = VecVT.getVectorElementType();
2510 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002511 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002512 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2513 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2514 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002515 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002516 if (NumElts == 2)
2517 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2518 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2519 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2520 N->getOperand(2), N->getOperand(3));
2521 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002522
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002523 case ARMISD::VLD2DUP: {
2524 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2525 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002526 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002527 }
2528
Bob Wilson86c6d802010-11-29 19:35:29 +00002529 case ARMISD::VLD3DUP: {
2530 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2531 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002532 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002533 }
2534
Bob Wilson6c4c9822010-11-30 00:00:35 +00002535 case ARMISD::VLD4DUP: {
2536 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2537 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002538 return SelectVLDDup(N, false, 4, Opcodes);
2539 }
2540
2541 case ARMISD::VLD2DUP_UPD: {
2542 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2543 ARM::VLD2DUPd32Pseudo_UPD };
2544 return SelectVLDDup(N, true, 2, Opcodes);
2545 }
2546
2547 case ARMISD::VLD3DUP_UPD: {
2548 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2549 ARM::VLD3DUPd32Pseudo_UPD };
2550 return SelectVLDDup(N, true, 3, Opcodes);
2551 }
2552
2553 case ARMISD::VLD4DUP_UPD: {
2554 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2555 ARM::VLD4DUPd32Pseudo_UPD };
2556 return SelectVLDDup(N, true, 4, Opcodes);
2557 }
2558
2559 case ARMISD::VLD1_UPD: {
2560 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2561 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2562 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2563 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2564 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2565 }
2566
2567 case ARMISD::VLD2_UPD: {
2568 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2569 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2570 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2571 ARM::VLD2q32Pseudo_UPD };
2572 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2573 }
2574
2575 case ARMISD::VLD3_UPD: {
2576 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2577 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2578 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2579 ARM::VLD3q16Pseudo_UPD,
2580 ARM::VLD3q32Pseudo_UPD };
2581 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2582 ARM::VLD3q16oddPseudo_UPD,
2583 ARM::VLD3q32oddPseudo_UPD };
2584 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2585 }
2586
2587 case ARMISD::VLD4_UPD: {
2588 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2589 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2590 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2591 ARM::VLD4q16Pseudo_UPD,
2592 ARM::VLD4q32Pseudo_UPD };
2593 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2594 ARM::VLD4q16oddPseudo_UPD,
2595 ARM::VLD4q32oddPseudo_UPD };
2596 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2597 }
2598
2599 case ARMISD::VLD2LN_UPD: {
2600 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2601 ARM::VLD2LNd32Pseudo_UPD };
2602 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2603 ARM::VLD2LNq32Pseudo_UPD };
2604 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2605 }
2606
2607 case ARMISD::VLD3LN_UPD: {
2608 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2609 ARM::VLD3LNd32Pseudo_UPD };
2610 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2611 ARM::VLD3LNq32Pseudo_UPD };
2612 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2613 }
2614
2615 case ARMISD::VLD4LN_UPD: {
2616 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2617 ARM::VLD4LNd32Pseudo_UPD };
2618 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2619 ARM::VLD4LNq32Pseudo_UPD };
2620 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2621 }
2622
2623 case ARMISD::VST1_UPD: {
2624 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2625 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2626 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2627 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2628 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2629 }
2630
2631 case ARMISD::VST2_UPD: {
2632 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2633 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2634 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2635 ARM::VST2q32Pseudo_UPD };
2636 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2637 }
2638
2639 case ARMISD::VST3_UPD: {
2640 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2641 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2642 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2643 ARM::VST3q16Pseudo_UPD,
2644 ARM::VST3q32Pseudo_UPD };
2645 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2646 ARM::VST3q16oddPseudo_UPD,
2647 ARM::VST3q32oddPseudo_UPD };
2648 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2649 }
2650
2651 case ARMISD::VST4_UPD: {
2652 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2653 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2654 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2655 ARM::VST4q16Pseudo_UPD,
2656 ARM::VST4q32Pseudo_UPD };
2657 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2658 ARM::VST4q16oddPseudo_UPD,
2659 ARM::VST4q32oddPseudo_UPD };
2660 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2661 }
2662
2663 case ARMISD::VST2LN_UPD: {
2664 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2665 ARM::VST2LNd32Pseudo_UPD };
2666 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2667 ARM::VST2LNq32Pseudo_UPD };
2668 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2669 }
2670
2671 case ARMISD::VST3LN_UPD: {
2672 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2673 ARM::VST3LNd32Pseudo_UPD };
2674 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2675 ARM::VST3LNq32Pseudo_UPD };
2676 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2677 }
2678
2679 case ARMISD::VST4LN_UPD: {
2680 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2681 ARM::VST4LNd32Pseudo_UPD };
2682 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2683 ARM::VST4LNq32Pseudo_UPD };
2684 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002685 }
2686
Bob Wilson31fb12f2009-08-26 17:39:53 +00002687 case ISD::INTRINSIC_VOID:
2688 case ISD::INTRINSIC_W_CHAIN: {
2689 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002690 switch (IntNo) {
2691 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002692 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002693
Bob Wilson621f1952010-03-23 05:25:43 +00002694 case Intrinsic::arm_neon_vld1: {
2695 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2696 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002697 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2698 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002699 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002700 }
2701
Bob Wilson31fb12f2009-08-26 17:39:53 +00002702 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002703 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2704 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2705 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2706 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002707 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002708 }
2709
2710 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002711 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2712 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2713 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2714 ARM::VLD3q16Pseudo_UPD,
2715 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002716 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2717 ARM::VLD3q16oddPseudo,
2718 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002719 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002720 }
2721
2722 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002723 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2724 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2725 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2726 ARM::VLD4q16Pseudo_UPD,
2727 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002728 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2729 ARM::VLD4q16oddPseudo,
2730 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002731 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002732 }
2733
Bob Wilson243fcc52009-09-01 04:26:28 +00002734 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002735 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2736 ARM::VLD2LNd32Pseudo };
2737 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002738 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002739 }
2740
2741 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002742 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2743 ARM::VLD3LNd32Pseudo };
2744 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002745 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002746 }
2747
2748 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002749 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2750 ARM::VLD4LNd32Pseudo };
2751 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002752 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002753 }
2754
Bob Wilson11d98992010-03-23 06:20:33 +00002755 case Intrinsic::arm_neon_vst1: {
2756 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2757 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002758 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2759 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002760 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002761 }
2762
Bob Wilson31fb12f2009-08-26 17:39:53 +00002763 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002764 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2765 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2766 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2767 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002768 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002769 }
2770
2771 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002772 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2773 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2774 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2775 ARM::VST3q16Pseudo_UPD,
2776 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002777 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2778 ARM::VST3q16oddPseudo,
2779 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002780 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002781 }
2782
2783 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002784 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002785 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002786 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2787 ARM::VST4q16Pseudo_UPD,
2788 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002789 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2790 ARM::VST4q16oddPseudo,
2791 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002792 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002793 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002794
2795 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002796 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2797 ARM::VST2LNd32Pseudo };
2798 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002799 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002800 }
2801
2802 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002803 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2804 ARM::VST3LNd32Pseudo };
2805 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002806 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002807 }
2808
2809 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002810 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2811 ARM::VST4LNd32Pseudo };
2812 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002813 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002814 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002815 }
Bob Wilson429009b2010-05-06 16:05:26 +00002816 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002817 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002818
Bob Wilsond491d6e2010-07-06 23:36:25 +00002819 case ISD::INTRINSIC_WO_CHAIN: {
2820 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2821 switch (IntNo) {
2822 default:
2823 break;
2824
2825 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002826 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002827 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002828 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002829 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002830 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002831
2832 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002833 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002834 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002835 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002836 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002837 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002838 }
2839 break;
2840 }
2841
Bill Wendling69a05a72011-03-14 23:02:38 +00002842 case ARMISD::VTBL1: {
2843 DebugLoc dl = N->getDebugLoc();
2844 EVT VT = N->getValueType(0);
2845 SmallVector<SDValue, 6> Ops;
2846
2847 Ops.push_back(N->getOperand(0));
2848 Ops.push_back(N->getOperand(1));
2849 Ops.push_back(getAL(CurDAG)); // Predicate
2850 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2851 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
2852 }
2853 case ARMISD::VTBL2: {
2854 DebugLoc dl = N->getDebugLoc();
2855 EVT VT = N->getValueType(0);
2856
2857 // Form a REG_SEQUENCE to force register allocation.
2858 SDValue V0 = N->getOperand(0);
2859 SDValue V1 = N->getOperand(1);
2860 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2861
2862 SmallVector<SDValue, 6> Ops;
2863 Ops.push_back(RegSeq);
2864 Ops.push_back(N->getOperand(2));
2865 Ops.push_back(getAL(CurDAG)); // Predicate
2866 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2867 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
2868 Ops.data(), Ops.size());
2869 }
2870
Bob Wilson429009b2010-05-06 16:05:26 +00002871 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002872 return SelectConcatVector(N);
2873 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002874
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002875 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002876}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002877
Bob Wilson224c2442009-05-19 05:53:42 +00002878bool ARMDAGToDAGISel::
2879SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2880 std::vector<SDValue> &OutOps) {
2881 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002882 // Require the address to be in a register. That is safe for all ARM
2883 // variants and it is hard to do anything much smarter without knowing
2884 // how the operand is used.
2885 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002886 return false;
2887}
2888
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002889/// createARMISelDag - This pass converts a legalized DAG into a
2890/// ARM-specific DAG, ready for instruction scheduling.
2891///
Bob Wilson522ce972009-09-28 14:30:20 +00002892FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2893 CodeGenOpt::Level OptLevel) {
2894 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002895}