blob: 1201d9126859e44aa97b486b4a86580a667339c1 [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"),
48 cl::init(false));
49
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
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000182 inline bool Pred_so_imm(SDNode *inN) const {
183 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000184 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000185 }
186
187 inline bool Pred_t2_so_imm(SDNode *inN) const {
188 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000189 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000190 }
191
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000192 // Include the pieces autogenerated from the target description.
193#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000194
195private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000196 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
197 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000198 SDNode *SelectARMIndexedLoad(SDNode *N);
199 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000200
Bob Wilson621f1952010-03-23 05:25:43 +0000201 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
202 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000203 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000204 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000205 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
206 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000207 unsigned *QOpcodes0, unsigned *QOpcodes1);
208
Bob Wilson24f995d2009-10-14 18:32:29 +0000209 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000210 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000213 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
214 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000215 unsigned *QOpcodes0, unsigned *QOpcodes1);
216
Bob Wilson96493442009-10-14 16:46:45 +0000217 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000218 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000219 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000220 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
221 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000222 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000223
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000224 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
225 /// should be 2, 3 or 4. The opcode array specifies the instructions used
226 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000227 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
228 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000229
Bob Wilson78dfbc32010-07-07 00:08:54 +0000230 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
231 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
232 /// generated to force the table registers to be consecutive.
233 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000234
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000235 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000236 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000237
Evan Cheng07ba9062009-11-19 21:45:22 +0000238 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000239 SDNode *SelectCMOVOp(SDNode *N);
240 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000241 ARMCC::CondCodes CCVal, SDValue CCR,
242 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000243 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000244 ARMCC::CondCodes CCVal, SDValue CCR,
245 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000246 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000247 ARMCC::CondCodes CCVal, SDValue CCR,
248 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000249 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000250 ARMCC::CondCodes CCVal, SDValue CCR,
251 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000252
Evan Chengde8aa4e2010-05-05 18:28:36 +0000253 SDNode *SelectConcatVector(SDNode *N);
254
Evan Chengaf4550f2009-07-02 01:23:32 +0000255 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
256 /// inline asm expressions.
257 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
258 char ConstraintCode,
259 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000260
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000261 // Form pairs of consecutive S, D, or Q registers.
262 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000263 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000264 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
265
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000266 // Form sequences of 4 consecutive S, D, or Q registers.
267 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000268 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000269 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000270
271 // Get the alignment operand for a NEON VLD or VST instruction.
272 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000273};
Evan Chenga8e29892007-01-19 07:51:42 +0000274}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000275
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000276/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
277/// operand. If so Imm will receive the 32-bit value.
278static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
279 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
280 Imm = cast<ConstantSDNode>(N)->getZExtValue();
281 return true;
282 }
283 return false;
284}
285
286// isInt32Immediate - This method tests to see if a constant operand.
287// If so Imm will receive the 32 bit value.
288static bool isInt32Immediate(SDValue N, unsigned &Imm) {
289 return isInt32Immediate(N.getNode(), Imm);
290}
291
292// isOpcWithIntImmediate - This method tests to see if the node is a specific
293// opcode and that it has a immediate integer right operand.
294// If so Imm will receive the 32 bit value.
295static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
296 return N->getOpcode() == Opc &&
297 isInt32Immediate(N->getOperand(1).getNode(), Imm);
298}
299
Daniel Dunbarec91d522011-01-19 15:12:16 +0000300/// \brief Check whether a particular node is a constant value representable as
301/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
302///
303/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
304static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
305 int RangeMin, int RangeMax,
306 int &ScaledConstant) {
307 assert(Scale && "Invalid scale!");
308
309 // Check that this is a constant.
310 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
311 if (!C)
312 return false;
313
314 ScaledConstant = (int) C->getZExtValue();
315 if ((ScaledConstant % Scale) != 0)
316 return false;
317
318 ScaledConstant /= Scale;
319 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
320}
321
Evan Cheng48575f62010-12-05 22:04:16 +0000322/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
323/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
324/// least on current ARM implementations) which should be avoidded.
325bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
326 if (OptLevel == CodeGenOpt::None)
327 return true;
328
329 if (!CheckVMLxHazard)
330 return true;
331
332 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
333 return true;
334
335 if (!N->hasOneUse())
336 return false;
337
338 SDNode *Use = *N->use_begin();
339 if (Use->getOpcode() == ISD::CopyToReg)
340 return true;
341 if (Use->isMachineOpcode()) {
342 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
343 if (TID.mayStore())
344 return true;
345 unsigned Opcode = TID.getOpcode();
346 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
347 return true;
348 // vmlx feeding into another vmlx. We actually want to unfold
349 // the use later in the MLxExpansion pass. e.g.
350 // vmla
351 // vmla (stall 8 cycles)
352 //
353 // vmul (5 cycles)
354 // vadd (5 cycles)
355 // vmla
356 // This adds up to about 18 - 19 cycles.
357 //
358 // vmla
359 // vmul (stall 4 cycles)
360 // vadd adds up to about 14 cycles.
361 return TII->isFpMLxInstruction(Opcode);
362 }
363
364 return false;
365}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000366
Evan Chengf40deed2010-10-27 23:41:30 +0000367bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
368 ARM_AM::ShiftOpc ShOpcVal,
369 unsigned ShAmt) {
370 if (!Subtarget->isCortexA9())
371 return true;
372 if (Shift.hasOneUse())
373 return true;
374 // R << 2 is free.
375 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
376}
377
Chris Lattner52a261b2010-09-21 20:31:19 +0000378bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000379 SDValue &BaseReg,
380 SDValue &ShReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000381 SDValue &Opc,
382 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000383 if (DisableShifterOp)
384 return false;
385
Evan Cheng055b0312009-06-29 07:51:04 +0000386 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
387
388 // Don't match base register only case. That is matched to a separate
389 // lower complexity pattern with explicit register operand.
390 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000391
Evan Cheng055b0312009-06-29 07:51:04 +0000392 BaseReg = N.getOperand(0);
393 unsigned ShImmVal = 0;
394 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000395 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000396 ShImmVal = RHS->getZExtValue() & 31;
397 } else {
398 ShReg = N.getOperand(1);
Owen Anderson099e5552011-03-18 19:46:58 +0000399 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
Evan Chengf40deed2010-10-27 23:41:30 +0000400 return false;
401 }
402 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
403 MVT::i32);
404 return true;
405}
406
Jim Grosbach3e556122010-10-26 22:37:02 +0000407bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
408 SDValue &Base,
409 SDValue &OffImm) {
410 // Match simple R + imm12 operands.
411
412 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000413 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
414 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000415 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000416 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000417 int FI = cast<FrameIndexSDNode>(N)->getIndex();
418 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
419 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
420 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000421 }
Owen Anderson099e5552011-03-18 19:46:58 +0000422
Chris Lattner0a9481f2011-02-13 22:25:43 +0000423 if (N.getOpcode() == ARMISD::Wrapper &&
424 !(Subtarget->useMovt() &&
425 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000426 Base = N.getOperand(0);
427 } else
428 Base = N;
429 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
430 return true;
431 }
432
433 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
434 int RHSC = (int)RHS->getZExtValue();
435 if (N.getOpcode() == ISD::SUB)
436 RHSC = -RHSC;
437
438 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
439 Base = N.getOperand(0);
440 if (Base.getOpcode() == ISD::FrameIndex) {
441 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
442 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
443 }
444 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
445 return true;
446 }
447 }
448
449 // Base only.
450 Base = N;
451 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
452 return true;
453}
454
455
456
457bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
458 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000459 if (N.getOpcode() == ISD::MUL &&
460 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000461 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
462 // X * [3,5,9] -> X + X * [2,4,8] etc.
463 int RHSC = (int)RHS->getZExtValue();
464 if (RHSC & 1) {
465 RHSC = RHSC & ~1;
466 ARM_AM::AddrOpc AddSub = ARM_AM::add;
467 if (RHSC < 0) {
468 AddSub = ARM_AM::sub;
469 RHSC = - RHSC;
470 }
471 if (isPowerOf2_32(RHSC)) {
472 unsigned ShAmt = Log2_32(RHSC);
473 Base = Offset = N.getOperand(0);
474 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
475 ARM_AM::lsl),
476 MVT::i32);
477 return true;
478 }
479 }
480 }
481 }
482
Chris Lattner0a9481f2011-02-13 22:25:43 +0000483 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
484 // ISD::OR that is equivalent to an ISD::ADD.
485 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000486 return false;
487
488 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000489 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000490 int RHSC;
491 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
492 -0x1000+1, 0x1000, RHSC)) // 12 bits.
493 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000494 }
495
Evan Chengf40deed2010-10-27 23:41:30 +0000496 if (Subtarget->isCortexA9() && !N.hasOneUse())
497 // Compute R +/- (R << N) and reuse it.
498 return false;
499
Jim Grosbach3e556122010-10-26 22:37:02 +0000500 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000501 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Jim Grosbach3e556122010-10-26 22:37:02 +0000502 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
503 unsigned ShAmt = 0;
504
505 Base = N.getOperand(0);
506 Offset = N.getOperand(1);
507
508 if (ShOpcVal != ARM_AM::no_shift) {
509 // Check to see if the RHS of the shift is a constant, if not, we can't fold
510 // it.
511 if (ConstantSDNode *Sh =
512 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
513 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000514 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
515 Offset = N.getOperand(1).getOperand(0);
516 else {
517 ShAmt = 0;
518 ShOpcVal = ARM_AM::no_shift;
519 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 } else {
521 ShOpcVal = ARM_AM::no_shift;
522 }
523 }
524
525 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000526 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000527 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000528 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
529 if (ShOpcVal != ARM_AM::no_shift) {
530 // Check to see if the RHS of the shift is a constant, if not, we can't
531 // fold it.
532 if (ConstantSDNode *Sh =
533 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
534 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000535 if (!Subtarget->isCortexA9() ||
536 (N.hasOneUse() &&
537 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
538 Offset = N.getOperand(0).getOperand(0);
539 Base = N.getOperand(1);
540 } else {
541 ShAmt = 0;
542 ShOpcVal = ARM_AM::no_shift;
543 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000544 } else {
545 ShOpcVal = ARM_AM::no_shift;
546 }
547 }
548 }
549
550 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
551 MVT::i32);
552 return true;
553}
554
555
556
557
558//-----
559
Jim Grosbach82891622010-09-29 19:03:54 +0000560AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
561 SDValue &Base,
562 SDValue &Offset,
563 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000564 if (N.getOpcode() == ISD::MUL &&
565 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000566 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
567 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000568 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000569 if (RHSC & 1) {
570 RHSC = RHSC & ~1;
571 ARM_AM::AddrOpc AddSub = ARM_AM::add;
572 if (RHSC < 0) {
573 AddSub = ARM_AM::sub;
574 RHSC = - RHSC;
575 }
576 if (isPowerOf2_32(RHSC)) {
577 unsigned ShAmt = Log2_32(RHSC);
578 Base = Offset = N.getOperand(0);
579 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
580 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000581 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000582 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000583 }
584 }
585 }
586 }
587
Chris Lattner0a9481f2011-02-13 22:25:43 +0000588 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
589 // ISD::OR that is equivalent to an ADD.
590 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000591 Base = N;
592 if (N.getOpcode() == ISD::FrameIndex) {
593 int FI = cast<FrameIndexSDNode>(N)->getIndex();
594 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000595 } else if (N.getOpcode() == ARMISD::Wrapper &&
596 !(Subtarget->useMovt() &&
597 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000598 Base = N.getOperand(0);
599 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000600 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000601 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
602 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000604 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000605 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000606
Evan Chenga8e29892007-01-19 07:51:42 +0000607 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000608 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000609 int RHSC;
610 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
611 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
612 Base = N.getOperand(0);
613 if (Base.getOpcode() == ISD::FrameIndex) {
614 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
615 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000616 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000617 Offset = CurDAG->getRegister(0, MVT::i32);
618
619 ARM_AM::AddrOpc AddSub = ARM_AM::add;
620 if (RHSC < 0) {
621 AddSub = ARM_AM::sub;
622 RHSC = - RHSC;
623 }
624 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
625 ARM_AM::no_shift),
626 MVT::i32);
627 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000628 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000629 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000630
Evan Chengf40deed2010-10-27 23:41:30 +0000631 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
632 // Compute R +/- (R << N) and reuse it.
633 Base = N;
634 Offset = CurDAG->getRegister(0, MVT::i32);
635 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
636 ARM_AM::no_shift),
637 MVT::i32);
638 return AM2_BASE;
639 }
640
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000641 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000642 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga8e29892007-01-19 07:51:42 +0000643 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
644 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000645
Evan Chenga8e29892007-01-19 07:51:42 +0000646 Base = N.getOperand(0);
647 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000648
Evan Chenga8e29892007-01-19 07:51:42 +0000649 if (ShOpcVal != ARM_AM::no_shift) {
650 // Check to see if the RHS of the shift is a constant, if not, we can't fold
651 // it.
652 if (ConstantSDNode *Sh =
653 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000654 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000655 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
656 Offset = N.getOperand(1).getOperand(0);
657 else {
658 ShAmt = 0;
659 ShOpcVal = ARM_AM::no_shift;
660 }
Evan Chenga8e29892007-01-19 07:51:42 +0000661 } else {
662 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000663 }
664 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000665
Evan Chenga8e29892007-01-19 07:51:42 +0000666 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000667 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000668 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000669 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
670 if (ShOpcVal != ARM_AM::no_shift) {
671 // Check to see if the RHS of the shift is a constant, if not, we can't
672 // fold it.
673 if (ConstantSDNode *Sh =
674 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000675 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000676 if (!Subtarget->isCortexA9() ||
677 (N.hasOneUse() &&
678 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
679 Offset = N.getOperand(0).getOperand(0);
680 Base = N.getOperand(1);
681 } else {
682 ShAmt = 0;
683 ShOpcVal = ARM_AM::no_shift;
684 }
Evan Chenga8e29892007-01-19 07:51:42 +0000685 } else {
686 ShOpcVal = ARM_AM::no_shift;
687 }
688 }
689 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000690
Evan Chenga8e29892007-01-19 07:51:42 +0000691 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000692 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000693 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000694}
695
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000696bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000697 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000698 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000699 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
700 ? cast<LoadSDNode>(Op)->getAddressingMode()
701 : cast<StoreSDNode>(Op)->getAddressingMode();
702 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
703 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000704 int Val;
705 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
706 Offset = CurDAG->getRegister(0, MVT::i32);
707 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
708 ARM_AM::no_shift),
709 MVT::i32);
710 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000711 }
712
713 Offset = N;
714 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
715 unsigned ShAmt = 0;
716 if (ShOpcVal != ARM_AM::no_shift) {
717 // Check to see if the RHS of the shift is a constant, if not, we can't fold
718 // it.
719 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000720 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000721 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
722 Offset = N.getOperand(0);
723 else {
724 ShAmt = 0;
725 ShOpcVal = ARM_AM::no_shift;
726 }
Evan Chenga8e29892007-01-19 07:51:42 +0000727 } else {
728 ShOpcVal = ARM_AM::no_shift;
729 }
730 }
731
732 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000733 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000734 return true;
735}
736
Evan Chenga8e29892007-01-19 07:51:42 +0000737
Chris Lattner52a261b2010-09-21 20:31:19 +0000738bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000739 SDValue &Base, SDValue &Offset,
740 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000741 if (N.getOpcode() == ISD::SUB) {
742 // X - C is canonicalize to X + -C, no need to handle it here.
743 Base = N.getOperand(0);
744 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000745 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000746 return true;
747 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000748
Chris Lattner0a9481f2011-02-13 22:25:43 +0000749 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000750 Base = N;
751 if (N.getOpcode() == ISD::FrameIndex) {
752 int FI = cast<FrameIndexSDNode>(N)->getIndex();
753 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
754 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 Offset = CurDAG->getRegister(0, MVT::i32);
756 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000757 return true;
758 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000759
Evan Chenga8e29892007-01-19 07:51:42 +0000760 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000761 int RHSC;
762 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
763 -256 + 1, 256, RHSC)) { // 8 bits.
764 Base = N.getOperand(0);
765 if (Base.getOpcode() == ISD::FrameIndex) {
766 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
767 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000768 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000769 Offset = CurDAG->getRegister(0, MVT::i32);
770
771 ARM_AM::AddrOpc AddSub = ARM_AM::add;
772 if (RHSC < 0) {
773 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000774 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000775 }
776 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
777 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000778 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000779
Evan Chenga8e29892007-01-19 07:51:42 +0000780 Base = N.getOperand(0);
781 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000782 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000783 return true;
784}
785
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000786bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000787 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000788 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000789 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
790 ? cast<LoadSDNode>(Op)->getAddressingMode()
791 : cast<StoreSDNode>(Op)->getAddressingMode();
792 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
793 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000794 int Val;
795 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
796 Offset = CurDAG->getRegister(0, MVT::i32);
797 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
798 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000799 }
800
801 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000802 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000803 return true;
804}
805
Jim Grosbach3ab56582010-10-21 19:38:40 +0000806bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000807 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000808 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000809 Base = N;
810 if (N.getOpcode() == ISD::FrameIndex) {
811 int FI = cast<FrameIndexSDNode>(N)->getIndex();
812 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000813 } else if (N.getOpcode() == ARMISD::Wrapper &&
814 !(Subtarget->useMovt() &&
815 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000816 Base = N.getOperand(0);
817 }
818 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000819 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000820 return true;
821 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000822
Evan Chenga8e29892007-01-19 07:51:42 +0000823 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000824 int RHSC;
825 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
826 -256 + 1, 256, RHSC)) {
827 Base = N.getOperand(0);
828 if (Base.getOpcode() == ISD::FrameIndex) {
829 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
830 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000831 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000832
833 ARM_AM::AddrOpc AddSub = ARM_AM::add;
834 if (RHSC < 0) {
835 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000836 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000837 }
838 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
839 MVT::i32);
840 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000841 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000842
Evan Chenga8e29892007-01-19 07:51:42 +0000843 Base = N;
844 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000846 return true;
847}
848
Bob Wilson665814b2010-11-01 23:40:51 +0000849bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
850 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000851 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000852
853 unsigned Alignment = 0;
854 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
855 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
856 // The maximum alignment is equal to the memory size being referenced.
857 unsigned LSNAlign = LSN->getAlignment();
858 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
859 if (LSNAlign > MemSize && MemSize > 1)
860 Alignment = MemSize;
861 } else {
862 // All other uses of addrmode6 are for intrinsics. For now just record
863 // the raw alignment value; it will be refined later based on the legal
864 // alignment operands for the intrinsic.
865 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
866 }
867
868 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000869 return true;
870}
871
Bob Wilsonda525062011-02-25 06:42:42 +0000872bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
873 SDValue &Offset) {
874 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
875 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
876 if (AM != ISD::POST_INC)
877 return false;
878 Offset = N;
879 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
880 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
881 Offset = CurDAG->getRegister(0, MVT::i32);
882 }
883 return true;
884}
885
Chris Lattner52a261b2010-09-21 20:31:19 +0000886bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000887 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000888 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
889 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000890 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000891 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
892 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000893 return true;
894 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000895
Evan Chenga8e29892007-01-19 07:51:42 +0000896 return false;
897}
898
Bill Wendlingf4caf692010-12-14 03:36:38 +0000899
900//===----------------------------------------------------------------------===//
901// Thumb Addressing Modes
902//===----------------------------------------------------------------------===//
903
Chris Lattner52a261b2010-09-21 20:31:19 +0000904bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000905 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000906 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000907 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000908 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000909 return false;
910
911 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000912 return true;
913 }
914
Evan Chenga8e29892007-01-19 07:51:42 +0000915 Base = N.getOperand(0);
916 Offset = N.getOperand(1);
917 return true;
918}
919
Evan Cheng79d43262007-01-24 02:21:22 +0000920bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000921ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
922 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000923 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000924 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000925 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000926 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000927
Evan Cheng012f2d92007-01-24 08:53:17 +0000928 if (N.getOpcode() == ARMISD::Wrapper &&
929 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
930 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000931 }
932
Chris Lattner0a9481f2011-02-13 22:25:43 +0000933 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000934 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000935
Evan Chengad0e4652007-02-06 00:22:06 +0000936 // Thumb does not have [sp, r] address mode.
937 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
938 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
939 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000940 (RHSR && RHSR->getReg() == ARM::SP))
941 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000942
Daniel Dunbarec91d522011-01-19 15:12:16 +0000943 // FIXME: Why do we explicitly check for a match here and then return false?
944 // Presumably to allow something else to match, but shouldn't this be
945 // documented?
946 int RHSC;
947 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
948 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000949
950 Base = N.getOperand(0);
951 Offset = N.getOperand(1);
952 return true;
953}
954
955bool
956ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
957 SDValue &Base,
958 SDValue &Offset) {
959 return SelectThumbAddrModeRI(N, Base, Offset, 1);
960}
961
962bool
963ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
964 SDValue &Base,
965 SDValue &Offset) {
966 return SelectThumbAddrModeRI(N, Base, Offset, 2);
967}
968
969bool
970ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
971 SDValue &Base,
972 SDValue &Offset) {
973 return SelectThumbAddrModeRI(N, Base, Offset, 4);
974}
975
976bool
977ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
978 SDValue &Base, SDValue &OffImm) {
979 if (Scale == 4) {
980 SDValue TmpBase, TmpOffImm;
981 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
982 return false; // We want to select tLDRspi / tSTRspi instead.
983
984 if (N.getOpcode() == ARMISD::Wrapper &&
985 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
986 return false; // We want to select tLDRpci instead.
987 }
988
Chris Lattner0a9481f2011-02-13 22:25:43 +0000989 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000990 if (N.getOpcode() == ARMISD::Wrapper &&
991 !(Subtarget->useMovt() &&
992 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
993 Base = N.getOperand(0);
994 } else {
995 Base = N;
996 }
997
Owen Anderson825b72b2009-08-11 20:47:22 +0000998 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000999 return true;
1000 }
1001
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001002 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1003 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1004 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1005 (RHSR && RHSR->getReg() == ARM::SP)) {
1006 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1007 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1008 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1009 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1010
1011 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1012 if (LHSC != 0 || RHSC != 0) return false;
1013
1014 Base = N;
1015 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1016 return true;
1017 }
1018
Evan Chenga8e29892007-01-19 07:51:42 +00001019 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001020 int RHSC;
1021 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1022 Base = N.getOperand(0);
1023 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1024 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001025 }
1026
Evan Chengc38f2bc2007-01-23 22:59:13 +00001027 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001028 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001029 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001030}
1031
Bill Wendlingf4caf692010-12-14 03:36:38 +00001032bool
1033ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1034 SDValue &OffImm) {
1035 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001036}
1037
Bill Wendlingf4caf692010-12-14 03:36:38 +00001038bool
1039ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1040 SDValue &OffImm) {
1041 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001042}
1043
Bill Wendlingf4caf692010-12-14 03:36:38 +00001044bool
1045ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1046 SDValue &OffImm) {
1047 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001048}
1049
Chris Lattner52a261b2010-09-21 20:31:19 +00001050bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1051 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001052 if (N.getOpcode() == ISD::FrameIndex) {
1053 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1054 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001055 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001056 return true;
1057 }
Evan Cheng79d43262007-01-24 02:21:22 +00001058
Chris Lattner0a9481f2011-02-13 22:25:43 +00001059 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001060 return false;
1061
1062 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001063 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1064 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001065 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001066 int RHSC;
1067 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1068 Base = N.getOperand(0);
1069 if (Base.getOpcode() == ISD::FrameIndex) {
1070 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1071 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001072 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001073 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1074 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001075 }
1076 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001077
Evan Chenga8e29892007-01-19 07:51:42 +00001078 return false;
1079}
1080
Bill Wendlingf4caf692010-12-14 03:36:38 +00001081
1082//===----------------------------------------------------------------------===//
1083// Thumb 2 Addressing Modes
1084//===----------------------------------------------------------------------===//
1085
1086
Chris Lattner52a261b2010-09-21 20:31:19 +00001087bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001088 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001089 if (DisableShifterOp)
1090 return false;
1091
Evan Cheng9cb9e672009-06-27 02:26:13 +00001092 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1093
1094 // Don't match base register only case. That is matched to a separate
1095 // lower complexity pattern with explicit register operand.
1096 if (ShOpcVal == ARM_AM::no_shift) return false;
1097
1098 BaseReg = N.getOperand(0);
1099 unsigned ShImmVal = 0;
1100 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1101 ShImmVal = RHS->getZExtValue() & 31;
1102 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1103 return true;
1104 }
1105
1106 return false;
1107}
1108
Chris Lattner52a261b2010-09-21 20:31:19 +00001109bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001110 SDValue &Base, SDValue &OffImm) {
1111 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001112
Evan Cheng3a214252009-08-11 08:52:18 +00001113 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001114 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1115 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001116 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001117 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001118 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1119 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001120 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001121 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001122 }
Owen Anderson099e5552011-03-18 19:46:58 +00001123
Chris Lattner0a9481f2011-02-13 22:25:43 +00001124 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001125 !(Subtarget->useMovt() &&
1126 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001127 Base = N.getOperand(0);
1128 if (Base.getOpcode() == ISD::TargetConstantPool)
1129 return false; // We want to select t2LDRpci instead.
1130 } else
1131 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001132 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001133 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001134 }
Evan Cheng055b0312009-06-29 07:51:04 +00001135
1136 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001137 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001138 // Let t2LDRi8 handle (R - imm8).
1139 return false;
1140
Evan Cheng055b0312009-06-29 07:51:04 +00001141 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001142 if (N.getOpcode() == ISD::SUB)
1143 RHSC = -RHSC;
1144
1145 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001146 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001147 if (Base.getOpcode() == ISD::FrameIndex) {
1148 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1149 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1150 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001151 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001152 return true;
1153 }
1154 }
1155
Evan Cheng3a214252009-08-11 08:52:18 +00001156 // Base only.
1157 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001158 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001159 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001160}
1161
Chris Lattner52a261b2010-09-21 20:31:19 +00001162bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001163 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001164 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001165 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1166 !CurDAG->isBaseWithConstantOffset(N))
1167 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001168
Chris Lattner0a9481f2011-02-13 22:25:43 +00001169 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1170 int RHSC = (int)RHS->getSExtValue();
1171 if (N.getOpcode() == ISD::SUB)
1172 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001173
Chris Lattner0a9481f2011-02-13 22:25:43 +00001174 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1175 Base = N.getOperand(0);
1176 if (Base.getOpcode() == ISD::FrameIndex) {
1177 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1178 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001179 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001180 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1181 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001182 }
1183 }
1184
1185 return false;
1186}
1187
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001188bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001189 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001190 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001191 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1192 ? cast<LoadSDNode>(Op)->getAddressingMode()
1193 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001194 int RHSC;
1195 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1196 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1197 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1198 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1199 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001200 }
1201
1202 return false;
1203}
1204
Chris Lattner52a261b2010-09-21 20:31:19 +00001205bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001206 SDValue &Base,
1207 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001208 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001209 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001210 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001211
Evan Cheng3a214252009-08-11 08:52:18 +00001212 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1213 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1214 int RHSC = (int)RHS->getZExtValue();
1215 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1216 return false;
1217 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001218 return false;
1219 }
1220
Evan Chengf40deed2010-10-27 23:41:30 +00001221 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1222 // Compute R + (R << [1,2,3]) and reuse it.
1223 Base = N;
1224 return false;
1225 }
1226
Evan Cheng055b0312009-06-29 07:51:04 +00001227 // Look for (R + R) or (R + (R << [1,2,3])).
1228 unsigned ShAmt = 0;
1229 Base = N.getOperand(0);
1230 OffReg = N.getOperand(1);
1231
1232 // Swap if it is ((R << c) + R).
1233 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1234 if (ShOpcVal != ARM_AM::lsl) {
1235 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1236 if (ShOpcVal == ARM_AM::lsl)
1237 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001238 }
1239
Evan Cheng055b0312009-06-29 07:51:04 +00001240 if (ShOpcVal == ARM_AM::lsl) {
1241 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1242 // it.
1243 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1244 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001245 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1246 OffReg = OffReg.getOperand(0);
1247 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001248 ShAmt = 0;
1249 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001250 }
Evan Cheng055b0312009-06-29 07:51:04 +00001251 } else {
1252 ShOpcVal = ARM_AM::no_shift;
1253 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001254 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001255
Owen Anderson825b72b2009-08-11 20:47:22 +00001256 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001257
1258 return true;
1259}
1260
1261//===--------------------------------------------------------------------===//
1262
Evan Chengee568cf2007-07-05 07:15:27 +00001263/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001264static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001265 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001266}
1267
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001268SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1269 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001270 ISD::MemIndexedMode AM = LD->getAddressingMode();
1271 if (AM == ISD::UNINDEXED)
1272 return NULL;
1273
Owen Andersone50ed302009-08-10 22:56:29 +00001274 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001275 SDValue Offset, AMOpc;
1276 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1277 unsigned Opcode = 0;
1278 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001280 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001281 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1282 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001283 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001284 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001285 Match = true;
1286 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1287 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1288 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001289 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001290 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001291 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001292 Match = true;
1293 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1294 }
1295 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001296 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001297 Match = true;
1298 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1299 }
1300 }
1301 }
1302
1303 if (Match) {
1304 SDValue Chain = LD->getChain();
1305 SDValue Base = LD->getBasePtr();
1306 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001307 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001308 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001309 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001310 }
1311
1312 return NULL;
1313}
1314
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001315SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1316 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001317 ISD::MemIndexedMode AM = LD->getAddressingMode();
1318 if (AM == ISD::UNINDEXED)
1319 return NULL;
1320
Owen Andersone50ed302009-08-10 22:56:29 +00001321 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001322 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001323 SDValue Offset;
1324 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1325 unsigned Opcode = 0;
1326 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001327 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 switch (LoadedVT.getSimpleVT().SimpleTy) {
1329 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001330 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1331 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001332 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001333 if (isSExtLd)
1334 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1335 else
1336 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001337 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001338 case MVT::i8:
1339 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001340 if (isSExtLd)
1341 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1342 else
1343 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001344 break;
1345 default:
1346 return NULL;
1347 }
1348 Match = true;
1349 }
1350
1351 if (Match) {
1352 SDValue Chain = LD->getChain();
1353 SDValue Base = LD->getBasePtr();
1354 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001355 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001356 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001357 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001358 }
1359
1360 return NULL;
1361}
1362
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001363/// PairSRegs - Form a D register from a pair of S registers.
1364///
1365SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1366 DebugLoc dl = V0.getNode()->getDebugLoc();
1367 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1368 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_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 Wilson40cbe7d2010-06-04 00:04:02 +00001371}
1372
Evan Cheng603afbf2010-05-10 17:34:18 +00001373/// PairDRegs - Form a quad register from a pair of D registers.
1374///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001375SDNode *ARMDAGToDAGISel::PairDRegs(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::dsub_0, MVT::i32);
1378 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001379 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1380 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001381}
1382
Evan Cheng7f687192010-05-14 00:21:45 +00001383/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001384///
1385SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1386 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001387 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1388 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001389 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1390 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1391}
1392
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001393/// QuadSRegs - Form 4 consecutive S registers.
1394///
1395SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1396 SDValue V2, SDValue V3) {
1397 DebugLoc dl = V0.getNode()->getDebugLoc();
1398 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1399 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1400 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1401 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1402 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1403 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1404}
1405
Evan Cheng7f687192010-05-14 00:21:45 +00001406/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001407///
1408SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1409 SDValue V2, SDValue V3) {
1410 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001411 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1412 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1413 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1414 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001415 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1416 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1417}
1418
Evan Cheng8f6de382010-05-16 03:27:48 +00001419/// QuadQRegs - Form 4 consecutive Q registers.
1420///
1421SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1422 SDValue V2, SDValue V3) {
1423 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001424 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1425 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1426 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1427 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1429 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1430}
1431
Bob Wilson2a6e6162010-09-23 23:42:37 +00001432/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1433/// of a NEON VLD or VST instruction. The supported values depend on the
1434/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001435SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1436 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001437 unsigned NumRegs = NumVecs;
1438 if (!is64BitVector && NumVecs < 3)
1439 NumRegs *= 2;
1440
Bob Wilson665814b2010-11-01 23:40:51 +00001441 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001442 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001443 Alignment = 32;
1444 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1445 Alignment = 16;
1446 else if (Alignment >= 8)
1447 Alignment = 8;
1448 else
1449 Alignment = 0;
1450
1451 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001452}
1453
Bob Wilson1c3ef902011-02-07 17:43:21 +00001454SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001455 unsigned *DOpcodes, unsigned *QOpcodes0,
1456 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001457 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001458 DebugLoc dl = N->getDebugLoc();
1459
Bob Wilson226036e2010-03-20 22:13:40 +00001460 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001461 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1462 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001463 return NULL;
1464
1465 SDValue Chain = N->getOperand(0);
1466 EVT VT = N->getValueType(0);
1467 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001468 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001469
Bob Wilson3e36f132009-10-14 17:28:52 +00001470 unsigned OpcodeIndex;
1471 switch (VT.getSimpleVT().SimpleTy) {
1472 default: llvm_unreachable("unhandled vld type");
1473 // Double-register operations:
1474 case MVT::v8i8: OpcodeIndex = 0; break;
1475 case MVT::v4i16: OpcodeIndex = 1; break;
1476 case MVT::v2f32:
1477 case MVT::v2i32: OpcodeIndex = 2; break;
1478 case MVT::v1i64: OpcodeIndex = 3; break;
1479 // Quad-register operations:
1480 case MVT::v16i8: OpcodeIndex = 0; break;
1481 case MVT::v8i16: OpcodeIndex = 1; break;
1482 case MVT::v4f32:
1483 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001484 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001485 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001486 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001487 }
1488
Bob Wilsonf5721912010-09-03 18:16:02 +00001489 EVT ResTy;
1490 if (NumVecs == 1)
1491 ResTy = VT;
1492 else {
1493 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1494 if (!is64BitVector)
1495 ResTyElts *= 2;
1496 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1497 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001498 std::vector<EVT> ResTys;
1499 ResTys.push_back(ResTy);
1500 if (isUpdating)
1501 ResTys.push_back(MVT::i32);
1502 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001503
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001504 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001505 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001506 SDNode *VLd;
1507 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001508
Bob Wilson1c3ef902011-02-07 17:43:21 +00001509 // Double registers and VLD1/VLD2 quad registers are directly supported.
1510 if (is64BitVector || NumVecs <= 2) {
1511 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1512 QOpcodes0[OpcodeIndex]);
1513 Ops.push_back(MemAddr);
1514 Ops.push_back(Align);
1515 if (isUpdating) {
1516 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1517 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001518 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001519 Ops.push_back(Pred);
1520 Ops.push_back(Reg0);
1521 Ops.push_back(Chain);
1522 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001523
Bob Wilson3e36f132009-10-14 17:28:52 +00001524 } else {
1525 // Otherwise, quad registers are loaded with two separate instructions,
1526 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001527 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001528
Bob Wilson1c3ef902011-02-07 17:43:21 +00001529 // Load the even subregs. This is always an updating load, so that it
1530 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001531 SDValue ImplDef =
1532 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1533 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001534 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1535 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001536 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001537
Bob Wilson24f995d2009-10-14 18:32:29 +00001538 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001539 Ops.push_back(SDValue(VLdA, 1));
1540 Ops.push_back(Align);
1541 if (isUpdating) {
1542 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1543 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1544 "only constant post-increment update allowed for VLD3/4");
1545 (void)Inc;
1546 Ops.push_back(Reg0);
1547 }
1548 Ops.push_back(SDValue(VLdA, 0));
1549 Ops.push_back(Pred);
1550 Ops.push_back(Reg0);
1551 Ops.push_back(Chain);
1552 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1553 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001554 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001555
Bob Wilson1c3ef902011-02-07 17:43:21 +00001556 if (NumVecs == 1)
1557 return VLd;
1558
1559 // Extract out the subregisters.
1560 SDValue SuperReg = SDValue(VLd, 0);
1561 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1562 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1563 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1564 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1565 ReplaceUses(SDValue(N, Vec),
1566 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1567 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1568 if (isUpdating)
1569 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001570 return NULL;
1571}
1572
Bob Wilson1c3ef902011-02-07 17:43:21 +00001573SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001574 unsigned *DOpcodes, unsigned *QOpcodes0,
1575 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001576 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001577 DebugLoc dl = N->getDebugLoc();
1578
Bob Wilson226036e2010-03-20 22:13:40 +00001579 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001580 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1581 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1582 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001583 return NULL;
1584
1585 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001586 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001587 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001588 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001589
Bob Wilson24f995d2009-10-14 18:32:29 +00001590 unsigned OpcodeIndex;
1591 switch (VT.getSimpleVT().SimpleTy) {
1592 default: llvm_unreachable("unhandled vst type");
1593 // Double-register operations:
1594 case MVT::v8i8: OpcodeIndex = 0; break;
1595 case MVT::v4i16: OpcodeIndex = 1; break;
1596 case MVT::v2f32:
1597 case MVT::v2i32: OpcodeIndex = 2; break;
1598 case MVT::v1i64: OpcodeIndex = 3; break;
1599 // Quad-register operations:
1600 case MVT::v16i8: OpcodeIndex = 0; break;
1601 case MVT::v8i16: OpcodeIndex = 1; break;
1602 case MVT::v4f32:
1603 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001604 case MVT::v2i64: OpcodeIndex = 3;
1605 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1606 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001607 }
1608
Bob Wilson1c3ef902011-02-07 17:43:21 +00001609 std::vector<EVT> ResTys;
1610 if (isUpdating)
1611 ResTys.push_back(MVT::i32);
1612 ResTys.push_back(MVT::Other);
1613
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001614 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001615 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001616 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001617
Bob Wilson1c3ef902011-02-07 17:43:21 +00001618 // Double registers and VST1/VST2 quad registers are directly supported.
1619 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001620 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001621 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001622 SrcReg = N->getOperand(Vec0Idx);
1623 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001624 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001625 SDValue V0 = N->getOperand(Vec0Idx + 0);
1626 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001627 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001628 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001629 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001630 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001631 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001632 // an undef.
1633 SDValue V3 = (NumVecs == 3)
1634 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001635 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001636 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001637 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001638 } else {
1639 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001640 SDValue Q0 = N->getOperand(Vec0Idx);
1641 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001642 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001643 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001644
1645 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1646 QOpcodes0[OpcodeIndex]);
1647 Ops.push_back(MemAddr);
1648 Ops.push_back(Align);
1649 if (isUpdating) {
1650 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1651 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1652 }
1653 Ops.push_back(SrcReg);
1654 Ops.push_back(Pred);
1655 Ops.push_back(Reg0);
1656 Ops.push_back(Chain);
1657 return CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001658 }
1659
1660 // Otherwise, quad registers are stored with two separate instructions,
1661 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001662
Bob Wilson07f6e802010-06-16 21:34:01 +00001663 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001664 SDValue V0 = N->getOperand(Vec0Idx + 0);
1665 SDValue V1 = N->getOperand(Vec0Idx + 1);
1666 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001667 SDValue V3 = (NumVecs == 3)
1668 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001669 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001670 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001671
Bob Wilson1c3ef902011-02-07 17:43:21 +00001672 // Store the even D registers. This is always an updating store, so that it
1673 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001674 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1675 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1676 MemAddr.getValueType(),
1677 MVT::Other, OpsA, 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001678 Chain = SDValue(VStA, 1);
1679
1680 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001681 Ops.push_back(SDValue(VStA, 0));
1682 Ops.push_back(Align);
1683 if (isUpdating) {
1684 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1685 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1686 "only constant post-increment update allowed for VST3/4");
1687 (void)Inc;
1688 Ops.push_back(Reg0);
1689 }
1690 Ops.push_back(RegSeq);
1691 Ops.push_back(Pred);
1692 Ops.push_back(Reg0);
1693 Ops.push_back(Chain);
1694 return CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1695 Ops.data(), Ops.size());
Bob Wilson24f995d2009-10-14 18:32:29 +00001696}
1697
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001698SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001699 bool isUpdating, unsigned NumVecs,
1700 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001701 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001702 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001703 DebugLoc dl = N->getDebugLoc();
1704
Bob Wilson226036e2010-03-20 22:13:40 +00001705 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001706 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1707 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1708 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001709 return NULL;
1710
1711 SDValue Chain = N->getOperand(0);
1712 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001713 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1714 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001715 bool is64BitVector = VT.is64BitVector();
1716
Bob Wilson665814b2010-11-01 23:40:51 +00001717 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001718 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001719 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001720 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1721 if (Alignment > NumBytes)
1722 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001723 if (Alignment < 8 && Alignment < NumBytes)
1724 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001725 // Alignment must be a power of two; make sure of that.
1726 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001727 if (Alignment == 1)
1728 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001729 }
Bob Wilson665814b2010-11-01 23:40:51 +00001730 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001731
Bob Wilsona7c397c2009-10-14 16:19:03 +00001732 unsigned OpcodeIndex;
1733 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001734 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001735 // Double-register operations:
1736 case MVT::v8i8: OpcodeIndex = 0; break;
1737 case MVT::v4i16: OpcodeIndex = 1; break;
1738 case MVT::v2f32:
1739 case MVT::v2i32: OpcodeIndex = 2; break;
1740 // Quad-register operations:
1741 case MVT::v8i16: OpcodeIndex = 0; break;
1742 case MVT::v4f32:
1743 case MVT::v4i32: OpcodeIndex = 1; break;
1744 }
1745
Bob Wilson1c3ef902011-02-07 17:43:21 +00001746 std::vector<EVT> ResTys;
1747 if (IsLoad) {
1748 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1749 if (!is64BitVector)
1750 ResTyElts *= 2;
1751 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1752 MVT::i64, ResTyElts));
1753 }
1754 if (isUpdating)
1755 ResTys.push_back(MVT::i32);
1756 ResTys.push_back(MVT::Other);
1757
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001758 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001759 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001760
Bob Wilson1c3ef902011-02-07 17:43:21 +00001761 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001762 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001763 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001764 if (isUpdating) {
1765 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1766 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1767 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001768
Bob Wilson8466fa12010-09-13 23:01:35 +00001769 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001770 SDValue V0 = N->getOperand(Vec0Idx + 0);
1771 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001772 if (NumVecs == 2) {
1773 if (is64BitVector)
1774 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1775 else
1776 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001777 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001778 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001779 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001780 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1781 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001782 if (is64BitVector)
1783 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1784 else
1785 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001786 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001787 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001788 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001789 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001790 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001791 Ops.push_back(Chain);
1792
Bob Wilson1c3ef902011-02-07 17:43:21 +00001793 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1794 QOpcodes[OpcodeIndex]);
1795 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1796 Ops.data(), Ops.size());
Bob Wilson96493442009-10-14 16:46:45 +00001797 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001799
Bob Wilson8466fa12010-09-13 23:01:35 +00001800 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001801 SuperReg = SDValue(VLdLn, 0);
1802 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1803 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1804 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001805 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1806 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001807 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1808 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1809 if (isUpdating)
1810 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001811 return NULL;
1812}
1813
Bob Wilson1c3ef902011-02-07 17:43:21 +00001814SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1815 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001816 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1817 DebugLoc dl = N->getDebugLoc();
1818
1819 SDValue MemAddr, Align;
1820 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1821 return NULL;
1822
1823 SDValue Chain = N->getOperand(0);
1824 EVT VT = N->getValueType(0);
1825
1826 unsigned Alignment = 0;
1827 if (NumVecs != 3) {
1828 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1829 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1830 if (Alignment > NumBytes)
1831 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001832 if (Alignment < 8 && Alignment < NumBytes)
1833 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001834 // Alignment must be a power of two; make sure of that.
1835 Alignment = (Alignment & -Alignment);
1836 if (Alignment == 1)
1837 Alignment = 0;
1838 }
1839 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1840
1841 unsigned OpcodeIndex;
1842 switch (VT.getSimpleVT().SimpleTy) {
1843 default: llvm_unreachable("unhandled vld-dup type");
1844 case MVT::v8i8: OpcodeIndex = 0; break;
1845 case MVT::v4i16: OpcodeIndex = 1; break;
1846 case MVT::v2f32:
1847 case MVT::v2i32: OpcodeIndex = 2; break;
1848 }
1849
1850 SDValue Pred = getAL(CurDAG);
1851 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1852 SDValue SuperReg;
1853 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001854 SmallVector<SDValue, 6> Ops;
1855 Ops.push_back(MemAddr);
1856 Ops.push_back(Align);
1857 if (isUpdating) {
1858 SDValue Inc = N->getOperand(2);
1859 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1860 }
1861 Ops.push_back(Pred);
1862 Ops.push_back(Reg0);
1863 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001864
1865 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001866 std::vector<EVT> ResTys;
1867 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts));
1868 if (isUpdating)
1869 ResTys.push_back(MVT::i32);
1870 ResTys.push_back(MVT::Other);
1871 SDNode *VLdDup =
1872 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001873 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001874
1875 // Extract the subregisters.
1876 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1877 unsigned SubIdx = ARM::dsub_0;
1878 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1879 ReplaceUses(SDValue(N, Vec),
1880 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001881 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1882 if (isUpdating)
1883 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001884 return NULL;
1885}
1886
Bob Wilson78dfbc32010-07-07 00:08:54 +00001887SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1888 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001889 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1890 DebugLoc dl = N->getDebugLoc();
1891 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001892 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001893
1894 // Form a REG_SEQUENCE to force register allocation.
1895 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001896 SDValue V0 = N->getOperand(FirstTblReg + 0);
1897 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001898 if (NumVecs == 2)
1899 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1900 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001901 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001902 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001903 // an undef.
1904 SDValue V3 = (NumVecs == 3)
1905 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001906 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001907 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1908 }
1909
Bob Wilson78dfbc32010-07-07 00:08:54 +00001910 SmallVector<SDValue, 6> Ops;
1911 if (IsExt)
1912 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001913 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001914 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001915 Ops.push_back(getAL(CurDAG)); // predicate
1916 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001917 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001918}
1919
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001920SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001921 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001922 if (!Subtarget->hasV6T2Ops())
1923 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001924
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001925 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1926 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1927
1928
1929 // For unsigned extracts, check for a shift right and mask
1930 unsigned And_imm = 0;
1931 if (N->getOpcode() == ISD::AND) {
1932 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1933
1934 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1935 if (And_imm & (And_imm + 1))
1936 return NULL;
1937
1938 unsigned Srl_imm = 0;
1939 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1940 Srl_imm)) {
1941 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1942
1943 unsigned Width = CountTrailingOnes_32(And_imm);
1944 unsigned LSB = Srl_imm;
1945 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1946 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1947 CurDAG->getTargetConstant(LSB, MVT::i32),
1948 CurDAG->getTargetConstant(Width, MVT::i32),
1949 getAL(CurDAG), Reg0 };
1950 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1951 }
1952 }
1953 return NULL;
1954 }
1955
1956 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001957 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001958 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001959 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1960 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001961 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001962 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1963 unsigned Width = 32 - Srl_imm;
1964 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001965 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001966 return NULL;
1967 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001968 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001969 CurDAG->getTargetConstant(LSB, MVT::i32),
1970 CurDAG->getTargetConstant(Width, MVT::i32),
1971 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001972 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001973 }
1974 }
1975 return NULL;
1976}
1977
Evan Cheng9ef48352009-11-20 00:54:03 +00001978SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001979SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001980 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1981 SDValue CPTmp0;
1982 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001983 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001984 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1985 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1986 unsigned Opc = 0;
1987 switch (SOShOp) {
1988 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1989 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1990 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1991 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1992 default:
1993 llvm_unreachable("Unknown so_reg opcode!");
1994 break;
1995 }
1996 SDValue SOShImm =
1997 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1998 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1999 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002000 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002001 }
2002 return 0;
2003}
2004
2005SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002006SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002007 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2008 SDValue CPTmp0;
2009 SDValue CPTmp1;
2010 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002011 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002012 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2013 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002014 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002015 }
2016 return 0;
2017}
2018
2019SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002020SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002021 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002022 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002023 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002024 return 0;
2025
Evan Cheng63f35442010-11-13 02:25:14 +00002026 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002027 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002028 if (is_t2_so_imm(TrueImm)) {
2029 Opc = ARM::t2MOVCCi;
2030 } else if (TrueImm <= 0xffff) {
2031 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002032 } else if (is_t2_so_imm_not(TrueImm)) {
2033 TrueImm = ~TrueImm;
2034 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002035 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002036 // Large immediate.
2037 Opc = ARM::t2MOVCCi32imm;
2038 }
2039
2040 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002041 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002042 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2043 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002044 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002045 }
Evan Cheng63f35442010-11-13 02:25:14 +00002046
Evan Cheng9ef48352009-11-20 00:54:03 +00002047 return 0;
2048}
2049
2050SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002051SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002052 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002053 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2054 if (!T)
2055 return 0;
2056
Evan Cheng63f35442010-11-13 02:25:14 +00002057 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002058 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002059 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002060 if (isSoImm) {
2061 Opc = ARM::MOVCCi;
2062 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2063 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002064 } else if (is_so_imm_not(TrueImm)) {
2065 TrueImm = ~TrueImm;
2066 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002067 } else if (TrueVal.getNode()->hasOneUse() &&
2068 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002069 // Large immediate.
2070 Opc = ARM::MOVCCi32imm;
2071 }
2072
2073 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002074 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002075 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2076 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002077 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002079
Evan Cheng9ef48352009-11-20 00:54:03 +00002080 return 0;
2081}
2082
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002083SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2084 EVT VT = N->getValueType(0);
2085 SDValue FalseVal = N->getOperand(0);
2086 SDValue TrueVal = N->getOperand(1);
2087 SDValue CC = N->getOperand(2);
2088 SDValue CCR = N->getOperand(3);
2089 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002090 assert(CC.getOpcode() == ISD::Constant);
2091 assert(CCR.getOpcode() == ISD::Register);
2092 ARMCC::CondCodes CCVal =
2093 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002094
2095 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2096 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2097 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2098 // Pattern complexity = 18 cost = 1 size = 0
2099 SDValue CPTmp0;
2100 SDValue CPTmp1;
2101 SDValue CPTmp2;
2102 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002103 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002104 CCVal, CCR, InFlag);
2105 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002107 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2108 if (Res)
2109 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002110 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002111 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002112 CCVal, CCR, InFlag);
2113 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002114 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002115 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2116 if (Res)
2117 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002118 }
2119
2120 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002121 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002122 // (imm:i32):$cc)
2123 // Emits: (MOVCCi:i32 GPR:i32:$false,
2124 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2125 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002126 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002127 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002128 CCVal, CCR, InFlag);
2129 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002130 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002131 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2132 if (Res)
2133 return Res;
2134 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002135 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002136 CCVal, CCR, InFlag);
2137 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002138 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002139 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2140 if (Res)
2141 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002142 }
2143 }
2144
2145 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2146 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2147 // Pattern complexity = 6 cost = 1 size = 0
2148 //
2149 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2150 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2151 // Pattern complexity = 6 cost = 11 size = 0
2152 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002153 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2155 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002156 unsigned Opc = 0;
2157 switch (VT.getSimpleVT().SimpleTy) {
2158 default: assert(false && "Illegal conditional move type!");
2159 break;
2160 case MVT::i32:
2161 Opc = Subtarget->isThumb()
2162 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2163 : ARM::MOVCCr;
2164 break;
2165 case MVT::f32:
2166 Opc = ARM::VMOVScc;
2167 break;
2168 case MVT::f64:
2169 Opc = ARM::VMOVDcc;
2170 break;
2171 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002172 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002173}
2174
Evan Chengde8aa4e2010-05-05 18:28:36 +00002175SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2176 // The only time a CONCAT_VECTORS operation can have legal types is when
2177 // two 64-bit vectors are concatenated to a 128-bit vector.
2178 EVT VT = N->getValueType(0);
2179 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2180 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002181 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002182}
2183
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002184SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002185 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002186
Dan Gohmane8be6c62008-07-17 19:10:17 +00002187 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002188 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002189
2190 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002191 default: break;
2192 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002193 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002194 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002195 if (Subtarget->hasThumb2())
2196 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2197 // be done with MOV + MOVT, at worst.
2198 UseCP = 0;
2199 else {
2200 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002201 UseCP = (Val > 255 && // MOV
2202 ~Val > 255 && // MOV + MVN
2203 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002204 } else
2205 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2206 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2207 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2208 }
2209
Evan Chenga8e29892007-01-19 07:51:42 +00002210 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002211 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002212 CurDAG->getTargetConstantPool(ConstantInt::get(
2213 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002214 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002215
2216 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002217 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002218 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002219 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002220 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002221 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002222 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002223 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002224 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002225 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002226 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002227 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002228 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002229 CurDAG->getEntryNode()
2230 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002231 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002232 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002233 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002234 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002235 return NULL;
2236 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002237
Evan Chenga8e29892007-01-19 07:51:42 +00002238 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002239 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002240 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002241 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002242 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002243 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002244 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002245 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002246 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2247 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002248 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002249 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2250 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002251 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2252 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2253 CurDAG->getRegister(0, MVT::i32) };
2254 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002255 }
Evan Chenga8e29892007-01-19 07:51:42 +00002256 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002257 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002258 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002259 return I;
2260 break;
2261 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002262 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002263 return I;
2264 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002265 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002266 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002267 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002268 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002269 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002270 if (!RHSV) break;
2271 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002272 unsigned ShImm = Log2_32(RHSV-1);
2273 if (ShImm >= 32)
2274 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002275 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002276 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002277 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2278 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002279 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002280 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002281 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002282 } else {
2283 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002284 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002285 }
Evan Chenga8e29892007-01-19 07:51:42 +00002286 }
2287 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002288 unsigned ShImm = Log2_32(RHSV+1);
2289 if (ShImm >= 32)
2290 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002291 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002292 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002293 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2294 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002295 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002296 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2297 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002298 } else {
2299 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002300 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002301 }
Evan Chenga8e29892007-01-19 07:51:42 +00002302 }
2303 }
2304 break;
Evan Cheng20956592009-10-21 08:15:52 +00002305 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002306 // Check for unsigned bitfield extract
2307 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2308 return I;
2309
Evan Cheng20956592009-10-21 08:15:52 +00002310 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2311 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2312 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2313 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2314 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002315 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002316 if (VT != MVT::i32)
2317 break;
2318 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2319 ? ARM::t2MOVTi16
2320 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2321 if (!Opc)
2322 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002323 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002324 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2325 if (!N1C)
2326 break;
2327 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2328 SDValue N2 = N0.getOperand(1);
2329 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2330 if (!N2C)
2331 break;
2332 unsigned N1CVal = N1C->getZExtValue();
2333 unsigned N2CVal = N2C->getZExtValue();
2334 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2335 (N1CVal & 0xffffU) == 0xffffU &&
2336 (N2CVal & 0xffffU) == 0x0U) {
2337 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2338 MVT::i32);
2339 SDValue Ops[] = { N0.getOperand(0), Imm16,
2340 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2341 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2342 }
2343 }
2344 break;
2345 }
Jim Grosbache5165492009-11-09 00:11:35 +00002346 case ARMISD::VMOVRRD:
2347 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002349 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002350 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002351 if (Subtarget->isThumb1Only())
2352 break;
2353 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002354 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002355 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2356 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002357 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002358 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002359 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002360 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2361 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002362 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2363 ARM::UMULL : ARM::UMULLv5,
2364 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002365 }
Evan Chengee568cf2007-07-05 07:15:27 +00002366 }
Dan Gohman525178c2007-10-08 18:33:35 +00002367 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002368 if (Subtarget->isThumb1Only())
2369 break;
2370 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002371 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002372 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002373 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002374 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002375 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002376 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2377 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002378 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2379 ARM::SMULL : ARM::SMULLv5,
2380 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002381 }
Evan Chengee568cf2007-07-05 07:15:27 +00002382 }
Evan Chenga8e29892007-01-19 07:51:42 +00002383 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002384 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002385 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002386 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002387 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002388 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002389 if (ResNode)
2390 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002391 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002392 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002393 }
Evan Chengee568cf2007-07-05 07:15:27 +00002394 case ARMISD::BRCOND: {
2395 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2396 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2397 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002398
Evan Chengee568cf2007-07-05 07:15:27 +00002399 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2400 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2401 // Pattern complexity = 6 cost = 1 size = 0
2402
David Goodwin5e47a9a2009-06-30 18:04:13 +00002403 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2404 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2405 // Pattern complexity = 6 cost = 1 size = 0
2406
Jim Grosbach764ab522009-08-11 15:33:49 +00002407 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002408 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002409 SDValue Chain = N->getOperand(0);
2410 SDValue N1 = N->getOperand(1);
2411 SDValue N2 = N->getOperand(2);
2412 SDValue N3 = N->getOperand(3);
2413 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002414 assert(N1.getOpcode() == ISD::BasicBlock);
2415 assert(N2.getOpcode() == ISD::Constant);
2416 assert(N3.getOpcode() == ISD::Register);
2417
Dan Gohman475871a2008-07-27 21:46:04 +00002418 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002419 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002420 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002421 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002422 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002423 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002424 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002425 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002426 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002427 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002428 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002429 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002430 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002431 return NULL;
2432 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002433 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002434 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002435 case ARMISD::VZIP: {
2436 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002437 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002438 switch (VT.getSimpleVT().SimpleTy) {
2439 default: return NULL;
2440 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2441 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2442 case MVT::v2f32:
2443 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2444 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2445 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2446 case MVT::v4f32:
2447 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2448 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002449 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002450 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2451 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2452 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002453 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002454 case ARMISD::VUZP: {
2455 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002456 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002457 switch (VT.getSimpleVT().SimpleTy) {
2458 default: return NULL;
2459 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2460 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2461 case MVT::v2f32:
2462 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2463 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2464 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2465 case MVT::v4f32:
2466 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2467 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002468 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002469 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2470 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2471 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002472 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002473 case ARMISD::VTRN: {
2474 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002475 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002476 switch (VT.getSimpleVT().SimpleTy) {
2477 default: return NULL;
2478 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2479 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2480 case MVT::v2f32:
2481 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2482 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2483 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2484 case MVT::v4f32:
2485 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2486 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002487 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002488 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2489 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2490 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002491 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002492 case ARMISD::BUILD_VECTOR: {
2493 EVT VecVT = N->getValueType(0);
2494 EVT EltVT = VecVT.getVectorElementType();
2495 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002496 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002497 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2498 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2499 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002500 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002501 if (NumElts == 2)
2502 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2503 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2504 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2505 N->getOperand(2), N->getOperand(3));
2506 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002507
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002508 case ARMISD::VLD2DUP: {
2509 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2510 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002511 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002512 }
2513
Bob Wilson86c6d802010-11-29 19:35:29 +00002514 case ARMISD::VLD3DUP: {
2515 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2516 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002517 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002518 }
2519
Bob Wilson6c4c9822010-11-30 00:00:35 +00002520 case ARMISD::VLD4DUP: {
2521 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2522 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002523 return SelectVLDDup(N, false, 4, Opcodes);
2524 }
2525
2526 case ARMISD::VLD2DUP_UPD: {
2527 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2528 ARM::VLD2DUPd32Pseudo_UPD };
2529 return SelectVLDDup(N, true, 2, Opcodes);
2530 }
2531
2532 case ARMISD::VLD3DUP_UPD: {
2533 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2534 ARM::VLD3DUPd32Pseudo_UPD };
2535 return SelectVLDDup(N, true, 3, Opcodes);
2536 }
2537
2538 case ARMISD::VLD4DUP_UPD: {
2539 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2540 ARM::VLD4DUPd32Pseudo_UPD };
2541 return SelectVLDDup(N, true, 4, Opcodes);
2542 }
2543
2544 case ARMISD::VLD1_UPD: {
2545 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2546 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2547 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2548 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2549 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2550 }
2551
2552 case ARMISD::VLD2_UPD: {
2553 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2554 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2555 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2556 ARM::VLD2q32Pseudo_UPD };
2557 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2558 }
2559
2560 case ARMISD::VLD3_UPD: {
2561 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2562 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2563 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2564 ARM::VLD3q16Pseudo_UPD,
2565 ARM::VLD3q32Pseudo_UPD };
2566 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2567 ARM::VLD3q16oddPseudo_UPD,
2568 ARM::VLD3q32oddPseudo_UPD };
2569 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2570 }
2571
2572 case ARMISD::VLD4_UPD: {
2573 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2574 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2575 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2576 ARM::VLD4q16Pseudo_UPD,
2577 ARM::VLD4q32Pseudo_UPD };
2578 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2579 ARM::VLD4q16oddPseudo_UPD,
2580 ARM::VLD4q32oddPseudo_UPD };
2581 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2582 }
2583
2584 case ARMISD::VLD2LN_UPD: {
2585 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2586 ARM::VLD2LNd32Pseudo_UPD };
2587 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2588 ARM::VLD2LNq32Pseudo_UPD };
2589 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2590 }
2591
2592 case ARMISD::VLD3LN_UPD: {
2593 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2594 ARM::VLD3LNd32Pseudo_UPD };
2595 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2596 ARM::VLD3LNq32Pseudo_UPD };
2597 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2598 }
2599
2600 case ARMISD::VLD4LN_UPD: {
2601 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2602 ARM::VLD4LNd32Pseudo_UPD };
2603 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2604 ARM::VLD4LNq32Pseudo_UPD };
2605 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2606 }
2607
2608 case ARMISD::VST1_UPD: {
2609 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2610 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2611 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2612 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2613 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2614 }
2615
2616 case ARMISD::VST2_UPD: {
2617 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2618 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2619 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2620 ARM::VST2q32Pseudo_UPD };
2621 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2622 }
2623
2624 case ARMISD::VST3_UPD: {
2625 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2626 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2627 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2628 ARM::VST3q16Pseudo_UPD,
2629 ARM::VST3q32Pseudo_UPD };
2630 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2631 ARM::VST3q16oddPseudo_UPD,
2632 ARM::VST3q32oddPseudo_UPD };
2633 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2634 }
2635
2636 case ARMISD::VST4_UPD: {
2637 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2638 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2639 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2640 ARM::VST4q16Pseudo_UPD,
2641 ARM::VST4q32Pseudo_UPD };
2642 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2643 ARM::VST4q16oddPseudo_UPD,
2644 ARM::VST4q32oddPseudo_UPD };
2645 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2646 }
2647
2648 case ARMISD::VST2LN_UPD: {
2649 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2650 ARM::VST2LNd32Pseudo_UPD };
2651 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2652 ARM::VST2LNq32Pseudo_UPD };
2653 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2654 }
2655
2656 case ARMISD::VST3LN_UPD: {
2657 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2658 ARM::VST3LNd32Pseudo_UPD };
2659 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2660 ARM::VST3LNq32Pseudo_UPD };
2661 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2662 }
2663
2664 case ARMISD::VST4LN_UPD: {
2665 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2666 ARM::VST4LNd32Pseudo_UPD };
2667 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2668 ARM::VST4LNq32Pseudo_UPD };
2669 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002670 }
2671
Bob Wilson31fb12f2009-08-26 17:39:53 +00002672 case ISD::INTRINSIC_VOID:
2673 case ISD::INTRINSIC_W_CHAIN: {
2674 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002675 switch (IntNo) {
2676 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002677 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002678
Bob Wilson621f1952010-03-23 05:25:43 +00002679 case Intrinsic::arm_neon_vld1: {
2680 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2681 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002682 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2683 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002684 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002685 }
2686
Bob Wilson31fb12f2009-08-26 17:39:53 +00002687 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002688 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2689 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2690 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2691 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002692 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002693 }
2694
2695 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002696 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2697 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2698 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2699 ARM::VLD3q16Pseudo_UPD,
2700 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002701 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2702 ARM::VLD3q16oddPseudo,
2703 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002704 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002705 }
2706
2707 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002708 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2709 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2710 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2711 ARM::VLD4q16Pseudo_UPD,
2712 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002713 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2714 ARM::VLD4q16oddPseudo,
2715 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002716 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002717 }
2718
Bob Wilson243fcc52009-09-01 04:26:28 +00002719 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002720 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2721 ARM::VLD2LNd32Pseudo };
2722 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002723 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002724 }
2725
2726 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002727 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2728 ARM::VLD3LNd32Pseudo };
2729 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002730 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002731 }
2732
2733 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002734 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2735 ARM::VLD4LNd32Pseudo };
2736 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002737 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002738 }
2739
Bob Wilson11d98992010-03-23 06:20:33 +00002740 case Intrinsic::arm_neon_vst1: {
2741 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2742 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002743 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2744 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002745 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002746 }
2747
Bob Wilson31fb12f2009-08-26 17:39:53 +00002748 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002749 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2750 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2751 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2752 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002753 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002754 }
2755
2756 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002757 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2758 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2759 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2760 ARM::VST3q16Pseudo_UPD,
2761 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002762 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2763 ARM::VST3q16oddPseudo,
2764 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002765 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002766 }
2767
2768 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002769 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002770 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002771 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2772 ARM::VST4q16Pseudo_UPD,
2773 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002774 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2775 ARM::VST4q16oddPseudo,
2776 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002777 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002778 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002779
2780 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002781 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2782 ARM::VST2LNd32Pseudo };
2783 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002784 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002785 }
2786
2787 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002788 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2789 ARM::VST3LNd32Pseudo };
2790 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002791 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002792 }
2793
2794 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002795 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2796 ARM::VST4LNd32Pseudo };
2797 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002798 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002799 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002800 }
Bob Wilson429009b2010-05-06 16:05:26 +00002801 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002802 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002803
Bob Wilsond491d6e2010-07-06 23:36:25 +00002804 case ISD::INTRINSIC_WO_CHAIN: {
2805 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2806 switch (IntNo) {
2807 default:
2808 break;
2809
2810 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002811 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002812 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002813 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002814 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002815 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002816
2817 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002818 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002819 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002820 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002821 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002822 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002823 }
2824 break;
2825 }
2826
Bill Wendling69a05a72011-03-14 23:02:38 +00002827 case ARMISD::VTBL1: {
2828 DebugLoc dl = N->getDebugLoc();
2829 EVT VT = N->getValueType(0);
2830 SmallVector<SDValue, 6> Ops;
2831
2832 Ops.push_back(N->getOperand(0));
2833 Ops.push_back(N->getOperand(1));
2834 Ops.push_back(getAL(CurDAG)); // Predicate
2835 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2836 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
2837 }
2838 case ARMISD::VTBL2: {
2839 DebugLoc dl = N->getDebugLoc();
2840 EVT VT = N->getValueType(0);
2841
2842 // Form a REG_SEQUENCE to force register allocation.
2843 SDValue V0 = N->getOperand(0);
2844 SDValue V1 = N->getOperand(1);
2845 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2846
2847 SmallVector<SDValue, 6> Ops;
2848 Ops.push_back(RegSeq);
2849 Ops.push_back(N->getOperand(2));
2850 Ops.push_back(getAL(CurDAG)); // Predicate
2851 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2852 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
2853 Ops.data(), Ops.size());
2854 }
2855
Bob Wilson429009b2010-05-06 16:05:26 +00002856 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002857 return SelectConcatVector(N);
2858 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002859
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002860 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002861}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002862
Bob Wilson224c2442009-05-19 05:53:42 +00002863bool ARMDAGToDAGISel::
2864SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2865 std::vector<SDValue> &OutOps) {
2866 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002867 // Require the address to be in a register. That is safe for all ARM
2868 // variants and it is hard to do anything much smarter without knowing
2869 // how the operand is used.
2870 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002871 return false;
2872}
2873
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002874/// createARMISelDag - This pass converts a legalized DAG into a
2875/// ARM-specific DAG, ready for instruction scheduling.
2876///
Bob Wilson522ce972009-09-28 14:30:20 +00002877FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2878 CodeGenOpt::Level OptLevel) {
2879 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002880}