blob: d3b4d7c97bfe395d712ac87d4dbefcc2ce9b611e [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,
Craig Topper51f50c12012-05-24 05:17:00 +0000208 const uint16_t *DOpcodes,
209 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson3e36f132009-10-14 17:28:52 +0000210
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,
Craig Topper51f50c12012-05-24 05:17:00 +0000216 const uint16_t *DOpcodes,
217 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson24f995d2009-10-14 18:32:29 +0000218
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,
Craig Topper51f50c12012-05-24 05:17:00 +0000224 const uint16_t *DOpcodes, const uint16_t *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,
Craig Topper51f50c12012-05-24 05:17:00 +0000230 const uint16_t *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
Bill Wendlingef2c86f2011-10-10 22:59:55 +0000255 // Select special operations if node forms integer ABS pattern
256 SDNode *SelectABSOp(SDNode *N);
257
Evan Chengde8aa4e2010-05-05 18:28:36 +0000258 SDNode *SelectConcatVector(SDNode *N);
259
Eli Friedman2bdffe42011-08-31 00:31:29 +0000260 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
261
Evan Chengaf4550f2009-07-02 01:23:32 +0000262 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
263 /// inline asm expressions.
264 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
265 char ConstraintCode,
266 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000267
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000268 // Form pairs of consecutive S, D, or Q registers.
269 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000270 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000271 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
272
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000273 // Form sequences of 4 consecutive S, D, or Q registers.
274 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000275 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000276 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000277
278 // Get the alignment operand for a NEON VLD or VST instruction.
279 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000280};
Evan Chenga8e29892007-01-19 07:51:42 +0000281}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000282
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000283/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
284/// operand. If so Imm will receive the 32-bit value.
285static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
286 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
287 Imm = cast<ConstantSDNode>(N)->getZExtValue();
288 return true;
289 }
290 return false;
291}
292
293// isInt32Immediate - This method tests to see if a constant operand.
294// If so Imm will receive the 32 bit value.
295static bool isInt32Immediate(SDValue N, unsigned &Imm) {
296 return isInt32Immediate(N.getNode(), Imm);
297}
298
299// isOpcWithIntImmediate - This method tests to see if the node is a specific
300// opcode and that it has a immediate integer right operand.
301// If so Imm will receive the 32 bit value.
302static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
303 return N->getOpcode() == Opc &&
304 isInt32Immediate(N->getOperand(1).getNode(), Imm);
305}
306
Daniel Dunbarec91d522011-01-19 15:12:16 +0000307/// \brief Check whether a particular node is a constant value representable as
308/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
309///
310/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000311static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbarec91d522011-01-19 15:12:16 +0000312 int RangeMin, int RangeMax,
313 int &ScaledConstant) {
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000314 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbarec91d522011-01-19 15:12:16 +0000315
316 // Check that this is a constant.
317 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
318 if (!C)
319 return false;
320
321 ScaledConstant = (int) C->getZExtValue();
322 if ((ScaledConstant % Scale) != 0)
323 return false;
324
325 ScaledConstant /= Scale;
326 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
327}
328
Evan Cheng48575f62010-12-05 22:04:16 +0000329/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
330/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
331/// least on current ARM implementations) which should be avoidded.
332bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
333 if (OptLevel == CodeGenOpt::None)
334 return true;
335
336 if (!CheckVMLxHazard)
337 return true;
Silviu Baranga616471d2012-09-13 15:05:10 +0000338 if (!Subtarget->isCortexA8() && !Subtarget->isLikeA9())
Evan Cheng48575f62010-12-05 22:04:16 +0000339 return true;
340
341 if (!N->hasOneUse())
342 return false;
343
344 SDNode *Use = *N->use_begin();
345 if (Use->getOpcode() == ISD::CopyToReg)
346 return true;
347 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000348 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
349 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000350 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000351 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000352 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
353 return true;
354 // vmlx feeding into another vmlx. We actually want to unfold
355 // the use later in the MLxExpansion pass. e.g.
356 // vmla
357 // vmla (stall 8 cycles)
358 //
359 // vmul (5 cycles)
360 // vadd (5 cycles)
361 // vmla
362 // This adds up to about 18 - 19 cycles.
363 //
364 // vmla
365 // vmul (stall 4 cycles)
366 // vadd adds up to about 14 cycles.
367 return TII->isFpMLxInstruction(Opcode);
368 }
369
370 return false;
371}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000372
Evan Chengf40deed2010-10-27 23:41:30 +0000373bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
374 ARM_AM::ShiftOpc ShOpcVal,
375 unsigned ShAmt) {
Silviu Baranga616471d2012-09-13 15:05:10 +0000376 if (!Subtarget->isLikeA9())
Evan Chengf40deed2010-10-27 23:41:30 +0000377 return true;
378 if (Shift.hasOneUse())
379 return true;
380 // R << 2 is free.
381 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
382}
383
Owen Anderson92a20222011-07-21 18:54:16 +0000384bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000385 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000386 SDValue &Opc,
387 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000388 if (DisableShifterOp)
389 return false;
390
Evan Chengee04a6d2011-07-20 23:34:39 +0000391 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000392
393 // Don't match base register only case. That is matched to a separate
394 // lower complexity pattern with explicit register operand.
395 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000396
Evan Cheng055b0312009-06-29 07:51:04 +0000397 BaseReg = N.getOperand(0);
398 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000399 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
400 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000401 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000402 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
403 MVT::i32);
404 return true;
405}
406
Owen Anderson92a20222011-07-21 18:54:16 +0000407bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
408 SDValue &BaseReg,
409 SDValue &ShReg,
410 SDValue &Opc,
411 bool CheckProfitability) {
412 if (DisableShifterOp)
413 return false;
414
415 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
416
417 // Don't match base register only case. That is matched to a separate
418 // lower complexity pattern with explicit register operand.
419 if (ShOpcVal == ARM_AM::no_shift) return false;
420
421 BaseReg = N.getOperand(0);
422 unsigned ShImmVal = 0;
423 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
424 if (RHS) return false;
425
426 ShReg = N.getOperand(1);
427 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
428 return false;
429 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
430 MVT::i32);
431 return true;
432}
433
434
Jim Grosbach3e556122010-10-26 22:37:02 +0000435bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
436 SDValue &Base,
437 SDValue &OffImm) {
438 // Match simple R + imm12 operands.
439
440 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000441 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
442 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000443 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000444 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000445 int FI = cast<FrameIndexSDNode>(N)->getIndex();
446 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
447 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
448 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000449 }
Owen Anderson099e5552011-03-18 19:46:58 +0000450
Chris Lattner0a9481f2011-02-13 22:25:43 +0000451 if (N.getOpcode() == ARMISD::Wrapper &&
452 !(Subtarget->useMovt() &&
453 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000454 Base = N.getOperand(0);
455 } else
456 Base = N;
457 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
458 return true;
459 }
460
461 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
462 int RHSC = (int)RHS->getZExtValue();
463 if (N.getOpcode() == ISD::SUB)
464 RHSC = -RHSC;
465
466 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
467 Base = N.getOperand(0);
468 if (Base.getOpcode() == ISD::FrameIndex) {
469 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
470 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
471 }
472 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
473 return true;
474 }
475 }
476
477 // Base only.
478 Base = N;
479 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
480 return true;
481}
482
483
484
485bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
486 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000487 if (N.getOpcode() == ISD::MUL &&
Silviu Baranga616471d2012-09-13 15:05:10 +0000488 (!Subtarget->isLikeA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000489 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
490 // X * [3,5,9] -> X + X * [2,4,8] etc.
491 int RHSC = (int)RHS->getZExtValue();
492 if (RHSC & 1) {
493 RHSC = RHSC & ~1;
494 ARM_AM::AddrOpc AddSub = ARM_AM::add;
495 if (RHSC < 0) {
496 AddSub = ARM_AM::sub;
497 RHSC = - RHSC;
498 }
499 if (isPowerOf2_32(RHSC)) {
500 unsigned ShAmt = Log2_32(RHSC);
501 Base = Offset = N.getOperand(0);
502 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
503 ARM_AM::lsl),
504 MVT::i32);
505 return true;
506 }
507 }
508 }
509 }
510
Chris Lattner0a9481f2011-02-13 22:25:43 +0000511 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
512 // ISD::OR that is equivalent to an ISD::ADD.
513 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000514 return false;
515
516 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000517 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000518 int RHSC;
519 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
520 -0x1000+1, 0x1000, RHSC)) // 12 bits.
521 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000522 }
523
524 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000525 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000526 ARM_AM::ShiftOpc ShOpcVal =
527 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000528 unsigned ShAmt = 0;
529
530 Base = N.getOperand(0);
531 Offset = N.getOperand(1);
532
533 if (ShOpcVal != ARM_AM::no_shift) {
534 // Check to see if the RHS of the shift is a constant, if not, we can't fold
535 // it.
536 if (ConstantSDNode *Sh =
537 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
538 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000539 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
540 Offset = N.getOperand(1).getOperand(0);
541 else {
542 ShAmt = 0;
543 ShOpcVal = ARM_AM::no_shift;
544 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000545 } else {
546 ShOpcVal = ARM_AM::no_shift;
547 }
548 }
549
550 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000551 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Silviu Baranga616471d2012-09-13 15:05:10 +0000552 !(Subtarget->isLikeA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000553 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000554 if (ShOpcVal != ARM_AM::no_shift) {
555 // Check to see if the RHS of the shift is a constant, if not, we can't
556 // fold it.
557 if (ConstantSDNode *Sh =
558 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
559 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000560 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000561 Offset = N.getOperand(0).getOperand(0);
562 Base = N.getOperand(1);
563 } else {
564 ShAmt = 0;
565 ShOpcVal = ARM_AM::no_shift;
566 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000567 } else {
568 ShOpcVal = ARM_AM::no_shift;
569 }
570 }
571 }
572
573 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
574 MVT::i32);
575 return true;
576}
577
578
Jim Grosbach3e556122010-10-26 22:37:02 +0000579//-----
580
Jim Grosbach82891622010-09-29 19:03:54 +0000581AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
582 SDValue &Base,
583 SDValue &Offset,
584 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000585 if (N.getOpcode() == ISD::MUL &&
Silviu Baranga616471d2012-09-13 15:05:10 +0000586 (!Subtarget->isLikeA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000587 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
588 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000589 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000590 if (RHSC & 1) {
591 RHSC = RHSC & ~1;
592 ARM_AM::AddrOpc AddSub = ARM_AM::add;
593 if (RHSC < 0) {
594 AddSub = ARM_AM::sub;
595 RHSC = - RHSC;
596 }
597 if (isPowerOf2_32(RHSC)) {
598 unsigned ShAmt = Log2_32(RHSC);
599 Base = Offset = N.getOperand(0);
600 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
601 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000602 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000603 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000604 }
605 }
606 }
607 }
608
Chris Lattner0a9481f2011-02-13 22:25:43 +0000609 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
610 // ISD::OR that is equivalent to an ADD.
611 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000612 Base = N;
613 if (N.getOpcode() == ISD::FrameIndex) {
614 int FI = cast<FrameIndexSDNode>(N)->getIndex();
615 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000616 } else if (N.getOpcode() == ARMISD::Wrapper &&
617 !(Subtarget->useMovt() &&
618 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000619 Base = N.getOperand(0);
620 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000621 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000622 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
623 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000624 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000625 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000626 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000627
Evan Chenga8e29892007-01-19 07:51:42 +0000628 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000629 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000630 int RHSC;
631 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
632 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
633 Base = N.getOperand(0);
634 if (Base.getOpcode() == ISD::FrameIndex) {
635 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
636 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000637 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000638 Offset = CurDAG->getRegister(0, MVT::i32);
639
640 ARM_AM::AddrOpc AddSub = ARM_AM::add;
641 if (RHSC < 0) {
642 AddSub = ARM_AM::sub;
643 RHSC = - RHSC;
644 }
645 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
646 ARM_AM::no_shift),
647 MVT::i32);
648 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000649 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000650 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000651
Silviu Baranga616471d2012-09-13 15:05:10 +0000652 if (Subtarget->isLikeA9() && !N.hasOneUse()) {
Evan Chengf40deed2010-10-27 23:41:30 +0000653 // Compute R +/- (R << N) and reuse it.
654 Base = N;
655 Offset = CurDAG->getRegister(0, MVT::i32);
656 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
657 ARM_AM::no_shift),
658 MVT::i32);
659 return AM2_BASE;
660 }
661
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000662 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000663 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000664 ARM_AM::ShiftOpc ShOpcVal =
665 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000666 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000667
Evan Chenga8e29892007-01-19 07:51:42 +0000668 Base = N.getOperand(0);
669 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000670
Evan Chenga8e29892007-01-19 07:51:42 +0000671 if (ShOpcVal != ARM_AM::no_shift) {
672 // Check to see if the RHS of the shift is a constant, if not, we can't fold
673 // it.
674 if (ConstantSDNode *Sh =
675 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000676 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000677 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
678 Offset = N.getOperand(1).getOperand(0);
679 else {
680 ShAmt = 0;
681 ShOpcVal = ARM_AM::no_shift;
682 }
Evan Chenga8e29892007-01-19 07:51:42 +0000683 } else {
684 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000685 }
686 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000687
Evan Chenga8e29892007-01-19 07:51:42 +0000688 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000689 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Silviu Baranga616471d2012-09-13 15:05:10 +0000690 !(Subtarget->isLikeA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000691 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000692 if (ShOpcVal != ARM_AM::no_shift) {
693 // Check to see if the RHS of the shift is a constant, if not, we can't
694 // fold it.
695 if (ConstantSDNode *Sh =
696 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000697 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000698 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000699 Offset = N.getOperand(0).getOperand(0);
700 Base = N.getOperand(1);
701 } else {
702 ShAmt = 0;
703 ShOpcVal = ARM_AM::no_shift;
704 }
Evan Chenga8e29892007-01-19 07:51:42 +0000705 } else {
706 ShOpcVal = ARM_AM::no_shift;
707 }
708 }
709 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000710
Evan Chenga8e29892007-01-19 07:51:42 +0000711 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000712 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000713 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000714}
715
Owen Anderson793e7962011-07-26 20:54:26 +0000716bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000717 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000718 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000719 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
720 ? cast<LoadSDNode>(Op)->getAddressingMode()
721 : cast<StoreSDNode>(Op)->getAddressingMode();
722 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
723 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000724 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000725 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
726 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000727
728 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000729 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000730 unsigned ShAmt = 0;
731 if (ShOpcVal != ARM_AM::no_shift) {
732 // Check to see if the RHS of the shift is a constant, if not, we can't fold
733 // it.
734 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000735 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000736 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
737 Offset = N.getOperand(0);
738 else {
739 ShAmt = 0;
740 ShOpcVal = ARM_AM::no_shift;
741 }
Evan Chenga8e29892007-01-19 07:51:42 +0000742 } else {
743 ShOpcVal = ARM_AM::no_shift;
744 }
745 }
746
747 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000748 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000749 return true;
750}
751
Owen Andersonc4e16de2011-08-29 20:16:50 +0000752bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
753 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000754 unsigned Opcode = Op->getOpcode();
755 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
756 ? cast<LoadSDNode>(Op)->getAddressingMode()
757 : cast<StoreSDNode>(Op)->getAddressingMode();
758 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
759 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000760 int Val;
761 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000762 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000763 Offset = CurDAG->getRegister(0, MVT::i32);
764 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
765 return true;
766 }
767
768 return false;
769}
770
771
Owen Anderson793e7962011-07-26 20:54:26 +0000772bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
773 SDValue &Offset, SDValue &Opc) {
774 unsigned Opcode = Op->getOpcode();
775 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
776 ? cast<LoadSDNode>(Op)->getAddressingMode()
777 : cast<StoreSDNode>(Op)->getAddressingMode();
778 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
779 ? ARM_AM::add : ARM_AM::sub;
780 int Val;
781 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
782 Offset = CurDAG->getRegister(0, MVT::i32);
783 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
784 ARM_AM::no_shift),
785 MVT::i32);
786 return true;
787 }
788
789 return false;
790}
791
Jim Grosbach19dec202011-08-05 20:35:44 +0000792bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
793 Base = N;
794 return true;
795}
Evan Chenga8e29892007-01-19 07:51:42 +0000796
Chris Lattner52a261b2010-09-21 20:31:19 +0000797bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000798 SDValue &Base, SDValue &Offset,
799 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000800 if (N.getOpcode() == ISD::SUB) {
801 // X - C is canonicalize to X + -C, no need to handle it here.
802 Base = N.getOperand(0);
803 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000804 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000805 return true;
806 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000807
Chris Lattner0a9481f2011-02-13 22:25:43 +0000808 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000809 Base = N;
810 if (N.getOpcode() == ISD::FrameIndex) {
811 int FI = cast<FrameIndexSDNode>(N)->getIndex();
812 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
813 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000814 Offset = CurDAG->getRegister(0, MVT::i32);
815 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000816 return true;
817 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000818
Evan Chenga8e29892007-01-19 07:51:42 +0000819 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000820 int RHSC;
821 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
822 -256 + 1, 256, RHSC)) { // 8 bits.
823 Base = N.getOperand(0);
824 if (Base.getOpcode() == ISD::FrameIndex) {
825 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
826 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000827 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000828 Offset = CurDAG->getRegister(0, MVT::i32);
829
830 ARM_AM::AddrOpc AddSub = ARM_AM::add;
831 if (RHSC < 0) {
832 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000833 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000834 }
835 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
836 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000837 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000838
Evan Chenga8e29892007-01-19 07:51:42 +0000839 Base = N.getOperand(0);
840 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000841 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000842 return true;
843}
844
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000845bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000846 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000847 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000848 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
849 ? cast<LoadSDNode>(Op)->getAddressingMode()
850 : cast<StoreSDNode>(Op)->getAddressingMode();
851 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
852 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000853 int Val;
854 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
855 Offset = CurDAG->getRegister(0, MVT::i32);
856 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
857 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000858 }
859
860 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000861 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000862 return true;
863}
864
Jim Grosbach3ab56582010-10-21 19:38:40 +0000865bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000866 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000867 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000868 Base = N;
869 if (N.getOpcode() == ISD::FrameIndex) {
870 int FI = cast<FrameIndexSDNode>(N)->getIndex();
871 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000872 } else if (N.getOpcode() == ARMISD::Wrapper &&
873 !(Subtarget->useMovt() &&
874 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000875 Base = N.getOperand(0);
876 }
877 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000879 return true;
880 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000881
Evan Chenga8e29892007-01-19 07:51:42 +0000882 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000883 int RHSC;
884 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
885 -256 + 1, 256, RHSC)) {
886 Base = N.getOperand(0);
887 if (Base.getOpcode() == ISD::FrameIndex) {
888 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
889 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000890 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000891
892 ARM_AM::AddrOpc AddSub = ARM_AM::add;
893 if (RHSC < 0) {
894 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000895 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000896 }
897 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
898 MVT::i32);
899 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000900 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000901
Evan Chenga8e29892007-01-19 07:51:42 +0000902 Base = N;
903 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000904 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000905 return true;
906}
907
Bob Wilson665814b2010-11-01 23:40:51 +0000908bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
909 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000910 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000911
912 unsigned Alignment = 0;
913 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
914 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
915 // The maximum alignment is equal to the memory size being referenced.
916 unsigned LSNAlign = LSN->getAlignment();
917 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000918 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000919 Alignment = MemSize;
920 } else {
921 // All other uses of addrmode6 are for intrinsics. For now just record
922 // the raw alignment value; it will be refined later based on the legal
923 // alignment operands for the intrinsic.
924 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
925 }
926
927 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000928 return true;
929}
930
Bob Wilsonda525062011-02-25 06:42:42 +0000931bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
932 SDValue &Offset) {
933 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
934 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
935 if (AM != ISD::POST_INC)
936 return false;
937 Offset = N;
938 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
939 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
940 Offset = CurDAG->getRegister(0, MVT::i32);
941 }
942 return true;
943}
944
Chris Lattner52a261b2010-09-21 20:31:19 +0000945bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000946 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000947 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
948 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000949 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000950 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
951 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000952 return true;
953 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000954
Evan Chenga8e29892007-01-19 07:51:42 +0000955 return false;
956}
957
Bill Wendlingf4caf692010-12-14 03:36:38 +0000958
959//===----------------------------------------------------------------------===//
960// Thumb Addressing Modes
961//===----------------------------------------------------------------------===//
962
Chris Lattner52a261b2010-09-21 20:31:19 +0000963bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000964 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000965 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000966 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000967 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000968 return false;
969
970 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000971 return true;
972 }
973
Evan Chenga8e29892007-01-19 07:51:42 +0000974 Base = N.getOperand(0);
975 Offset = N.getOperand(1);
976 return true;
977}
978
Evan Cheng79d43262007-01-24 02:21:22 +0000979bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000980ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
981 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000982 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000983 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000984 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000985 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000986
Evan Cheng012f2d92007-01-24 08:53:17 +0000987 if (N.getOpcode() == ARMISD::Wrapper &&
988 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
989 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000990 }
991
Chris Lattner0a9481f2011-02-13 22:25:43 +0000992 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000993 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000994
Evan Chengad0e4652007-02-06 00:22:06 +0000995 // Thumb does not have [sp, r] address mode.
996 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
997 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
998 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000999 (RHSR && RHSR->getReg() == ARM::SP))
1000 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001001
Daniel Dunbarec91d522011-01-19 15:12:16 +00001002 // FIXME: Why do we explicitly check for a match here and then return false?
1003 // Presumably to allow something else to match, but shouldn't this be
1004 // documented?
1005 int RHSC;
1006 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1007 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001008
1009 Base = N.getOperand(0);
1010 Offset = N.getOperand(1);
1011 return true;
1012}
1013
1014bool
1015ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1016 SDValue &Base,
1017 SDValue &Offset) {
1018 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1019}
1020
1021bool
1022ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1023 SDValue &Base,
1024 SDValue &Offset) {
1025 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1026}
1027
1028bool
1029ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1030 SDValue &Base,
1031 SDValue &Offset) {
1032 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1033}
1034
1035bool
1036ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1037 SDValue &Base, SDValue &OffImm) {
1038 if (Scale == 4) {
1039 SDValue TmpBase, TmpOffImm;
1040 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1041 return false; // We want to select tLDRspi / tSTRspi instead.
1042
1043 if (N.getOpcode() == ARMISD::Wrapper &&
1044 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1045 return false; // We want to select tLDRpci instead.
1046 }
1047
Chris Lattner0a9481f2011-02-13 22:25:43 +00001048 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001049 if (N.getOpcode() == ARMISD::Wrapper &&
1050 !(Subtarget->useMovt() &&
1051 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1052 Base = N.getOperand(0);
1053 } else {
1054 Base = N;
1055 }
1056
Owen Anderson825b72b2009-08-11 20:47:22 +00001057 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001058 return true;
1059 }
1060
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001061 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1062 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1063 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1064 (RHSR && RHSR->getReg() == ARM::SP)) {
1065 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1066 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1067 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1068 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1069
1070 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1071 if (LHSC != 0 || RHSC != 0) return false;
1072
1073 Base = N;
1074 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1075 return true;
1076 }
1077
Evan Chenga8e29892007-01-19 07:51:42 +00001078 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001079 int RHSC;
1080 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1081 Base = N.getOperand(0);
1082 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1083 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001084 }
1085
Evan Chengc38f2bc2007-01-23 22:59:13 +00001086 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001087 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001088 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001089}
1090
Bill Wendlingf4caf692010-12-14 03:36:38 +00001091bool
1092ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1093 SDValue &OffImm) {
1094 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001095}
1096
Bill Wendlingf4caf692010-12-14 03:36:38 +00001097bool
1098ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1099 SDValue &OffImm) {
1100 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001101}
1102
Bill Wendlingf4caf692010-12-14 03:36:38 +00001103bool
1104ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1105 SDValue &OffImm) {
1106 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001107}
1108
Chris Lattner52a261b2010-09-21 20:31:19 +00001109bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1110 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001111 if (N.getOpcode() == ISD::FrameIndex) {
1112 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1113 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001114 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001115 return true;
1116 }
Evan Cheng79d43262007-01-24 02:21:22 +00001117
Chris Lattner0a9481f2011-02-13 22:25:43 +00001118 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001119 return false;
1120
1121 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001122 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1123 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001124 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001125 int RHSC;
1126 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1127 Base = N.getOperand(0);
1128 if (Base.getOpcode() == ISD::FrameIndex) {
1129 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1130 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001131 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001132 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1133 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001134 }
1135 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001136
Evan Chenga8e29892007-01-19 07:51:42 +00001137 return false;
1138}
1139
Bill Wendlingf4caf692010-12-14 03:36:38 +00001140
1141//===----------------------------------------------------------------------===//
1142// Thumb 2 Addressing Modes
1143//===----------------------------------------------------------------------===//
1144
1145
Chris Lattner52a261b2010-09-21 20:31:19 +00001146bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001147 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001148 if (DisableShifterOp)
1149 return false;
1150
Evan Chengee04a6d2011-07-20 23:34:39 +00001151 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001152
1153 // Don't match base register only case. That is matched to a separate
1154 // lower complexity pattern with explicit register operand.
1155 if (ShOpcVal == ARM_AM::no_shift) return false;
1156
1157 BaseReg = N.getOperand(0);
1158 unsigned ShImmVal = 0;
1159 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1160 ShImmVal = RHS->getZExtValue() & 31;
1161 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1162 return true;
1163 }
1164
1165 return false;
1166}
1167
Chris Lattner52a261b2010-09-21 20:31:19 +00001168bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001169 SDValue &Base, SDValue &OffImm) {
1170 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001171
Evan Cheng3a214252009-08-11 08:52:18 +00001172 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001173 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1174 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001175 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001176 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001177 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1178 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001179 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001180 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001181 }
Owen Anderson099e5552011-03-18 19:46:58 +00001182
Chris Lattner0a9481f2011-02-13 22:25:43 +00001183 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001184 !(Subtarget->useMovt() &&
1185 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001186 Base = N.getOperand(0);
1187 if (Base.getOpcode() == ISD::TargetConstantPool)
1188 return false; // We want to select t2LDRpci instead.
1189 } else
1190 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001191 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001192 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001193 }
Evan Cheng055b0312009-06-29 07:51:04 +00001194
1195 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001196 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001197 // Let t2LDRi8 handle (R - imm8).
1198 return false;
1199
Evan Cheng055b0312009-06-29 07:51:04 +00001200 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001201 if (N.getOpcode() == ISD::SUB)
1202 RHSC = -RHSC;
1203
1204 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001205 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001206 if (Base.getOpcode() == ISD::FrameIndex) {
1207 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1208 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1209 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001210 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001211 return true;
1212 }
1213 }
1214
Evan Cheng3a214252009-08-11 08:52:18 +00001215 // Base only.
1216 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001217 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001218 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001219}
1220
Chris Lattner52a261b2010-09-21 20:31:19 +00001221bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001222 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001223 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001224 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1225 !CurDAG->isBaseWithConstantOffset(N))
1226 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001227
Chris Lattner0a9481f2011-02-13 22:25:43 +00001228 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1229 int RHSC = (int)RHS->getSExtValue();
1230 if (N.getOpcode() == ISD::SUB)
1231 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001232
Chris Lattner0a9481f2011-02-13 22:25:43 +00001233 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1234 Base = N.getOperand(0);
1235 if (Base.getOpcode() == ISD::FrameIndex) {
1236 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1237 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001238 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001239 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1240 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001241 }
1242 }
1243
1244 return false;
1245}
1246
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001247bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001248 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001249 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001250 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1251 ? cast<LoadSDNode>(Op)->getAddressingMode()
1252 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001253 int RHSC;
1254 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1255 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1256 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1257 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1258 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001259 }
1260
1261 return false;
1262}
1263
Chris Lattner52a261b2010-09-21 20:31:19 +00001264bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001265 SDValue &Base,
1266 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001267 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001268 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001269 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001270
Evan Cheng3a214252009-08-11 08:52:18 +00001271 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1272 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1273 int RHSC = (int)RHS->getZExtValue();
1274 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1275 return false;
1276 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001277 return false;
1278 }
1279
Evan Cheng055b0312009-06-29 07:51:04 +00001280 // Look for (R + R) or (R + (R << [1,2,3])).
1281 unsigned ShAmt = 0;
1282 Base = N.getOperand(0);
1283 OffReg = N.getOperand(1);
1284
1285 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001286 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001287 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001288 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001289 if (ShOpcVal == ARM_AM::lsl)
1290 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001291 }
1292
Evan Cheng055b0312009-06-29 07:51:04 +00001293 if (ShOpcVal == ARM_AM::lsl) {
1294 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1295 // it.
1296 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1297 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001298 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1299 OffReg = OffReg.getOperand(0);
1300 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001301 ShAmt = 0;
1302 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001303 }
Evan Cheng055b0312009-06-29 07:51:04 +00001304 } else {
1305 ShOpcVal = ARM_AM::no_shift;
1306 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001307 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001308
Owen Anderson825b72b2009-08-11 20:47:22 +00001309 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001310
1311 return true;
1312}
1313
1314//===--------------------------------------------------------------------===//
1315
Evan Chengee568cf2007-07-05 07:15:27 +00001316/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001317static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001318 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001319}
1320
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001321SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1322 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001323 ISD::MemIndexedMode AM = LD->getAddressingMode();
1324 if (AM == ISD::UNINDEXED)
1325 return NULL;
1326
Owen Andersone50ed302009-08-10 22:56:29 +00001327 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001328 SDValue Offset, AMOpc;
1329 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1330 unsigned Opcode = 0;
1331 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001332 if (LoadedVT == MVT::i32 && isPre &&
1333 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1334 Opcode = ARM::LDR_PRE_IMM;
1335 Match = true;
1336 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001337 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001338 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001339 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001340 } else if (LoadedVT == MVT::i32 &&
1341 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001342 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001343 Match = true;
1344
Owen Anderson825b72b2009-08-11 20:47:22 +00001345 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001346 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001347 Match = true;
1348 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1349 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1350 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001351 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001352 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001353 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001354 Match = true;
1355 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1356 }
1357 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001358 if (isPre &&
1359 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001360 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001361 Opcode = ARM::LDRB_PRE_IMM;
1362 } else if (!isPre &&
1363 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1364 Match = true;
1365 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001366 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1367 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001368 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001369 }
1370 }
1371 }
1372
1373 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001374 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1375 SDValue Chain = LD->getChain();
1376 SDValue Base = LD->getBasePtr();
1377 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1378 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001379 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1380 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001381 } else {
1382 SDValue Chain = LD->getChain();
1383 SDValue Base = LD->getBasePtr();
1384 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1385 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001386 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1387 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001388 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001389 }
1390
1391 return NULL;
1392}
1393
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001394SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1395 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001396 ISD::MemIndexedMode AM = LD->getAddressingMode();
1397 if (AM == ISD::UNINDEXED)
1398 return NULL;
1399
Owen Andersone50ed302009-08-10 22:56:29 +00001400 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001401 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001402 SDValue Offset;
1403 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1404 unsigned Opcode = 0;
1405 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001406 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001407 switch (LoadedVT.getSimpleVT().SimpleTy) {
1408 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001409 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1410 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001411 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001412 if (isSExtLd)
1413 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1414 else
1415 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001416 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001417 case MVT::i8:
1418 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001419 if (isSExtLd)
1420 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1421 else
1422 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001423 break;
1424 default:
1425 return NULL;
1426 }
1427 Match = true;
1428 }
1429
1430 if (Match) {
1431 SDValue Chain = LD->getChain();
1432 SDValue Base = LD->getBasePtr();
1433 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001434 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001435 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001436 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001437 }
1438
1439 return NULL;
1440}
1441
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001442/// PairSRegs - Form a D register from a pair of S registers.
1443///
1444SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1445 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001446 SDValue RegClass =
1447 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001448 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1449 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001450 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1451 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001452}
1453
Evan Cheng603afbf2010-05-10 17:34:18 +00001454/// PairDRegs - Form a quad register from a pair of D registers.
1455///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001456SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1457 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001458 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001459 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1460 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001461 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1462 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001463}
1464
Evan Cheng7f687192010-05-14 00:21:45 +00001465/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001466///
1467SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1468 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001469 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001470 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1471 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001472 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1473 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001474}
1475
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001476/// QuadSRegs - Form 4 consecutive S registers.
1477///
1478SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1479 SDValue V2, SDValue V3) {
1480 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001481 SDValue RegClass =
1482 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001483 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1484 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1485 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1486 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001487 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1488 V2, SubReg2, V3, SubReg3 };
1489 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001490}
1491
Evan Cheng7f687192010-05-14 00:21:45 +00001492/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001493///
1494SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1495 SDValue V2, SDValue V3) {
1496 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001497 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001498 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1499 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1500 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1501 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001502 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1503 V2, SubReg2, V3, SubReg3 };
1504 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001505}
1506
Evan Cheng8f6de382010-05-16 03:27:48 +00001507/// QuadQRegs - Form 4 consecutive Q registers.
1508///
1509SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1510 SDValue V2, SDValue V3) {
1511 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001512 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001513 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1514 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1515 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1516 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001517 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1518 V2, SubReg2, V3, SubReg3 };
1519 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001520}
1521
Bob Wilson2a6e6162010-09-23 23:42:37 +00001522/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1523/// of a NEON VLD or VST instruction. The supported values depend on the
1524/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001525SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1526 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001527 unsigned NumRegs = NumVecs;
1528 if (!is64BitVector && NumVecs < 3)
1529 NumRegs *= 2;
1530
Bob Wilson665814b2010-11-01 23:40:51 +00001531 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001532 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001533 Alignment = 32;
1534 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1535 Alignment = 16;
1536 else if (Alignment >= 8)
1537 Alignment = 8;
1538 else
1539 Alignment = 0;
1540
1541 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001542}
1543
Jim Grosbach10b90a92011-10-24 21:45:13 +00001544// Get the register stride update opcode of a VLD/VST instruction that
1545// is otherwise equivalent to the given fixed stride updating instruction.
1546static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1547 switch (Opc) {
1548 default: break;
1549 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1550 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1551 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1552 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1553 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1554 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1555 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1556 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001557
1558 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1559 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1560 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1561 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1562 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1563 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1564 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1565 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001566 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001567 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001568
Jim Grosbach28f08c92012-03-05 19:33:30 +00001569 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1570 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1571 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001572 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1573 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1574 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1575
Jim Grosbach28f08c92012-03-05 19:33:30 +00001576 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1577 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1578 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001579 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1580 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1581 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001582
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001583 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1584 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1585 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001586 }
1587 return Opc; // If not one we handle, return it unchanged.
1588}
1589
Bob Wilson1c3ef902011-02-07 17:43:21 +00001590SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001591 const uint16_t *DOpcodes,
1592 const uint16_t *QOpcodes0,
1593 const uint16_t *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001594 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001595 DebugLoc dl = N->getDebugLoc();
1596
Bob Wilson226036e2010-03-20 22:13:40 +00001597 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001598 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1599 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001600 return NULL;
1601
1602 SDValue Chain = N->getOperand(0);
1603 EVT VT = N->getValueType(0);
1604 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001605 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001606
Bob Wilson3e36f132009-10-14 17:28:52 +00001607 unsigned OpcodeIndex;
1608 switch (VT.getSimpleVT().SimpleTy) {
1609 default: llvm_unreachable("unhandled vld type");
1610 // Double-register operations:
1611 case MVT::v8i8: OpcodeIndex = 0; break;
1612 case MVT::v4i16: OpcodeIndex = 1; break;
1613 case MVT::v2f32:
1614 case MVT::v2i32: OpcodeIndex = 2; break;
1615 case MVT::v1i64: OpcodeIndex = 3; break;
1616 // Quad-register operations:
1617 case MVT::v16i8: OpcodeIndex = 0; break;
1618 case MVT::v8i16: OpcodeIndex = 1; break;
1619 case MVT::v4f32:
1620 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001621 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001622 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001623 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001624 }
1625
Bob Wilsonf5721912010-09-03 18:16:02 +00001626 EVT ResTy;
1627 if (NumVecs == 1)
1628 ResTy = VT;
1629 else {
1630 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1631 if (!is64BitVector)
1632 ResTyElts *= 2;
1633 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1634 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001635 std::vector<EVT> ResTys;
1636 ResTys.push_back(ResTy);
1637 if (isUpdating)
1638 ResTys.push_back(MVT::i32);
1639 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001640
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001641 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001642 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001643 SDNode *VLd;
1644 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001645
Bob Wilson1c3ef902011-02-07 17:43:21 +00001646 // Double registers and VLD1/VLD2 quad registers are directly supported.
1647 if (is64BitVector || NumVecs <= 2) {
1648 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1649 QOpcodes0[OpcodeIndex]);
1650 Ops.push_back(MemAddr);
1651 Ops.push_back(Align);
1652 if (isUpdating) {
1653 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001654 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001655 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001656 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001657 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001658 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001659 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001660 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001661 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001662 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001663 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001664 Ops.push_back(Pred);
1665 Ops.push_back(Reg0);
1666 Ops.push_back(Chain);
1667 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001668
Bob Wilson3e36f132009-10-14 17:28:52 +00001669 } else {
1670 // Otherwise, quad registers are loaded with two separate instructions,
1671 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001672 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001673
Bob Wilson1c3ef902011-02-07 17:43:21 +00001674 // Load the even subregs. This is always an updating load, so that it
1675 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001676 SDValue ImplDef =
1677 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1678 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001679 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1680 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001681 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001682
Bob Wilson24f995d2009-10-14 18:32:29 +00001683 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001684 Ops.push_back(SDValue(VLdA, 1));
1685 Ops.push_back(Align);
1686 if (isUpdating) {
1687 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1688 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1689 "only constant post-increment update allowed for VLD3/4");
1690 (void)Inc;
1691 Ops.push_back(Reg0);
1692 }
1693 Ops.push_back(SDValue(VLdA, 0));
1694 Ops.push_back(Pred);
1695 Ops.push_back(Reg0);
1696 Ops.push_back(Chain);
1697 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1698 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001699 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001700
Evan Chengb58a3402011-04-19 00:04:03 +00001701 // Transfer memoperands.
1702 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1703 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1704 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1705
Bob Wilson1c3ef902011-02-07 17:43:21 +00001706 if (NumVecs == 1)
1707 return VLd;
1708
1709 // Extract out the subregisters.
1710 SDValue SuperReg = SDValue(VLd, 0);
1711 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1712 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1713 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1714 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1715 ReplaceUses(SDValue(N, Vec),
1716 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1717 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1718 if (isUpdating)
1719 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001720 return NULL;
1721}
1722
Bob Wilson1c3ef902011-02-07 17:43:21 +00001723SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001724 const uint16_t *DOpcodes,
1725 const uint16_t *QOpcodes0,
1726 const uint16_t *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001727 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001728 DebugLoc dl = N->getDebugLoc();
1729
Bob Wilson226036e2010-03-20 22:13:40 +00001730 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001731 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1732 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1733 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001734 return NULL;
1735
Evan Chengb58a3402011-04-19 00:04:03 +00001736 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1737 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1738
Bob Wilson24f995d2009-10-14 18:32:29 +00001739 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001740 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001741 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001742 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001743
Bob Wilson24f995d2009-10-14 18:32:29 +00001744 unsigned OpcodeIndex;
1745 switch (VT.getSimpleVT().SimpleTy) {
1746 default: llvm_unreachable("unhandled vst type");
1747 // Double-register operations:
1748 case MVT::v8i8: OpcodeIndex = 0; break;
1749 case MVT::v4i16: OpcodeIndex = 1; break;
1750 case MVT::v2f32:
1751 case MVT::v2i32: OpcodeIndex = 2; break;
1752 case MVT::v1i64: OpcodeIndex = 3; break;
1753 // Quad-register operations:
1754 case MVT::v16i8: OpcodeIndex = 0; break;
1755 case MVT::v8i16: OpcodeIndex = 1; break;
1756 case MVT::v4f32:
1757 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001758 case MVT::v2i64: OpcodeIndex = 3;
1759 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1760 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001761 }
1762
Bob Wilson1c3ef902011-02-07 17:43:21 +00001763 std::vector<EVT> ResTys;
1764 if (isUpdating)
1765 ResTys.push_back(MVT::i32);
1766 ResTys.push_back(MVT::Other);
1767
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001768 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001769 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001770 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001771
Bob Wilson1c3ef902011-02-07 17:43:21 +00001772 // Double registers and VST1/VST2 quad registers are directly supported.
1773 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001774 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001775 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001776 SrcReg = N->getOperand(Vec0Idx);
1777 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001778 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001779 SDValue V0 = N->getOperand(Vec0Idx + 0);
1780 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001781 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001782 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001783 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001784 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001785 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001786 // an undef.
1787 SDValue V3 = (NumVecs == 3)
1788 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001789 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001790 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001791 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001792 } else {
1793 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001794 SDValue Q0 = N->getOperand(Vec0Idx);
1795 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001796 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001797 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001798
1799 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1800 QOpcodes0[OpcodeIndex]);
1801 Ops.push_back(MemAddr);
1802 Ops.push_back(Align);
1803 if (isUpdating) {
1804 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001805 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001806 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001807 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001808 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1809 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1810 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001811 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001812 !isa<ConstantSDNode>(Inc.getNode()))
1813 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001814 }
1815 Ops.push_back(SrcReg);
1816 Ops.push_back(Pred);
1817 Ops.push_back(Reg0);
1818 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001819 SDNode *VSt =
1820 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1821
1822 // Transfer memoperands.
1823 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1824
1825 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001826 }
1827
1828 // Otherwise, quad registers are stored with two separate instructions,
1829 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001830
Bob Wilson07f6e802010-06-16 21:34:01 +00001831 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001832 SDValue V0 = N->getOperand(Vec0Idx + 0);
1833 SDValue V1 = N->getOperand(Vec0Idx + 1);
1834 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001835 SDValue V3 = (NumVecs == 3)
1836 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001837 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001838 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001839
Bob Wilson1c3ef902011-02-07 17:43:21 +00001840 // Store the even D registers. This is always an updating store, so that it
1841 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001842 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1843 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1844 MemAddr.getValueType(),
1845 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001846 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001847 Chain = SDValue(VStA, 1);
1848
1849 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001850 Ops.push_back(SDValue(VStA, 0));
1851 Ops.push_back(Align);
1852 if (isUpdating) {
1853 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1854 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1855 "only constant post-increment update allowed for VST3/4");
1856 (void)Inc;
1857 Ops.push_back(Reg0);
1858 }
1859 Ops.push_back(RegSeq);
1860 Ops.push_back(Pred);
1861 Ops.push_back(Reg0);
1862 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001863 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1864 Ops.data(), Ops.size());
1865 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1866 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001867}
1868
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001869SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001870 bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001871 const uint16_t *DOpcodes,
1872 const uint16_t *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001873 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001874 DebugLoc dl = N->getDebugLoc();
1875
Bob Wilson226036e2010-03-20 22:13:40 +00001876 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001877 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1878 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1879 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001880 return NULL;
1881
Evan Chengb58a3402011-04-19 00:04:03 +00001882 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1883 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1884
Bob Wilsona7c397c2009-10-14 16:19:03 +00001885 SDValue Chain = N->getOperand(0);
1886 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001887 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1888 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001889 bool is64BitVector = VT.is64BitVector();
1890
Bob Wilson665814b2010-11-01 23:40:51 +00001891 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001892 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001893 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001894 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1895 if (Alignment > NumBytes)
1896 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001897 if (Alignment < 8 && Alignment < NumBytes)
1898 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001899 // Alignment must be a power of two; make sure of that.
1900 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001901 if (Alignment == 1)
1902 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001903 }
Bob Wilson665814b2010-11-01 23:40:51 +00001904 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001905
Bob Wilsona7c397c2009-10-14 16:19:03 +00001906 unsigned OpcodeIndex;
1907 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001908 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001909 // Double-register operations:
1910 case MVT::v8i8: OpcodeIndex = 0; break;
1911 case MVT::v4i16: OpcodeIndex = 1; break;
1912 case MVT::v2f32:
1913 case MVT::v2i32: OpcodeIndex = 2; break;
1914 // Quad-register operations:
1915 case MVT::v8i16: OpcodeIndex = 0; break;
1916 case MVT::v4f32:
1917 case MVT::v4i32: OpcodeIndex = 1; break;
1918 }
1919
Bob Wilson1c3ef902011-02-07 17:43:21 +00001920 std::vector<EVT> ResTys;
1921 if (IsLoad) {
1922 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1923 if (!is64BitVector)
1924 ResTyElts *= 2;
1925 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1926 MVT::i64, ResTyElts));
1927 }
1928 if (isUpdating)
1929 ResTys.push_back(MVT::i32);
1930 ResTys.push_back(MVT::Other);
1931
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001932 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001933 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001934
Bob Wilson1c3ef902011-02-07 17:43:21 +00001935 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001936 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001937 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001938 if (isUpdating) {
1939 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1940 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1941 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001942
Bob Wilson8466fa12010-09-13 23:01:35 +00001943 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001944 SDValue V0 = N->getOperand(Vec0Idx + 0);
1945 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001946 if (NumVecs == 2) {
1947 if (is64BitVector)
1948 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1949 else
1950 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001951 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001952 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001953 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001954 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1955 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001956 if (is64BitVector)
1957 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1958 else
1959 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001960 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001961 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001962 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001963 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001964 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001965 Ops.push_back(Chain);
1966
Bob Wilson1c3ef902011-02-07 17:43:21 +00001967 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1968 QOpcodes[OpcodeIndex]);
1969 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1970 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001971 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001972 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001973 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001974
Bob Wilson8466fa12010-09-13 23:01:35 +00001975 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001976 SuperReg = SDValue(VLdLn, 0);
1977 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1978 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1979 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001980 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1981 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001982 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1983 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1984 if (isUpdating)
1985 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001986 return NULL;
1987}
1988
Bob Wilson1c3ef902011-02-07 17:43:21 +00001989SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper51f50c12012-05-24 05:17:00 +00001990 unsigned NumVecs,
1991 const uint16_t *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001992 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1993 DebugLoc dl = N->getDebugLoc();
1994
1995 SDValue MemAddr, Align;
1996 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1997 return NULL;
1998
Evan Chengb58a3402011-04-19 00:04:03 +00001999 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2000 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2001
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002002 SDValue Chain = N->getOperand(0);
2003 EVT VT = N->getValueType(0);
2004
2005 unsigned Alignment = 0;
2006 if (NumVecs != 3) {
2007 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2008 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2009 if (Alignment > NumBytes)
2010 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002011 if (Alignment < 8 && Alignment < NumBytes)
2012 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002013 // Alignment must be a power of two; make sure of that.
2014 Alignment = (Alignment & -Alignment);
2015 if (Alignment == 1)
2016 Alignment = 0;
2017 }
2018 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2019
2020 unsigned OpcodeIndex;
2021 switch (VT.getSimpleVT().SimpleTy) {
2022 default: llvm_unreachable("unhandled vld-dup type");
2023 case MVT::v8i8: OpcodeIndex = 0; break;
2024 case MVT::v4i16: OpcodeIndex = 1; break;
2025 case MVT::v2f32:
2026 case MVT::v2i32: OpcodeIndex = 2; break;
2027 }
2028
2029 SDValue Pred = getAL(CurDAG);
2030 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2031 SDValue SuperReg;
2032 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002033 SmallVector<SDValue, 6> Ops;
2034 Ops.push_back(MemAddr);
2035 Ops.push_back(Align);
2036 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002037 // fixed-stride update instructions don't have an explicit writeback
2038 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002039 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002040 if (!isa<ConstantSDNode>(Inc.getNode()))
2041 Ops.push_back(Inc);
2042 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2043 else if (NumVecs > 2)
2044 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002045 }
2046 Ops.push_back(Pred);
2047 Ops.push_back(Reg0);
2048 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002049
2050 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002051 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002052 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002053 if (isUpdating)
2054 ResTys.push_back(MVT::i32);
2055 ResTys.push_back(MVT::Other);
2056 SDNode *VLdDup =
2057 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002058 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002059 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002060
2061 // Extract the subregisters.
2062 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2063 unsigned SubIdx = ARM::dsub_0;
2064 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2065 ReplaceUses(SDValue(N, Vec),
2066 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002067 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2068 if (isUpdating)
2069 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002070 return NULL;
2071}
2072
Bob Wilson78dfbc32010-07-07 00:08:54 +00002073SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2074 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002075 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2076 DebugLoc dl = N->getDebugLoc();
2077 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002078 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002079
2080 // Form a REG_SEQUENCE to force register allocation.
2081 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002082 SDValue V0 = N->getOperand(FirstTblReg + 0);
2083 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002084 if (NumVecs == 2)
2085 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2086 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002087 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002088 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002089 // an undef.
2090 SDValue V3 = (NumVecs == 3)
2091 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002092 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002093 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2094 }
2095
Bob Wilson78dfbc32010-07-07 00:08:54 +00002096 SmallVector<SDValue, 6> Ops;
2097 if (IsExt)
2098 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002099 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002100 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002101 Ops.push_back(getAL(CurDAG)); // predicate
2102 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002103 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002104}
2105
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002106SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002107 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002108 if (!Subtarget->hasV6T2Ops())
2109 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002110
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002111 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2112 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2113
2114
2115 // For unsigned extracts, check for a shift right and mask
2116 unsigned And_imm = 0;
2117 if (N->getOpcode() == ISD::AND) {
2118 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2119
2120 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2121 if (And_imm & (And_imm + 1))
2122 return NULL;
2123
2124 unsigned Srl_imm = 0;
2125 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2126 Srl_imm)) {
2127 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2128
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002129 // Note: The width operand is encoded as width-1.
2130 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002131 unsigned LSB = Srl_imm;
2132 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2133 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2134 CurDAG->getTargetConstant(LSB, MVT::i32),
2135 CurDAG->getTargetConstant(Width, MVT::i32),
2136 getAL(CurDAG), Reg0 };
2137 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2138 }
2139 }
2140 return NULL;
2141 }
2142
2143 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002144 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002145 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002146 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2147 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002149 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002150 // Note: The width operand is encoded as width-1.
2151 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002152 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002153 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002154 return NULL;
2155 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002156 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002157 CurDAG->getTargetConstant(LSB, MVT::i32),
2158 CurDAG->getTargetConstant(Width, MVT::i32),
2159 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002160 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002161 }
2162 }
2163 return NULL;
2164}
2165
Evan Cheng9ef48352009-11-20 00:54:03 +00002166SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002167SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002168 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2169 SDValue CPTmp0;
2170 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002171 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2173 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2174 unsigned Opc = 0;
2175 switch (SOShOp) {
2176 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2177 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2178 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2179 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2180 default:
2181 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng9ef48352009-11-20 00:54:03 +00002182 }
2183 SDValue SOShImm =
2184 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2185 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2186 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002187 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002188 }
2189 return 0;
2190}
2191
2192SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002193SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002194 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2195 SDValue CPTmp0;
2196 SDValue CPTmp1;
2197 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002198 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002199 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002200 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2201 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002202 }
2203
2204 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2205 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2206 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2207 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 }
2209 return 0;
2210}
2211
2212SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002213SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002214 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002215 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002216 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002217 return 0;
2218
Evan Cheng63f35442010-11-13 02:25:14 +00002219 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002220 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002221 if (is_t2_so_imm(TrueImm)) {
2222 Opc = ARM::t2MOVCCi;
2223 } else if (TrueImm <= 0xffff) {
2224 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002225 } else if (is_t2_so_imm_not(TrueImm)) {
2226 TrueImm = ~TrueImm;
2227 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002228 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002229 // Large immediate.
2230 Opc = ARM::t2MOVCCi32imm;
2231 }
2232
2233 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002234 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002235 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2236 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002237 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002238 }
Evan Cheng63f35442010-11-13 02:25:14 +00002239
Evan Cheng9ef48352009-11-20 00:54:03 +00002240 return 0;
2241}
2242
2243SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002244SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002245 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002246 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2247 if (!T)
2248 return 0;
2249
Evan Cheng63f35442010-11-13 02:25:14 +00002250 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002251 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002252 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002253 if (isSoImm) {
2254 Opc = ARM::MOVCCi;
2255 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2256 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002257 } else if (is_so_imm_not(TrueImm)) {
2258 TrueImm = ~TrueImm;
2259 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002260 } else if (TrueVal.getNode()->hasOneUse() &&
2261 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002262 // Large immediate.
2263 Opc = ARM::MOVCCi32imm;
2264 }
2265
2266 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002267 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002268 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2269 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002270 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002271 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002272
Evan Cheng9ef48352009-11-20 00:54:03 +00002273 return 0;
2274}
2275
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002276SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2277 EVT VT = N->getValueType(0);
2278 SDValue FalseVal = N->getOperand(0);
2279 SDValue TrueVal = N->getOperand(1);
2280 SDValue CC = N->getOperand(2);
2281 SDValue CCR = N->getOperand(3);
2282 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002283 assert(CC.getOpcode() == ISD::Constant);
2284 assert(CCR.getOpcode() == ISD::Register);
2285 ARMCC::CondCodes CCVal =
2286 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002287
2288 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2289 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2290 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2291 // Pattern complexity = 18 cost = 1 size = 0
Evan Cheng07ba9062009-11-19 21:45:22 +00002292 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002293 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002294 CCVal, CCR, InFlag);
2295 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002296 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002297 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2298 if (Res)
2299 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002300 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002302 CCVal, CCR, InFlag);
2303 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002304 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002305 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2306 if (Res)
2307 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002308 }
2309
2310 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002311 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002312 // (imm:i32):$cc)
2313 // Emits: (MOVCCi:i32 GPR:i32:$false,
2314 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2315 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002316 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002317 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002318 CCVal, CCR, InFlag);
2319 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002320 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002321 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2322 if (Res)
2323 return Res;
2324 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002325 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002326 CCVal, CCR, InFlag);
2327 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002328 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002329 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2330 if (Res)
2331 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002332 }
2333 }
2334
2335 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2336 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2337 // Pattern complexity = 6 cost = 1 size = 0
2338 //
2339 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2340 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2341 // Pattern complexity = 6 cost = 11 size = 0
2342 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002343 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002344 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2345 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002346 unsigned Opc = 0;
2347 switch (VT.getSimpleVT().SimpleTy) {
Craig Topperbc219812012-02-07 02:50:20 +00002348 default: llvm_unreachable("Illegal conditional move type!");
Evan Cheng07ba9062009-11-19 21:45:22 +00002349 case MVT::i32:
2350 Opc = Subtarget->isThumb()
2351 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2352 : ARM::MOVCCr;
2353 break;
2354 case MVT::f32:
2355 Opc = ARM::VMOVScc;
2356 break;
2357 case MVT::f64:
2358 Opc = ARM::VMOVDcc;
2359 break;
2360 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002361 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002362}
2363
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002364/// Target-specific DAG combining for ISD::XOR.
2365/// Target-independent combining lowers SELECT_CC nodes of the form
2366/// select_cc setg[ge] X, 0, X, -X
2367/// select_cc setgt X, -1, X, -X
2368/// select_cc setl[te] X, 0, -X, X
2369/// select_cc setlt X, 1, -X, X
2370/// which represent Integer ABS into:
2371/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2372/// ARM instruction selection detects the latter and matches it to
2373/// ARM::ABS or ARM::t2ABS machine node.
2374SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2375 SDValue XORSrc0 = N->getOperand(0);
2376 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002377 EVT VT = N->getValueType(0);
2378
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002379 if (Subtarget->isThumb1Only())
2380 return NULL;
2381
Jim Grosbach27690282012-08-01 20:33:00 +00002382 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002383 return NULL;
2384
2385 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2386 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2387 SDValue SRASrc0 = XORSrc1.getOperand(0);
2388 SDValue SRASrc1 = XORSrc1.getOperand(1);
2389 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2390 EVT XType = SRASrc0.getValueType();
2391 unsigned Size = XType.getSizeInBits() - 1;
2392
Jim Grosbach27690282012-08-01 20:33:00 +00002393 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2394 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002395 Size == SRAConstant->getZExtValue()) {
Jim Grosbach27690282012-08-01 20:33:00 +00002396 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002397 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2398 }
2399
2400 return NULL;
2401}
2402
Evan Chengde8aa4e2010-05-05 18:28:36 +00002403SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2404 // The only time a CONCAT_VECTORS operation can have legal types is when
2405 // two 64-bit vectors are concatenated to a 128-bit vector.
2406 EVT VT = N->getValueType(0);
2407 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2408 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002409 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002410}
2411
Eli Friedman2bdffe42011-08-31 00:31:29 +00002412SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002413 SmallVector<SDValue, 6> Ops;
2414 Ops.push_back(Node->getOperand(1)); // Ptr
2415 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2416 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002417 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002418 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2419 Ops.push_back(Node->getOperand(5)); // High part of Val2
2420 }
2421 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002422 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2423 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002424 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002425 MVT::i32, MVT::i32, MVT::Other,
2426 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002427 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2428 return ResNode;
2429}
2430
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002431SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002432 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002433
Dan Gohmane8be6c62008-07-17 19:10:17 +00002434 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002435 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002436
2437 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002438 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002439 case ISD::XOR: {
2440 // Select special operations if XOR node forms integer ABS pattern
2441 SDNode *ResNode = SelectABSOp(N);
2442 if (ResNode)
2443 return ResNode;
2444 // Other cases are autogenerated.
2445 break;
2446 }
Evan Chenga8e29892007-01-19 07:51:42 +00002447 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002448 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002449 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002450 if (Subtarget->hasThumb2())
2451 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2452 // be done with MOV + MOVT, at worst.
2453 UseCP = 0;
2454 else {
2455 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002456 UseCP = (Val > 255 && // MOV
2457 ~Val > 255 && // MOV + MVN
2458 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002459 } else
2460 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2461 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2462 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2463 }
2464
Evan Chenga8e29892007-01-19 07:51:42 +00002465 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002466 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002467 CurDAG->getTargetConstantPool(ConstantInt::get(
2468 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002469 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002470
2471 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002472 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002473 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002474 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002475 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002476 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002477 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002478 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002479 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002480 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002481 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002482 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002483 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002484 CurDAG->getEntryNode()
2485 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002486 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002487 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002488 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002489 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002490 return NULL;
2491 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002492
Evan Chenga8e29892007-01-19 07:51:42 +00002493 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002494 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002495 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002496 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002497 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002498 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002499 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002500 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002501 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2502 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2503 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002504 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002505 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2506 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002507 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2508 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2509 CurDAG->getRegister(0, MVT::i32) };
2510 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002511 }
Evan Chenga8e29892007-01-19 07:51:42 +00002512 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002513 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002514 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002515 return I;
2516 break;
2517 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002518 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002519 return I;
2520 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002521 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002522 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002523 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002524 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002525 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002526 if (!RHSV) break;
2527 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002528 unsigned ShImm = Log2_32(RHSV-1);
2529 if (ShImm >= 32)
2530 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002531 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002532 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002533 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2534 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002535 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002536 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002537 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002538 } else {
2539 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002540 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002541 }
Evan Chenga8e29892007-01-19 07:51:42 +00002542 }
2543 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002544 unsigned ShImm = Log2_32(RHSV+1);
2545 if (ShImm >= 32)
2546 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002547 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002548 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002549 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2550 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002551 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002552 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2553 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002554 } else {
2555 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002556 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002557 }
Evan Chenga8e29892007-01-19 07:51:42 +00002558 }
2559 }
2560 break;
Evan Cheng20956592009-10-21 08:15:52 +00002561 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002562 // Check for unsigned bitfield extract
2563 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2564 return I;
2565
Evan Cheng20956592009-10-21 08:15:52 +00002566 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2567 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2568 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2569 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2570 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002571 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002572 if (VT != MVT::i32)
2573 break;
2574 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2575 ? ARM::t2MOVTi16
2576 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2577 if (!Opc)
2578 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002579 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002580 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2581 if (!N1C)
2582 break;
2583 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2584 SDValue N2 = N0.getOperand(1);
2585 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2586 if (!N2C)
2587 break;
2588 unsigned N1CVal = N1C->getZExtValue();
2589 unsigned N2CVal = N2C->getZExtValue();
2590 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2591 (N1CVal & 0xffffU) == 0xffffU &&
2592 (N2CVal & 0xffffU) == 0x0U) {
2593 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2594 MVT::i32);
2595 SDValue Ops[] = { N0.getOperand(0), Imm16,
2596 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2597 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2598 }
2599 }
2600 break;
2601 }
Jim Grosbache5165492009-11-09 00:11:35 +00002602 case ARMISD::VMOVRRD:
2603 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002604 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002605 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002606 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002607 if (Subtarget->isThumb1Only())
2608 break;
2609 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002610 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002611 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2612 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002613 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002614 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002615 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002616 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2617 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002618 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2619 ARM::UMULL : ARM::UMULLv5,
2620 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002621 }
Evan Chengee568cf2007-07-05 07:15:27 +00002622 }
Dan Gohman525178c2007-10-08 18:33:35 +00002623 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002624 if (Subtarget->isThumb1Only())
2625 break;
2626 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002627 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002628 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002629 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002630 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002631 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002632 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2633 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002634 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2635 ARM::SMULL : ARM::SMULLv5,
2636 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002637 }
Evan Chengee568cf2007-07-05 07:15:27 +00002638 }
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002639 case ARMISD::UMLAL:{
2640 if (Subtarget->isThumb()) {
2641 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2642 N->getOperand(3), getAL(CurDAG),
2643 CurDAG->getRegister(0, MVT::i32)};
2644 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops, 6);
2645 }else{
2646 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2647 N->getOperand(3), getAL(CurDAG),
2648 CurDAG->getRegister(0, MVT::i32),
2649 CurDAG->getRegister(0, MVT::i32) };
2650 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2651 ARM::UMLAL : ARM::UMLALv5,
2652 dl, MVT::i32, MVT::i32, Ops, 7);
2653 }
2654 }
2655 case ARMISD::SMLAL:{
2656 if (Subtarget->isThumb()) {
2657 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2658 N->getOperand(3), getAL(CurDAG),
2659 CurDAG->getRegister(0, MVT::i32)};
2660 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops, 6);
2661 }else{
2662 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2663 N->getOperand(3), getAL(CurDAG),
2664 CurDAG->getRegister(0, MVT::i32),
2665 CurDAG->getRegister(0, MVT::i32) };
2666 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2667 ARM::SMLAL : ARM::SMLALv5,
2668 dl, MVT::i32, MVT::i32, Ops, 7);
2669 }
2670 }
Evan Chenga8e29892007-01-19 07:51:42 +00002671 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002672 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002673 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002674 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002675 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002676 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002677 if (ResNode)
2678 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002679 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002680 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002681 }
Evan Chengee568cf2007-07-05 07:15:27 +00002682 case ARMISD::BRCOND: {
2683 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2684 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2685 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002686
Evan Chengee568cf2007-07-05 07:15:27 +00002687 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2688 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2689 // Pattern complexity = 6 cost = 1 size = 0
2690
David Goodwin5e47a9a2009-06-30 18:04:13 +00002691 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2692 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2693 // Pattern complexity = 6 cost = 1 size = 0
2694
Jim Grosbach764ab522009-08-11 15:33:49 +00002695 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002696 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002697 SDValue Chain = N->getOperand(0);
2698 SDValue N1 = N->getOperand(1);
2699 SDValue N2 = N->getOperand(2);
2700 SDValue N3 = N->getOperand(3);
2701 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002702 assert(N1.getOpcode() == ISD::BasicBlock);
2703 assert(N2.getOpcode() == ISD::Constant);
2704 assert(N3.getOpcode() == ISD::Register);
2705
Dan Gohman475871a2008-07-27 21:46:04 +00002706 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002707 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002708 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002709 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002710 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002711 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002712 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002713 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002714 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002715 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002716 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002717 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002718 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002719 return NULL;
2720 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002721 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002722 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002723 case ARMISD::VZIP: {
2724 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002725 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002726 switch (VT.getSimpleVT().SimpleTy) {
2727 default: return NULL;
2728 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2729 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2730 case MVT::v2f32:
Jim Grosbach6073b302012-04-11 16:53:25 +00002731 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2732 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002733 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2734 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2735 case MVT::v4f32:
2736 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2737 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002738 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002739 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2740 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2741 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002742 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002743 case ARMISD::VUZP: {
2744 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002745 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002746 switch (VT.getSimpleVT().SimpleTy) {
2747 default: return NULL;
2748 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2749 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2750 case MVT::v2f32:
Jim Grosbach18355472012-04-11 17:40:18 +00002751 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2752 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002753 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2754 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2755 case MVT::v4f32:
2756 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2757 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002758 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002759 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2760 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2761 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002762 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002763 case ARMISD::VTRN: {
2764 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002765 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002766 switch (VT.getSimpleVT().SimpleTy) {
2767 default: return NULL;
2768 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2769 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2770 case MVT::v2f32:
2771 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2772 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2773 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2774 case MVT::v4f32:
2775 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2776 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002777 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002778 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2779 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2780 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002781 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002782 case ARMISD::BUILD_VECTOR: {
2783 EVT VecVT = N->getValueType(0);
2784 EVT EltVT = VecVT.getVectorElementType();
2785 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002786 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002787 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2788 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2789 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002790 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002791 if (NumElts == 2)
2792 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2793 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2794 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2795 N->getOperand(2), N->getOperand(3));
2796 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002797
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002798 case ARMISD::VLD2DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002799 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2800 ARM::VLD2DUPd32 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002801 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002802 }
2803
Bob Wilson86c6d802010-11-29 19:35:29 +00002804 case ARMISD::VLD3DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002805 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2806 ARM::VLD3DUPd16Pseudo,
2807 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002808 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002809 }
2810
Bob Wilson6c4c9822010-11-30 00:00:35 +00002811 case ARMISD::VLD4DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002812 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2813 ARM::VLD4DUPd16Pseudo,
2814 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002815 return SelectVLDDup(N, false, 4, Opcodes);
2816 }
2817
2818 case ARMISD::VLD2DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002819 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2820 ARM::VLD2DUPd16wb_fixed,
2821 ARM::VLD2DUPd32wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002822 return SelectVLDDup(N, true, 2, Opcodes);
2823 }
2824
2825 case ARMISD::VLD3DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002826 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2827 ARM::VLD3DUPd16Pseudo_UPD,
2828 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002829 return SelectVLDDup(N, true, 3, Opcodes);
2830 }
2831
2832 case ARMISD::VLD4DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002833 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2834 ARM::VLD4DUPd16Pseudo_UPD,
2835 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002836 return SelectVLDDup(N, true, 4, Opcodes);
2837 }
2838
2839 case ARMISD::VLD1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002840 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2841 ARM::VLD1d16wb_fixed,
2842 ARM::VLD1d32wb_fixed,
2843 ARM::VLD1d64wb_fixed };
2844 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2845 ARM::VLD1q16wb_fixed,
2846 ARM::VLD1q32wb_fixed,
2847 ARM::VLD1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002848 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2849 }
2850
2851 case ARMISD::VLD2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002852 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2853 ARM::VLD2d16wb_fixed,
2854 ARM::VLD2d32wb_fixed,
2855 ARM::VLD1q64wb_fixed};
2856 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2857 ARM::VLD2q16PseudoWB_fixed,
2858 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002859 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2860 }
2861
2862 case ARMISD::VLD3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002863 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2864 ARM::VLD3d16Pseudo_UPD,
2865 ARM::VLD3d32Pseudo_UPD,
2866 ARM::VLD1q64wb_fixed};
2867 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2868 ARM::VLD3q16Pseudo_UPD,
2869 ARM::VLD3q32Pseudo_UPD };
2870 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2871 ARM::VLD3q16oddPseudo_UPD,
2872 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002873 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2874 }
2875
2876 case ARMISD::VLD4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002877 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2878 ARM::VLD4d16Pseudo_UPD,
2879 ARM::VLD4d32Pseudo_UPD,
2880 ARM::VLD1q64wb_fixed};
2881 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2882 ARM::VLD4q16Pseudo_UPD,
2883 ARM::VLD4q32Pseudo_UPD };
2884 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2885 ARM::VLD4q16oddPseudo_UPD,
2886 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002887 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2888 }
2889
2890 case ARMISD::VLD2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002891 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2892 ARM::VLD2LNd16Pseudo_UPD,
2893 ARM::VLD2LNd32Pseudo_UPD };
2894 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2895 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002896 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2897 }
2898
2899 case ARMISD::VLD3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002900 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2901 ARM::VLD3LNd16Pseudo_UPD,
2902 ARM::VLD3LNd32Pseudo_UPD };
2903 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2904 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002905 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2906 }
2907
2908 case ARMISD::VLD4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002909 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2910 ARM::VLD4LNd16Pseudo_UPD,
2911 ARM::VLD4LNd32Pseudo_UPD };
2912 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2913 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002914 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2915 }
2916
2917 case ARMISD::VST1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002918 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2919 ARM::VST1d16wb_fixed,
2920 ARM::VST1d32wb_fixed,
2921 ARM::VST1d64wb_fixed };
2922 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2923 ARM::VST1q16wb_fixed,
2924 ARM::VST1q32wb_fixed,
2925 ARM::VST1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002926 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2927 }
2928
2929 case ARMISD::VST2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002930 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2931 ARM::VST2d16wb_fixed,
2932 ARM::VST2d32wb_fixed,
2933 ARM::VST1q64wb_fixed};
2934 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2935 ARM::VST2q16PseudoWB_fixed,
2936 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002937 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2938 }
2939
2940 case ARMISD::VST3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002941 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2942 ARM::VST3d16Pseudo_UPD,
2943 ARM::VST3d32Pseudo_UPD,
2944 ARM::VST1d64TPseudoWB_fixed};
2945 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2946 ARM::VST3q16Pseudo_UPD,
2947 ARM::VST3q32Pseudo_UPD };
2948 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2949 ARM::VST3q16oddPseudo_UPD,
2950 ARM::VST3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002951 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2952 }
2953
2954 case ARMISD::VST4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002955 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2956 ARM::VST4d16Pseudo_UPD,
2957 ARM::VST4d32Pseudo_UPD,
2958 ARM::VST1d64QPseudoWB_fixed};
2959 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2960 ARM::VST4q16Pseudo_UPD,
2961 ARM::VST4q32Pseudo_UPD };
2962 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2963 ARM::VST4q16oddPseudo_UPD,
2964 ARM::VST4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002965 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2966 }
2967
2968 case ARMISD::VST2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002969 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2970 ARM::VST2LNd16Pseudo_UPD,
2971 ARM::VST2LNd32Pseudo_UPD };
2972 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2973 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002974 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2975 }
2976
2977 case ARMISD::VST3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002978 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2979 ARM::VST3LNd16Pseudo_UPD,
2980 ARM::VST3LNd32Pseudo_UPD };
2981 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2982 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002983 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2984 }
2985
2986 case ARMISD::VST4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002987 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2988 ARM::VST4LNd16Pseudo_UPD,
2989 ARM::VST4LNd32Pseudo_UPD };
2990 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2991 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002992 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002993 }
2994
Bob Wilson31fb12f2009-08-26 17:39:53 +00002995 case ISD::INTRINSIC_VOID:
2996 case ISD::INTRINSIC_W_CHAIN: {
2997 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002998 switch (IntNo) {
2999 default:
Bob Wilson429009b2010-05-06 16:05:26 +00003000 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003001
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00003002 case Intrinsic::arm_ldrexd: {
3003 SDValue MemAddr = N->getOperand(2);
3004 DebugLoc dl = N->getDebugLoc();
3005 SDValue Chain = N->getOperand(0);
3006
3007 unsigned NewOpc = ARM::LDREXD;
3008 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3009 NewOpc = ARM::t2LDREXD;
3010
3011 // arm_ldrexd returns a i64 value in {i32, i32}
3012 std::vector<EVT> ResTys;
3013 ResTys.push_back(MVT::i32);
3014 ResTys.push_back(MVT::i32);
3015 ResTys.push_back(MVT::Other);
3016
3017 // place arguments in the right order
3018 SmallVector<SDValue, 7> Ops;
3019 Ops.push_back(MemAddr);
3020 Ops.push_back(getAL(CurDAG));
3021 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3022 Ops.push_back(Chain);
3023 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3024 Ops.size());
3025 // Transfer memoperands.
3026 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3027 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3028 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3029
3030 // Until there's support for specifing explicit register constraints
3031 // like the use of even/odd register pair, hardcode ldrexd to always
3032 // use the pair [R0, R1] to hold the load result.
3033 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3034 SDValue(Ld, 0), SDValue(0,0));
3035 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3036 SDValue(Ld, 1), Chain.getValue(1));
3037
3038 // Remap uses.
3039 SDValue Glue = Chain.getValue(1);
3040 if (!SDValue(N, 0).use_empty()) {
3041 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3042 ARM::R0, MVT::i32, Glue);
3043 Glue = Result.getValue(2);
3044 ReplaceUses(SDValue(N, 0), Result);
3045 }
3046 if (!SDValue(N, 1).use_empty()) {
3047 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3048 ARM::R1, MVT::i32, Glue);
3049 Glue = Result.getValue(2);
3050 ReplaceUses(SDValue(N, 1), Result);
3051 }
3052
3053 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3054 return NULL;
3055 }
3056
3057 case Intrinsic::arm_strexd: {
3058 DebugLoc dl = N->getDebugLoc();
3059 SDValue Chain = N->getOperand(0);
3060 SDValue Val0 = N->getOperand(2);
3061 SDValue Val1 = N->getOperand(3);
3062 SDValue MemAddr = N->getOperand(4);
3063
3064 // Until there's support for specifing explicit register constraints
3065 // like the use of even/odd register pair, hardcode strexd to always
3066 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3067 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3068 SDValue(0, 0));
3069 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3070
3071 SDValue Glue = Chain.getValue(1);
3072 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3073 ARM::R2, MVT::i32, Glue);
3074 Glue = Val0.getValue(1);
3075 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3076 ARM::R3, MVT::i32, Glue);
3077
3078 // Store exclusive double return a i32 value which is the return status
3079 // of the issued store.
3080 std::vector<EVT> ResTys;
3081 ResTys.push_back(MVT::i32);
3082 ResTys.push_back(MVT::Other);
3083
3084 // place arguments in the right order
3085 SmallVector<SDValue, 7> Ops;
3086 Ops.push_back(Val0);
3087 Ops.push_back(Val1);
3088 Ops.push_back(MemAddr);
3089 Ops.push_back(getAL(CurDAG));
3090 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3091 Ops.push_back(Chain);
3092
3093 unsigned NewOpc = ARM::STREXD;
3094 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3095 NewOpc = ARM::t2STREXD;
3096
3097 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3098 Ops.size());
3099 // Transfer memoperands.
3100 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3101 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3102 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3103
3104 return St;
3105 }
3106
Bob Wilson621f1952010-03-23 05:25:43 +00003107 case Intrinsic::arm_neon_vld1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003108 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3109 ARM::VLD1d32, ARM::VLD1d64 };
3110 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3111 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003112 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003113 }
3114
Bob Wilson31fb12f2009-08-26 17:39:53 +00003115 case Intrinsic::arm_neon_vld2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003116 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3117 ARM::VLD2d32, ARM::VLD1q64 };
3118 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3119 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003120 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003121 }
3122
3123 case Intrinsic::arm_neon_vld3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003124 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3125 ARM::VLD3d16Pseudo,
3126 ARM::VLD3d32Pseudo,
3127 ARM::VLD1d64TPseudo };
3128 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3129 ARM::VLD3q16Pseudo_UPD,
3130 ARM::VLD3q32Pseudo_UPD };
3131 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3132 ARM::VLD3q16oddPseudo,
3133 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003134 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003135 }
3136
3137 case Intrinsic::arm_neon_vld4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003138 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3139 ARM::VLD4d16Pseudo,
3140 ARM::VLD4d32Pseudo,
3141 ARM::VLD1d64QPseudo };
3142 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3143 ARM::VLD4q16Pseudo_UPD,
3144 ARM::VLD4q32Pseudo_UPD };
3145 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3146 ARM::VLD4q16oddPseudo,
3147 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003148 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003149 }
3150
Bob Wilson243fcc52009-09-01 04:26:28 +00003151 case Intrinsic::arm_neon_vld2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003152 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3153 ARM::VLD2LNd16Pseudo,
3154 ARM::VLD2LNd32Pseudo };
3155 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3156 ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003157 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003158 }
3159
3160 case Intrinsic::arm_neon_vld3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003161 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3162 ARM::VLD3LNd16Pseudo,
3163 ARM::VLD3LNd32Pseudo };
3164 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3165 ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003166 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003167 }
3168
3169 case Intrinsic::arm_neon_vld4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003170 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3171 ARM::VLD4LNd16Pseudo,
3172 ARM::VLD4LNd32Pseudo };
3173 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3174 ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003175 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003176 }
3177
Bob Wilson11d98992010-03-23 06:20:33 +00003178 case Intrinsic::arm_neon_vst1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003179 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3180 ARM::VST1d32, ARM::VST1d64 };
3181 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3182 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003183 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003184 }
3185
Bob Wilson31fb12f2009-08-26 17:39:53 +00003186 case Intrinsic::arm_neon_vst2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003187 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3188 ARM::VST2d32, ARM::VST1q64 };
3189 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3190 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003191 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003192 }
3193
3194 case Intrinsic::arm_neon_vst3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003195 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3196 ARM::VST3d16Pseudo,
3197 ARM::VST3d32Pseudo,
3198 ARM::VST1d64TPseudo };
3199 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3200 ARM::VST3q16Pseudo_UPD,
3201 ARM::VST3q32Pseudo_UPD };
3202 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3203 ARM::VST3q16oddPseudo,
3204 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003205 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003206 }
3207
3208 case Intrinsic::arm_neon_vst4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003209 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3210 ARM::VST4d16Pseudo,
3211 ARM::VST4d32Pseudo,
3212 ARM::VST1d64QPseudo };
3213 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3214 ARM::VST4q16Pseudo_UPD,
3215 ARM::VST4q32Pseudo_UPD };
3216 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3217 ARM::VST4q16oddPseudo,
3218 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003219 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003220 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003221
3222 case Intrinsic::arm_neon_vst2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003223 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3224 ARM::VST2LNd16Pseudo,
3225 ARM::VST2LNd32Pseudo };
3226 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3227 ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003228 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003229 }
3230
3231 case Intrinsic::arm_neon_vst3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003232 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3233 ARM::VST3LNd16Pseudo,
3234 ARM::VST3LNd32Pseudo };
3235 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3236 ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003237 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003238 }
3239
3240 case Intrinsic::arm_neon_vst4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003241 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3242 ARM::VST4LNd16Pseudo,
3243 ARM::VST4LNd32Pseudo };
3244 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3245 ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003246 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003247 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003248 }
Bob Wilson429009b2010-05-06 16:05:26 +00003249 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003250 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003251
Bob Wilsond491d6e2010-07-06 23:36:25 +00003252 case ISD::INTRINSIC_WO_CHAIN: {
3253 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3254 switch (IntNo) {
3255 default:
3256 break;
3257
3258 case Intrinsic::arm_neon_vtbl2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003259 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003260 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003261 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003262 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003263 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003264
3265 case Intrinsic::arm_neon_vtbx2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003266 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003267 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003268 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003269 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003270 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003271 }
3272 break;
3273 }
3274
Bill Wendling69a05a72011-03-14 23:02:38 +00003275 case ARMISD::VTBL1: {
3276 DebugLoc dl = N->getDebugLoc();
3277 EVT VT = N->getValueType(0);
3278 SmallVector<SDValue, 6> Ops;
3279
3280 Ops.push_back(N->getOperand(0));
3281 Ops.push_back(N->getOperand(1));
3282 Ops.push_back(getAL(CurDAG)); // Predicate
3283 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3284 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3285 }
3286 case ARMISD::VTBL2: {
3287 DebugLoc dl = N->getDebugLoc();
3288 EVT VT = N->getValueType(0);
3289
3290 // Form a REG_SEQUENCE to force register allocation.
3291 SDValue V0 = N->getOperand(0);
3292 SDValue V1 = N->getOperand(1);
3293 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3294
3295 SmallVector<SDValue, 6> Ops;
3296 Ops.push_back(RegSeq);
3297 Ops.push_back(N->getOperand(2));
3298 Ops.push_back(getAL(CurDAG)); // Predicate
3299 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Jim Grosbach28f08c92012-03-05 19:33:30 +00003300 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT,
Bill Wendling69a05a72011-03-14 23:02:38 +00003301 Ops.data(), Ops.size());
3302 }
3303
Bob Wilson429009b2010-05-06 16:05:26 +00003304 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003305 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003306
3307 case ARMISD::ATOMOR64_DAG:
3308 return SelectAtomic64(N, ARM::ATOMOR6432);
3309 case ARMISD::ATOMXOR64_DAG:
3310 return SelectAtomic64(N, ARM::ATOMXOR6432);
3311 case ARMISD::ATOMADD64_DAG:
3312 return SelectAtomic64(N, ARM::ATOMADD6432);
3313 case ARMISD::ATOMSUB64_DAG:
3314 return SelectAtomic64(N, ARM::ATOMSUB6432);
3315 case ARMISD::ATOMNAND64_DAG:
3316 return SelectAtomic64(N, ARM::ATOMNAND6432);
3317 case ARMISD::ATOMAND64_DAG:
3318 return SelectAtomic64(N, ARM::ATOMAND6432);
3319 case ARMISD::ATOMSWAP64_DAG:
3320 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003321 case ARMISD::ATOMCMPXCHG64_DAG:
3322 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003323 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003324
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003325 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003326}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003327
Bob Wilson224c2442009-05-19 05:53:42 +00003328bool ARMDAGToDAGISel::
3329SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3330 std::vector<SDValue> &OutOps) {
3331 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003332 // Require the address to be in a register. That is safe for all ARM
3333 // variants and it is hard to do anything much smarter without knowing
3334 // how the operand is used.
3335 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003336 return false;
3337}
3338
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003339/// createARMISelDag - This pass converts a legalized DAG into a
3340/// ARM-specific DAG, ready for instruction scheduling.
3341///
Bob Wilson522ce972009-09-28 14:30:20 +00003342FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3343 CodeGenOpt::Level OptLevel) {
3344 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003345}