blob: 01bb2be0aa705c9f1a29fbd202bdddf8b4bbea09 [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
Evan Chengb58a3402011-04-19 00:04:03 +00001556 // Transfer memoperands.
1557 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1558 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1559 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1560
Bob Wilson1c3ef902011-02-07 17:43:21 +00001561 if (NumVecs == 1)
1562 return VLd;
1563
1564 // Extract out the subregisters.
1565 SDValue SuperReg = SDValue(VLd, 0);
1566 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1567 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1568 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1569 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1570 ReplaceUses(SDValue(N, Vec),
1571 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1572 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1573 if (isUpdating)
1574 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001575 return NULL;
1576}
1577
Bob Wilson1c3ef902011-02-07 17:43:21 +00001578SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001579 unsigned *DOpcodes, unsigned *QOpcodes0,
1580 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001581 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001582 DebugLoc dl = N->getDebugLoc();
1583
Bob Wilson226036e2010-03-20 22:13:40 +00001584 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001585 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1586 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1587 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001588 return NULL;
1589
Evan Chengb58a3402011-04-19 00:04:03 +00001590 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1591 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1592
Bob Wilson24f995d2009-10-14 18:32:29 +00001593 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001594 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001595 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001596 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001597
Bob Wilson24f995d2009-10-14 18:32:29 +00001598 unsigned OpcodeIndex;
1599 switch (VT.getSimpleVT().SimpleTy) {
1600 default: llvm_unreachable("unhandled vst type");
1601 // Double-register operations:
1602 case MVT::v8i8: OpcodeIndex = 0; break;
1603 case MVT::v4i16: OpcodeIndex = 1; break;
1604 case MVT::v2f32:
1605 case MVT::v2i32: OpcodeIndex = 2; break;
1606 case MVT::v1i64: OpcodeIndex = 3; break;
1607 // Quad-register operations:
1608 case MVT::v16i8: OpcodeIndex = 0; break;
1609 case MVT::v8i16: OpcodeIndex = 1; break;
1610 case MVT::v4f32:
1611 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001612 case MVT::v2i64: OpcodeIndex = 3;
1613 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1614 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001615 }
1616
Bob Wilson1c3ef902011-02-07 17:43:21 +00001617 std::vector<EVT> ResTys;
1618 if (isUpdating)
1619 ResTys.push_back(MVT::i32);
1620 ResTys.push_back(MVT::Other);
1621
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001622 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001623 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001624 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001625
Bob Wilson1c3ef902011-02-07 17:43:21 +00001626 // Double registers and VST1/VST2 quad registers are directly supported.
1627 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001628 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001629 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001630 SrcReg = N->getOperand(Vec0Idx);
1631 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001632 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001633 SDValue V0 = N->getOperand(Vec0Idx + 0);
1634 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001635 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001636 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001637 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001638 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001639 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001640 // an undef.
1641 SDValue V3 = (NumVecs == 3)
1642 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001643 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001644 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001645 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001646 } else {
1647 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001648 SDValue Q0 = N->getOperand(Vec0Idx);
1649 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001650 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001651 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001652
1653 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1654 QOpcodes0[OpcodeIndex]);
1655 Ops.push_back(MemAddr);
1656 Ops.push_back(Align);
1657 if (isUpdating) {
1658 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1659 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1660 }
1661 Ops.push_back(SrcReg);
1662 Ops.push_back(Pred);
1663 Ops.push_back(Reg0);
1664 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001665 SDNode *VSt =
1666 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1667
1668 // Transfer memoperands.
1669 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1670
1671 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001672 }
1673
1674 // Otherwise, quad registers are stored with two separate instructions,
1675 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001676
Bob Wilson07f6e802010-06-16 21:34:01 +00001677 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001678 SDValue V0 = N->getOperand(Vec0Idx + 0);
1679 SDValue V1 = N->getOperand(Vec0Idx + 1);
1680 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001681 SDValue V3 = (NumVecs == 3)
1682 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001683 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001684 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001685
Bob Wilson1c3ef902011-02-07 17:43:21 +00001686 // Store the even D registers. This is always an updating store, so that it
1687 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001688 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1689 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1690 MemAddr.getValueType(),
1691 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001692 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001693 Chain = SDValue(VStA, 1);
1694
1695 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001696 Ops.push_back(SDValue(VStA, 0));
1697 Ops.push_back(Align);
1698 if (isUpdating) {
1699 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1700 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1701 "only constant post-increment update allowed for VST3/4");
1702 (void)Inc;
1703 Ops.push_back(Reg0);
1704 }
1705 Ops.push_back(RegSeq);
1706 Ops.push_back(Pred);
1707 Ops.push_back(Reg0);
1708 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001709 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1710 Ops.data(), Ops.size());
1711 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1712 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001713}
1714
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001715SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001716 bool isUpdating, unsigned NumVecs,
1717 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001718 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001719 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001720 DebugLoc dl = N->getDebugLoc();
1721
Bob Wilson226036e2010-03-20 22:13:40 +00001722 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001723 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1724 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1725 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001726 return NULL;
1727
Evan Chengb58a3402011-04-19 00:04:03 +00001728 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1729 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1730
Bob Wilsona7c397c2009-10-14 16:19:03 +00001731 SDValue Chain = N->getOperand(0);
1732 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001733 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1734 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001735 bool is64BitVector = VT.is64BitVector();
1736
Bob Wilson665814b2010-11-01 23:40:51 +00001737 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001738 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001739 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001740 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1741 if (Alignment > NumBytes)
1742 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001743 if (Alignment < 8 && Alignment < NumBytes)
1744 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001745 // Alignment must be a power of two; make sure of that.
1746 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001747 if (Alignment == 1)
1748 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001749 }
Bob Wilson665814b2010-11-01 23:40:51 +00001750 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001751
Bob Wilsona7c397c2009-10-14 16:19:03 +00001752 unsigned OpcodeIndex;
1753 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001754 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001755 // Double-register operations:
1756 case MVT::v8i8: OpcodeIndex = 0; break;
1757 case MVT::v4i16: OpcodeIndex = 1; break;
1758 case MVT::v2f32:
1759 case MVT::v2i32: OpcodeIndex = 2; break;
1760 // Quad-register operations:
1761 case MVT::v8i16: OpcodeIndex = 0; break;
1762 case MVT::v4f32:
1763 case MVT::v4i32: OpcodeIndex = 1; break;
1764 }
1765
Bob Wilson1c3ef902011-02-07 17:43:21 +00001766 std::vector<EVT> ResTys;
1767 if (IsLoad) {
1768 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1769 if (!is64BitVector)
1770 ResTyElts *= 2;
1771 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1772 MVT::i64, ResTyElts));
1773 }
1774 if (isUpdating)
1775 ResTys.push_back(MVT::i32);
1776 ResTys.push_back(MVT::Other);
1777
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001778 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001779 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001780
Bob Wilson1c3ef902011-02-07 17:43:21 +00001781 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001782 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001783 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001784 if (isUpdating) {
1785 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1786 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1787 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001788
Bob Wilson8466fa12010-09-13 23:01:35 +00001789 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 SDValue V0 = N->getOperand(Vec0Idx + 0);
1791 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001792 if (NumVecs == 2) {
1793 if (is64BitVector)
1794 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1795 else
1796 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001797 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001799 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001800 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1801 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001802 if (is64BitVector)
1803 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1804 else
1805 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001806 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001807 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001808 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001809 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001810 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001811 Ops.push_back(Chain);
1812
Bob Wilson1c3ef902011-02-07 17:43:21 +00001813 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1814 QOpcodes[OpcodeIndex]);
1815 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1816 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001817 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001818 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001819 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001820
Bob Wilson8466fa12010-09-13 23:01:35 +00001821 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001822 SuperReg = SDValue(VLdLn, 0);
1823 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1824 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1825 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001826 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1827 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001828 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1829 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1830 if (isUpdating)
1831 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001832 return NULL;
1833}
1834
Bob Wilson1c3ef902011-02-07 17:43:21 +00001835SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1836 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001837 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1838 DebugLoc dl = N->getDebugLoc();
1839
1840 SDValue MemAddr, Align;
1841 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1842 return NULL;
1843
Evan Chengb58a3402011-04-19 00:04:03 +00001844 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1845 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1846
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001847 SDValue Chain = N->getOperand(0);
1848 EVT VT = N->getValueType(0);
1849
1850 unsigned Alignment = 0;
1851 if (NumVecs != 3) {
1852 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1853 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1854 if (Alignment > NumBytes)
1855 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001856 if (Alignment < 8 && Alignment < NumBytes)
1857 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001858 // Alignment must be a power of two; make sure of that.
1859 Alignment = (Alignment & -Alignment);
1860 if (Alignment == 1)
1861 Alignment = 0;
1862 }
1863 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1864
1865 unsigned OpcodeIndex;
1866 switch (VT.getSimpleVT().SimpleTy) {
1867 default: llvm_unreachable("unhandled vld-dup type");
1868 case MVT::v8i8: OpcodeIndex = 0; break;
1869 case MVT::v4i16: OpcodeIndex = 1; break;
1870 case MVT::v2f32:
1871 case MVT::v2i32: OpcodeIndex = 2; break;
1872 }
1873
1874 SDValue Pred = getAL(CurDAG);
1875 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1876 SDValue SuperReg;
1877 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001878 SmallVector<SDValue, 6> Ops;
1879 Ops.push_back(MemAddr);
1880 Ops.push_back(Align);
1881 if (isUpdating) {
1882 SDValue Inc = N->getOperand(2);
1883 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1884 }
1885 Ops.push_back(Pred);
1886 Ops.push_back(Reg0);
1887 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001888
1889 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001890 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001891 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001892 if (isUpdating)
1893 ResTys.push_back(MVT::i32);
1894 ResTys.push_back(MVT::Other);
1895 SDNode *VLdDup =
1896 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001897 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001898 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001899
1900 // Extract the subregisters.
1901 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1902 unsigned SubIdx = ARM::dsub_0;
1903 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1904 ReplaceUses(SDValue(N, Vec),
1905 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001906 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
1907 if (isUpdating)
1908 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001909 return NULL;
1910}
1911
Bob Wilson78dfbc32010-07-07 00:08:54 +00001912SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1913 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001914 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1915 DebugLoc dl = N->getDebugLoc();
1916 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001917 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001918
1919 // Form a REG_SEQUENCE to force register allocation.
1920 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001921 SDValue V0 = N->getOperand(FirstTblReg + 0);
1922 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001923 if (NumVecs == 2)
1924 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1925 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001926 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001927 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001928 // an undef.
1929 SDValue V3 = (NumVecs == 3)
1930 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001931 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001932 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1933 }
1934
Bob Wilson78dfbc32010-07-07 00:08:54 +00001935 SmallVector<SDValue, 6> Ops;
1936 if (IsExt)
1937 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001938 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001939 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001940 Ops.push_back(getAL(CurDAG)); // predicate
1941 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001942 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001943}
1944
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001945SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001946 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001947 if (!Subtarget->hasV6T2Ops())
1948 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001949
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001950 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1951 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1952
1953
1954 // For unsigned extracts, check for a shift right and mask
1955 unsigned And_imm = 0;
1956 if (N->getOpcode() == ISD::AND) {
1957 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1958
1959 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1960 if (And_imm & (And_imm + 1))
1961 return NULL;
1962
1963 unsigned Srl_imm = 0;
1964 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1965 Srl_imm)) {
1966 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1967
1968 unsigned Width = CountTrailingOnes_32(And_imm);
1969 unsigned LSB = Srl_imm;
1970 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1971 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1972 CurDAG->getTargetConstant(LSB, MVT::i32),
1973 CurDAG->getTargetConstant(Width, MVT::i32),
1974 getAL(CurDAG), Reg0 };
1975 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1976 }
1977 }
1978 return NULL;
1979 }
1980
1981 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001982 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001983 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001984 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1985 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001986 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001987 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1988 unsigned Width = 32 - Srl_imm;
1989 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001990 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001991 return NULL;
1992 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001993 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001994 CurDAG->getTargetConstant(LSB, MVT::i32),
1995 CurDAG->getTargetConstant(Width, MVT::i32),
1996 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001997 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001998 }
1999 }
2000 return NULL;
2001}
2002
Evan Cheng9ef48352009-11-20 00:54:03 +00002003SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002004SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002005 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2006 SDValue CPTmp0;
2007 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002008 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002009 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2010 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2011 unsigned Opc = 0;
2012 switch (SOShOp) {
2013 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2014 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2015 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2016 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2017 default:
2018 llvm_unreachable("Unknown so_reg opcode!");
2019 break;
2020 }
2021 SDValue SOShImm =
2022 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2023 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2024 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002025 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002026 }
2027 return 0;
2028}
2029
2030SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002031SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002032 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2033 SDValue CPTmp0;
2034 SDValue CPTmp1;
2035 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00002036 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002037 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2038 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002039 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002040 }
2041 return 0;
2042}
2043
2044SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002045SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002046 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002047 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002048 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002049 return 0;
2050
Evan Cheng63f35442010-11-13 02:25:14 +00002051 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002052 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002053 if (is_t2_so_imm(TrueImm)) {
2054 Opc = ARM::t2MOVCCi;
2055 } else if (TrueImm <= 0xffff) {
2056 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002057 } else if (is_t2_so_imm_not(TrueImm)) {
2058 TrueImm = ~TrueImm;
2059 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002060 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002061 // Large immediate.
2062 Opc = ARM::t2MOVCCi32imm;
2063 }
2064
2065 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002066 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002067 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2068 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002069 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 }
Evan Cheng63f35442010-11-13 02:25:14 +00002071
Evan Cheng9ef48352009-11-20 00:54:03 +00002072 return 0;
2073}
2074
2075SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002076SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002077 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2079 if (!T)
2080 return 0;
2081
Evan Cheng63f35442010-11-13 02:25:14 +00002082 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002083 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002084 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002085 if (isSoImm) {
2086 Opc = ARM::MOVCCi;
2087 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2088 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002089 } else if (is_so_imm_not(TrueImm)) {
2090 TrueImm = ~TrueImm;
2091 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002092 } else if (TrueVal.getNode()->hasOneUse() &&
2093 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002094 // Large immediate.
2095 Opc = ARM::MOVCCi32imm;
2096 }
2097
2098 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002099 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002100 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2101 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002102 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002103 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002104
Evan Cheng9ef48352009-11-20 00:54:03 +00002105 return 0;
2106}
2107
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002108SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2109 EVT VT = N->getValueType(0);
2110 SDValue FalseVal = N->getOperand(0);
2111 SDValue TrueVal = N->getOperand(1);
2112 SDValue CC = N->getOperand(2);
2113 SDValue CCR = N->getOperand(3);
2114 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002115 assert(CC.getOpcode() == ISD::Constant);
2116 assert(CCR.getOpcode() == ISD::Register);
2117 ARMCC::CondCodes CCVal =
2118 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002119
2120 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2121 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2122 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2123 // Pattern complexity = 18 cost = 1 size = 0
2124 SDValue CPTmp0;
2125 SDValue CPTmp1;
2126 SDValue CPTmp2;
2127 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002128 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002129 CCVal, CCR, InFlag);
2130 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002131 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002132 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2133 if (Res)
2134 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002135 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002136 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002137 CCVal, CCR, InFlag);
2138 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002139 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002140 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2141 if (Res)
2142 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002143 }
2144
2145 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002146 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002147 // (imm:i32):$cc)
2148 // Emits: (MOVCCi:i32 GPR:i32:$false,
2149 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2150 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002151 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002152 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002153 CCVal, CCR, InFlag);
2154 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002155 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002156 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2157 if (Res)
2158 return Res;
2159 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002160 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002161 CCVal, CCR, InFlag);
2162 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002163 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002164 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2165 if (Res)
2166 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002167 }
2168 }
2169
2170 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2171 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2172 // Pattern complexity = 6 cost = 1 size = 0
2173 //
2174 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2175 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2176 // Pattern complexity = 6 cost = 11 size = 0
2177 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002178 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002179 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2180 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002181 unsigned Opc = 0;
2182 switch (VT.getSimpleVT().SimpleTy) {
2183 default: assert(false && "Illegal conditional move type!");
2184 break;
2185 case MVT::i32:
2186 Opc = Subtarget->isThumb()
2187 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2188 : ARM::MOVCCr;
2189 break;
2190 case MVT::f32:
2191 Opc = ARM::VMOVScc;
2192 break;
2193 case MVT::f64:
2194 Opc = ARM::VMOVDcc;
2195 break;
2196 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002197 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002198}
2199
Evan Chengde8aa4e2010-05-05 18:28:36 +00002200SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2201 // The only time a CONCAT_VECTORS operation can have legal types is when
2202 // two 64-bit vectors are concatenated to a 128-bit vector.
2203 EVT VT = N->getValueType(0);
2204 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2205 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002206 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002207}
2208
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002209SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002210 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002211
Dan Gohmane8be6c62008-07-17 19:10:17 +00002212 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002213 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002214
2215 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002216 default: break;
2217 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002218 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002219 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002220 if (Subtarget->hasThumb2())
2221 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2222 // be done with MOV + MOVT, at worst.
2223 UseCP = 0;
2224 else {
2225 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002226 UseCP = (Val > 255 && // MOV
2227 ~Val > 255 && // MOV + MVN
2228 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002229 } else
2230 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2231 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2232 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2233 }
2234
Evan Chenga8e29892007-01-19 07:51:42 +00002235 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002236 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002237 CurDAG->getTargetConstantPool(ConstantInt::get(
2238 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002239 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002240
2241 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002242 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002243 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002244 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002245 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002246 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002247 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002248 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002249 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002250 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002251 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002252 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002253 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002254 CurDAG->getEntryNode()
2255 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002256 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002257 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002258 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002259 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002260 return NULL;
2261 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002262
Evan Chenga8e29892007-01-19 07:51:42 +00002263 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002264 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002265 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002266 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002267 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002268 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002269 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002270 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002271 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2272 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002273 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002274 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2275 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002276 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2277 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2278 CurDAG->getRegister(0, MVT::i32) };
2279 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002280 }
Evan Chenga8e29892007-01-19 07:51:42 +00002281 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002282 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002283 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002284 return I;
2285 break;
2286 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002287 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002288 return I;
2289 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002290 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002291 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002292 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002293 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002294 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002295 if (!RHSV) break;
2296 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002297 unsigned ShImm = Log2_32(RHSV-1);
2298 if (ShImm >= 32)
2299 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002300 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002301 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002302 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2303 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002304 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002305 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002306 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002307 } else {
2308 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002309 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002310 }
Evan Chenga8e29892007-01-19 07:51:42 +00002311 }
2312 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002313 unsigned ShImm = Log2_32(RHSV+1);
2314 if (ShImm >= 32)
2315 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002316 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002317 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002318 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2319 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002320 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002321 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2322 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002323 } else {
2324 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002325 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002326 }
Evan Chenga8e29892007-01-19 07:51:42 +00002327 }
2328 }
2329 break;
Evan Cheng20956592009-10-21 08:15:52 +00002330 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002331 // Check for unsigned bitfield extract
2332 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2333 return I;
2334
Evan Cheng20956592009-10-21 08:15:52 +00002335 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2336 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2337 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2338 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2339 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002340 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002341 if (VT != MVT::i32)
2342 break;
2343 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2344 ? ARM::t2MOVTi16
2345 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2346 if (!Opc)
2347 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002349 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2350 if (!N1C)
2351 break;
2352 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2353 SDValue N2 = N0.getOperand(1);
2354 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2355 if (!N2C)
2356 break;
2357 unsigned N1CVal = N1C->getZExtValue();
2358 unsigned N2CVal = N2C->getZExtValue();
2359 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2360 (N1CVal & 0xffffU) == 0xffffU &&
2361 (N2CVal & 0xffffU) == 0x0U) {
2362 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2363 MVT::i32);
2364 SDValue Ops[] = { N0.getOperand(0), Imm16,
2365 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2366 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2367 }
2368 }
2369 break;
2370 }
Jim Grosbache5165492009-11-09 00:11:35 +00002371 case ARMISD::VMOVRRD:
2372 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002373 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002374 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002375 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002376 if (Subtarget->isThumb1Only())
2377 break;
2378 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002379 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002380 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2381 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002382 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002383 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002384 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002385 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2386 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002387 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2388 ARM::UMULL : ARM::UMULLv5,
2389 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002390 }
Evan Chengee568cf2007-07-05 07:15:27 +00002391 }
Dan Gohman525178c2007-10-08 18:33:35 +00002392 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002393 if (Subtarget->isThumb1Only())
2394 break;
2395 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002396 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002397 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002398 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002399 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002400 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002401 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2402 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002403 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2404 ARM::SMULL : ARM::SMULLv5,
2405 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002406 }
Evan Chengee568cf2007-07-05 07:15:27 +00002407 }
Evan Chenga8e29892007-01-19 07:51:42 +00002408 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002409 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002410 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002411 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002412 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002413 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002414 if (ResNode)
2415 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002416 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002417 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002418 }
Evan Chengee568cf2007-07-05 07:15:27 +00002419 case ARMISD::BRCOND: {
2420 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2421 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2422 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002423
Evan Chengee568cf2007-07-05 07:15:27 +00002424 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2425 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2426 // Pattern complexity = 6 cost = 1 size = 0
2427
David Goodwin5e47a9a2009-06-30 18:04:13 +00002428 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2429 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2430 // Pattern complexity = 6 cost = 1 size = 0
2431
Jim Grosbach764ab522009-08-11 15:33:49 +00002432 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002433 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002434 SDValue Chain = N->getOperand(0);
2435 SDValue N1 = N->getOperand(1);
2436 SDValue N2 = N->getOperand(2);
2437 SDValue N3 = N->getOperand(3);
2438 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002439 assert(N1.getOpcode() == ISD::BasicBlock);
2440 assert(N2.getOpcode() == ISD::Constant);
2441 assert(N3.getOpcode() == ISD::Register);
2442
Dan Gohman475871a2008-07-27 21:46:04 +00002443 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002444 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002445 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002446 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002447 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002448 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002449 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002450 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002451 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002452 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002453 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002454 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002455 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002456 return NULL;
2457 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002458 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002459 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002460 case ARMISD::VZIP: {
2461 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002462 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002463 switch (VT.getSimpleVT().SimpleTy) {
2464 default: return NULL;
2465 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2466 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2467 case MVT::v2f32:
2468 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2469 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2470 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2471 case MVT::v4f32:
2472 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2473 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002474 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002475 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2476 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2477 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002478 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002479 case ARMISD::VUZP: {
2480 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002481 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002482 switch (VT.getSimpleVT().SimpleTy) {
2483 default: return NULL;
2484 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2485 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2486 case MVT::v2f32:
2487 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2488 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2489 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2490 case MVT::v4f32:
2491 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2492 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002493 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002494 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2495 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2496 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002497 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002498 case ARMISD::VTRN: {
2499 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002500 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002501 switch (VT.getSimpleVT().SimpleTy) {
2502 default: return NULL;
2503 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2504 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2505 case MVT::v2f32:
2506 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2507 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2508 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2509 case MVT::v4f32:
2510 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2511 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002512 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002513 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2514 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2515 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002516 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002517 case ARMISD::BUILD_VECTOR: {
2518 EVT VecVT = N->getValueType(0);
2519 EVT EltVT = VecVT.getVectorElementType();
2520 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002521 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002522 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2523 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2524 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002525 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002526 if (NumElts == 2)
2527 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2528 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2529 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2530 N->getOperand(2), N->getOperand(3));
2531 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002532
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002533 case ARMISD::VLD2DUP: {
2534 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2535 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002536 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002537 }
2538
Bob Wilson86c6d802010-11-29 19:35:29 +00002539 case ARMISD::VLD3DUP: {
2540 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2541 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002542 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002543 }
2544
Bob Wilson6c4c9822010-11-30 00:00:35 +00002545 case ARMISD::VLD4DUP: {
2546 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2547 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002548 return SelectVLDDup(N, false, 4, Opcodes);
2549 }
2550
2551 case ARMISD::VLD2DUP_UPD: {
2552 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2553 ARM::VLD2DUPd32Pseudo_UPD };
2554 return SelectVLDDup(N, true, 2, Opcodes);
2555 }
2556
2557 case ARMISD::VLD3DUP_UPD: {
2558 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2559 ARM::VLD3DUPd32Pseudo_UPD };
2560 return SelectVLDDup(N, true, 3, Opcodes);
2561 }
2562
2563 case ARMISD::VLD4DUP_UPD: {
2564 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2565 ARM::VLD4DUPd32Pseudo_UPD };
2566 return SelectVLDDup(N, true, 4, Opcodes);
2567 }
2568
2569 case ARMISD::VLD1_UPD: {
2570 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2571 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2572 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2573 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2574 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2575 }
2576
2577 case ARMISD::VLD2_UPD: {
2578 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2579 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2580 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2581 ARM::VLD2q32Pseudo_UPD };
2582 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2583 }
2584
2585 case ARMISD::VLD3_UPD: {
2586 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2587 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2588 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2589 ARM::VLD3q16Pseudo_UPD,
2590 ARM::VLD3q32Pseudo_UPD };
2591 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2592 ARM::VLD3q16oddPseudo_UPD,
2593 ARM::VLD3q32oddPseudo_UPD };
2594 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2595 }
2596
2597 case ARMISD::VLD4_UPD: {
2598 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2599 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2600 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2601 ARM::VLD4q16Pseudo_UPD,
2602 ARM::VLD4q32Pseudo_UPD };
2603 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2604 ARM::VLD4q16oddPseudo_UPD,
2605 ARM::VLD4q32oddPseudo_UPD };
2606 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2607 }
2608
2609 case ARMISD::VLD2LN_UPD: {
2610 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2611 ARM::VLD2LNd32Pseudo_UPD };
2612 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2613 ARM::VLD2LNq32Pseudo_UPD };
2614 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2615 }
2616
2617 case ARMISD::VLD3LN_UPD: {
2618 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2619 ARM::VLD3LNd32Pseudo_UPD };
2620 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2621 ARM::VLD3LNq32Pseudo_UPD };
2622 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2623 }
2624
2625 case ARMISD::VLD4LN_UPD: {
2626 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2627 ARM::VLD4LNd32Pseudo_UPD };
2628 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2629 ARM::VLD4LNq32Pseudo_UPD };
2630 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2631 }
2632
2633 case ARMISD::VST1_UPD: {
2634 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2635 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2636 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2637 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2638 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2639 }
2640
2641 case ARMISD::VST2_UPD: {
2642 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2643 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2644 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2645 ARM::VST2q32Pseudo_UPD };
2646 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2647 }
2648
2649 case ARMISD::VST3_UPD: {
2650 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2651 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2652 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2653 ARM::VST3q16Pseudo_UPD,
2654 ARM::VST3q32Pseudo_UPD };
2655 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2656 ARM::VST3q16oddPseudo_UPD,
2657 ARM::VST3q32oddPseudo_UPD };
2658 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2659 }
2660
2661 case ARMISD::VST4_UPD: {
2662 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2663 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2664 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2665 ARM::VST4q16Pseudo_UPD,
2666 ARM::VST4q32Pseudo_UPD };
2667 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2668 ARM::VST4q16oddPseudo_UPD,
2669 ARM::VST4q32oddPseudo_UPD };
2670 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2671 }
2672
2673 case ARMISD::VST2LN_UPD: {
2674 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2675 ARM::VST2LNd32Pseudo_UPD };
2676 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2677 ARM::VST2LNq32Pseudo_UPD };
2678 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2679 }
2680
2681 case ARMISD::VST3LN_UPD: {
2682 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2683 ARM::VST3LNd32Pseudo_UPD };
2684 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2685 ARM::VST3LNq32Pseudo_UPD };
2686 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2687 }
2688
2689 case ARMISD::VST4LN_UPD: {
2690 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2691 ARM::VST4LNd32Pseudo_UPD };
2692 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2693 ARM::VST4LNq32Pseudo_UPD };
2694 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002695 }
2696
Bob Wilson31fb12f2009-08-26 17:39:53 +00002697 case ISD::INTRINSIC_VOID:
2698 case ISD::INTRINSIC_W_CHAIN: {
2699 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002700 switch (IntNo) {
2701 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002702 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002703
Bob Wilson621f1952010-03-23 05:25:43 +00002704 case Intrinsic::arm_neon_vld1: {
2705 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2706 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002707 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2708 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002709 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002710 }
2711
Bob Wilson31fb12f2009-08-26 17:39:53 +00002712 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002713 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2714 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2715 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2716 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002717 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002718 }
2719
2720 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002721 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2722 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2723 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2724 ARM::VLD3q16Pseudo_UPD,
2725 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002726 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2727 ARM::VLD3q16oddPseudo,
2728 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002729 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002730 }
2731
2732 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002733 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2734 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2735 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2736 ARM::VLD4q16Pseudo_UPD,
2737 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002738 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2739 ARM::VLD4q16oddPseudo,
2740 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002741 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002742 }
2743
Bob Wilson243fcc52009-09-01 04:26:28 +00002744 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002745 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2746 ARM::VLD2LNd32Pseudo };
2747 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002748 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002749 }
2750
2751 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002752 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2753 ARM::VLD3LNd32Pseudo };
2754 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002755 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002756 }
2757
2758 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002759 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2760 ARM::VLD4LNd32Pseudo };
2761 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002762 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002763 }
2764
Bob Wilson11d98992010-03-23 06:20:33 +00002765 case Intrinsic::arm_neon_vst1: {
2766 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2767 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002768 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2769 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002770 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002771 }
2772
Bob Wilson31fb12f2009-08-26 17:39:53 +00002773 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002774 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2775 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2776 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2777 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002778 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002779 }
2780
2781 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002782 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2783 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2784 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2785 ARM::VST3q16Pseudo_UPD,
2786 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002787 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
2788 ARM::VST3q16oddPseudo,
2789 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002790 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002791 }
2792
2793 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002794 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002795 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002796 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2797 ARM::VST4q16Pseudo_UPD,
2798 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002799 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
2800 ARM::VST4q16oddPseudo,
2801 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002802 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002803 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002804
2805 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002806 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2807 ARM::VST2LNd32Pseudo };
2808 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002809 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002810 }
2811
2812 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002813 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2814 ARM::VST3LNd32Pseudo };
2815 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002816 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002817 }
2818
2819 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002820 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2821 ARM::VST4LNd32Pseudo };
2822 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002823 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002824 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002825 }
Bob Wilson429009b2010-05-06 16:05:26 +00002826 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002827 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002828
Bob Wilsond491d6e2010-07-06 23:36:25 +00002829 case ISD::INTRINSIC_WO_CHAIN: {
2830 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2831 switch (IntNo) {
2832 default:
2833 break;
2834
2835 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002836 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002837 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002838 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002839 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002840 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002841
2842 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002843 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002844 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002845 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002846 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002847 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002848 }
2849 break;
2850 }
2851
Bill Wendling69a05a72011-03-14 23:02:38 +00002852 case ARMISD::VTBL1: {
2853 DebugLoc dl = N->getDebugLoc();
2854 EVT VT = N->getValueType(0);
2855 SmallVector<SDValue, 6> Ops;
2856
2857 Ops.push_back(N->getOperand(0));
2858 Ops.push_back(N->getOperand(1));
2859 Ops.push_back(getAL(CurDAG)); // Predicate
2860 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2861 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
2862 }
2863 case ARMISD::VTBL2: {
2864 DebugLoc dl = N->getDebugLoc();
2865 EVT VT = N->getValueType(0);
2866
2867 // Form a REG_SEQUENCE to force register allocation.
2868 SDValue V0 = N->getOperand(0);
2869 SDValue V1 = N->getOperand(1);
2870 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2871
2872 SmallVector<SDValue, 6> Ops;
2873 Ops.push_back(RegSeq);
2874 Ops.push_back(N->getOperand(2));
2875 Ops.push_back(getAL(CurDAG)); // Predicate
2876 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
2877 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
2878 Ops.data(), Ops.size());
2879 }
2880
Bob Wilson429009b2010-05-06 16:05:26 +00002881 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002882 return SelectConcatVector(N);
2883 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002884
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002885 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002886}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002887
Bob Wilson224c2442009-05-19 05:53:42 +00002888bool ARMDAGToDAGISel::
2889SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2890 std::vector<SDValue> &OutOps) {
2891 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002892 // Require the address to be in a register. That is safe for all ARM
2893 // variants and it is hard to do anything much smarter without knowing
2894 // how the operand is used.
2895 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002896 return false;
2897}
2898
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002899/// createARMISelDag - This pass converts a legalized DAG into a
2900/// ARM-specific DAG, ready for instruction scheduling.
2901///
Bob Wilson522ce972009-09-28 14:30:20 +00002902FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2903 CodeGenOpt::Level OptLevel) {
2904 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002905}