blob: efd6d2b8399ec57ef8e0e400477a72c1c3562c22 [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
Dmitri Gribenkoc5252da2012-09-14 14:57:36 +0000308/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbarec91d522011-01-19 15:12:16 +0000309///
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;
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000338
339 if (!Subtarget->isCortexA8() && !Subtarget->isLikeA9() &&
340 !Subtarget->isSwift())
Evan Cheng48575f62010-12-05 22:04:16 +0000341 return true;
342
343 if (!N->hasOneUse())
344 return false;
345
346 SDNode *Use = *N->use_begin();
347 if (Use->getOpcode() == ISD::CopyToReg)
348 return true;
349 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000350 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
351 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000352 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000353 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000354 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
355 return true;
356 // vmlx feeding into another vmlx. We actually want to unfold
357 // the use later in the MLxExpansion pass. e.g.
358 // vmla
359 // vmla (stall 8 cycles)
360 //
361 // vmul (5 cycles)
362 // vadd (5 cycles)
363 // vmla
364 // This adds up to about 18 - 19 cycles.
365 //
366 // vmla
367 // vmul (stall 4 cycles)
368 // vadd adds up to about 14 cycles.
369 return TII->isFpMLxInstruction(Opcode);
370 }
371
372 return false;
373}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000374
Evan Chengf40deed2010-10-27 23:41:30 +0000375bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
376 ARM_AM::ShiftOpc ShOpcVal,
377 unsigned ShAmt) {
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000378 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Chengf40deed2010-10-27 23:41:30 +0000379 return true;
380 if (Shift.hasOneUse())
381 return true;
382 // R << 2 is free.
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000383 return ShOpcVal == ARM_AM::lsl &&
384 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Chengf40deed2010-10-27 23:41:30 +0000385}
386
Owen Anderson92a20222011-07-21 18:54:16 +0000387bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000388 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000389 SDValue &Opc,
390 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000391 if (DisableShifterOp)
392 return false;
393
Evan Chengee04a6d2011-07-20 23:34:39 +0000394 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000395
396 // Don't match base register only case. That is matched to a separate
397 // lower complexity pattern with explicit register operand.
398 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000399
Evan Cheng055b0312009-06-29 07:51:04 +0000400 BaseReg = N.getOperand(0);
401 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000402 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
403 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000404 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000405 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
406 MVT::i32);
407 return true;
408}
409
Owen Anderson92a20222011-07-21 18:54:16 +0000410bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
411 SDValue &BaseReg,
412 SDValue &ShReg,
413 SDValue &Opc,
414 bool CheckProfitability) {
415 if (DisableShifterOp)
416 return false;
417
418 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
419
420 // Don't match base register only case. That is matched to a separate
421 // lower complexity pattern with explicit register operand.
422 if (ShOpcVal == ARM_AM::no_shift) return false;
423
424 BaseReg = N.getOperand(0);
425 unsigned ShImmVal = 0;
426 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
427 if (RHS) return false;
428
429 ShReg = N.getOperand(1);
430 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
431 return false;
432 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
433 MVT::i32);
434 return true;
435}
436
437
Jim Grosbach3e556122010-10-26 22:37:02 +0000438bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
439 SDValue &Base,
440 SDValue &OffImm) {
441 // Match simple R + imm12 operands.
442
443 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000444 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
445 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000446 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000447 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000448 int FI = cast<FrameIndexSDNode>(N)->getIndex();
449 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
450 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
451 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000452 }
Owen Anderson099e5552011-03-18 19:46:58 +0000453
Chris Lattner0a9481f2011-02-13 22:25:43 +0000454 if (N.getOpcode() == ARMISD::Wrapper &&
455 !(Subtarget->useMovt() &&
456 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000457 Base = N.getOperand(0);
458 } else
459 Base = N;
460 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
461 return true;
462 }
463
464 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
465 int RHSC = (int)RHS->getZExtValue();
466 if (N.getOpcode() == ISD::SUB)
467 RHSC = -RHSC;
468
469 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
470 Base = N.getOperand(0);
471 if (Base.getOpcode() == ISD::FrameIndex) {
472 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
473 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
474 }
475 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
476 return true;
477 }
478 }
479
480 // Base only.
481 Base = N;
482 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
483 return true;
484}
485
486
487
488bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
489 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000490 if (N.getOpcode() == ISD::MUL &&
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000491 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000492 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
493 // X * [3,5,9] -> X + X * [2,4,8] etc.
494 int RHSC = (int)RHS->getZExtValue();
495 if (RHSC & 1) {
496 RHSC = RHSC & ~1;
497 ARM_AM::AddrOpc AddSub = ARM_AM::add;
498 if (RHSC < 0) {
499 AddSub = ARM_AM::sub;
500 RHSC = - RHSC;
501 }
502 if (isPowerOf2_32(RHSC)) {
503 unsigned ShAmt = Log2_32(RHSC);
504 Base = Offset = N.getOperand(0);
505 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
506 ARM_AM::lsl),
507 MVT::i32);
508 return true;
509 }
510 }
511 }
512 }
513
Chris Lattner0a9481f2011-02-13 22:25:43 +0000514 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
515 // ISD::OR that is equivalent to an ISD::ADD.
516 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000517 return false;
518
519 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000520 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000521 int RHSC;
522 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
523 -0x1000+1, 0x1000, RHSC)) // 12 bits.
524 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000525 }
526
527 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000528 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000529 ARM_AM::ShiftOpc ShOpcVal =
530 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000531 unsigned ShAmt = 0;
532
533 Base = N.getOperand(0);
534 Offset = N.getOperand(1);
535
536 if (ShOpcVal != ARM_AM::no_shift) {
537 // Check to see if the RHS of the shift is a constant, if not, we can't fold
538 // it.
539 if (ConstantSDNode *Sh =
540 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
541 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000542 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
543 Offset = N.getOperand(1).getOperand(0);
544 else {
545 ShAmt = 0;
546 ShOpcVal = ARM_AM::no_shift;
547 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000548 } else {
549 ShOpcVal = ARM_AM::no_shift;
550 }
551 }
552
553 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000554 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000555 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
556 N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000557 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000558 if (ShOpcVal != ARM_AM::no_shift) {
559 // Check to see if the RHS of the shift is a constant, if not, we can't
560 // fold it.
561 if (ConstantSDNode *Sh =
562 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
563 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000564 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000565 Offset = N.getOperand(0).getOperand(0);
566 Base = N.getOperand(1);
567 } else {
568 ShAmt = 0;
569 ShOpcVal = ARM_AM::no_shift;
570 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000571 } else {
572 ShOpcVal = ARM_AM::no_shift;
573 }
574 }
575 }
576
577 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
578 MVT::i32);
579 return true;
580}
581
582
Jim Grosbach3e556122010-10-26 22:37:02 +0000583//-----
584
Jim Grosbach82891622010-09-29 19:03:54 +0000585AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
586 SDValue &Base,
587 SDValue &Offset,
588 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000589 if (N.getOpcode() == ISD::MUL &&
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000590 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000591 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
592 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000593 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000594 if (RHSC & 1) {
595 RHSC = RHSC & ~1;
596 ARM_AM::AddrOpc AddSub = ARM_AM::add;
597 if (RHSC < 0) {
598 AddSub = ARM_AM::sub;
599 RHSC = - RHSC;
600 }
601 if (isPowerOf2_32(RHSC)) {
602 unsigned ShAmt = Log2_32(RHSC);
603 Base = Offset = N.getOperand(0);
604 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
605 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000606 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000607 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000608 }
609 }
610 }
611 }
612
Chris Lattner0a9481f2011-02-13 22:25:43 +0000613 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
614 // ISD::OR that is equivalent to an ADD.
615 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000616 Base = N;
617 if (N.getOpcode() == ISD::FrameIndex) {
618 int FI = cast<FrameIndexSDNode>(N)->getIndex();
619 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000620 } else if (N.getOpcode() == ARMISD::Wrapper &&
621 !(Subtarget->useMovt() &&
622 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000623 Base = N.getOperand(0);
624 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000626 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
627 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000629 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000630 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000631
Evan Chenga8e29892007-01-19 07:51:42 +0000632 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000633 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000634 int RHSC;
635 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
636 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
637 Base = N.getOperand(0);
638 if (Base.getOpcode() == ISD::FrameIndex) {
639 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
640 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000641 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000642 Offset = CurDAG->getRegister(0, MVT::i32);
643
644 ARM_AM::AddrOpc AddSub = ARM_AM::add;
645 if (RHSC < 0) {
646 AddSub = ARM_AM::sub;
647 RHSC = - RHSC;
648 }
649 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
650 ARM_AM::no_shift),
651 MVT::i32);
652 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000653 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000654 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000655
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000656 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Chengf40deed2010-10-27 23:41:30 +0000657 // Compute R +/- (R << N) and reuse it.
658 Base = N;
659 Offset = CurDAG->getRegister(0, MVT::i32);
660 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
661 ARM_AM::no_shift),
662 MVT::i32);
663 return AM2_BASE;
664 }
665
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000666 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000667 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000668 ARM_AM::ShiftOpc ShOpcVal =
669 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000670 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000671
Evan Chenga8e29892007-01-19 07:51:42 +0000672 Base = N.getOperand(0);
673 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000674
Evan Chenga8e29892007-01-19 07:51:42 +0000675 if (ShOpcVal != ARM_AM::no_shift) {
676 // Check to see if the RHS of the shift is a constant, if not, we can't fold
677 // it.
678 if (ConstantSDNode *Sh =
679 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000680 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000681 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
682 Offset = N.getOperand(1).getOperand(0);
683 else {
684 ShAmt = 0;
685 ShOpcVal = ARM_AM::no_shift;
686 }
Evan Chenga8e29892007-01-19 07:51:42 +0000687 } else {
688 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000689 }
690 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000691
Evan Chenga8e29892007-01-19 07:51:42 +0000692 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000693 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsoneb1641d2012-09-29 21:43:49 +0000694 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
695 N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000696 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000697 if (ShOpcVal != ARM_AM::no_shift) {
698 // Check to see if the RHS of the shift is a constant, if not, we can't
699 // fold it.
700 if (ConstantSDNode *Sh =
701 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000702 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000703 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000704 Offset = N.getOperand(0).getOperand(0);
705 Base = N.getOperand(1);
706 } else {
707 ShAmt = 0;
708 ShOpcVal = ARM_AM::no_shift;
709 }
Evan Chenga8e29892007-01-19 07:51:42 +0000710 } else {
711 ShOpcVal = ARM_AM::no_shift;
712 }
713 }
714 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000715
Evan Chenga8e29892007-01-19 07:51:42 +0000716 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000717 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000718 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000719}
720
Owen Anderson793e7962011-07-26 20:54:26 +0000721bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000722 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000723 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000724 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
725 ? cast<LoadSDNode>(Op)->getAddressingMode()
726 : cast<StoreSDNode>(Op)->getAddressingMode();
727 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
728 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000729 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000730 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
731 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000732
733 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000734 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000735 unsigned ShAmt = 0;
736 if (ShOpcVal != ARM_AM::no_shift) {
737 // Check to see if the RHS of the shift is a constant, if not, we can't fold
738 // it.
739 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000740 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000741 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
742 Offset = N.getOperand(0);
743 else {
744 ShAmt = 0;
745 ShOpcVal = ARM_AM::no_shift;
746 }
Evan Chenga8e29892007-01-19 07:51:42 +0000747 } else {
748 ShOpcVal = ARM_AM::no_shift;
749 }
750 }
751
752 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000753 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000754 return true;
755}
756
Owen Andersonc4e16de2011-08-29 20:16:50 +0000757bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
758 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000759 unsigned Opcode = Op->getOpcode();
760 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
761 ? cast<LoadSDNode>(Op)->getAddressingMode()
762 : cast<StoreSDNode>(Op)->getAddressingMode();
763 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
764 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000765 int Val;
766 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000767 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000768 Offset = CurDAG->getRegister(0, MVT::i32);
769 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
770 return true;
771 }
772
773 return false;
774}
775
776
Owen Anderson793e7962011-07-26 20:54:26 +0000777bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
778 SDValue &Offset, SDValue &Opc) {
779 unsigned Opcode = Op->getOpcode();
780 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
781 ? cast<LoadSDNode>(Op)->getAddressingMode()
782 : cast<StoreSDNode>(Op)->getAddressingMode();
783 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
784 ? ARM_AM::add : ARM_AM::sub;
785 int Val;
786 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
787 Offset = CurDAG->getRegister(0, MVT::i32);
788 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
789 ARM_AM::no_shift),
790 MVT::i32);
791 return true;
792 }
793
794 return false;
795}
796
Jim Grosbach19dec202011-08-05 20:35:44 +0000797bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
798 Base = N;
799 return true;
800}
Evan Chenga8e29892007-01-19 07:51:42 +0000801
Chris Lattner52a261b2010-09-21 20:31:19 +0000802bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000803 SDValue &Base, SDValue &Offset,
804 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000805 if (N.getOpcode() == ISD::SUB) {
806 // X - C is canonicalize to X + -C, no need to handle it here.
807 Base = N.getOperand(0);
808 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000809 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000810 return true;
811 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000812
Chris Lattner0a9481f2011-02-13 22:25:43 +0000813 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000814 Base = N;
815 if (N.getOpcode() == ISD::FrameIndex) {
816 int FI = cast<FrameIndexSDNode>(N)->getIndex();
817 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
818 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000819 Offset = CurDAG->getRegister(0, MVT::i32);
820 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000821 return true;
822 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000823
Evan Chenga8e29892007-01-19 07:51:42 +0000824 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000825 int RHSC;
826 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
827 -256 + 1, 256, RHSC)) { // 8 bits.
828 Base = N.getOperand(0);
829 if (Base.getOpcode() == ISD::FrameIndex) {
830 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
831 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000832 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000833 Offset = CurDAG->getRegister(0, MVT::i32);
834
835 ARM_AM::AddrOpc AddSub = ARM_AM::add;
836 if (RHSC < 0) {
837 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000838 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000839 }
840 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
841 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000842 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000843
Evan Chenga8e29892007-01-19 07:51:42 +0000844 Base = N.getOperand(0);
845 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000846 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000847 return true;
848}
849
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000850bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000851 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000852 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000853 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
854 ? cast<LoadSDNode>(Op)->getAddressingMode()
855 : cast<StoreSDNode>(Op)->getAddressingMode();
856 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
857 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000858 int Val;
859 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
860 Offset = CurDAG->getRegister(0, MVT::i32);
861 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
862 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000863 }
864
865 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000866 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000867 return true;
868}
869
Jim Grosbach3ab56582010-10-21 19:38:40 +0000870bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000871 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000872 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000873 Base = N;
874 if (N.getOpcode() == ISD::FrameIndex) {
875 int FI = cast<FrameIndexSDNode>(N)->getIndex();
876 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000877 } else if (N.getOpcode() == ARMISD::Wrapper &&
878 !(Subtarget->useMovt() &&
879 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000880 Base = N.getOperand(0);
881 }
882 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000883 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000884 return true;
885 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000886
Evan Chenga8e29892007-01-19 07:51:42 +0000887 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000888 int RHSC;
889 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
890 -256 + 1, 256, RHSC)) {
891 Base = N.getOperand(0);
892 if (Base.getOpcode() == ISD::FrameIndex) {
893 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
894 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000895 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000896
897 ARM_AM::AddrOpc AddSub = ARM_AM::add;
898 if (RHSC < 0) {
899 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000900 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000901 }
902 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
903 MVT::i32);
904 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000905 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000906
Evan Chenga8e29892007-01-19 07:51:42 +0000907 Base = N;
908 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000909 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000910 return true;
911}
912
Bob Wilson665814b2010-11-01 23:40:51 +0000913bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
914 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000915 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000916
917 unsigned Alignment = 0;
918 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
919 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
920 // The maximum alignment is equal to the memory size being referenced.
921 unsigned LSNAlign = LSN->getAlignment();
922 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000923 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000924 Alignment = MemSize;
925 } else {
926 // All other uses of addrmode6 are for intrinsics. For now just record
927 // the raw alignment value; it will be refined later based on the legal
928 // alignment operands for the intrinsic.
929 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
930 }
931
932 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000933 return true;
934}
935
Bob Wilsonda525062011-02-25 06:42:42 +0000936bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
937 SDValue &Offset) {
938 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
939 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
940 if (AM != ISD::POST_INC)
941 return false;
942 Offset = N;
943 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
944 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
945 Offset = CurDAG->getRegister(0, MVT::i32);
946 }
947 return true;
948}
949
Chris Lattner52a261b2010-09-21 20:31:19 +0000950bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000951 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000952 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
953 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000954 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000955 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
956 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000957 return true;
958 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000959
Evan Chenga8e29892007-01-19 07:51:42 +0000960 return false;
961}
962
Bill Wendlingf4caf692010-12-14 03:36:38 +0000963
964//===----------------------------------------------------------------------===//
965// Thumb Addressing Modes
966//===----------------------------------------------------------------------===//
967
Chris Lattner52a261b2010-09-21 20:31:19 +0000968bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000969 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000970 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000971 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000972 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000973 return false;
974
975 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000976 return true;
977 }
978
Evan Chenga8e29892007-01-19 07:51:42 +0000979 Base = N.getOperand(0);
980 Offset = N.getOperand(1);
981 return true;
982}
983
Evan Cheng79d43262007-01-24 02:21:22 +0000984bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000985ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
986 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000987 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000988 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000989 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000990 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000991
Evan Cheng012f2d92007-01-24 08:53:17 +0000992 if (N.getOpcode() == ARMISD::Wrapper &&
993 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
994 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000995 }
996
Chris Lattner0a9481f2011-02-13 22:25:43 +0000997 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000998 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000999
Evan Chengad0e4652007-02-06 00:22:06 +00001000 // Thumb does not have [sp, r] address mode.
1001 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1002 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1003 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001004 (RHSR && RHSR->getReg() == ARM::SP))
1005 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001006
Daniel Dunbarec91d522011-01-19 15:12:16 +00001007 // FIXME: Why do we explicitly check for a match here and then return false?
1008 // Presumably to allow something else to match, but shouldn't this be
1009 // documented?
1010 int RHSC;
1011 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1012 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001013
1014 Base = N.getOperand(0);
1015 Offset = N.getOperand(1);
1016 return true;
1017}
1018
1019bool
1020ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1021 SDValue &Base,
1022 SDValue &Offset) {
1023 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1024}
1025
1026bool
1027ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1028 SDValue &Base,
1029 SDValue &Offset) {
1030 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1031}
1032
1033bool
1034ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1035 SDValue &Base,
1036 SDValue &Offset) {
1037 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1038}
1039
1040bool
1041ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1042 SDValue &Base, SDValue &OffImm) {
1043 if (Scale == 4) {
1044 SDValue TmpBase, TmpOffImm;
1045 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1046 return false; // We want to select tLDRspi / tSTRspi instead.
1047
1048 if (N.getOpcode() == ARMISD::Wrapper &&
1049 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1050 return false; // We want to select tLDRpci instead.
1051 }
1052
Chris Lattner0a9481f2011-02-13 22:25:43 +00001053 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001054 if (N.getOpcode() == ARMISD::Wrapper &&
1055 !(Subtarget->useMovt() &&
1056 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1057 Base = N.getOperand(0);
1058 } else {
1059 Base = N;
1060 }
1061
Owen Anderson825b72b2009-08-11 20:47:22 +00001062 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001063 return true;
1064 }
1065
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001066 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1067 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1068 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1069 (RHSR && RHSR->getReg() == ARM::SP)) {
1070 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1071 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1072 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1073 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1074
1075 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1076 if (LHSC != 0 || RHSC != 0) return false;
1077
1078 Base = N;
1079 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1080 return true;
1081 }
1082
Evan Chenga8e29892007-01-19 07:51:42 +00001083 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001084 int RHSC;
1085 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1086 Base = N.getOperand(0);
1087 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1088 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001089 }
1090
Evan Chengc38f2bc2007-01-23 22:59:13 +00001091 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001092 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001093 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001094}
1095
Bill Wendlingf4caf692010-12-14 03:36:38 +00001096bool
1097ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1098 SDValue &OffImm) {
1099 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001100}
1101
Bill Wendlingf4caf692010-12-14 03:36:38 +00001102bool
1103ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1104 SDValue &OffImm) {
1105 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001106}
1107
Bill Wendlingf4caf692010-12-14 03:36:38 +00001108bool
1109ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1110 SDValue &OffImm) {
1111 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001112}
1113
Chris Lattner52a261b2010-09-21 20:31:19 +00001114bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1115 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001116 if (N.getOpcode() == ISD::FrameIndex) {
1117 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1118 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001119 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001120 return true;
1121 }
Evan Cheng79d43262007-01-24 02:21:22 +00001122
Chris Lattner0a9481f2011-02-13 22:25:43 +00001123 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001124 return false;
1125
1126 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001127 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1128 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001129 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001130 int RHSC;
1131 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1132 Base = N.getOperand(0);
1133 if (Base.getOpcode() == ISD::FrameIndex) {
1134 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1135 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001136 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001137 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1138 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001139 }
1140 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001141
Evan Chenga8e29892007-01-19 07:51:42 +00001142 return false;
1143}
1144
Bill Wendlingf4caf692010-12-14 03:36:38 +00001145
1146//===----------------------------------------------------------------------===//
1147// Thumb 2 Addressing Modes
1148//===----------------------------------------------------------------------===//
1149
1150
Chris Lattner52a261b2010-09-21 20:31:19 +00001151bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001152 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001153 if (DisableShifterOp)
1154 return false;
1155
Evan Chengee04a6d2011-07-20 23:34:39 +00001156 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001157
1158 // Don't match base register only case. That is matched to a separate
1159 // lower complexity pattern with explicit register operand.
1160 if (ShOpcVal == ARM_AM::no_shift) return false;
1161
1162 BaseReg = N.getOperand(0);
1163 unsigned ShImmVal = 0;
1164 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1165 ShImmVal = RHS->getZExtValue() & 31;
1166 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1167 return true;
1168 }
1169
1170 return false;
1171}
1172
Chris Lattner52a261b2010-09-21 20:31:19 +00001173bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001174 SDValue &Base, SDValue &OffImm) {
1175 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001176
Evan Cheng3a214252009-08-11 08:52:18 +00001177 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001178 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1179 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001180 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001181 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001182 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1183 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001184 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001185 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001186 }
Owen Anderson099e5552011-03-18 19:46:58 +00001187
Chris Lattner0a9481f2011-02-13 22:25:43 +00001188 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001189 !(Subtarget->useMovt() &&
1190 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001191 Base = N.getOperand(0);
1192 if (Base.getOpcode() == ISD::TargetConstantPool)
1193 return false; // We want to select t2LDRpci instead.
1194 } else
1195 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001196 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001197 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001198 }
Evan Cheng055b0312009-06-29 07:51:04 +00001199
1200 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001201 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001202 // Let t2LDRi8 handle (R - imm8).
1203 return false;
1204
Evan Cheng055b0312009-06-29 07:51:04 +00001205 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001206 if (N.getOpcode() == ISD::SUB)
1207 RHSC = -RHSC;
1208
1209 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001210 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001211 if (Base.getOpcode() == ISD::FrameIndex) {
1212 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1213 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1214 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001215 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001216 return true;
1217 }
1218 }
1219
Evan Cheng3a214252009-08-11 08:52:18 +00001220 // Base only.
1221 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001222 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001223 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001224}
1225
Chris Lattner52a261b2010-09-21 20:31:19 +00001226bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001227 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001228 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001229 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1230 !CurDAG->isBaseWithConstantOffset(N))
1231 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001232
Chris Lattner0a9481f2011-02-13 22:25:43 +00001233 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1234 int RHSC = (int)RHS->getSExtValue();
1235 if (N.getOpcode() == ISD::SUB)
1236 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001237
Chris Lattner0a9481f2011-02-13 22:25:43 +00001238 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1239 Base = N.getOperand(0);
1240 if (Base.getOpcode() == ISD::FrameIndex) {
1241 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1242 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001243 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001244 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1245 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001246 }
1247 }
1248
1249 return false;
1250}
1251
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001252bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001253 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001254 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001255 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1256 ? cast<LoadSDNode>(Op)->getAddressingMode()
1257 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001258 int RHSC;
1259 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1260 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1261 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1262 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1263 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001264 }
1265
1266 return false;
1267}
1268
Chris Lattner52a261b2010-09-21 20:31:19 +00001269bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001270 SDValue &Base,
1271 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001272 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001273 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001274 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001275
Evan Cheng3a214252009-08-11 08:52:18 +00001276 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1277 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1278 int RHSC = (int)RHS->getZExtValue();
1279 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1280 return false;
1281 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001282 return false;
1283 }
1284
Evan Cheng055b0312009-06-29 07:51:04 +00001285 // Look for (R + R) or (R + (R << [1,2,3])).
1286 unsigned ShAmt = 0;
1287 Base = N.getOperand(0);
1288 OffReg = N.getOperand(1);
1289
1290 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001291 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001292 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001293 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001294 if (ShOpcVal == ARM_AM::lsl)
1295 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001296 }
1297
Evan Cheng055b0312009-06-29 07:51:04 +00001298 if (ShOpcVal == ARM_AM::lsl) {
1299 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1300 // it.
1301 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1302 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001303 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1304 OffReg = OffReg.getOperand(0);
1305 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001306 ShAmt = 0;
1307 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001308 }
Evan Cheng055b0312009-06-29 07:51:04 +00001309 } else {
1310 ShOpcVal = ARM_AM::no_shift;
1311 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001312 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001313
Owen Anderson825b72b2009-08-11 20:47:22 +00001314 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001315
1316 return true;
1317}
1318
1319//===--------------------------------------------------------------------===//
1320
Evan Chengee568cf2007-07-05 07:15:27 +00001321/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001322static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001323 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001324}
1325
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001326SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1327 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001328 ISD::MemIndexedMode AM = LD->getAddressingMode();
1329 if (AM == ISD::UNINDEXED)
1330 return NULL;
1331
Owen Andersone50ed302009-08-10 22:56:29 +00001332 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001333 SDValue Offset, AMOpc;
1334 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1335 unsigned Opcode = 0;
1336 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001337 if (LoadedVT == MVT::i32 && isPre &&
1338 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1339 Opcode = ARM::LDR_PRE_IMM;
1340 Match = true;
1341 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001342 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001343 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001344 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001345 } else if (LoadedVT == MVT::i32 &&
1346 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001347 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001348 Match = true;
1349
Owen Anderson825b72b2009-08-11 20:47:22 +00001350 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001351 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001352 Match = true;
1353 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1354 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1355 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001356 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001357 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001358 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001359 Match = true;
1360 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1361 }
1362 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001363 if (isPre &&
1364 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001365 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001366 Opcode = ARM::LDRB_PRE_IMM;
1367 } else if (!isPre &&
1368 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1369 Match = true;
1370 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001371 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1372 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001373 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001374 }
1375 }
1376 }
1377
1378 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001379 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1380 SDValue Chain = LD->getChain();
1381 SDValue Base = LD->getBasePtr();
1382 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1383 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001384 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1385 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001386 } else {
1387 SDValue Chain = LD->getChain();
1388 SDValue Base = LD->getBasePtr();
1389 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1390 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001391 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1392 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001393 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001394 }
1395
1396 return NULL;
1397}
1398
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001399SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1400 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001401 ISD::MemIndexedMode AM = LD->getAddressingMode();
1402 if (AM == ISD::UNINDEXED)
1403 return NULL;
1404
Owen Andersone50ed302009-08-10 22:56:29 +00001405 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001406 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001407 SDValue Offset;
1408 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1409 unsigned Opcode = 0;
1410 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001411 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001412 switch (LoadedVT.getSimpleVT().SimpleTy) {
1413 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001414 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1415 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001416 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001417 if (isSExtLd)
1418 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1419 else
1420 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001421 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001422 case MVT::i8:
1423 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001424 if (isSExtLd)
1425 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1426 else
1427 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001428 break;
1429 default:
1430 return NULL;
1431 }
1432 Match = true;
1433 }
1434
1435 if (Match) {
1436 SDValue Chain = LD->getChain();
1437 SDValue Base = LD->getBasePtr();
1438 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001439 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001440 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001441 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001442 }
1443
1444 return NULL;
1445}
1446
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001447/// PairSRegs - Form a D register from a pair of S registers.
1448///
1449SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1450 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001451 SDValue RegClass =
1452 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001453 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1454 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001455 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1456 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001457}
1458
Evan Cheng603afbf2010-05-10 17:34:18 +00001459/// PairDRegs - Form a quad register from a pair of D registers.
1460///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001461SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1462 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001463 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001464 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1465 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001466 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1467 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001468}
1469
Evan Cheng7f687192010-05-14 00:21:45 +00001470/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001471///
1472SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1473 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001474 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001475 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1476 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001477 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1478 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001479}
1480
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001481/// QuadSRegs - Form 4 consecutive S registers.
1482///
1483SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1484 SDValue V2, SDValue V3) {
1485 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001486 SDValue RegClass =
1487 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001488 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1489 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1490 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1491 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001492 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1493 V2, SubReg2, V3, SubReg3 };
1494 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001495}
1496
Evan Cheng7f687192010-05-14 00:21:45 +00001497/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001498///
1499SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1500 SDValue V2, SDValue V3) {
1501 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001502 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001503 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1504 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1505 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1506 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001507 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1508 V2, SubReg2, V3, SubReg3 };
1509 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001510}
1511
Evan Cheng8f6de382010-05-16 03:27:48 +00001512/// QuadQRegs - Form 4 consecutive Q registers.
1513///
1514SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1515 SDValue V2, SDValue V3) {
1516 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001517 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001518 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1519 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1520 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1521 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001522 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1523 V2, SubReg2, V3, SubReg3 };
1524 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001525}
1526
Bob Wilson2a6e6162010-09-23 23:42:37 +00001527/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1528/// of a NEON VLD or VST instruction. The supported values depend on the
1529/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001530SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1531 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001532 unsigned NumRegs = NumVecs;
1533 if (!is64BitVector && NumVecs < 3)
1534 NumRegs *= 2;
1535
Bob Wilson665814b2010-11-01 23:40:51 +00001536 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001537 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001538 Alignment = 32;
1539 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1540 Alignment = 16;
1541 else if (Alignment >= 8)
1542 Alignment = 8;
1543 else
1544 Alignment = 0;
1545
1546 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001547}
1548
Jim Grosbach10b90a92011-10-24 21:45:13 +00001549// Get the register stride update opcode of a VLD/VST instruction that
1550// is otherwise equivalent to the given fixed stride updating instruction.
1551static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1552 switch (Opc) {
1553 default: break;
1554 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1555 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1556 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1557 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1558 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1559 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1560 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1561 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001562
1563 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1564 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1565 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1566 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1567 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1568 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1569 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1570 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001571 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001572 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001573
Jim Grosbach28f08c92012-03-05 19:33:30 +00001574 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1575 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1576 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001577 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1578 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1579 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1580
Jim Grosbach28f08c92012-03-05 19:33:30 +00001581 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1582 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1583 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001584 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1585 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1586 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001587
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001588 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1589 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1590 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001591 }
1592 return Opc; // If not one we handle, return it unchanged.
1593}
1594
Bob Wilson1c3ef902011-02-07 17:43:21 +00001595SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001596 const uint16_t *DOpcodes,
1597 const uint16_t *QOpcodes0,
1598 const uint16_t *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001599 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001600 DebugLoc dl = N->getDebugLoc();
1601
Bob Wilson226036e2010-03-20 22:13:40 +00001602 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001603 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1604 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001605 return NULL;
1606
1607 SDValue Chain = N->getOperand(0);
1608 EVT VT = N->getValueType(0);
1609 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001610 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001611
Bob Wilson3e36f132009-10-14 17:28:52 +00001612 unsigned OpcodeIndex;
1613 switch (VT.getSimpleVT().SimpleTy) {
1614 default: llvm_unreachable("unhandled vld type");
1615 // Double-register operations:
1616 case MVT::v8i8: OpcodeIndex = 0; break;
1617 case MVT::v4i16: OpcodeIndex = 1; break;
1618 case MVT::v2f32:
1619 case MVT::v2i32: OpcodeIndex = 2; break;
1620 case MVT::v1i64: OpcodeIndex = 3; break;
1621 // Quad-register operations:
1622 case MVT::v16i8: OpcodeIndex = 0; break;
1623 case MVT::v8i16: OpcodeIndex = 1; break;
1624 case MVT::v4f32:
1625 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001626 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001627 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001628 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001629 }
1630
Bob Wilsonf5721912010-09-03 18:16:02 +00001631 EVT ResTy;
1632 if (NumVecs == 1)
1633 ResTy = VT;
1634 else {
1635 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1636 if (!is64BitVector)
1637 ResTyElts *= 2;
1638 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1639 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001640 std::vector<EVT> ResTys;
1641 ResTys.push_back(ResTy);
1642 if (isUpdating)
1643 ResTys.push_back(MVT::i32);
1644 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001645
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001646 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001647 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001648 SDNode *VLd;
1649 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001650
Bob Wilson1c3ef902011-02-07 17:43:21 +00001651 // Double registers and VLD1/VLD2 quad registers are directly supported.
1652 if (is64BitVector || NumVecs <= 2) {
1653 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1654 QOpcodes0[OpcodeIndex]);
1655 Ops.push_back(MemAddr);
1656 Ops.push_back(Align);
1657 if (isUpdating) {
1658 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001659 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001660 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001661 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001662 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001663 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001664 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001665 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001666 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001667 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001668 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001669 Ops.push_back(Pred);
1670 Ops.push_back(Reg0);
1671 Ops.push_back(Chain);
1672 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001673
Bob Wilson3e36f132009-10-14 17:28:52 +00001674 } else {
1675 // Otherwise, quad registers are loaded with two separate instructions,
1676 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001677 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001678
Bob Wilson1c3ef902011-02-07 17:43:21 +00001679 // Load the even subregs. This is always an updating load, so that it
1680 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001681 SDValue ImplDef =
1682 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1683 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001684 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1685 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001686 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001687
Bob Wilson24f995d2009-10-14 18:32:29 +00001688 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001689 Ops.push_back(SDValue(VLdA, 1));
1690 Ops.push_back(Align);
1691 if (isUpdating) {
1692 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1693 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1694 "only constant post-increment update allowed for VLD3/4");
1695 (void)Inc;
1696 Ops.push_back(Reg0);
1697 }
1698 Ops.push_back(SDValue(VLdA, 0));
1699 Ops.push_back(Pred);
1700 Ops.push_back(Reg0);
1701 Ops.push_back(Chain);
1702 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1703 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001704 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001705
Evan Chengb58a3402011-04-19 00:04:03 +00001706 // Transfer memoperands.
1707 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1708 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1709 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1710
Bob Wilson1c3ef902011-02-07 17:43:21 +00001711 if (NumVecs == 1)
1712 return VLd;
1713
1714 // Extract out the subregisters.
1715 SDValue SuperReg = SDValue(VLd, 0);
1716 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1717 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1718 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1719 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1720 ReplaceUses(SDValue(N, Vec),
1721 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1722 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1723 if (isUpdating)
1724 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001725 return NULL;
1726}
1727
Bob Wilson1c3ef902011-02-07 17:43:21 +00001728SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001729 const uint16_t *DOpcodes,
1730 const uint16_t *QOpcodes0,
1731 const uint16_t *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001732 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001733 DebugLoc dl = N->getDebugLoc();
1734
Bob Wilson226036e2010-03-20 22:13:40 +00001735 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001736 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1737 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1738 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001739 return NULL;
1740
Evan Chengb58a3402011-04-19 00:04:03 +00001741 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1742 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1743
Bob Wilson24f995d2009-10-14 18:32:29 +00001744 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001745 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001746 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001747 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001748
Bob Wilson24f995d2009-10-14 18:32:29 +00001749 unsigned OpcodeIndex;
1750 switch (VT.getSimpleVT().SimpleTy) {
1751 default: llvm_unreachable("unhandled vst type");
1752 // Double-register operations:
1753 case MVT::v8i8: OpcodeIndex = 0; break;
1754 case MVT::v4i16: OpcodeIndex = 1; break;
1755 case MVT::v2f32:
1756 case MVT::v2i32: OpcodeIndex = 2; break;
1757 case MVT::v1i64: OpcodeIndex = 3; break;
1758 // Quad-register operations:
1759 case MVT::v16i8: OpcodeIndex = 0; break;
1760 case MVT::v8i16: OpcodeIndex = 1; break;
1761 case MVT::v4f32:
1762 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001763 case MVT::v2i64: OpcodeIndex = 3;
1764 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1765 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001766 }
1767
Bob Wilson1c3ef902011-02-07 17:43:21 +00001768 std::vector<EVT> ResTys;
1769 if (isUpdating)
1770 ResTys.push_back(MVT::i32);
1771 ResTys.push_back(MVT::Other);
1772
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001773 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001774 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001775 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001776
Bob Wilson1c3ef902011-02-07 17:43:21 +00001777 // Double registers and VST1/VST2 quad registers are directly supported.
1778 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001779 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001780 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001781 SrcReg = N->getOperand(Vec0Idx);
1782 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001783 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001784 SDValue V0 = N->getOperand(Vec0Idx + 0);
1785 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001786 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001787 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001788 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001789 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001790 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001791 // an undef.
1792 SDValue V3 = (NumVecs == 3)
1793 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001794 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001795 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001796 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001797 } else {
1798 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001799 SDValue Q0 = N->getOperand(Vec0Idx);
1800 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001801 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001802 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001803
1804 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1805 QOpcodes0[OpcodeIndex]);
1806 Ops.push_back(MemAddr);
1807 Ops.push_back(Align);
1808 if (isUpdating) {
1809 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001810 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001811 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001812 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001813 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1814 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1815 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001816 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001817 !isa<ConstantSDNode>(Inc.getNode()))
1818 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001819 }
1820 Ops.push_back(SrcReg);
1821 Ops.push_back(Pred);
1822 Ops.push_back(Reg0);
1823 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001824 SDNode *VSt =
1825 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1826
1827 // Transfer memoperands.
1828 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1829
1830 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001831 }
1832
1833 // Otherwise, quad registers are stored with two separate instructions,
1834 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001835
Bob Wilson07f6e802010-06-16 21:34:01 +00001836 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001837 SDValue V0 = N->getOperand(Vec0Idx + 0);
1838 SDValue V1 = N->getOperand(Vec0Idx + 1);
1839 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001840 SDValue V3 = (NumVecs == 3)
1841 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001842 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001843 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001844
Bob Wilson1c3ef902011-02-07 17:43:21 +00001845 // Store the even D registers. This is always an updating store, so that it
1846 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001847 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1848 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1849 MemAddr.getValueType(),
1850 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001851 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001852 Chain = SDValue(VStA, 1);
1853
1854 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001855 Ops.push_back(SDValue(VStA, 0));
1856 Ops.push_back(Align);
1857 if (isUpdating) {
1858 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1859 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1860 "only constant post-increment update allowed for VST3/4");
1861 (void)Inc;
1862 Ops.push_back(Reg0);
1863 }
1864 Ops.push_back(RegSeq);
1865 Ops.push_back(Pred);
1866 Ops.push_back(Reg0);
1867 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001868 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1869 Ops.data(), Ops.size());
1870 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1871 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001872}
1873
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001874SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001875 bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001876 const uint16_t *DOpcodes,
1877 const uint16_t *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001878 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001879 DebugLoc dl = N->getDebugLoc();
1880
Bob Wilson226036e2010-03-20 22:13:40 +00001881 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001882 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1883 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1884 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001885 return NULL;
1886
Evan Chengb58a3402011-04-19 00:04:03 +00001887 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1888 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1889
Bob Wilsona7c397c2009-10-14 16:19:03 +00001890 SDValue Chain = N->getOperand(0);
1891 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001892 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1893 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001894 bool is64BitVector = VT.is64BitVector();
1895
Bob Wilson665814b2010-11-01 23:40:51 +00001896 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001897 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001898 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001899 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1900 if (Alignment > NumBytes)
1901 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001902 if (Alignment < 8 && Alignment < NumBytes)
1903 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001904 // Alignment must be a power of two; make sure of that.
1905 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001906 if (Alignment == 1)
1907 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001908 }
Bob Wilson665814b2010-11-01 23:40:51 +00001909 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001910
Bob Wilsona7c397c2009-10-14 16:19:03 +00001911 unsigned OpcodeIndex;
1912 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001913 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001914 // Double-register operations:
1915 case MVT::v8i8: OpcodeIndex = 0; break;
1916 case MVT::v4i16: OpcodeIndex = 1; break;
1917 case MVT::v2f32:
1918 case MVT::v2i32: OpcodeIndex = 2; break;
1919 // Quad-register operations:
1920 case MVT::v8i16: OpcodeIndex = 0; break;
1921 case MVT::v4f32:
1922 case MVT::v4i32: OpcodeIndex = 1; break;
1923 }
1924
Bob Wilson1c3ef902011-02-07 17:43:21 +00001925 std::vector<EVT> ResTys;
1926 if (IsLoad) {
1927 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1928 if (!is64BitVector)
1929 ResTyElts *= 2;
1930 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1931 MVT::i64, ResTyElts));
1932 }
1933 if (isUpdating)
1934 ResTys.push_back(MVT::i32);
1935 ResTys.push_back(MVT::Other);
1936
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001937 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001938 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001939
Bob Wilson1c3ef902011-02-07 17:43:21 +00001940 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001941 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001942 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001943 if (isUpdating) {
1944 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1945 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1946 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001947
Bob Wilson8466fa12010-09-13 23:01:35 +00001948 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001949 SDValue V0 = N->getOperand(Vec0Idx + 0);
1950 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001951 if (NumVecs == 2) {
1952 if (is64BitVector)
1953 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1954 else
1955 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001956 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001957 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001958 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001959 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1960 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001961 if (is64BitVector)
1962 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1963 else
1964 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001965 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001966 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001967 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001968 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001969 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001970 Ops.push_back(Chain);
1971
Bob Wilson1c3ef902011-02-07 17:43:21 +00001972 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1973 QOpcodes[OpcodeIndex]);
1974 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1975 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001976 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001977 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001978 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001979
Bob Wilson8466fa12010-09-13 23:01:35 +00001980 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001981 SuperReg = SDValue(VLdLn, 0);
1982 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1983 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1984 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001985 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1986 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001987 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1988 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1989 if (isUpdating)
1990 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001991 return NULL;
1992}
1993
Bob Wilson1c3ef902011-02-07 17:43:21 +00001994SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper51f50c12012-05-24 05:17:00 +00001995 unsigned NumVecs,
1996 const uint16_t *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001997 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1998 DebugLoc dl = N->getDebugLoc();
1999
2000 SDValue MemAddr, Align;
2001 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2002 return NULL;
2003
Evan Chengb58a3402011-04-19 00:04:03 +00002004 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2005 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2006
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002007 SDValue Chain = N->getOperand(0);
2008 EVT VT = N->getValueType(0);
2009
2010 unsigned Alignment = 0;
2011 if (NumVecs != 3) {
2012 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2013 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2014 if (Alignment > NumBytes)
2015 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002016 if (Alignment < 8 && Alignment < NumBytes)
2017 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002018 // Alignment must be a power of two; make sure of that.
2019 Alignment = (Alignment & -Alignment);
2020 if (Alignment == 1)
2021 Alignment = 0;
2022 }
2023 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2024
2025 unsigned OpcodeIndex;
2026 switch (VT.getSimpleVT().SimpleTy) {
2027 default: llvm_unreachable("unhandled vld-dup type");
2028 case MVT::v8i8: OpcodeIndex = 0; break;
2029 case MVT::v4i16: OpcodeIndex = 1; break;
2030 case MVT::v2f32:
2031 case MVT::v2i32: OpcodeIndex = 2; break;
2032 }
2033
2034 SDValue Pred = getAL(CurDAG);
2035 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2036 SDValue SuperReg;
2037 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002038 SmallVector<SDValue, 6> Ops;
2039 Ops.push_back(MemAddr);
2040 Ops.push_back(Align);
2041 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002042 // fixed-stride update instructions don't have an explicit writeback
2043 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002044 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002045 if (!isa<ConstantSDNode>(Inc.getNode()))
2046 Ops.push_back(Inc);
2047 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2048 else if (NumVecs > 2)
2049 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002050 }
2051 Ops.push_back(Pred);
2052 Ops.push_back(Reg0);
2053 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002054
2055 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002056 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002057 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002058 if (isUpdating)
2059 ResTys.push_back(MVT::i32);
2060 ResTys.push_back(MVT::Other);
2061 SDNode *VLdDup =
2062 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002063 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002064 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002065
2066 // Extract the subregisters.
2067 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2068 unsigned SubIdx = ARM::dsub_0;
2069 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2070 ReplaceUses(SDValue(N, Vec),
2071 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002072 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2073 if (isUpdating)
2074 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002075 return NULL;
2076}
2077
Bob Wilson78dfbc32010-07-07 00:08:54 +00002078SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2079 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002080 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2081 DebugLoc dl = N->getDebugLoc();
2082 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002083 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002084
2085 // Form a REG_SEQUENCE to force register allocation.
2086 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002087 SDValue V0 = N->getOperand(FirstTblReg + 0);
2088 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002089 if (NumVecs == 2)
2090 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2091 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002092 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002093 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002094 // an undef.
2095 SDValue V3 = (NumVecs == 3)
2096 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002097 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002098 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2099 }
2100
Bob Wilson78dfbc32010-07-07 00:08:54 +00002101 SmallVector<SDValue, 6> Ops;
2102 if (IsExt)
2103 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002104 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002105 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002106 Ops.push_back(getAL(CurDAG)); // predicate
2107 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002108 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002109}
2110
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002111SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002112 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002113 if (!Subtarget->hasV6T2Ops())
2114 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002115
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002116 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2117 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2118
2119
2120 // For unsigned extracts, check for a shift right and mask
2121 unsigned And_imm = 0;
2122 if (N->getOpcode() == ISD::AND) {
2123 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2124
Sylvestre Ledru94c22712012-09-27 10:14:43 +00002125 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002126 if (And_imm & (And_imm + 1))
2127 return NULL;
2128
2129 unsigned Srl_imm = 0;
2130 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2131 Srl_imm)) {
2132 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2133
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002134 // Note: The width operand is encoded as width-1.
2135 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002136 unsigned LSB = Srl_imm;
2137 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2138 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2139 CurDAG->getTargetConstant(LSB, MVT::i32),
2140 CurDAG->getTargetConstant(Width, MVT::i32),
2141 getAL(CurDAG), Reg0 };
2142 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2143 }
2144 }
2145 return NULL;
2146 }
2147
2148 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002149 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002150 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002151 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2152 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002153 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002154 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002155 // Note: The width operand is encoded as width-1.
2156 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002157 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002158 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002159 return NULL;
2160 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002161 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002162 CurDAG->getTargetConstant(LSB, MVT::i32),
2163 CurDAG->getTargetConstant(Width, MVT::i32),
2164 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002165 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002166 }
2167 }
2168 return NULL;
2169}
2170
Evan Cheng9ef48352009-11-20 00:54:03 +00002171SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002172SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002173 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2174 SDValue CPTmp0;
2175 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002176 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002177 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2178 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2179 unsigned Opc = 0;
2180 switch (SOShOp) {
2181 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2182 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2183 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2184 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2185 default:
2186 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng9ef48352009-11-20 00:54:03 +00002187 }
2188 SDValue SOShImm =
2189 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2190 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2191 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002192 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002193 }
2194 return 0;
2195}
2196
2197SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002198SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002199 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2200 SDValue CPTmp0;
2201 SDValue CPTmp1;
2202 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002203 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002204 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002205 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2206 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002207 }
2208
2209 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2210 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2211 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2212 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002213 }
2214 return 0;
2215}
2216
2217SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002218SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002219 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002220 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002221 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002222 return 0;
2223
Evan Cheng63f35442010-11-13 02:25:14 +00002224 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002225 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002226 if (is_t2_so_imm(TrueImm)) {
2227 Opc = ARM::t2MOVCCi;
2228 } else if (TrueImm <= 0xffff) {
2229 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002230 } else if (is_t2_so_imm_not(TrueImm)) {
2231 TrueImm = ~TrueImm;
2232 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002233 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002234 // Large immediate.
2235 Opc = ARM::t2MOVCCi32imm;
2236 }
2237
2238 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002239 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002240 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2241 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002242 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002243 }
Evan Cheng63f35442010-11-13 02:25:14 +00002244
Evan Cheng9ef48352009-11-20 00:54:03 +00002245 return 0;
2246}
2247
2248SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002249SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002250 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002251 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2252 if (!T)
2253 return 0;
2254
Evan Cheng63f35442010-11-13 02:25:14 +00002255 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002256 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002257 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002258 if (isSoImm) {
2259 Opc = ARM::MOVCCi;
2260 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2261 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002262 } else if (is_so_imm_not(TrueImm)) {
2263 TrueImm = ~TrueImm;
2264 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002265 } else if (TrueVal.getNode()->hasOneUse() &&
2266 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002267 // Large immediate.
2268 Opc = ARM::MOVCCi32imm;
2269 }
2270
2271 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002272 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002273 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2274 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002275 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002276 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002277
Evan Cheng9ef48352009-11-20 00:54:03 +00002278 return 0;
2279}
2280
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002281SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2282 EVT VT = N->getValueType(0);
2283 SDValue FalseVal = N->getOperand(0);
2284 SDValue TrueVal = N->getOperand(1);
2285 SDValue CC = N->getOperand(2);
2286 SDValue CCR = N->getOperand(3);
2287 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002288 assert(CC.getOpcode() == ISD::Constant);
2289 assert(CCR.getOpcode() == ISD::Register);
2290 ARMCC::CondCodes CCVal =
2291 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002292
2293 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2294 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2295 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2296 // Pattern complexity = 18 cost = 1 size = 0
Evan Cheng07ba9062009-11-19 21:45:22 +00002297 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002298 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002299 CCVal, CCR, InFlag);
2300 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002301 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002302 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2303 if (Res)
2304 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002305 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002306 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002307 CCVal, CCR, InFlag);
2308 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002309 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002310 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2311 if (Res)
2312 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002313 }
2314
2315 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002316 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002317 // (imm:i32):$cc)
2318 // Emits: (MOVCCi:i32 GPR:i32:$false,
2319 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2320 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002321 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002322 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002323 CCVal, CCR, InFlag);
2324 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002325 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002326 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2327 if (Res)
2328 return Res;
2329 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002330 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002331 CCVal, CCR, InFlag);
2332 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002333 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002334 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2335 if (Res)
2336 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002337 }
2338 }
2339
2340 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2341 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2342 // Pattern complexity = 6 cost = 1 size = 0
2343 //
2344 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2345 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2346 // Pattern complexity = 6 cost = 11 size = 0
2347 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002348 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002349 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2350 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002351 unsigned Opc = 0;
2352 switch (VT.getSimpleVT().SimpleTy) {
Craig Topperbc219812012-02-07 02:50:20 +00002353 default: llvm_unreachable("Illegal conditional move type!");
Evan Cheng07ba9062009-11-19 21:45:22 +00002354 case MVT::i32:
2355 Opc = Subtarget->isThumb()
2356 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2357 : ARM::MOVCCr;
2358 break;
2359 case MVT::f32:
2360 Opc = ARM::VMOVScc;
2361 break;
2362 case MVT::f64:
2363 Opc = ARM::VMOVDcc;
2364 break;
2365 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002366 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002367}
2368
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002369/// Target-specific DAG combining for ISD::XOR.
2370/// Target-independent combining lowers SELECT_CC nodes of the form
2371/// select_cc setg[ge] X, 0, X, -X
2372/// select_cc setgt X, -1, X, -X
2373/// select_cc setl[te] X, 0, -X, X
2374/// select_cc setlt X, 1, -X, X
2375/// which represent Integer ABS into:
2376/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2377/// ARM instruction selection detects the latter and matches it to
2378/// ARM::ABS or ARM::t2ABS machine node.
2379SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2380 SDValue XORSrc0 = N->getOperand(0);
2381 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002382 EVT VT = N->getValueType(0);
2383
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002384 if (Subtarget->isThumb1Only())
2385 return NULL;
2386
Jim Grosbach27690282012-08-01 20:33:00 +00002387 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002388 return NULL;
2389
2390 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2391 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2392 SDValue SRASrc0 = XORSrc1.getOperand(0);
2393 SDValue SRASrc1 = XORSrc1.getOperand(1);
2394 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2395 EVT XType = SRASrc0.getValueType();
2396 unsigned Size = XType.getSizeInBits() - 1;
2397
Jim Grosbach27690282012-08-01 20:33:00 +00002398 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2399 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002400 Size == SRAConstant->getZExtValue()) {
Jim Grosbach27690282012-08-01 20:33:00 +00002401 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002402 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2403 }
2404
2405 return NULL;
2406}
2407
Evan Chengde8aa4e2010-05-05 18:28:36 +00002408SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2409 // The only time a CONCAT_VECTORS operation can have legal types is when
2410 // two 64-bit vectors are concatenated to a 128-bit vector.
2411 EVT VT = N->getValueType(0);
2412 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2413 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002414 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002415}
2416
Eli Friedman2bdffe42011-08-31 00:31:29 +00002417SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002418 SmallVector<SDValue, 6> Ops;
2419 Ops.push_back(Node->getOperand(1)); // Ptr
2420 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2421 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002422 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002423 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2424 Ops.push_back(Node->getOperand(5)); // High part of Val2
2425 }
2426 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002427 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2428 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002429 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002430 MVT::i32, MVT::i32, MVT::Other,
2431 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002432 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2433 return ResNode;
2434}
2435
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002436SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002437 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002438
Dan Gohmane8be6c62008-07-17 19:10:17 +00002439 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002440 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002441
2442 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002443 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002444 case ISD::XOR: {
2445 // Select special operations if XOR node forms integer ABS pattern
2446 SDNode *ResNode = SelectABSOp(N);
2447 if (ResNode)
2448 return ResNode;
2449 // Other cases are autogenerated.
2450 break;
2451 }
Evan Chenga8e29892007-01-19 07:51:42 +00002452 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002453 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002454 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002455 if (Subtarget->hasThumb2())
2456 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2457 // be done with MOV + MOVT, at worst.
2458 UseCP = 0;
2459 else {
2460 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002461 UseCP = (Val > 255 && // MOV
2462 ~Val > 255 && // MOV + MVN
2463 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002464 } else
2465 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2466 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2467 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2468 }
2469
Evan Chenga8e29892007-01-19 07:51:42 +00002470 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002471 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002472 CurDAG->getTargetConstantPool(ConstantInt::get(
2473 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002474 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002475
2476 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002477 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002478 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002479 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002480 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002481 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002482 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002483 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002484 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002485 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002486 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002487 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002488 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002489 CurDAG->getEntryNode()
2490 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002491 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002492 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002493 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002494 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002495 return NULL;
2496 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002497
Evan Chenga8e29892007-01-19 07:51:42 +00002498 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002499 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002500 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002501 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002502 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002503 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002504 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002505 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002506 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2507 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2508 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002509 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002510 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2511 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002512 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2513 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2514 CurDAG->getRegister(0, MVT::i32) };
2515 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002516 }
Evan Chenga8e29892007-01-19 07:51:42 +00002517 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002518 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002519 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002520 return I;
2521 break;
2522 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002523 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002524 return I;
2525 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002526 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002527 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002528 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002529 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002530 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002531 if (!RHSV) break;
2532 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002533 unsigned ShImm = Log2_32(RHSV-1);
2534 if (ShImm >= 32)
2535 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002536 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002537 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002538 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2539 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002540 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002541 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002542 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002543 } else {
2544 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002545 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002546 }
Evan Chenga8e29892007-01-19 07:51:42 +00002547 }
2548 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002549 unsigned ShImm = Log2_32(RHSV+1);
2550 if (ShImm >= 32)
2551 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002552 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002553 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002554 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2555 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002556 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002557 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2558 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002559 } else {
2560 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002561 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002562 }
Evan Chenga8e29892007-01-19 07:51:42 +00002563 }
2564 }
2565 break;
Evan Cheng20956592009-10-21 08:15:52 +00002566 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002567 // Check for unsigned bitfield extract
2568 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2569 return I;
2570
Evan Cheng20956592009-10-21 08:15:52 +00002571 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2572 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2573 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2574 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2575 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002576 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002577 if (VT != MVT::i32)
2578 break;
2579 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2580 ? ARM::t2MOVTi16
2581 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2582 if (!Opc)
2583 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002584 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002585 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2586 if (!N1C)
2587 break;
2588 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2589 SDValue N2 = N0.getOperand(1);
2590 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2591 if (!N2C)
2592 break;
2593 unsigned N1CVal = N1C->getZExtValue();
2594 unsigned N2CVal = N2C->getZExtValue();
2595 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2596 (N1CVal & 0xffffU) == 0xffffU &&
2597 (N2CVal & 0xffffU) == 0x0U) {
2598 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2599 MVT::i32);
2600 SDValue Ops[] = { N0.getOperand(0), Imm16,
2601 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2602 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2603 }
2604 }
2605 break;
2606 }
Jim Grosbache5165492009-11-09 00:11:35 +00002607 case ARMISD::VMOVRRD:
2608 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002609 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002610 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002611 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002612 if (Subtarget->isThumb1Only())
2613 break;
2614 if (Subtarget->isThumb()) {
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) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002618 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002619 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002620 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002621 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2622 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002623 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2624 ARM::UMULL : ARM::UMULLv5,
2625 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002626 }
Evan Chengee568cf2007-07-05 07:15:27 +00002627 }
Dan Gohman525178c2007-10-08 18:33:35 +00002628 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002629 if (Subtarget->isThumb1Only())
2630 break;
2631 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002632 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002633 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002634 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002635 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002636 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002637 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2638 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002639 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2640 ARM::SMULL : ARM::SMULLv5,
2641 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002642 }
Evan Chengee568cf2007-07-05 07:15:27 +00002643 }
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002644 case ARMISD::UMLAL:{
2645 if (Subtarget->isThumb()) {
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 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops, 6);
2650 }else{
2651 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2652 N->getOperand(3), getAL(CurDAG),
2653 CurDAG->getRegister(0, MVT::i32),
2654 CurDAG->getRegister(0, MVT::i32) };
2655 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2656 ARM::UMLAL : ARM::UMLALv5,
2657 dl, MVT::i32, MVT::i32, Ops, 7);
2658 }
2659 }
2660 case ARMISD::SMLAL:{
2661 if (Subtarget->isThumb()) {
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 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops, 6);
2666 }else{
2667 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2668 N->getOperand(3), getAL(CurDAG),
2669 CurDAG->getRegister(0, MVT::i32),
2670 CurDAG->getRegister(0, MVT::i32) };
2671 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2672 ARM::SMLAL : ARM::SMLALv5,
2673 dl, MVT::i32, MVT::i32, Ops, 7);
2674 }
2675 }
Evan Chenga8e29892007-01-19 07:51:42 +00002676 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002677 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002678 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002679 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002680 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002681 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002682 if (ResNode)
2683 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002684 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002685 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002686 }
Evan Chengee568cf2007-07-05 07:15:27 +00002687 case ARMISD::BRCOND: {
2688 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2689 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2690 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002691
Evan Chengee568cf2007-07-05 07:15:27 +00002692 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2693 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2694 // Pattern complexity = 6 cost = 1 size = 0
2695
David Goodwin5e47a9a2009-06-30 18:04:13 +00002696 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2697 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2698 // Pattern complexity = 6 cost = 1 size = 0
2699
Jim Grosbach764ab522009-08-11 15:33:49 +00002700 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002701 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002702 SDValue Chain = N->getOperand(0);
2703 SDValue N1 = N->getOperand(1);
2704 SDValue N2 = N->getOperand(2);
2705 SDValue N3 = N->getOperand(3);
2706 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002707 assert(N1.getOpcode() == ISD::BasicBlock);
2708 assert(N2.getOpcode() == ISD::Constant);
2709 assert(N3.getOpcode() == ISD::Register);
2710
Dan Gohman475871a2008-07-27 21:46:04 +00002711 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002712 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002713 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002714 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002715 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002716 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002717 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002718 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002719 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002720 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002721 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002722 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002723 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002724 return NULL;
2725 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002726 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002727 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002728 case ARMISD::VZIP: {
2729 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002730 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002731 switch (VT.getSimpleVT().SimpleTy) {
2732 default: return NULL;
2733 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2734 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2735 case MVT::v2f32:
Jim Grosbach6073b302012-04-11 16:53:25 +00002736 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2737 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002738 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2739 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2740 case MVT::v4f32:
2741 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2742 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002743 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002744 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2745 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2746 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002747 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002748 case ARMISD::VUZP: {
2749 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002750 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002751 switch (VT.getSimpleVT().SimpleTy) {
2752 default: return NULL;
2753 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2754 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2755 case MVT::v2f32:
Jim Grosbach18355472012-04-11 17:40:18 +00002756 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2757 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002758 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2759 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2760 case MVT::v4f32:
2761 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2762 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002763 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002764 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2765 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2766 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002767 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002768 case ARMISD::VTRN: {
2769 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002770 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002771 switch (VT.getSimpleVT().SimpleTy) {
2772 default: return NULL;
2773 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2774 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2775 case MVT::v2f32:
2776 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2777 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2778 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2779 case MVT::v4f32:
2780 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2781 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002782 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002783 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2784 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2785 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002786 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002787 case ARMISD::BUILD_VECTOR: {
2788 EVT VecVT = N->getValueType(0);
2789 EVT EltVT = VecVT.getVectorElementType();
2790 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002791 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002792 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2793 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2794 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002795 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002796 if (NumElts == 2)
2797 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2798 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2799 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2800 N->getOperand(2), N->getOperand(3));
2801 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002802
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002803 case ARMISD::VLD2DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002804 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2805 ARM::VLD2DUPd32 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002806 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002807 }
2808
Bob Wilson86c6d802010-11-29 19:35:29 +00002809 case ARMISD::VLD3DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002810 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2811 ARM::VLD3DUPd16Pseudo,
2812 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002813 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002814 }
2815
Bob Wilson6c4c9822010-11-30 00:00:35 +00002816 case ARMISD::VLD4DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002817 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2818 ARM::VLD4DUPd16Pseudo,
2819 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002820 return SelectVLDDup(N, false, 4, Opcodes);
2821 }
2822
2823 case ARMISD::VLD2DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002824 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2825 ARM::VLD2DUPd16wb_fixed,
2826 ARM::VLD2DUPd32wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002827 return SelectVLDDup(N, true, 2, Opcodes);
2828 }
2829
2830 case ARMISD::VLD3DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002831 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2832 ARM::VLD3DUPd16Pseudo_UPD,
2833 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002834 return SelectVLDDup(N, true, 3, Opcodes);
2835 }
2836
2837 case ARMISD::VLD4DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002838 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2839 ARM::VLD4DUPd16Pseudo_UPD,
2840 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002841 return SelectVLDDup(N, true, 4, Opcodes);
2842 }
2843
2844 case ARMISD::VLD1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002845 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2846 ARM::VLD1d16wb_fixed,
2847 ARM::VLD1d32wb_fixed,
2848 ARM::VLD1d64wb_fixed };
2849 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2850 ARM::VLD1q16wb_fixed,
2851 ARM::VLD1q32wb_fixed,
2852 ARM::VLD1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002853 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2854 }
2855
2856 case ARMISD::VLD2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002857 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2858 ARM::VLD2d16wb_fixed,
2859 ARM::VLD2d32wb_fixed,
2860 ARM::VLD1q64wb_fixed};
2861 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2862 ARM::VLD2q16PseudoWB_fixed,
2863 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002864 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2865 }
2866
2867 case ARMISD::VLD3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002868 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2869 ARM::VLD3d16Pseudo_UPD,
2870 ARM::VLD3d32Pseudo_UPD,
2871 ARM::VLD1q64wb_fixed};
2872 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2873 ARM::VLD3q16Pseudo_UPD,
2874 ARM::VLD3q32Pseudo_UPD };
2875 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2876 ARM::VLD3q16oddPseudo_UPD,
2877 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002878 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2879 }
2880
2881 case ARMISD::VLD4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002882 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2883 ARM::VLD4d16Pseudo_UPD,
2884 ARM::VLD4d32Pseudo_UPD,
2885 ARM::VLD1q64wb_fixed};
2886 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2887 ARM::VLD4q16Pseudo_UPD,
2888 ARM::VLD4q32Pseudo_UPD };
2889 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2890 ARM::VLD4q16oddPseudo_UPD,
2891 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002892 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2893 }
2894
2895 case ARMISD::VLD2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002896 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2897 ARM::VLD2LNd16Pseudo_UPD,
2898 ARM::VLD2LNd32Pseudo_UPD };
2899 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2900 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002901 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2902 }
2903
2904 case ARMISD::VLD3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002905 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2906 ARM::VLD3LNd16Pseudo_UPD,
2907 ARM::VLD3LNd32Pseudo_UPD };
2908 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2909 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002910 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2911 }
2912
2913 case ARMISD::VLD4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002914 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2915 ARM::VLD4LNd16Pseudo_UPD,
2916 ARM::VLD4LNd32Pseudo_UPD };
2917 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2918 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002919 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2920 }
2921
2922 case ARMISD::VST1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002923 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2924 ARM::VST1d16wb_fixed,
2925 ARM::VST1d32wb_fixed,
2926 ARM::VST1d64wb_fixed };
2927 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2928 ARM::VST1q16wb_fixed,
2929 ARM::VST1q32wb_fixed,
2930 ARM::VST1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002931 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2932 }
2933
2934 case ARMISD::VST2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002935 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2936 ARM::VST2d16wb_fixed,
2937 ARM::VST2d32wb_fixed,
2938 ARM::VST1q64wb_fixed};
2939 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2940 ARM::VST2q16PseudoWB_fixed,
2941 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002942 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2943 }
2944
2945 case ARMISD::VST3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002946 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2947 ARM::VST3d16Pseudo_UPD,
2948 ARM::VST3d32Pseudo_UPD,
2949 ARM::VST1d64TPseudoWB_fixed};
2950 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2951 ARM::VST3q16Pseudo_UPD,
2952 ARM::VST3q32Pseudo_UPD };
2953 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2954 ARM::VST3q16oddPseudo_UPD,
2955 ARM::VST3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002956 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2957 }
2958
2959 case ARMISD::VST4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002960 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2961 ARM::VST4d16Pseudo_UPD,
2962 ARM::VST4d32Pseudo_UPD,
2963 ARM::VST1d64QPseudoWB_fixed};
2964 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2965 ARM::VST4q16Pseudo_UPD,
2966 ARM::VST4q32Pseudo_UPD };
2967 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2968 ARM::VST4q16oddPseudo_UPD,
2969 ARM::VST4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002970 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2971 }
2972
2973 case ARMISD::VST2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002974 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2975 ARM::VST2LNd16Pseudo_UPD,
2976 ARM::VST2LNd32Pseudo_UPD };
2977 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2978 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002979 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2980 }
2981
2982 case ARMISD::VST3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002983 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2984 ARM::VST3LNd16Pseudo_UPD,
2985 ARM::VST3LNd32Pseudo_UPD };
2986 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2987 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002988 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2989 }
2990
2991 case ARMISD::VST4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002992 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2993 ARM::VST4LNd16Pseudo_UPD,
2994 ARM::VST4LNd32Pseudo_UPD };
2995 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2996 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002997 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002998 }
2999
Bob Wilson31fb12f2009-08-26 17:39:53 +00003000 case ISD::INTRINSIC_VOID:
3001 case ISD::INTRINSIC_W_CHAIN: {
3002 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00003003 switch (IntNo) {
3004 default:
Bob Wilson429009b2010-05-06 16:05:26 +00003005 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003006
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00003007 case Intrinsic::arm_ldrexd: {
3008 SDValue MemAddr = N->getOperand(2);
3009 DebugLoc dl = N->getDebugLoc();
3010 SDValue Chain = N->getOperand(0);
3011
3012 unsigned NewOpc = ARM::LDREXD;
3013 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3014 NewOpc = ARM::t2LDREXD;
3015
3016 // arm_ldrexd returns a i64 value in {i32, i32}
3017 std::vector<EVT> ResTys;
3018 ResTys.push_back(MVT::i32);
3019 ResTys.push_back(MVT::i32);
3020 ResTys.push_back(MVT::Other);
3021
3022 // place arguments in the right order
3023 SmallVector<SDValue, 7> Ops;
3024 Ops.push_back(MemAddr);
3025 Ops.push_back(getAL(CurDAG));
3026 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3027 Ops.push_back(Chain);
3028 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3029 Ops.size());
3030 // Transfer memoperands.
3031 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3032 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3033 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3034
3035 // Until there's support for specifing explicit register constraints
3036 // like the use of even/odd register pair, hardcode ldrexd to always
3037 // use the pair [R0, R1] to hold the load result.
3038 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3039 SDValue(Ld, 0), SDValue(0,0));
3040 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3041 SDValue(Ld, 1), Chain.getValue(1));
3042
3043 // Remap uses.
3044 SDValue Glue = Chain.getValue(1);
3045 if (!SDValue(N, 0).use_empty()) {
3046 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3047 ARM::R0, MVT::i32, Glue);
3048 Glue = Result.getValue(2);
3049 ReplaceUses(SDValue(N, 0), Result);
3050 }
3051 if (!SDValue(N, 1).use_empty()) {
3052 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3053 ARM::R1, MVT::i32, Glue);
3054 Glue = Result.getValue(2);
3055 ReplaceUses(SDValue(N, 1), Result);
3056 }
3057
3058 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3059 return NULL;
3060 }
3061
3062 case Intrinsic::arm_strexd: {
3063 DebugLoc dl = N->getDebugLoc();
3064 SDValue Chain = N->getOperand(0);
3065 SDValue Val0 = N->getOperand(2);
3066 SDValue Val1 = N->getOperand(3);
3067 SDValue MemAddr = N->getOperand(4);
3068
3069 // Until there's support for specifing explicit register constraints
3070 // like the use of even/odd register pair, hardcode strexd to always
3071 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3072 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3073 SDValue(0, 0));
3074 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3075
3076 SDValue Glue = Chain.getValue(1);
3077 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3078 ARM::R2, MVT::i32, Glue);
3079 Glue = Val0.getValue(1);
3080 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3081 ARM::R3, MVT::i32, Glue);
3082
3083 // Store exclusive double return a i32 value which is the return status
3084 // of the issued store.
3085 std::vector<EVT> ResTys;
3086 ResTys.push_back(MVT::i32);
3087 ResTys.push_back(MVT::Other);
3088
3089 // place arguments in the right order
3090 SmallVector<SDValue, 7> Ops;
3091 Ops.push_back(Val0);
3092 Ops.push_back(Val1);
3093 Ops.push_back(MemAddr);
3094 Ops.push_back(getAL(CurDAG));
3095 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3096 Ops.push_back(Chain);
3097
3098 unsigned NewOpc = ARM::STREXD;
3099 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3100 NewOpc = ARM::t2STREXD;
3101
3102 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3103 Ops.size());
3104 // Transfer memoperands.
3105 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3106 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3107 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3108
3109 return St;
3110 }
3111
Bob Wilson621f1952010-03-23 05:25:43 +00003112 case Intrinsic::arm_neon_vld1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003113 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3114 ARM::VLD1d32, ARM::VLD1d64 };
3115 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3116 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003117 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003118 }
3119
Bob Wilson31fb12f2009-08-26 17:39:53 +00003120 case Intrinsic::arm_neon_vld2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003121 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3122 ARM::VLD2d32, ARM::VLD1q64 };
3123 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3124 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003125 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003126 }
3127
3128 case Intrinsic::arm_neon_vld3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003129 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3130 ARM::VLD3d16Pseudo,
3131 ARM::VLD3d32Pseudo,
3132 ARM::VLD1d64TPseudo };
3133 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3134 ARM::VLD3q16Pseudo_UPD,
3135 ARM::VLD3q32Pseudo_UPD };
3136 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3137 ARM::VLD3q16oddPseudo,
3138 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003139 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003140 }
3141
3142 case Intrinsic::arm_neon_vld4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003143 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3144 ARM::VLD4d16Pseudo,
3145 ARM::VLD4d32Pseudo,
3146 ARM::VLD1d64QPseudo };
3147 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3148 ARM::VLD4q16Pseudo_UPD,
3149 ARM::VLD4q32Pseudo_UPD };
3150 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3151 ARM::VLD4q16oddPseudo,
3152 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003153 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003154 }
3155
Bob Wilson243fcc52009-09-01 04:26:28 +00003156 case Intrinsic::arm_neon_vld2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003157 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3158 ARM::VLD2LNd16Pseudo,
3159 ARM::VLD2LNd32Pseudo };
3160 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3161 ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003162 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003163 }
3164
3165 case Intrinsic::arm_neon_vld3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003166 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3167 ARM::VLD3LNd16Pseudo,
3168 ARM::VLD3LNd32Pseudo };
3169 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3170 ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003171 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003172 }
3173
3174 case Intrinsic::arm_neon_vld4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003175 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3176 ARM::VLD4LNd16Pseudo,
3177 ARM::VLD4LNd32Pseudo };
3178 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3179 ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003180 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003181 }
3182
Bob Wilson11d98992010-03-23 06:20:33 +00003183 case Intrinsic::arm_neon_vst1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003184 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3185 ARM::VST1d32, ARM::VST1d64 };
3186 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3187 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003188 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003189 }
3190
Bob Wilson31fb12f2009-08-26 17:39:53 +00003191 case Intrinsic::arm_neon_vst2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003192 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3193 ARM::VST2d32, ARM::VST1q64 };
3194 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3195 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003196 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003197 }
3198
3199 case Intrinsic::arm_neon_vst3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003200 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3201 ARM::VST3d16Pseudo,
3202 ARM::VST3d32Pseudo,
3203 ARM::VST1d64TPseudo };
3204 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3205 ARM::VST3q16Pseudo_UPD,
3206 ARM::VST3q32Pseudo_UPD };
3207 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3208 ARM::VST3q16oddPseudo,
3209 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003210 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003211 }
3212
3213 case Intrinsic::arm_neon_vst4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003214 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3215 ARM::VST4d16Pseudo,
3216 ARM::VST4d32Pseudo,
3217 ARM::VST1d64QPseudo };
3218 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3219 ARM::VST4q16Pseudo_UPD,
3220 ARM::VST4q32Pseudo_UPD };
3221 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3222 ARM::VST4q16oddPseudo,
3223 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003224 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003225 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003226
3227 case Intrinsic::arm_neon_vst2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003228 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3229 ARM::VST2LNd16Pseudo,
3230 ARM::VST2LNd32Pseudo };
3231 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3232 ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003233 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003234 }
3235
3236 case Intrinsic::arm_neon_vst3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003237 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3238 ARM::VST3LNd16Pseudo,
3239 ARM::VST3LNd32Pseudo };
3240 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3241 ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003242 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003243 }
3244
3245 case Intrinsic::arm_neon_vst4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003246 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3247 ARM::VST4LNd16Pseudo,
3248 ARM::VST4LNd32Pseudo };
3249 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3250 ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003251 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003252 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003253 }
Bob Wilson429009b2010-05-06 16:05:26 +00003254 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003255 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003256
Bob Wilsond491d6e2010-07-06 23:36:25 +00003257 case ISD::INTRINSIC_WO_CHAIN: {
3258 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3259 switch (IntNo) {
3260 default:
3261 break;
3262
3263 case Intrinsic::arm_neon_vtbl2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003264 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003265 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003266 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003267 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003268 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003269
3270 case Intrinsic::arm_neon_vtbx2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003271 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003272 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003273 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003274 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003275 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003276 }
3277 break;
3278 }
3279
Bill Wendling69a05a72011-03-14 23:02:38 +00003280 case ARMISD::VTBL1: {
3281 DebugLoc dl = N->getDebugLoc();
3282 EVT VT = N->getValueType(0);
3283 SmallVector<SDValue, 6> Ops;
3284
3285 Ops.push_back(N->getOperand(0));
3286 Ops.push_back(N->getOperand(1));
3287 Ops.push_back(getAL(CurDAG)); // Predicate
3288 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3289 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3290 }
3291 case ARMISD::VTBL2: {
3292 DebugLoc dl = N->getDebugLoc();
3293 EVT VT = N->getValueType(0);
3294
3295 // Form a REG_SEQUENCE to force register allocation.
3296 SDValue V0 = N->getOperand(0);
3297 SDValue V1 = N->getOperand(1);
3298 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3299
3300 SmallVector<SDValue, 6> Ops;
3301 Ops.push_back(RegSeq);
3302 Ops.push_back(N->getOperand(2));
3303 Ops.push_back(getAL(CurDAG)); // Predicate
3304 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Jim Grosbach28f08c92012-03-05 19:33:30 +00003305 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT,
Bill Wendling69a05a72011-03-14 23:02:38 +00003306 Ops.data(), Ops.size());
3307 }
3308
Bob Wilson429009b2010-05-06 16:05:26 +00003309 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003310 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003311
3312 case ARMISD::ATOMOR64_DAG:
3313 return SelectAtomic64(N, ARM::ATOMOR6432);
3314 case ARMISD::ATOMXOR64_DAG:
3315 return SelectAtomic64(N, ARM::ATOMXOR6432);
3316 case ARMISD::ATOMADD64_DAG:
3317 return SelectAtomic64(N, ARM::ATOMADD6432);
3318 case ARMISD::ATOMSUB64_DAG:
3319 return SelectAtomic64(N, ARM::ATOMSUB6432);
3320 case ARMISD::ATOMNAND64_DAG:
3321 return SelectAtomic64(N, ARM::ATOMNAND6432);
3322 case ARMISD::ATOMAND64_DAG:
3323 return SelectAtomic64(N, ARM::ATOMAND6432);
3324 case ARMISD::ATOMSWAP64_DAG:
3325 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003326 case ARMISD::ATOMCMPXCHG64_DAG:
3327 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003328 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003329
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003330 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003331}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003332
Bob Wilson224c2442009-05-19 05:53:42 +00003333bool ARMDAGToDAGISel::
3334SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3335 std::vector<SDValue> &OutOps) {
3336 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003337 // Require the address to be in a register. That is safe for all ARM
3338 // variants and it is hard to do anything much smarter without knowing
3339 // how the operand is used.
3340 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003341 return false;
3342}
3343
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003344/// createARMISelDag - This pass converts a legalized DAG into a
3345/// ARM-specific DAG, ready for instruction scheduling.
3346///
Bob Wilson522ce972009-09-28 14:30:20 +00003347FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3348 CodeGenOpt::Level OptLevel) {
3349 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003350}