blob: 73a4322b820741539ec2cb859f926a8076b85eef [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000107 }
108
Jim Grosbach3e556122010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach82891622010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
Owen Anderson793e7962011-07-26 20:54:26 +0000132 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
133 SDValue &Offset, SDValue &Opc);
134 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000136 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
137 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000138 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000144 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000145 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000146 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000147
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000148 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000152 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
153 unsigned Scale);
154 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
156 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
157 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
158 SDValue &OffImm);
159 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
160 SDValue &OffImm);
161 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
162 SDValue &OffImm);
163 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
164 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000166
Bill Wendlingf4caf692010-12-14 03:36:38 +0000167 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000168 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000169 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
171 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000172 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000173 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000174 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000176 SDValue &OffReg, SDValue &ShImm);
177
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 inline bool is_so_imm(unsigned Imm) const {
179 return ARM_AM::getSOImmVal(Imm) != -1;
180 }
181
182 inline bool is_so_imm_not(unsigned Imm) const {
183 return ARM_AM::getSOImmVal(~Imm) != -1;
184 }
185
186 inline bool is_t2_so_imm(unsigned Imm) const {
187 return ARM_AM::getT2SOImmVal(Imm) != -1;
188 }
189
190 inline bool is_t2_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getT2SOImmVal(~Imm) != -1;
192 }
193
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000194 // Include the pieces autogenerated from the target description.
195#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000196
197private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000198 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
199 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000200 SDNode *SelectARMIndexedLoad(SDNode *N);
201 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000202
Bob Wilson621f1952010-03-23 05:25:43 +0000203 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
204 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000205 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000207 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
208 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000209 unsigned *QOpcodes0, unsigned *QOpcodes1);
210
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000213 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000214 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000215 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
216 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000217 unsigned *QOpcodes0, unsigned *QOpcodes1);
218
Bob Wilson96493442009-10-14 16:46:45 +0000219 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000220 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000221 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000222 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
223 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000224 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000226 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
227 /// should be 2, 3 or 4. The opcode array specifies the instructions used
228 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000229 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
230 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231
Bob Wilson78dfbc32010-07-07 00:08:54 +0000232 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
233 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
234 /// generated to force the table registers to be consecutive.
235 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000236
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000237 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000238 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000239
Evan Cheng07ba9062009-11-19 21:45:22 +0000240 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000241 SDNode *SelectCMOVOp(SDNode *N);
242 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000243 ARMCC::CondCodes CCVal, SDValue CCR,
244 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000245 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000248 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000251 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000254
Evan Chengde8aa4e2010-05-05 18:28:36 +0000255 SDNode *SelectConcatVector(SDNode *N);
256
Eli Friedman2bdffe42011-08-31 00:31:29 +0000257 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
258
Evan Chengaf4550f2009-07-02 01:23:32 +0000259 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
260 /// inline asm expressions.
261 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
262 char ConstraintCode,
263 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000264
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000265 // Form pairs of consecutive S, D, or Q registers.
266 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000267 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000268 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
269
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000270 // Form sequences of 4 consecutive S, D, or Q registers.
271 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000272 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000273 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000274
275 // Get the alignment operand for a NEON VLD or VST instruction.
276 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000277};
Evan Chenga8e29892007-01-19 07:51:42 +0000278}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000279
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000280/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
281/// operand. If so Imm will receive the 32-bit value.
282static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
283 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
284 Imm = cast<ConstantSDNode>(N)->getZExtValue();
285 return true;
286 }
287 return false;
288}
289
290// isInt32Immediate - This method tests to see if a constant operand.
291// If so Imm will receive the 32 bit value.
292static bool isInt32Immediate(SDValue N, unsigned &Imm) {
293 return isInt32Immediate(N.getNode(), Imm);
294}
295
296// isOpcWithIntImmediate - This method tests to see if the node is a specific
297// opcode and that it has a immediate integer right operand.
298// If so Imm will receive the 32 bit value.
299static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
300 return N->getOpcode() == Opc &&
301 isInt32Immediate(N->getOperand(1).getNode(), Imm);
302}
303
Daniel Dunbarec91d522011-01-19 15:12:16 +0000304/// \brief Check whether a particular node is a constant value representable as
305/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
306///
307/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
308static bool isScaledConstantInRange(SDValue Node, unsigned Scale,
309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
311 assert(Scale && "Invalid scale!");
312
313 // Check that this is a constant.
314 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
315 if (!C)
316 return false;
317
318 ScaledConstant = (int) C->getZExtValue();
319 if ((ScaledConstant % Scale) != 0)
320 return false;
321
322 ScaledConstant /= Scale;
323 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
324}
325
Evan Cheng48575f62010-12-05 22:04:16 +0000326/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
327/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
328/// least on current ARM implementations) which should be avoidded.
329bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
330 if (OptLevel == CodeGenOpt::None)
331 return true;
332
333 if (!CheckVMLxHazard)
334 return true;
335
336 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
337 return true;
338
339 if (!N->hasOneUse())
340 return false;
341
342 SDNode *Use = *N->use_begin();
343 if (Use->getOpcode() == ISD::CopyToReg)
344 return true;
345 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000346 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
347 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000348 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000349 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000350 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
351 return true;
352 // vmlx feeding into another vmlx. We actually want to unfold
353 // the use later in the MLxExpansion pass. e.g.
354 // vmla
355 // vmla (stall 8 cycles)
356 //
357 // vmul (5 cycles)
358 // vadd (5 cycles)
359 // vmla
360 // This adds up to about 18 - 19 cycles.
361 //
362 // vmla
363 // vmul (stall 4 cycles)
364 // vadd adds up to about 14 cycles.
365 return TII->isFpMLxInstruction(Opcode);
366 }
367
368 return false;
369}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000370
Evan Chengf40deed2010-10-27 23:41:30 +0000371bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
372 ARM_AM::ShiftOpc ShOpcVal,
373 unsigned ShAmt) {
374 if (!Subtarget->isCortexA9())
375 return true;
376 if (Shift.hasOneUse())
377 return true;
378 // R << 2 is free.
379 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
380}
381
Owen Anderson92a20222011-07-21 18:54:16 +0000382bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000383 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000384 SDValue &Opc,
385 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000386 if (DisableShifterOp)
387 return false;
388
Evan Chengee04a6d2011-07-20 23:34:39 +0000389 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000390
391 // Don't match base register only case. That is matched to a separate
392 // lower complexity pattern with explicit register operand.
393 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000394
Evan Cheng055b0312009-06-29 07:51:04 +0000395 BaseReg = N.getOperand(0);
396 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000397 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
398 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000399 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000400 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
401 MVT::i32);
402 return true;
403}
404
Owen Anderson92a20222011-07-21 18:54:16 +0000405bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
406 SDValue &BaseReg,
407 SDValue &ShReg,
408 SDValue &Opc,
409 bool CheckProfitability) {
410 if (DisableShifterOp)
411 return false;
412
413 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
414
415 // Don't match base register only case. That is matched to a separate
416 // lower complexity pattern with explicit register operand.
417 if (ShOpcVal == ARM_AM::no_shift) return false;
418
419 BaseReg = N.getOperand(0);
420 unsigned ShImmVal = 0;
421 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
422 if (RHS) return false;
423
424 ShReg = N.getOperand(1);
425 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
426 return false;
427 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
428 MVT::i32);
429 return true;
430}
431
432
Jim Grosbach3e556122010-10-26 22:37:02 +0000433bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
434 SDValue &Base,
435 SDValue &OffImm) {
436 // Match simple R + imm12 operands.
437
438 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000439 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
440 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000441 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000442 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000443 int FI = cast<FrameIndexSDNode>(N)->getIndex();
444 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
445 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
446 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000447 }
Owen Anderson099e5552011-03-18 19:46:58 +0000448
Chris Lattner0a9481f2011-02-13 22:25:43 +0000449 if (N.getOpcode() == ARMISD::Wrapper &&
450 !(Subtarget->useMovt() &&
451 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000452 Base = N.getOperand(0);
453 } else
454 Base = N;
455 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
456 return true;
457 }
458
459 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
460 int RHSC = (int)RHS->getZExtValue();
461 if (N.getOpcode() == ISD::SUB)
462 RHSC = -RHSC;
463
464 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
465 Base = N.getOperand(0);
466 if (Base.getOpcode() == ISD::FrameIndex) {
467 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
468 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
469 }
470 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
471 return true;
472 }
473 }
474
475 // Base only.
476 Base = N;
477 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
478 return true;
479}
480
481
482
483bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
484 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000485 if (N.getOpcode() == ISD::MUL &&
486 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000487 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
488 // X * [3,5,9] -> X + X * [2,4,8] etc.
489 int RHSC = (int)RHS->getZExtValue();
490 if (RHSC & 1) {
491 RHSC = RHSC & ~1;
492 ARM_AM::AddrOpc AddSub = ARM_AM::add;
493 if (RHSC < 0) {
494 AddSub = ARM_AM::sub;
495 RHSC = - RHSC;
496 }
497 if (isPowerOf2_32(RHSC)) {
498 unsigned ShAmt = Log2_32(RHSC);
499 Base = Offset = N.getOperand(0);
500 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
501 ARM_AM::lsl),
502 MVT::i32);
503 return true;
504 }
505 }
506 }
507 }
508
Chris Lattner0a9481f2011-02-13 22:25:43 +0000509 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
510 // ISD::OR that is equivalent to an ISD::ADD.
511 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000512 return false;
513
514 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000515 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000516 int RHSC;
517 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
518 -0x1000+1, 0x1000, RHSC)) // 12 bits.
519 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 }
521
Evan Chengf40deed2010-10-27 23:41:30 +0000522 if (Subtarget->isCortexA9() && !N.hasOneUse())
523 // Compute R +/- (R << N) and reuse it.
524 return false;
525
Jim Grosbach3e556122010-10-26 22:37:02 +0000526 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000527 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000528 ARM_AM::ShiftOpc ShOpcVal =
529 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000530 unsigned ShAmt = 0;
531
532 Base = N.getOperand(0);
533 Offset = N.getOperand(1);
534
535 if (ShOpcVal != ARM_AM::no_shift) {
536 // Check to see if the RHS of the shift is a constant, if not, we can't fold
537 // it.
538 if (ConstantSDNode *Sh =
539 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
540 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000541 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
542 Offset = N.getOperand(1).getOperand(0);
543 else {
544 ShAmt = 0;
545 ShOpcVal = ARM_AM::no_shift;
546 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000547 } else {
548 ShOpcVal = ARM_AM::no_shift;
549 }
550 }
551
552 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000553 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000554 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000555 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000556 if (ShOpcVal != ARM_AM::no_shift) {
557 // Check to see if the RHS of the shift is a constant, if not, we can't
558 // fold it.
559 if (ConstantSDNode *Sh =
560 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
561 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000562 if (!Subtarget->isCortexA9() ||
563 (N.hasOneUse() &&
564 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
565 Offset = N.getOperand(0).getOperand(0);
566 Base = N.getOperand(1);
567 } else {
568 ShAmt = 0;
569 ShOpcVal = ARM_AM::no_shift;
570 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000571 } else {
572 ShOpcVal = ARM_AM::no_shift;
573 }
574 }
575 }
576
577 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
578 MVT::i32);
579 return true;
580}
581
582
583
584
585//-----
586
Jim Grosbach82891622010-09-29 19:03:54 +0000587AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
588 SDValue &Base,
589 SDValue &Offset,
590 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000591 if (N.getOpcode() == ISD::MUL &&
592 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000593 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
594 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000595 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000596 if (RHSC & 1) {
597 RHSC = RHSC & ~1;
598 ARM_AM::AddrOpc AddSub = ARM_AM::add;
599 if (RHSC < 0) {
600 AddSub = ARM_AM::sub;
601 RHSC = - RHSC;
602 }
603 if (isPowerOf2_32(RHSC)) {
604 unsigned ShAmt = Log2_32(RHSC);
605 Base = Offset = N.getOperand(0);
606 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
607 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000608 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000609 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000610 }
611 }
612 }
613 }
614
Chris Lattner0a9481f2011-02-13 22:25:43 +0000615 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
616 // ISD::OR that is equivalent to an ADD.
617 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000618 Base = N;
619 if (N.getOpcode() == ISD::FrameIndex) {
620 int FI = cast<FrameIndexSDNode>(N)->getIndex();
621 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000622 } else if (N.getOpcode() == ARMISD::Wrapper &&
623 !(Subtarget->useMovt() &&
624 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000625 Base = N.getOperand(0);
626 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000627 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000628 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
629 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000630 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000631 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000632 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000633
Evan Chenga8e29892007-01-19 07:51:42 +0000634 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000635 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000636 int RHSC;
637 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
638 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
639 Base = N.getOperand(0);
640 if (Base.getOpcode() == ISD::FrameIndex) {
641 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
642 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000643 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000644 Offset = CurDAG->getRegister(0, MVT::i32);
645
646 ARM_AM::AddrOpc AddSub = ARM_AM::add;
647 if (RHSC < 0) {
648 AddSub = ARM_AM::sub;
649 RHSC = - RHSC;
650 }
651 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
652 ARM_AM::no_shift),
653 MVT::i32);
654 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000655 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000656 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000657
Evan Chengf40deed2010-10-27 23:41:30 +0000658 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
659 // Compute R +/- (R << N) and reuse it.
660 Base = N;
661 Offset = CurDAG->getRegister(0, MVT::i32);
662 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
663 ARM_AM::no_shift),
664 MVT::i32);
665 return AM2_BASE;
666 }
667
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000668 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000669 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000670 ARM_AM::ShiftOpc ShOpcVal =
671 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000672 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000673
Evan Chenga8e29892007-01-19 07:51:42 +0000674 Base = N.getOperand(0);
675 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000676
Evan Chenga8e29892007-01-19 07:51:42 +0000677 if (ShOpcVal != ARM_AM::no_shift) {
678 // Check to see if the RHS of the shift is a constant, if not, we can't fold
679 // it.
680 if (ConstantSDNode *Sh =
681 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000682 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000683 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
684 Offset = N.getOperand(1).getOperand(0);
685 else {
686 ShAmt = 0;
687 ShOpcVal = ARM_AM::no_shift;
688 }
Evan Chenga8e29892007-01-19 07:51:42 +0000689 } else {
690 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000691 }
692 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000693
Evan Chenga8e29892007-01-19 07:51:42 +0000694 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000695 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000696 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000697 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000698 if (ShOpcVal != ARM_AM::no_shift) {
699 // Check to see if the RHS of the shift is a constant, if not, we can't
700 // fold it.
701 if (ConstantSDNode *Sh =
702 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000703 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000704 if (!Subtarget->isCortexA9() ||
705 (N.hasOneUse() &&
706 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
707 Offset = N.getOperand(0).getOperand(0);
708 Base = N.getOperand(1);
709 } else {
710 ShAmt = 0;
711 ShOpcVal = ARM_AM::no_shift;
712 }
Evan Chenga8e29892007-01-19 07:51:42 +0000713 } else {
714 ShOpcVal = ARM_AM::no_shift;
715 }
716 }
717 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000718
Evan Chenga8e29892007-01-19 07:51:42 +0000719 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000720 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000721 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000722}
723
Owen Anderson793e7962011-07-26 20:54:26 +0000724bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000725 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000726 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000727 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
728 ? cast<LoadSDNode>(Op)->getAddressingMode()
729 : cast<StoreSDNode>(Op)->getAddressingMode();
730 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
731 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000732 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000733 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
734 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000735
736 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000737 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000738 unsigned ShAmt = 0;
739 if (ShOpcVal != ARM_AM::no_shift) {
740 // Check to see if the RHS of the shift is a constant, if not, we can't fold
741 // it.
742 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000743 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000744 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
745 Offset = N.getOperand(0);
746 else {
747 ShAmt = 0;
748 ShOpcVal = ARM_AM::no_shift;
749 }
Evan Chenga8e29892007-01-19 07:51:42 +0000750 } else {
751 ShOpcVal = ARM_AM::no_shift;
752 }
753 }
754
755 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000756 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000757 return true;
758}
759
Owen Andersonc4e16de2011-08-29 20:16:50 +0000760bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
761 SDValue &Offset, SDValue &Opc) {
762 int Val;
763 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
764 Offset = CurDAG->getRegister(0, MVT::i32);
765 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
766 return true;
767 }
768
769 return false;
770}
771
772
Owen Anderson793e7962011-07-26 20:54:26 +0000773bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
774 SDValue &Offset, SDValue &Opc) {
775 unsigned Opcode = Op->getOpcode();
776 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
777 ? cast<LoadSDNode>(Op)->getAddressingMode()
778 : cast<StoreSDNode>(Op)->getAddressingMode();
779 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
780 ? ARM_AM::add : ARM_AM::sub;
781 int Val;
782 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
783 Offset = CurDAG->getRegister(0, MVT::i32);
784 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
785 ARM_AM::no_shift),
786 MVT::i32);
787 return true;
788 }
789
790 return false;
791}
792
Jim Grosbach19dec202011-08-05 20:35:44 +0000793bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
794 Base = N;
795 return true;
796}
Evan Chenga8e29892007-01-19 07:51:42 +0000797
Chris Lattner52a261b2010-09-21 20:31:19 +0000798bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000799 SDValue &Base, SDValue &Offset,
800 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000801 if (N.getOpcode() == ISD::SUB) {
802 // X - C is canonicalize to X + -C, no need to handle it here.
803 Base = N.getOperand(0);
804 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000805 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000806 return true;
807 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000808
Chris Lattner0a9481f2011-02-13 22:25:43 +0000809 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000810 Base = N;
811 if (N.getOpcode() == ISD::FrameIndex) {
812 int FI = cast<FrameIndexSDNode>(N)->getIndex();
813 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
814 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000815 Offset = CurDAG->getRegister(0, MVT::i32);
816 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000817 return true;
818 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000819
Evan Chenga8e29892007-01-19 07:51:42 +0000820 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000821 int RHSC;
822 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
823 -256 + 1, 256, RHSC)) { // 8 bits.
824 Base = N.getOperand(0);
825 if (Base.getOpcode() == ISD::FrameIndex) {
826 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
827 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000828 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000829 Offset = CurDAG->getRegister(0, MVT::i32);
830
831 ARM_AM::AddrOpc AddSub = ARM_AM::add;
832 if (RHSC < 0) {
833 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000834 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000835 }
836 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
837 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000838 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000839
Evan Chenga8e29892007-01-19 07:51:42 +0000840 Base = N.getOperand(0);
841 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000842 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000843 return true;
844}
845
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000846bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000847 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000848 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000849 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
850 ? cast<LoadSDNode>(Op)->getAddressingMode()
851 : cast<StoreSDNode>(Op)->getAddressingMode();
852 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
853 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000854 int Val;
855 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
856 Offset = CurDAG->getRegister(0, MVT::i32);
857 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
858 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000859 }
860
861 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000863 return true;
864}
865
Jim Grosbach3ab56582010-10-21 19:38:40 +0000866bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000867 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000868 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000869 Base = N;
870 if (N.getOpcode() == ISD::FrameIndex) {
871 int FI = cast<FrameIndexSDNode>(N)->getIndex();
872 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000873 } else if (N.getOpcode() == ARMISD::Wrapper &&
874 !(Subtarget->useMovt() &&
875 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000876 Base = N.getOperand(0);
877 }
878 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000880 return true;
881 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000882
Evan Chenga8e29892007-01-19 07:51:42 +0000883 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000884 int RHSC;
885 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
886 -256 + 1, 256, RHSC)) {
887 Base = N.getOperand(0);
888 if (Base.getOpcode() == ISD::FrameIndex) {
889 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
890 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000891 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000892
893 ARM_AM::AddrOpc AddSub = ARM_AM::add;
894 if (RHSC < 0) {
895 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000896 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000897 }
898 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
899 MVT::i32);
900 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000901 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000902
Evan Chenga8e29892007-01-19 07:51:42 +0000903 Base = N;
904 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000905 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000906 return true;
907}
908
Bob Wilson665814b2010-11-01 23:40:51 +0000909bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
910 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000911 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000912
913 unsigned Alignment = 0;
914 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
915 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
916 // The maximum alignment is equal to the memory size being referenced.
917 unsigned LSNAlign = LSN->getAlignment();
918 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
919 if (LSNAlign > MemSize && MemSize > 1)
920 Alignment = MemSize;
921 } else {
922 // All other uses of addrmode6 are for intrinsics. For now just record
923 // the raw alignment value; it will be refined later based on the legal
924 // alignment operands for the intrinsic.
925 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
926 }
927
928 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000929 return true;
930}
931
Bob Wilsonda525062011-02-25 06:42:42 +0000932bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
933 SDValue &Offset) {
934 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
935 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
936 if (AM != ISD::POST_INC)
937 return false;
938 Offset = N;
939 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
940 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
941 Offset = CurDAG->getRegister(0, MVT::i32);
942 }
943 return true;
944}
945
Chris Lattner52a261b2010-09-21 20:31:19 +0000946bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000947 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000948 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
949 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000950 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000951 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
952 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000953 return true;
954 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000955
Evan Chenga8e29892007-01-19 07:51:42 +0000956 return false;
957}
958
Bill Wendlingf4caf692010-12-14 03:36:38 +0000959
960//===----------------------------------------------------------------------===//
961// Thumb Addressing Modes
962//===----------------------------------------------------------------------===//
963
Chris Lattner52a261b2010-09-21 20:31:19 +0000964bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000965 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000966 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000967 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000968 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000969 return false;
970
971 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000972 return true;
973 }
974
Evan Chenga8e29892007-01-19 07:51:42 +0000975 Base = N.getOperand(0);
976 Offset = N.getOperand(1);
977 return true;
978}
979
Evan Cheng79d43262007-01-24 02:21:22 +0000980bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000981ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
982 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000983 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000984 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000985 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000986 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000987
Evan Cheng012f2d92007-01-24 08:53:17 +0000988 if (N.getOpcode() == ARMISD::Wrapper &&
989 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
990 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000991 }
992
Chris Lattner0a9481f2011-02-13 22:25:43 +0000993 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000994 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000995
Evan Chengad0e4652007-02-06 00:22:06 +0000996 // Thumb does not have [sp, r] address mode.
997 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
998 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
999 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001000 (RHSR && RHSR->getReg() == ARM::SP))
1001 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001002
Daniel Dunbarec91d522011-01-19 15:12:16 +00001003 // FIXME: Why do we explicitly check for a match here and then return false?
1004 // Presumably to allow something else to match, but shouldn't this be
1005 // documented?
1006 int RHSC;
1007 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1008 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001009
1010 Base = N.getOperand(0);
1011 Offset = N.getOperand(1);
1012 return true;
1013}
1014
1015bool
1016ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1017 SDValue &Base,
1018 SDValue &Offset) {
1019 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1020}
1021
1022bool
1023ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1024 SDValue &Base,
1025 SDValue &Offset) {
1026 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1027}
1028
1029bool
1030ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1031 SDValue &Base,
1032 SDValue &Offset) {
1033 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1034}
1035
1036bool
1037ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1038 SDValue &Base, SDValue &OffImm) {
1039 if (Scale == 4) {
1040 SDValue TmpBase, TmpOffImm;
1041 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1042 return false; // We want to select tLDRspi / tSTRspi instead.
1043
1044 if (N.getOpcode() == ARMISD::Wrapper &&
1045 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1046 return false; // We want to select tLDRpci instead.
1047 }
1048
Chris Lattner0a9481f2011-02-13 22:25:43 +00001049 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001050 if (N.getOpcode() == ARMISD::Wrapper &&
1051 !(Subtarget->useMovt() &&
1052 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1053 Base = N.getOperand(0);
1054 } else {
1055 Base = N;
1056 }
1057
Owen Anderson825b72b2009-08-11 20:47:22 +00001058 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001059 return true;
1060 }
1061
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001062 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1063 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1064 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1065 (RHSR && RHSR->getReg() == ARM::SP)) {
1066 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1067 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1068 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1069 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1070
1071 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1072 if (LHSC != 0 || RHSC != 0) return false;
1073
1074 Base = N;
1075 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1076 return true;
1077 }
1078
Evan Chenga8e29892007-01-19 07:51:42 +00001079 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001080 int RHSC;
1081 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1082 Base = N.getOperand(0);
1083 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1084 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001085 }
1086
Evan Chengc38f2bc2007-01-23 22:59:13 +00001087 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001088 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001089 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001090}
1091
Bill Wendlingf4caf692010-12-14 03:36:38 +00001092bool
1093ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1094 SDValue &OffImm) {
1095 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001096}
1097
Bill Wendlingf4caf692010-12-14 03:36:38 +00001098bool
1099ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1100 SDValue &OffImm) {
1101 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001102}
1103
Bill Wendlingf4caf692010-12-14 03:36:38 +00001104bool
1105ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1106 SDValue &OffImm) {
1107 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001108}
1109
Chris Lattner52a261b2010-09-21 20:31:19 +00001110bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1111 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001112 if (N.getOpcode() == ISD::FrameIndex) {
1113 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1114 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001115 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001116 return true;
1117 }
Evan Cheng79d43262007-01-24 02:21:22 +00001118
Chris Lattner0a9481f2011-02-13 22:25:43 +00001119 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001120 return false;
1121
1122 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001123 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1124 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001125 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001126 int RHSC;
1127 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1128 Base = N.getOperand(0);
1129 if (Base.getOpcode() == ISD::FrameIndex) {
1130 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1131 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001132 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001133 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1134 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001135 }
1136 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001137
Evan Chenga8e29892007-01-19 07:51:42 +00001138 return false;
1139}
1140
Bill Wendlingf4caf692010-12-14 03:36:38 +00001141
1142//===----------------------------------------------------------------------===//
1143// Thumb 2 Addressing Modes
1144//===----------------------------------------------------------------------===//
1145
1146
Chris Lattner52a261b2010-09-21 20:31:19 +00001147bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001148 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001149 if (DisableShifterOp)
1150 return false;
1151
Evan Chengee04a6d2011-07-20 23:34:39 +00001152 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001153
1154 // Don't match base register only case. That is matched to a separate
1155 // lower complexity pattern with explicit register operand.
1156 if (ShOpcVal == ARM_AM::no_shift) return false;
1157
1158 BaseReg = N.getOperand(0);
1159 unsigned ShImmVal = 0;
1160 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1161 ShImmVal = RHS->getZExtValue() & 31;
1162 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1163 return true;
1164 }
1165
1166 return false;
1167}
1168
Chris Lattner52a261b2010-09-21 20:31:19 +00001169bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001170 SDValue &Base, SDValue &OffImm) {
1171 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001172
Evan Cheng3a214252009-08-11 08:52:18 +00001173 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001174 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1175 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001176 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001177 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001178 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1179 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001180 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001181 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001182 }
Owen Anderson099e5552011-03-18 19:46:58 +00001183
Chris Lattner0a9481f2011-02-13 22:25:43 +00001184 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001185 !(Subtarget->useMovt() &&
1186 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001187 Base = N.getOperand(0);
1188 if (Base.getOpcode() == ISD::TargetConstantPool)
1189 return false; // We want to select t2LDRpci instead.
1190 } else
1191 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001192 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001193 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001194 }
Evan Cheng055b0312009-06-29 07:51:04 +00001195
1196 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001197 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001198 // Let t2LDRi8 handle (R - imm8).
1199 return false;
1200
Evan Cheng055b0312009-06-29 07:51:04 +00001201 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001202 if (N.getOpcode() == ISD::SUB)
1203 RHSC = -RHSC;
1204
1205 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001206 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001207 if (Base.getOpcode() == ISD::FrameIndex) {
1208 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1209 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1210 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001211 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001212 return true;
1213 }
1214 }
1215
Evan Cheng3a214252009-08-11 08:52:18 +00001216 // Base only.
1217 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001218 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001219 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001220}
1221
Chris Lattner52a261b2010-09-21 20:31:19 +00001222bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001223 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001224 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001225 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1226 !CurDAG->isBaseWithConstantOffset(N))
1227 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001228
Chris Lattner0a9481f2011-02-13 22:25:43 +00001229 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1230 int RHSC = (int)RHS->getSExtValue();
1231 if (N.getOpcode() == ISD::SUB)
1232 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001233
Chris Lattner0a9481f2011-02-13 22:25:43 +00001234 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1235 Base = N.getOperand(0);
1236 if (Base.getOpcode() == ISD::FrameIndex) {
1237 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1238 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001239 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001240 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1241 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001242 }
1243 }
1244
1245 return false;
1246}
1247
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001248bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001249 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001250 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001251 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1252 ? cast<LoadSDNode>(Op)->getAddressingMode()
1253 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001254 int RHSC;
1255 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1256 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1257 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1258 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1259 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001260 }
1261
1262 return false;
1263}
1264
Chris Lattner52a261b2010-09-21 20:31:19 +00001265bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001266 SDValue &Base,
1267 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001268 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001269 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001270 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001271
Evan Cheng3a214252009-08-11 08:52:18 +00001272 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1274 int RHSC = (int)RHS->getZExtValue();
1275 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1276 return false;
1277 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001278 return false;
1279 }
1280
Evan Chengf40deed2010-10-27 23:41:30 +00001281 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1282 // Compute R + (R << [1,2,3]) and reuse it.
1283 Base = N;
1284 return false;
1285 }
1286
Evan Cheng055b0312009-06-29 07:51:04 +00001287 // Look for (R + R) or (R + (R << [1,2,3])).
1288 unsigned ShAmt = 0;
1289 Base = N.getOperand(0);
1290 OffReg = N.getOperand(1);
1291
1292 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001293 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001294 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001295 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001296 if (ShOpcVal == ARM_AM::lsl)
1297 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001298 }
1299
Evan Cheng055b0312009-06-29 07:51:04 +00001300 if (ShOpcVal == ARM_AM::lsl) {
1301 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1302 // it.
1303 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1304 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001305 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1306 OffReg = OffReg.getOperand(0);
1307 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001308 ShAmt = 0;
1309 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001310 }
Evan Cheng055b0312009-06-29 07:51:04 +00001311 } else {
1312 ShOpcVal = ARM_AM::no_shift;
1313 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001314 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001315
Owen Anderson825b72b2009-08-11 20:47:22 +00001316 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001317
1318 return true;
1319}
1320
1321//===--------------------------------------------------------------------===//
1322
Evan Chengee568cf2007-07-05 07:15:27 +00001323/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001324static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001325 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001326}
1327
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001328SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1329 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001330 ISD::MemIndexedMode AM = LD->getAddressingMode();
1331 if (AM == ISD::UNINDEXED)
1332 return NULL;
1333
Owen Andersone50ed302009-08-10 22:56:29 +00001334 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001335 SDValue Offset, AMOpc;
1336 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1337 unsigned Opcode = 0;
1338 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001339 if (LoadedVT == MVT::i32 && isPre &&
1340 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1341 Opcode = ARM::LDR_PRE_IMM;
1342 Match = true;
1343 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001344 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001345 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001346 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001347 } else if (LoadedVT == MVT::i32 &&
1348 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001349 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001350 Match = true;
1351
Owen Anderson825b72b2009-08-11 20:47:22 +00001352 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001353 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001354 Match = true;
1355 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1356 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1357 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001358 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001359 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001360 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001361 Match = true;
1362 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1363 }
1364 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001365 if (isPre &&
1366 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001367 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001368 Opcode = ARM::LDRB_PRE_IMM;
1369 } else if (!isPre &&
1370 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1371 Match = true;
1372 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001373 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1374 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001375 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001376 }
1377 }
1378 }
1379
1380 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001381 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1382 SDValue Chain = LD->getChain();
1383 SDValue Base = LD->getBasePtr();
1384 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1385 CurDAG->getRegister(0, MVT::i32), Chain };
1386 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1387 MVT::Other, Ops, 5);
1388 } else {
1389 SDValue Chain = LD->getChain();
1390 SDValue Base = LD->getBasePtr();
1391 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1392 CurDAG->getRegister(0, MVT::i32), Chain };
1393 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
1394 MVT::Other, Ops, 6);
1395 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001396 }
1397
1398 return NULL;
1399}
1400
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001401SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1402 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001403 ISD::MemIndexedMode AM = LD->getAddressingMode();
1404 if (AM == ISD::UNINDEXED)
1405 return NULL;
1406
Owen Andersone50ed302009-08-10 22:56:29 +00001407 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001408 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001409 SDValue Offset;
1410 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1411 unsigned Opcode = 0;
1412 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001413 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001414 switch (LoadedVT.getSimpleVT().SimpleTy) {
1415 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001416 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1417 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001418 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001419 if (isSExtLd)
1420 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1421 else
1422 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001423 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001424 case MVT::i8:
1425 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001426 if (isSExtLd)
1427 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1428 else
1429 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001430 break;
1431 default:
1432 return NULL;
1433 }
1434 Match = true;
1435 }
1436
1437 if (Match) {
1438 SDValue Chain = LD->getChain();
1439 SDValue Base = LD->getBasePtr();
1440 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001441 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001442 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001443 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001444 }
1445
1446 return NULL;
1447}
1448
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001449/// PairSRegs - Form a D register from a pair of S registers.
1450///
1451SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1452 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001453 SDValue RegClass =
1454 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001455 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1456 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001457 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1458 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001459}
1460
Evan Cheng603afbf2010-05-10 17:34:18 +00001461/// PairDRegs - Form a quad register from a pair of D registers.
1462///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001463SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1464 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001465 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001466 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1467 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001468 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1469 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001470}
1471
Evan Cheng7f687192010-05-14 00:21:45 +00001472/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001473///
1474SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1475 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001476 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001477 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1478 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001479 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1480 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001481}
1482
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001483/// QuadSRegs - Form 4 consecutive S registers.
1484///
1485SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1486 SDValue V2, SDValue V3) {
1487 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001488 SDValue RegClass =
1489 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001490 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1491 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1492 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1493 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001494 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1495 V2, SubReg2, V3, SubReg3 };
1496 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001497}
1498
Evan Cheng7f687192010-05-14 00:21:45 +00001499/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001500///
1501SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1502 SDValue V2, SDValue V3) {
1503 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001504 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001505 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1506 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1507 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1508 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001509 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1510 V2, SubReg2, V3, SubReg3 };
1511 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001512}
1513
Evan Cheng8f6de382010-05-16 03:27:48 +00001514/// QuadQRegs - Form 4 consecutive Q registers.
1515///
1516SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1517 SDValue V2, SDValue V3) {
1518 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001519 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001520 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1521 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1522 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1523 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001524 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1525 V2, SubReg2, V3, SubReg3 };
1526 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001527}
1528
Bob Wilson2a6e6162010-09-23 23:42:37 +00001529/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1530/// of a NEON VLD or VST instruction. The supported values depend on the
1531/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001532SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1533 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001534 unsigned NumRegs = NumVecs;
1535 if (!is64BitVector && NumVecs < 3)
1536 NumRegs *= 2;
1537
Bob Wilson665814b2010-11-01 23:40:51 +00001538 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001539 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001540 Alignment = 32;
1541 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1542 Alignment = 16;
1543 else if (Alignment >= 8)
1544 Alignment = 8;
1545 else
1546 Alignment = 0;
1547
1548 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001549}
1550
Bob Wilson1c3ef902011-02-07 17:43:21 +00001551SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001552 unsigned *DOpcodes, unsigned *QOpcodes0,
1553 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001554 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001555 DebugLoc dl = N->getDebugLoc();
1556
Bob Wilson226036e2010-03-20 22:13:40 +00001557 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001558 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1559 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001560 return NULL;
1561
1562 SDValue Chain = N->getOperand(0);
1563 EVT VT = N->getValueType(0);
1564 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001565 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001566
Bob Wilson3e36f132009-10-14 17:28:52 +00001567 unsigned OpcodeIndex;
1568 switch (VT.getSimpleVT().SimpleTy) {
1569 default: llvm_unreachable("unhandled vld type");
1570 // Double-register operations:
1571 case MVT::v8i8: OpcodeIndex = 0; break;
1572 case MVT::v4i16: OpcodeIndex = 1; break;
1573 case MVT::v2f32:
1574 case MVT::v2i32: OpcodeIndex = 2; break;
1575 case MVT::v1i64: OpcodeIndex = 3; break;
1576 // Quad-register operations:
1577 case MVT::v16i8: OpcodeIndex = 0; break;
1578 case MVT::v8i16: OpcodeIndex = 1; break;
1579 case MVT::v4f32:
1580 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001581 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001582 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001583 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001584 }
1585
Bob Wilsonf5721912010-09-03 18:16:02 +00001586 EVT ResTy;
1587 if (NumVecs == 1)
1588 ResTy = VT;
1589 else {
1590 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1591 if (!is64BitVector)
1592 ResTyElts *= 2;
1593 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1594 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001595 std::vector<EVT> ResTys;
1596 ResTys.push_back(ResTy);
1597 if (isUpdating)
1598 ResTys.push_back(MVT::i32);
1599 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001600
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001601 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001602 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001603 SDNode *VLd;
1604 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001605
Bob Wilson1c3ef902011-02-07 17:43:21 +00001606 // Double registers and VLD1/VLD2 quad registers are directly supported.
1607 if (is64BitVector || NumVecs <= 2) {
1608 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1609 QOpcodes0[OpcodeIndex]);
1610 Ops.push_back(MemAddr);
1611 Ops.push_back(Align);
1612 if (isUpdating) {
1613 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1614 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001615 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001616 Ops.push_back(Pred);
1617 Ops.push_back(Reg0);
1618 Ops.push_back(Chain);
1619 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001620
Bob Wilson3e36f132009-10-14 17:28:52 +00001621 } else {
1622 // Otherwise, quad registers are loaded with two separate instructions,
1623 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001624 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001625
Bob Wilson1c3ef902011-02-07 17:43:21 +00001626 // Load the even subregs. This is always an updating load, so that it
1627 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001628 SDValue ImplDef =
1629 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1630 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001631 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1632 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001633 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001634
Bob Wilson24f995d2009-10-14 18:32:29 +00001635 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001636 Ops.push_back(SDValue(VLdA, 1));
1637 Ops.push_back(Align);
1638 if (isUpdating) {
1639 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1640 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1641 "only constant post-increment update allowed for VLD3/4");
1642 (void)Inc;
1643 Ops.push_back(Reg0);
1644 }
1645 Ops.push_back(SDValue(VLdA, 0));
1646 Ops.push_back(Pred);
1647 Ops.push_back(Reg0);
1648 Ops.push_back(Chain);
1649 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1650 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001651 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001652
Evan Chengb58a3402011-04-19 00:04:03 +00001653 // Transfer memoperands.
1654 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1655 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1656 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1657
Bob Wilson1c3ef902011-02-07 17:43:21 +00001658 if (NumVecs == 1)
1659 return VLd;
1660
1661 // Extract out the subregisters.
1662 SDValue SuperReg = SDValue(VLd, 0);
1663 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1664 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1665 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1666 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1667 ReplaceUses(SDValue(N, Vec),
1668 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1669 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1670 if (isUpdating)
1671 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001672 return NULL;
1673}
1674
Bob Wilson1c3ef902011-02-07 17:43:21 +00001675SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001676 unsigned *DOpcodes, unsigned *QOpcodes0,
1677 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001678 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001679 DebugLoc dl = N->getDebugLoc();
1680
Bob Wilson226036e2010-03-20 22:13:40 +00001681 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001682 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1683 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1684 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001685 return NULL;
1686
Evan Chengb58a3402011-04-19 00:04:03 +00001687 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1688 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1689
Bob Wilson24f995d2009-10-14 18:32:29 +00001690 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001691 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001692 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001693 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001694
Bob Wilson24f995d2009-10-14 18:32:29 +00001695 unsigned OpcodeIndex;
1696 switch (VT.getSimpleVT().SimpleTy) {
1697 default: llvm_unreachable("unhandled vst type");
1698 // Double-register operations:
1699 case MVT::v8i8: OpcodeIndex = 0; break;
1700 case MVT::v4i16: OpcodeIndex = 1; break;
1701 case MVT::v2f32:
1702 case MVT::v2i32: OpcodeIndex = 2; break;
1703 case MVT::v1i64: OpcodeIndex = 3; break;
1704 // Quad-register operations:
1705 case MVT::v16i8: OpcodeIndex = 0; break;
1706 case MVT::v8i16: OpcodeIndex = 1; break;
1707 case MVT::v4f32:
1708 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001709 case MVT::v2i64: OpcodeIndex = 3;
1710 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1711 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001712 }
1713
Bob Wilson1c3ef902011-02-07 17:43:21 +00001714 std::vector<EVT> ResTys;
1715 if (isUpdating)
1716 ResTys.push_back(MVT::i32);
1717 ResTys.push_back(MVT::Other);
1718
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001719 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001720 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001721 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001722
Bob Wilson1c3ef902011-02-07 17:43:21 +00001723 // Double registers and VST1/VST2 quad registers are directly supported.
1724 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001725 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001726 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001727 SrcReg = N->getOperand(Vec0Idx);
1728 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001729 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001730 SDValue V0 = N->getOperand(Vec0Idx + 0);
1731 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001732 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001733 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001734 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001735 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001736 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001737 // an undef.
1738 SDValue V3 = (NumVecs == 3)
1739 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001740 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001741 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001742 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001743 } else {
1744 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001745 SDValue Q0 = N->getOperand(Vec0Idx);
1746 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001747 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001748 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001749
1750 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1751 QOpcodes0[OpcodeIndex]);
1752 Ops.push_back(MemAddr);
1753 Ops.push_back(Align);
1754 if (isUpdating) {
1755 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1756 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1757 }
1758 Ops.push_back(SrcReg);
1759 Ops.push_back(Pred);
1760 Ops.push_back(Reg0);
1761 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001762 SDNode *VSt =
1763 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1764
1765 // Transfer memoperands.
1766 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1767
1768 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001769 }
1770
1771 // Otherwise, quad registers are stored with two separate instructions,
1772 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001773
Bob Wilson07f6e802010-06-16 21:34:01 +00001774 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001775 SDValue V0 = N->getOperand(Vec0Idx + 0);
1776 SDValue V1 = N->getOperand(Vec0Idx + 1);
1777 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001778 SDValue V3 = (NumVecs == 3)
1779 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001780 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001781 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001782
Bob Wilson1c3ef902011-02-07 17:43:21 +00001783 // Store the even D registers. This is always an updating store, so that it
1784 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001785 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1786 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1787 MemAddr.getValueType(),
1788 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001789 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001790 Chain = SDValue(VStA, 1);
1791
1792 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001793 Ops.push_back(SDValue(VStA, 0));
1794 Ops.push_back(Align);
1795 if (isUpdating) {
1796 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1797 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1798 "only constant post-increment update allowed for VST3/4");
1799 (void)Inc;
1800 Ops.push_back(Reg0);
1801 }
1802 Ops.push_back(RegSeq);
1803 Ops.push_back(Pred);
1804 Ops.push_back(Reg0);
1805 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001806 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1807 Ops.data(), Ops.size());
1808 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1809 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001810}
1811
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001812SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001813 bool isUpdating, unsigned NumVecs,
1814 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001815 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001816 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001817 DebugLoc dl = N->getDebugLoc();
1818
Bob Wilson226036e2010-03-20 22:13:40 +00001819 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001820 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1821 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1822 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001823 return NULL;
1824
Evan Chengb58a3402011-04-19 00:04:03 +00001825 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1826 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1827
Bob Wilsona7c397c2009-10-14 16:19:03 +00001828 SDValue Chain = N->getOperand(0);
1829 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001830 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1831 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001832 bool is64BitVector = VT.is64BitVector();
1833
Bob Wilson665814b2010-11-01 23:40:51 +00001834 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001835 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001836 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001837 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1838 if (Alignment > NumBytes)
1839 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001840 if (Alignment < 8 && Alignment < NumBytes)
1841 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001842 // Alignment must be a power of two; make sure of that.
1843 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001844 if (Alignment == 1)
1845 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001846 }
Bob Wilson665814b2010-11-01 23:40:51 +00001847 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001848
Bob Wilsona7c397c2009-10-14 16:19:03 +00001849 unsigned OpcodeIndex;
1850 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001851 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001852 // Double-register operations:
1853 case MVT::v8i8: OpcodeIndex = 0; break;
1854 case MVT::v4i16: OpcodeIndex = 1; break;
1855 case MVT::v2f32:
1856 case MVT::v2i32: OpcodeIndex = 2; break;
1857 // Quad-register operations:
1858 case MVT::v8i16: OpcodeIndex = 0; break;
1859 case MVT::v4f32:
1860 case MVT::v4i32: OpcodeIndex = 1; break;
1861 }
1862
Bob Wilson1c3ef902011-02-07 17:43:21 +00001863 std::vector<EVT> ResTys;
1864 if (IsLoad) {
1865 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1866 if (!is64BitVector)
1867 ResTyElts *= 2;
1868 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1869 MVT::i64, ResTyElts));
1870 }
1871 if (isUpdating)
1872 ResTys.push_back(MVT::i32);
1873 ResTys.push_back(MVT::Other);
1874
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001875 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001876 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001877
Bob Wilson1c3ef902011-02-07 17:43:21 +00001878 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001879 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001880 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001881 if (isUpdating) {
1882 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1883 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1884 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001885
Bob Wilson8466fa12010-09-13 23:01:35 +00001886 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001887 SDValue V0 = N->getOperand(Vec0Idx + 0);
1888 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001889 if (NumVecs == 2) {
1890 if (is64BitVector)
1891 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1892 else
1893 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001894 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001895 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001896 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001897 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1898 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001899 if (is64BitVector)
1900 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1901 else
1902 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001903 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001904 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001905 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001906 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001907 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001908 Ops.push_back(Chain);
1909
Bob Wilson1c3ef902011-02-07 17:43:21 +00001910 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1911 QOpcodes[OpcodeIndex]);
1912 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1913 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001914 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001915 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001916 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001917
Bob Wilson8466fa12010-09-13 23:01:35 +00001918 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001919 SuperReg = SDValue(VLdLn, 0);
1920 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1921 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1922 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001923 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1924 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001925 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1926 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1927 if (isUpdating)
1928 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001929 return NULL;
1930}
1931
Bob Wilson1c3ef902011-02-07 17:43:21 +00001932SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1933 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001934 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1935 DebugLoc dl = N->getDebugLoc();
1936
1937 SDValue MemAddr, Align;
1938 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1939 return NULL;
1940
Evan Chengb58a3402011-04-19 00:04:03 +00001941 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1942 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1943
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001944 SDValue Chain = N->getOperand(0);
1945 EVT VT = N->getValueType(0);
1946
1947 unsigned Alignment = 0;
1948 if (NumVecs != 3) {
1949 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1950 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1951 if (Alignment > NumBytes)
1952 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001953 if (Alignment < 8 && Alignment < NumBytes)
1954 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001955 // Alignment must be a power of two; make sure of that.
1956 Alignment = (Alignment & -Alignment);
1957 if (Alignment == 1)
1958 Alignment = 0;
1959 }
1960 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1961
1962 unsigned OpcodeIndex;
1963 switch (VT.getSimpleVT().SimpleTy) {
1964 default: llvm_unreachable("unhandled vld-dup type");
1965 case MVT::v8i8: OpcodeIndex = 0; break;
1966 case MVT::v4i16: OpcodeIndex = 1; break;
1967 case MVT::v2f32:
1968 case MVT::v2i32: OpcodeIndex = 2; break;
1969 }
1970
1971 SDValue Pred = getAL(CurDAG);
1972 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1973 SDValue SuperReg;
1974 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001975 SmallVector<SDValue, 6> Ops;
1976 Ops.push_back(MemAddr);
1977 Ops.push_back(Align);
1978 if (isUpdating) {
1979 SDValue Inc = N->getOperand(2);
1980 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1981 }
1982 Ops.push_back(Pred);
1983 Ops.push_back(Reg0);
1984 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001985
1986 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001987 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001988 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001989 if (isUpdating)
1990 ResTys.push_back(MVT::i32);
1991 ResTys.push_back(MVT::Other);
1992 SDNode *VLdDup =
1993 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001994 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001995 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001996
1997 // Extract the subregisters.
1998 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1999 unsigned SubIdx = ARM::dsub_0;
2000 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2001 ReplaceUses(SDValue(N, Vec),
2002 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002003 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2004 if (isUpdating)
2005 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002006 return NULL;
2007}
2008
Bob Wilson78dfbc32010-07-07 00:08:54 +00002009SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2010 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002011 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2012 DebugLoc dl = N->getDebugLoc();
2013 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002014 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002015
2016 // Form a REG_SEQUENCE to force register allocation.
2017 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002018 SDValue V0 = N->getOperand(FirstTblReg + 0);
2019 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002020 if (NumVecs == 2)
2021 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2022 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002023 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002024 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002025 // an undef.
2026 SDValue V3 = (NumVecs == 3)
2027 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002028 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002029 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2030 }
2031
Bob Wilson78dfbc32010-07-07 00:08:54 +00002032 SmallVector<SDValue, 6> Ops;
2033 if (IsExt)
2034 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002035 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002036 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002037 Ops.push_back(getAL(CurDAG)); // predicate
2038 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002039 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002040}
2041
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002042SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002043 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002044 if (!Subtarget->hasV6T2Ops())
2045 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002046
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002047 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2048 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2049
2050
2051 // For unsigned extracts, check for a shift right and mask
2052 unsigned And_imm = 0;
2053 if (N->getOpcode() == ISD::AND) {
2054 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2055
2056 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2057 if (And_imm & (And_imm + 1))
2058 return NULL;
2059
2060 unsigned Srl_imm = 0;
2061 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2062 Srl_imm)) {
2063 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2064
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002065 // Note: The width operand is encoded as width-1.
2066 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002067 unsigned LSB = Srl_imm;
2068 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2069 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2070 CurDAG->getTargetConstant(LSB, MVT::i32),
2071 CurDAG->getTargetConstant(Width, MVT::i32),
2072 getAL(CurDAG), Reg0 };
2073 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2074 }
2075 }
2076 return NULL;
2077 }
2078
2079 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002080 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002081 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002082 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2083 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002084 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002085 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002086 // Note: The width operand is encoded as width-1.
2087 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002088 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002089 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002090 return NULL;
2091 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002092 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002093 CurDAG->getTargetConstant(LSB, MVT::i32),
2094 CurDAG->getTargetConstant(Width, MVT::i32),
2095 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002096 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002097 }
2098 }
2099 return NULL;
2100}
2101
Evan Cheng9ef48352009-11-20 00:54:03 +00002102SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002103SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002104 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2105 SDValue CPTmp0;
2106 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002107 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002108 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2109 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2110 unsigned Opc = 0;
2111 switch (SOShOp) {
2112 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2113 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2114 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2115 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2116 default:
2117 llvm_unreachable("Unknown so_reg opcode!");
2118 break;
2119 }
2120 SDValue SOShImm =
2121 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2122 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2123 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002124 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002125 }
2126 return 0;
2127}
2128
2129SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002131 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2132 SDValue CPTmp0;
2133 SDValue CPTmp1;
2134 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002135 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002136 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002137 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2138 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002139 }
2140
2141 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2142 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2143 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2144 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002145 }
2146 return 0;
2147}
2148
2149SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002150SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002151 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002152 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002153 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002154 return 0;
2155
Evan Cheng63f35442010-11-13 02:25:14 +00002156 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002157 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002158 if (is_t2_so_imm(TrueImm)) {
2159 Opc = ARM::t2MOVCCi;
2160 } else if (TrueImm <= 0xffff) {
2161 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002162 } else if (is_t2_so_imm_not(TrueImm)) {
2163 TrueImm = ~TrueImm;
2164 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002165 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002166 // Large immediate.
2167 Opc = ARM::t2MOVCCi32imm;
2168 }
2169
2170 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002171 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2173 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002174 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002175 }
Evan Cheng63f35442010-11-13 02:25:14 +00002176
Evan Cheng9ef48352009-11-20 00:54:03 +00002177 return 0;
2178}
2179
2180SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002181SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002182 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002183 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2184 if (!T)
2185 return 0;
2186
Evan Cheng63f35442010-11-13 02:25:14 +00002187 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002188 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002189 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002190 if (isSoImm) {
2191 Opc = ARM::MOVCCi;
2192 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2193 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002194 } else if (is_so_imm_not(TrueImm)) {
2195 TrueImm = ~TrueImm;
2196 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002197 } else if (TrueVal.getNode()->hasOneUse() &&
2198 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002199 // Large immediate.
2200 Opc = ARM::MOVCCi32imm;
2201 }
2202
2203 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002204 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002205 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2206 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002207 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002209
Evan Cheng9ef48352009-11-20 00:54:03 +00002210 return 0;
2211}
2212
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002213SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2214 EVT VT = N->getValueType(0);
2215 SDValue FalseVal = N->getOperand(0);
2216 SDValue TrueVal = N->getOperand(1);
2217 SDValue CC = N->getOperand(2);
2218 SDValue CCR = N->getOperand(3);
2219 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002220 assert(CC.getOpcode() == ISD::Constant);
2221 assert(CCR.getOpcode() == ISD::Register);
2222 ARMCC::CondCodes CCVal =
2223 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002224
2225 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2226 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2227 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2228 // Pattern complexity = 18 cost = 1 size = 0
2229 SDValue CPTmp0;
2230 SDValue CPTmp1;
2231 SDValue CPTmp2;
2232 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002233 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002234 CCVal, CCR, InFlag);
2235 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002236 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002237 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2238 if (Res)
2239 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002240 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002241 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002242 CCVal, CCR, InFlag);
2243 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002244 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002245 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2246 if (Res)
2247 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002248 }
2249
2250 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002251 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002252 // (imm:i32):$cc)
2253 // Emits: (MOVCCi:i32 GPR:i32:$false,
2254 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2255 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002256 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002257 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002258 CCVal, CCR, InFlag);
2259 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002260 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002261 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2262 if (Res)
2263 return Res;
2264 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002265 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002266 CCVal, CCR, InFlag);
2267 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002268 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002269 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2270 if (Res)
2271 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002272 }
2273 }
2274
2275 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2276 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2277 // Pattern complexity = 6 cost = 1 size = 0
2278 //
2279 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2280 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2281 // Pattern complexity = 6 cost = 11 size = 0
2282 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002283 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002284 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2285 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002286 unsigned Opc = 0;
2287 switch (VT.getSimpleVT().SimpleTy) {
2288 default: assert(false && "Illegal conditional move type!");
2289 break;
2290 case MVT::i32:
2291 Opc = Subtarget->isThumb()
2292 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2293 : ARM::MOVCCr;
2294 break;
2295 case MVT::f32:
2296 Opc = ARM::VMOVScc;
2297 break;
2298 case MVT::f64:
2299 Opc = ARM::VMOVDcc;
2300 break;
2301 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002302 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002303}
2304
Evan Chengde8aa4e2010-05-05 18:28:36 +00002305SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2306 // The only time a CONCAT_VECTORS operation can have legal types is when
2307 // two 64-bit vectors are concatenated to a 128-bit vector.
2308 EVT VT = N->getValueType(0);
2309 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2310 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002311 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002312}
2313
Eli Friedman2bdffe42011-08-31 00:31:29 +00002314SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002315 SmallVector<SDValue, 6> Ops;
2316 Ops.push_back(Node->getOperand(1)); // Ptr
2317 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2318 Ops.push_back(Node->getOperand(3)); // High part of Val1
2319 if (Opc == ARM::ATOMCMPXCHG6432) {
2320 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2321 Ops.push_back(Node->getOperand(5)); // High part of Val2
2322 }
2323 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002324 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2325 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002326 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002327 MVT::i32, MVT::i32, MVT::Other,
2328 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002329 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2330 return ResNode;
2331}
2332
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002333SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002334 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002335
Dan Gohmane8be6c62008-07-17 19:10:17 +00002336 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002337 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002338
2339 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002340 default: break;
2341 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002342 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002343 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002344 if (Subtarget->hasThumb2())
2345 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2346 // be done with MOV + MOVT, at worst.
2347 UseCP = 0;
2348 else {
2349 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002350 UseCP = (Val > 255 && // MOV
2351 ~Val > 255 && // MOV + MVN
2352 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002353 } else
2354 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2355 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2356 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2357 }
2358
Evan Chenga8e29892007-01-19 07:51:42 +00002359 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002360 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002361 CurDAG->getTargetConstantPool(ConstantInt::get(
2362 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002363 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002364
2365 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002366 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002367 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002368 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002369 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002370 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002371 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002372 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002373 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002374 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002375 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002376 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002377 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002378 CurDAG->getEntryNode()
2379 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002380 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002381 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002382 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002383 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002384 return NULL;
2385 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002386
Evan Chenga8e29892007-01-19 07:51:42 +00002387 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002388 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002389 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002390 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002391 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002392 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002393 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002394 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002395 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2396 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2397 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002398 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002399 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2400 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002401 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2402 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2403 CurDAG->getRegister(0, MVT::i32) };
2404 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002405 }
Evan Chenga8e29892007-01-19 07:51:42 +00002406 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002407 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002408 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002409 return I;
2410 break;
2411 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002412 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002413 return I;
2414 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002415 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002416 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002417 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002418 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002419 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002420 if (!RHSV) break;
2421 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002422 unsigned ShImm = Log2_32(RHSV-1);
2423 if (ShImm >= 32)
2424 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002425 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002426 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002427 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2428 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002429 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002430 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002431 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002432 } else {
2433 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002434 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002435 }
Evan Chenga8e29892007-01-19 07:51:42 +00002436 }
2437 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002438 unsigned ShImm = Log2_32(RHSV+1);
2439 if (ShImm >= 32)
2440 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002441 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002442 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002443 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2444 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002445 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002446 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2447 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002448 } else {
2449 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002450 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002451 }
Evan Chenga8e29892007-01-19 07:51:42 +00002452 }
2453 }
2454 break;
Evan Cheng20956592009-10-21 08:15:52 +00002455 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002456 // Check for unsigned bitfield extract
2457 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2458 return I;
2459
Evan Cheng20956592009-10-21 08:15:52 +00002460 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2461 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2462 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2463 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2464 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002465 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002466 if (VT != MVT::i32)
2467 break;
2468 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2469 ? ARM::t2MOVTi16
2470 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2471 if (!Opc)
2472 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002473 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002474 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2475 if (!N1C)
2476 break;
2477 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2478 SDValue N2 = N0.getOperand(1);
2479 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2480 if (!N2C)
2481 break;
2482 unsigned N1CVal = N1C->getZExtValue();
2483 unsigned N2CVal = N2C->getZExtValue();
2484 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2485 (N1CVal & 0xffffU) == 0xffffU &&
2486 (N2CVal & 0xffffU) == 0x0U) {
2487 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2488 MVT::i32);
2489 SDValue Ops[] = { N0.getOperand(0), Imm16,
2490 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2491 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2492 }
2493 }
2494 break;
2495 }
Jim Grosbache5165492009-11-09 00:11:35 +00002496 case ARMISD::VMOVRRD:
2497 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002498 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002499 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002500 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002501 if (Subtarget->isThumb1Only())
2502 break;
2503 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002504 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002505 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2506 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002507 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002508 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002509 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002510 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2511 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002512 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2513 ARM::UMULL : ARM::UMULLv5,
2514 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002515 }
Evan Chengee568cf2007-07-05 07:15:27 +00002516 }
Dan Gohman525178c2007-10-08 18:33:35 +00002517 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002518 if (Subtarget->isThumb1Only())
2519 break;
2520 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002521 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002522 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002523 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002524 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002525 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002526 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2527 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002528 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2529 ARM::SMULL : ARM::SMULLv5,
2530 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002531 }
Evan Chengee568cf2007-07-05 07:15:27 +00002532 }
Evan Chenga8e29892007-01-19 07:51:42 +00002533 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002534 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002535 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002536 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002537 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002538 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002539 if (ResNode)
2540 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002541 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002542 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002543 }
Evan Chengee568cf2007-07-05 07:15:27 +00002544 case ARMISD::BRCOND: {
2545 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2546 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2547 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002548
Evan Chengee568cf2007-07-05 07:15:27 +00002549 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2550 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2551 // Pattern complexity = 6 cost = 1 size = 0
2552
David Goodwin5e47a9a2009-06-30 18:04:13 +00002553 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2554 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2555 // Pattern complexity = 6 cost = 1 size = 0
2556
Jim Grosbach764ab522009-08-11 15:33:49 +00002557 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002558 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002559 SDValue Chain = N->getOperand(0);
2560 SDValue N1 = N->getOperand(1);
2561 SDValue N2 = N->getOperand(2);
2562 SDValue N3 = N->getOperand(3);
2563 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002564 assert(N1.getOpcode() == ISD::BasicBlock);
2565 assert(N2.getOpcode() == ISD::Constant);
2566 assert(N3.getOpcode() == ISD::Register);
2567
Dan Gohman475871a2008-07-27 21:46:04 +00002568 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002569 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002570 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002571 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002572 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002573 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002574 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002575 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002576 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002577 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002578 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002579 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002580 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002581 return NULL;
2582 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002583 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002584 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002585 case ARMISD::VZIP: {
2586 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002587 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002588 switch (VT.getSimpleVT().SimpleTy) {
2589 default: return NULL;
2590 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2591 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2592 case MVT::v2f32:
2593 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2594 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2595 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2596 case MVT::v4f32:
2597 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2598 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002599 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002600 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2601 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2602 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002603 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002604 case ARMISD::VUZP: {
2605 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002606 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002607 switch (VT.getSimpleVT().SimpleTy) {
2608 default: return NULL;
2609 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2610 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2611 case MVT::v2f32:
2612 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2613 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2614 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2615 case MVT::v4f32:
2616 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2617 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002618 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002619 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2620 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2621 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002622 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002623 case ARMISD::VTRN: {
2624 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002625 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002626 switch (VT.getSimpleVT().SimpleTy) {
2627 default: return NULL;
2628 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2629 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2630 case MVT::v2f32:
2631 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2632 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2633 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2634 case MVT::v4f32:
2635 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2636 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002637 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002638 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2639 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2640 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002641 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002642 case ARMISD::BUILD_VECTOR: {
2643 EVT VecVT = N->getValueType(0);
2644 EVT EltVT = VecVT.getVectorElementType();
2645 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002646 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002647 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2648 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2649 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002650 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002651 if (NumElts == 2)
2652 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2653 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2654 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2655 N->getOperand(2), N->getOperand(3));
2656 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002657
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002658 case ARMISD::VLD2DUP: {
2659 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2660 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002661 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002662 }
2663
Bob Wilson86c6d802010-11-29 19:35:29 +00002664 case ARMISD::VLD3DUP: {
2665 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2666 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002667 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002668 }
2669
Bob Wilson6c4c9822010-11-30 00:00:35 +00002670 case ARMISD::VLD4DUP: {
2671 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2672 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002673 return SelectVLDDup(N, false, 4, Opcodes);
2674 }
2675
2676 case ARMISD::VLD2DUP_UPD: {
2677 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2678 ARM::VLD2DUPd32Pseudo_UPD };
2679 return SelectVLDDup(N, true, 2, Opcodes);
2680 }
2681
2682 case ARMISD::VLD3DUP_UPD: {
2683 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2684 ARM::VLD3DUPd32Pseudo_UPD };
2685 return SelectVLDDup(N, true, 3, Opcodes);
2686 }
2687
2688 case ARMISD::VLD4DUP_UPD: {
2689 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2690 ARM::VLD4DUPd32Pseudo_UPD };
2691 return SelectVLDDup(N, true, 4, Opcodes);
2692 }
2693
2694 case ARMISD::VLD1_UPD: {
2695 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2696 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2697 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2698 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2699 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2700 }
2701
2702 case ARMISD::VLD2_UPD: {
2703 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2704 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2705 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2706 ARM::VLD2q32Pseudo_UPD };
2707 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2708 }
2709
2710 case ARMISD::VLD3_UPD: {
2711 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2712 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2713 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2714 ARM::VLD3q16Pseudo_UPD,
2715 ARM::VLD3q32Pseudo_UPD };
2716 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2717 ARM::VLD3q16oddPseudo_UPD,
2718 ARM::VLD3q32oddPseudo_UPD };
2719 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2720 }
2721
2722 case ARMISD::VLD4_UPD: {
2723 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2724 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2725 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2726 ARM::VLD4q16Pseudo_UPD,
2727 ARM::VLD4q32Pseudo_UPD };
2728 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2729 ARM::VLD4q16oddPseudo_UPD,
2730 ARM::VLD4q32oddPseudo_UPD };
2731 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2732 }
2733
2734 case ARMISD::VLD2LN_UPD: {
2735 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2736 ARM::VLD2LNd32Pseudo_UPD };
2737 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2738 ARM::VLD2LNq32Pseudo_UPD };
2739 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2740 }
2741
2742 case ARMISD::VLD3LN_UPD: {
2743 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2744 ARM::VLD3LNd32Pseudo_UPD };
2745 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2746 ARM::VLD3LNq32Pseudo_UPD };
2747 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2748 }
2749
2750 case ARMISD::VLD4LN_UPD: {
2751 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2752 ARM::VLD4LNd32Pseudo_UPD };
2753 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2754 ARM::VLD4LNq32Pseudo_UPD };
2755 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2756 }
2757
2758 case ARMISD::VST1_UPD: {
2759 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2760 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2761 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2762 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2763 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2764 }
2765
2766 case ARMISD::VST2_UPD: {
2767 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2768 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2769 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2770 ARM::VST2q32Pseudo_UPD };
2771 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2772 }
2773
2774 case ARMISD::VST3_UPD: {
2775 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2776 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2777 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2778 ARM::VST3q16Pseudo_UPD,
2779 ARM::VST3q32Pseudo_UPD };
2780 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2781 ARM::VST3q16oddPseudo_UPD,
2782 ARM::VST3q32oddPseudo_UPD };
2783 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2784 }
2785
2786 case ARMISD::VST4_UPD: {
2787 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2788 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2789 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2790 ARM::VST4q16Pseudo_UPD,
2791 ARM::VST4q32Pseudo_UPD };
2792 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2793 ARM::VST4q16oddPseudo_UPD,
2794 ARM::VST4q32oddPseudo_UPD };
2795 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2796 }
2797
2798 case ARMISD::VST2LN_UPD: {
2799 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2800 ARM::VST2LNd32Pseudo_UPD };
2801 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2802 ARM::VST2LNq32Pseudo_UPD };
2803 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2804 }
2805
2806 case ARMISD::VST3LN_UPD: {
2807 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2808 ARM::VST3LNd32Pseudo_UPD };
2809 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2810 ARM::VST3LNq32Pseudo_UPD };
2811 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2812 }
2813
2814 case ARMISD::VST4LN_UPD: {
2815 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2816 ARM::VST4LNd32Pseudo_UPD };
2817 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2818 ARM::VST4LNq32Pseudo_UPD };
2819 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002820 }
2821
Bob Wilson31fb12f2009-08-26 17:39:53 +00002822 case ISD::INTRINSIC_VOID:
2823 case ISD::INTRINSIC_W_CHAIN: {
2824 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002825 switch (IntNo) {
2826 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002827 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002828
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002829 case Intrinsic::arm_ldrexd: {
2830 SDValue MemAddr = N->getOperand(2);
2831 DebugLoc dl = N->getDebugLoc();
2832 SDValue Chain = N->getOperand(0);
2833
2834 unsigned NewOpc = ARM::LDREXD;
2835 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2836 NewOpc = ARM::t2LDREXD;
2837
2838 // arm_ldrexd returns a i64 value in {i32, i32}
2839 std::vector<EVT> ResTys;
2840 ResTys.push_back(MVT::i32);
2841 ResTys.push_back(MVT::i32);
2842 ResTys.push_back(MVT::Other);
2843
2844 // place arguments in the right order
2845 SmallVector<SDValue, 7> Ops;
2846 Ops.push_back(MemAddr);
2847 Ops.push_back(getAL(CurDAG));
2848 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2849 Ops.push_back(Chain);
2850 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2851 Ops.size());
2852 // Transfer memoperands.
2853 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2854 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2855 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2856
2857 // Until there's support for specifing explicit register constraints
2858 // like the use of even/odd register pair, hardcode ldrexd to always
2859 // use the pair [R0, R1] to hold the load result.
2860 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2861 SDValue(Ld, 0), SDValue(0,0));
2862 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2863 SDValue(Ld, 1), Chain.getValue(1));
2864
2865 // Remap uses.
2866 SDValue Glue = Chain.getValue(1);
2867 if (!SDValue(N, 0).use_empty()) {
2868 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2869 ARM::R0, MVT::i32, Glue);
2870 Glue = Result.getValue(2);
2871 ReplaceUses(SDValue(N, 0), Result);
2872 }
2873 if (!SDValue(N, 1).use_empty()) {
2874 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2875 ARM::R1, MVT::i32, Glue);
2876 Glue = Result.getValue(2);
2877 ReplaceUses(SDValue(N, 1), Result);
2878 }
2879
2880 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2881 return NULL;
2882 }
2883
2884 case Intrinsic::arm_strexd: {
2885 DebugLoc dl = N->getDebugLoc();
2886 SDValue Chain = N->getOperand(0);
2887 SDValue Val0 = N->getOperand(2);
2888 SDValue Val1 = N->getOperand(3);
2889 SDValue MemAddr = N->getOperand(4);
2890
2891 // Until there's support for specifing explicit register constraints
2892 // like the use of even/odd register pair, hardcode strexd to always
2893 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2894 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2895 SDValue(0, 0));
2896 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2897
2898 SDValue Glue = Chain.getValue(1);
2899 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2900 ARM::R2, MVT::i32, Glue);
2901 Glue = Val0.getValue(1);
2902 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2903 ARM::R3, MVT::i32, Glue);
2904
2905 // Store exclusive double return a i32 value which is the return status
2906 // of the issued store.
2907 std::vector<EVT> ResTys;
2908 ResTys.push_back(MVT::i32);
2909 ResTys.push_back(MVT::Other);
2910
2911 // place arguments in the right order
2912 SmallVector<SDValue, 7> Ops;
2913 Ops.push_back(Val0);
2914 Ops.push_back(Val1);
2915 Ops.push_back(MemAddr);
2916 Ops.push_back(getAL(CurDAG));
2917 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2918 Ops.push_back(Chain);
2919
2920 unsigned NewOpc = ARM::STREXD;
2921 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2922 NewOpc = ARM::t2STREXD;
2923
2924 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2925 Ops.size());
2926 // Transfer memoperands.
2927 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2928 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2929 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2930
2931 return St;
2932 }
2933
Bob Wilson621f1952010-03-23 05:25:43 +00002934 case Intrinsic::arm_neon_vld1: {
2935 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2936 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002937 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2938 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002939 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002940 }
2941
Bob Wilson31fb12f2009-08-26 17:39:53 +00002942 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002943 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2944 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2945 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2946 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002947 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002948 }
2949
2950 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002951 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2952 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2953 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2954 ARM::VLD3q16Pseudo_UPD,
2955 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002956 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2957 ARM::VLD3q16oddPseudo,
2958 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002959 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002960 }
2961
2962 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002963 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2964 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2965 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2966 ARM::VLD4q16Pseudo_UPD,
2967 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002968 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2969 ARM::VLD4q16oddPseudo,
2970 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002971 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002972 }
2973
Bob Wilson243fcc52009-09-01 04:26:28 +00002974 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002975 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2976 ARM::VLD2LNd32Pseudo };
2977 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002978 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002979 }
2980
2981 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002982 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2983 ARM::VLD3LNd32Pseudo };
2984 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002985 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002986 }
2987
2988 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002989 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2990 ARM::VLD4LNd32Pseudo };
2991 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002992 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002993 }
2994
Bob Wilson11d98992010-03-23 06:20:33 +00002995 case Intrinsic::arm_neon_vst1: {
2996 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2997 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002998 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2999 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003000 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003001 }
3002
Bob Wilson31fb12f2009-08-26 17:39:53 +00003003 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003004 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
3005 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
3006 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3007 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003008 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003009 }
3010
3011 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00003012 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
3013 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
3014 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3015 ARM::VST3q16Pseudo_UPD,
3016 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003017 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
3018 ARM::VST3q16oddPseudo,
3019 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003020 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003021 }
3022
3023 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00003024 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00003025 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00003026 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3027 ARM::VST4q16Pseudo_UPD,
3028 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003029 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
3030 ARM::VST4q16oddPseudo,
3031 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003032 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003033 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003034
3035 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003036 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
3037 ARM::VST2LNd32Pseudo };
3038 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003039 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003040 }
3041
3042 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003043 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
3044 ARM::VST3LNd32Pseudo };
3045 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003046 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003047 }
3048
3049 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003050 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3051 ARM::VST4LNd32Pseudo };
3052 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003053 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003054 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003055 }
Bob Wilson429009b2010-05-06 16:05:26 +00003056 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003057 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003058
Bob Wilsond491d6e2010-07-06 23:36:25 +00003059 case ISD::INTRINSIC_WO_CHAIN: {
3060 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3061 switch (IntNo) {
3062 default:
3063 break;
3064
3065 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003066 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003067 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003068 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003069 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003070 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003071
3072 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003073 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003074 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003075 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003076 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003077 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003078 }
3079 break;
3080 }
3081
Bill Wendling69a05a72011-03-14 23:02:38 +00003082 case ARMISD::VTBL1: {
3083 DebugLoc dl = N->getDebugLoc();
3084 EVT VT = N->getValueType(0);
3085 SmallVector<SDValue, 6> Ops;
3086
3087 Ops.push_back(N->getOperand(0));
3088 Ops.push_back(N->getOperand(1));
3089 Ops.push_back(getAL(CurDAG)); // Predicate
3090 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3091 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3092 }
3093 case ARMISD::VTBL2: {
3094 DebugLoc dl = N->getDebugLoc();
3095 EVT VT = N->getValueType(0);
3096
3097 // Form a REG_SEQUENCE to force register allocation.
3098 SDValue V0 = N->getOperand(0);
3099 SDValue V1 = N->getOperand(1);
3100 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3101
3102 SmallVector<SDValue, 6> Ops;
3103 Ops.push_back(RegSeq);
3104 Ops.push_back(N->getOperand(2));
3105 Ops.push_back(getAL(CurDAG)); // Predicate
3106 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3107 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3108 Ops.data(), Ops.size());
3109 }
3110
Bob Wilson429009b2010-05-06 16:05:26 +00003111 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003112 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003113
3114 case ARMISD::ATOMOR64_DAG:
3115 return SelectAtomic64(N, ARM::ATOMOR6432);
3116 case ARMISD::ATOMXOR64_DAG:
3117 return SelectAtomic64(N, ARM::ATOMXOR6432);
3118 case ARMISD::ATOMADD64_DAG:
3119 return SelectAtomic64(N, ARM::ATOMADD6432);
3120 case ARMISD::ATOMSUB64_DAG:
3121 return SelectAtomic64(N, ARM::ATOMSUB6432);
3122 case ARMISD::ATOMNAND64_DAG:
3123 return SelectAtomic64(N, ARM::ATOMNAND6432);
3124 case ARMISD::ATOMAND64_DAG:
3125 return SelectAtomic64(N, ARM::ATOMAND6432);
3126 case ARMISD::ATOMSWAP64_DAG:
3127 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003128 case ARMISD::ATOMCMPXCHG64_DAG:
3129 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003130 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003131
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003132 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003133}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003134
Bob Wilson224c2442009-05-19 05:53:42 +00003135bool ARMDAGToDAGISel::
3136SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3137 std::vector<SDValue> &OutOps) {
3138 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003139 // Require the address to be in a register. That is safe for all ARM
3140 // variants and it is hard to do anything much smarter without knowing
3141 // how the operand is used.
3142 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003143 return false;
3144}
3145
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003146/// createARMISelDag - This pass converts a legalized DAG into a
3147/// ARM-specific DAG, ready for instruction scheduling.
3148///
Bob Wilson522ce972009-09-28 14:30:20 +00003149FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3150 CodeGenOpt::Level OptLevel) {
3151 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003152}