blob: c6f9d15c8752c096b754dc12d4e42b6702d5d4b1 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000107 }
108
Jim Grosbach3e556122010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach82891622010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
Owen Anderson793e7962011-07-26 20:54:26 +0000132 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
133 SDValue &Offset, SDValue &Opc);
134 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000136 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
137 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000138 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000144 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000145 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000146 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000147
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000148 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000152 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
153 unsigned Scale);
154 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
156 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
157 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
158 SDValue &OffImm);
159 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
160 SDValue &OffImm);
161 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
162 SDValue &OffImm);
163 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
164 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000166
Bill Wendlingf4caf692010-12-14 03:36:38 +0000167 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000168 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000169 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
171 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000172 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000173 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000174 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000176 SDValue &OffReg, SDValue &ShImm);
177
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 inline bool is_so_imm(unsigned Imm) const {
179 return ARM_AM::getSOImmVal(Imm) != -1;
180 }
181
182 inline bool is_so_imm_not(unsigned Imm) const {
183 return ARM_AM::getSOImmVal(~Imm) != -1;
184 }
185
186 inline bool is_t2_so_imm(unsigned Imm) const {
187 return ARM_AM::getT2SOImmVal(Imm) != -1;
188 }
189
190 inline bool is_t2_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getT2SOImmVal(~Imm) != -1;
192 }
193
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000194 // Include the pieces autogenerated from the target description.
195#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000196
197private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000198 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
199 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000200 SDNode *SelectARMIndexedLoad(SDNode *N);
201 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000202
Bob Wilson621f1952010-03-23 05:25:43 +0000203 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
204 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000205 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000207 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +0000208 const uint16_t *DOpcodes,
209 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson3e36f132009-10-14 17:28:52 +0000210
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000213 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000214 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000215 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +0000216 const uint16_t *DOpcodes,
217 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson24f995d2009-10-14 18:32:29 +0000218
Bob Wilson96493442009-10-14 16:46:45 +0000219 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000220 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000221 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000222 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
223 bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +0000224 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000226 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
227 /// should be 2, 3 or 4. The opcode array specifies the instructions used
228 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000229 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +0000230 const uint16_t *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231
Bob Wilson78dfbc32010-07-07 00:08:54 +0000232 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
233 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
234 /// generated to force the table registers to be consecutive.
235 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000236
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000237 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000238 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000239
Evan Cheng07ba9062009-11-19 21:45:22 +0000240 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000241 SDNode *SelectCMOVOp(SDNode *N);
242 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000243 ARMCC::CondCodes CCVal, SDValue CCR,
244 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000245 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000248 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000251 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000254
Bill Wendlingef2c86f2011-10-10 22:59:55 +0000255 // Select special operations if node forms integer ABS pattern
256 SDNode *SelectABSOp(SDNode *N);
257
Evan Chengde8aa4e2010-05-05 18:28:36 +0000258 SDNode *SelectConcatVector(SDNode *N);
259
Eli Friedman2bdffe42011-08-31 00:31:29 +0000260 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
261
Evan Chengaf4550f2009-07-02 01:23:32 +0000262 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
263 /// inline asm expressions.
264 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
265 char ConstraintCode,
266 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000267
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000268 // Form pairs of consecutive S, D, or Q registers.
269 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000270 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000271 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
272
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000273 // Form sequences of 4 consecutive S, D, or Q registers.
274 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000275 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000276 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000277
278 // Get the alignment operand for a NEON VLD or VST instruction.
279 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000280};
Evan Chenga8e29892007-01-19 07:51:42 +0000281}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000282
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000283/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
284/// operand. If so Imm will receive the 32-bit value.
285static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
286 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
287 Imm = cast<ConstantSDNode>(N)->getZExtValue();
288 return true;
289 }
290 return false;
291}
292
293// isInt32Immediate - This method tests to see if a constant operand.
294// If so Imm will receive the 32 bit value.
295static bool isInt32Immediate(SDValue N, unsigned &Imm) {
296 return isInt32Immediate(N.getNode(), Imm);
297}
298
299// isOpcWithIntImmediate - This method tests to see if the node is a specific
300// opcode and that it has a immediate integer right operand.
301// If so Imm will receive the 32 bit value.
302static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
303 return N->getOpcode() == Opc &&
304 isInt32Immediate(N->getOperand(1).getNode(), Imm);
305}
306
Daniel Dunbarec91d522011-01-19 15:12:16 +0000307/// \brief Check whether a particular node is a constant value representable as
308/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
309///
310/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000311static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbarec91d522011-01-19 15:12:16 +0000312 int RangeMin, int RangeMax,
313 int &ScaledConstant) {
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000314 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbarec91d522011-01-19 15:12:16 +0000315
316 // Check that this is a constant.
317 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
318 if (!C)
319 return false;
320
321 ScaledConstant = (int) C->getZExtValue();
322 if ((ScaledConstant % Scale) != 0)
323 return false;
324
325 ScaledConstant /= Scale;
326 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
327}
328
Evan Cheng48575f62010-12-05 22:04:16 +0000329/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
330/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
331/// least on current ARM implementations) which should be avoidded.
332bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
333 if (OptLevel == CodeGenOpt::None)
334 return true;
335
336 if (!CheckVMLxHazard)
337 return true;
338
339 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
340 return true;
341
342 if (!N->hasOneUse())
343 return false;
344
345 SDNode *Use = *N->use_begin();
346 if (Use->getOpcode() == ISD::CopyToReg)
347 return true;
348 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000349 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
350 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000351 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000352 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000353 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
354 return true;
355 // vmlx feeding into another vmlx. We actually want to unfold
356 // the use later in the MLxExpansion pass. e.g.
357 // vmla
358 // vmla (stall 8 cycles)
359 //
360 // vmul (5 cycles)
361 // vadd (5 cycles)
362 // vmla
363 // This adds up to about 18 - 19 cycles.
364 //
365 // vmla
366 // vmul (stall 4 cycles)
367 // vadd adds up to about 14 cycles.
368 return TII->isFpMLxInstruction(Opcode);
369 }
370
371 return false;
372}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000373
Evan Chengf40deed2010-10-27 23:41:30 +0000374bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
375 ARM_AM::ShiftOpc ShOpcVal,
376 unsigned ShAmt) {
377 if (!Subtarget->isCortexA9())
378 return true;
379 if (Shift.hasOneUse())
380 return true;
381 // R << 2 is free.
382 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
383}
384
Owen Anderson92a20222011-07-21 18:54:16 +0000385bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000386 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000387 SDValue &Opc,
388 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000389 if (DisableShifterOp)
390 return false;
391
Evan Chengee04a6d2011-07-20 23:34:39 +0000392 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000393
394 // Don't match base register only case. That is matched to a separate
395 // lower complexity pattern with explicit register operand.
396 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000397
Evan Cheng055b0312009-06-29 07:51:04 +0000398 BaseReg = N.getOperand(0);
399 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000400 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
401 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000402 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000403 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
404 MVT::i32);
405 return true;
406}
407
Owen Anderson92a20222011-07-21 18:54:16 +0000408bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
409 SDValue &BaseReg,
410 SDValue &ShReg,
411 SDValue &Opc,
412 bool CheckProfitability) {
413 if (DisableShifterOp)
414 return false;
415
416 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
417
418 // Don't match base register only case. That is matched to a separate
419 // lower complexity pattern with explicit register operand.
420 if (ShOpcVal == ARM_AM::no_shift) return false;
421
422 BaseReg = N.getOperand(0);
423 unsigned ShImmVal = 0;
424 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
425 if (RHS) return false;
426
427 ShReg = N.getOperand(1);
428 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
429 return false;
430 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
431 MVT::i32);
432 return true;
433}
434
435
Jim Grosbach3e556122010-10-26 22:37:02 +0000436bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
437 SDValue &Base,
438 SDValue &OffImm) {
439 // Match simple R + imm12 operands.
440
441 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000442 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
443 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000444 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000445 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000446 int FI = cast<FrameIndexSDNode>(N)->getIndex();
447 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
448 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
449 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000450 }
Owen Anderson099e5552011-03-18 19:46:58 +0000451
Chris Lattner0a9481f2011-02-13 22:25:43 +0000452 if (N.getOpcode() == ARMISD::Wrapper &&
453 !(Subtarget->useMovt() &&
454 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000455 Base = N.getOperand(0);
456 } else
457 Base = N;
458 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
459 return true;
460 }
461
462 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
463 int RHSC = (int)RHS->getZExtValue();
464 if (N.getOpcode() == ISD::SUB)
465 RHSC = -RHSC;
466
467 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
468 Base = N.getOperand(0);
469 if (Base.getOpcode() == ISD::FrameIndex) {
470 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
471 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
472 }
473 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
474 return true;
475 }
476 }
477
478 // Base only.
479 Base = N;
480 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
481 return true;
482}
483
484
485
486bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
487 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000488 if (N.getOpcode() == ISD::MUL &&
489 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000490 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
491 // X * [3,5,9] -> X + X * [2,4,8] etc.
492 int RHSC = (int)RHS->getZExtValue();
493 if (RHSC & 1) {
494 RHSC = RHSC & ~1;
495 ARM_AM::AddrOpc AddSub = ARM_AM::add;
496 if (RHSC < 0) {
497 AddSub = ARM_AM::sub;
498 RHSC = - RHSC;
499 }
500 if (isPowerOf2_32(RHSC)) {
501 unsigned ShAmt = Log2_32(RHSC);
502 Base = Offset = N.getOperand(0);
503 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
504 ARM_AM::lsl),
505 MVT::i32);
506 return true;
507 }
508 }
509 }
510 }
511
Chris Lattner0a9481f2011-02-13 22:25:43 +0000512 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
513 // ISD::OR that is equivalent to an ISD::ADD.
514 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000515 return false;
516
517 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000518 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000519 int RHSC;
520 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
521 -0x1000+1, 0x1000, RHSC)) // 12 bits.
522 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000523 }
524
525 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000526 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000527 ARM_AM::ShiftOpc ShOpcVal =
528 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000529 unsigned ShAmt = 0;
530
531 Base = N.getOperand(0);
532 Offset = N.getOperand(1);
533
534 if (ShOpcVal != ARM_AM::no_shift) {
535 // Check to see if the RHS of the shift is a constant, if not, we can't fold
536 // it.
537 if (ConstantSDNode *Sh =
538 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
539 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000540 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
541 Offset = N.getOperand(1).getOperand(0);
542 else {
543 ShAmt = 0;
544 ShOpcVal = ARM_AM::no_shift;
545 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000546 } else {
547 ShOpcVal = ARM_AM::no_shift;
548 }
549 }
550
551 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000552 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000553 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000554 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000555 if (ShOpcVal != ARM_AM::no_shift) {
556 // Check to see if the RHS of the shift is a constant, if not, we can't
557 // fold it.
558 if (ConstantSDNode *Sh =
559 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
560 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000561 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000562 Offset = N.getOperand(0).getOperand(0);
563 Base = N.getOperand(1);
564 } else {
565 ShAmt = 0;
566 ShOpcVal = ARM_AM::no_shift;
567 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000568 } else {
569 ShOpcVal = ARM_AM::no_shift;
570 }
571 }
572 }
573
574 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
575 MVT::i32);
576 return true;
577}
578
579
Jim Grosbach3e556122010-10-26 22:37:02 +0000580//-----
581
Jim Grosbach82891622010-09-29 19:03:54 +0000582AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
583 SDValue &Base,
584 SDValue &Offset,
585 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000586 if (N.getOpcode() == ISD::MUL &&
587 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000588 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
589 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000590 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000591 if (RHSC & 1) {
592 RHSC = RHSC & ~1;
593 ARM_AM::AddrOpc AddSub = ARM_AM::add;
594 if (RHSC < 0) {
595 AddSub = ARM_AM::sub;
596 RHSC = - RHSC;
597 }
598 if (isPowerOf2_32(RHSC)) {
599 unsigned ShAmt = Log2_32(RHSC);
600 Base = Offset = N.getOperand(0);
601 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
602 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000603 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000604 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000605 }
606 }
607 }
608 }
609
Chris Lattner0a9481f2011-02-13 22:25:43 +0000610 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
611 // ISD::OR that is equivalent to an ADD.
612 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000613 Base = N;
614 if (N.getOpcode() == ISD::FrameIndex) {
615 int FI = cast<FrameIndexSDNode>(N)->getIndex();
616 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000617 } else if (N.getOpcode() == ARMISD::Wrapper &&
618 !(Subtarget->useMovt() &&
619 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000620 Base = N.getOperand(0);
621 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000622 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000623 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
624 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000625 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000626 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000627 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000628
Evan Chenga8e29892007-01-19 07:51:42 +0000629 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000630 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000631 int RHSC;
632 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
633 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
634 Base = N.getOperand(0);
635 if (Base.getOpcode() == ISD::FrameIndex) {
636 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
637 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000638 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000639 Offset = CurDAG->getRegister(0, MVT::i32);
640
641 ARM_AM::AddrOpc AddSub = ARM_AM::add;
642 if (RHSC < 0) {
643 AddSub = ARM_AM::sub;
644 RHSC = - RHSC;
645 }
646 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
647 ARM_AM::no_shift),
648 MVT::i32);
649 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000650 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000651 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000652
Evan Chengf40deed2010-10-27 23:41:30 +0000653 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
654 // Compute R +/- (R << N) and reuse it.
655 Base = N;
656 Offset = CurDAG->getRegister(0, MVT::i32);
657 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
658 ARM_AM::no_shift),
659 MVT::i32);
660 return AM2_BASE;
661 }
662
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000663 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000664 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000665 ARM_AM::ShiftOpc ShOpcVal =
666 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000667 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000668
Evan Chenga8e29892007-01-19 07:51:42 +0000669 Base = N.getOperand(0);
670 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000671
Evan Chenga8e29892007-01-19 07:51:42 +0000672 if (ShOpcVal != ARM_AM::no_shift) {
673 // Check to see if the RHS of the shift is a constant, if not, we can't fold
674 // it.
675 if (ConstantSDNode *Sh =
676 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000677 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000678 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
679 Offset = N.getOperand(1).getOperand(0);
680 else {
681 ShAmt = 0;
682 ShOpcVal = ARM_AM::no_shift;
683 }
Evan Chenga8e29892007-01-19 07:51:42 +0000684 } else {
685 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000686 }
687 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000688
Evan Chenga8e29892007-01-19 07:51:42 +0000689 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000690 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000691 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000692 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000693 if (ShOpcVal != ARM_AM::no_shift) {
694 // Check to see if the RHS of the shift is a constant, if not, we can't
695 // fold it.
696 if (ConstantSDNode *Sh =
697 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000698 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000699 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000700 Offset = N.getOperand(0).getOperand(0);
701 Base = N.getOperand(1);
702 } else {
703 ShAmt = 0;
704 ShOpcVal = ARM_AM::no_shift;
705 }
Evan Chenga8e29892007-01-19 07:51:42 +0000706 } else {
707 ShOpcVal = ARM_AM::no_shift;
708 }
709 }
710 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000711
Evan Chenga8e29892007-01-19 07:51:42 +0000712 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000713 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000714 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000715}
716
Owen Anderson793e7962011-07-26 20:54:26 +0000717bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000718 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000719 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000720 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
721 ? cast<LoadSDNode>(Op)->getAddressingMode()
722 : cast<StoreSDNode>(Op)->getAddressingMode();
723 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
724 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000725 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000726 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
727 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000728
729 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000730 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000731 unsigned ShAmt = 0;
732 if (ShOpcVal != ARM_AM::no_shift) {
733 // Check to see if the RHS of the shift is a constant, if not, we can't fold
734 // it.
735 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000736 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000737 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
738 Offset = N.getOperand(0);
739 else {
740 ShAmt = 0;
741 ShOpcVal = ARM_AM::no_shift;
742 }
Evan Chenga8e29892007-01-19 07:51:42 +0000743 } else {
744 ShOpcVal = ARM_AM::no_shift;
745 }
746 }
747
748 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000749 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000750 return true;
751}
752
Owen Andersonc4e16de2011-08-29 20:16:50 +0000753bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
754 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000755 unsigned Opcode = Op->getOpcode();
756 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
757 ? cast<LoadSDNode>(Op)->getAddressingMode()
758 : cast<StoreSDNode>(Op)->getAddressingMode();
759 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
760 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000761 int Val;
762 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000763 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000764 Offset = CurDAG->getRegister(0, MVT::i32);
765 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
766 return true;
767 }
768
769 return false;
770}
771
772
Owen Anderson793e7962011-07-26 20:54:26 +0000773bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
774 SDValue &Offset, SDValue &Opc) {
775 unsigned Opcode = Op->getOpcode();
776 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
777 ? cast<LoadSDNode>(Op)->getAddressingMode()
778 : cast<StoreSDNode>(Op)->getAddressingMode();
779 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
780 ? ARM_AM::add : ARM_AM::sub;
781 int Val;
782 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
783 Offset = CurDAG->getRegister(0, MVT::i32);
784 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
785 ARM_AM::no_shift),
786 MVT::i32);
787 return true;
788 }
789
790 return false;
791}
792
Jim Grosbach19dec202011-08-05 20:35:44 +0000793bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
794 Base = N;
795 return true;
796}
Evan Chenga8e29892007-01-19 07:51:42 +0000797
Chris Lattner52a261b2010-09-21 20:31:19 +0000798bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000799 SDValue &Base, SDValue &Offset,
800 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000801 if (N.getOpcode() == ISD::SUB) {
802 // X - C is canonicalize to X + -C, no need to handle it here.
803 Base = N.getOperand(0);
804 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000805 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000806 return true;
807 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000808
Chris Lattner0a9481f2011-02-13 22:25:43 +0000809 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000810 Base = N;
811 if (N.getOpcode() == ISD::FrameIndex) {
812 int FI = cast<FrameIndexSDNode>(N)->getIndex();
813 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
814 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000815 Offset = CurDAG->getRegister(0, MVT::i32);
816 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000817 return true;
818 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000819
Evan Chenga8e29892007-01-19 07:51:42 +0000820 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000821 int RHSC;
822 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
823 -256 + 1, 256, RHSC)) { // 8 bits.
824 Base = N.getOperand(0);
825 if (Base.getOpcode() == ISD::FrameIndex) {
826 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
827 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000828 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000829 Offset = CurDAG->getRegister(0, MVT::i32);
830
831 ARM_AM::AddrOpc AddSub = ARM_AM::add;
832 if (RHSC < 0) {
833 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000834 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000835 }
836 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
837 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000838 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000839
Evan Chenga8e29892007-01-19 07:51:42 +0000840 Base = N.getOperand(0);
841 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000842 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000843 return true;
844}
845
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000846bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000847 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000848 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000849 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
850 ? cast<LoadSDNode>(Op)->getAddressingMode()
851 : cast<StoreSDNode>(Op)->getAddressingMode();
852 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
853 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000854 int Val;
855 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
856 Offset = CurDAG->getRegister(0, MVT::i32);
857 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
858 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000859 }
860
861 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000862 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000863 return true;
864}
865
Jim Grosbach3ab56582010-10-21 19:38:40 +0000866bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000867 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000868 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000869 Base = N;
870 if (N.getOpcode() == ISD::FrameIndex) {
871 int FI = cast<FrameIndexSDNode>(N)->getIndex();
872 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000873 } else if (N.getOpcode() == ARMISD::Wrapper &&
874 !(Subtarget->useMovt() &&
875 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000876 Base = N.getOperand(0);
877 }
878 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000879 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000880 return true;
881 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000882
Evan Chenga8e29892007-01-19 07:51:42 +0000883 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000884 int RHSC;
885 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
886 -256 + 1, 256, RHSC)) {
887 Base = N.getOperand(0);
888 if (Base.getOpcode() == ISD::FrameIndex) {
889 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
890 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000891 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000892
893 ARM_AM::AddrOpc AddSub = ARM_AM::add;
894 if (RHSC < 0) {
895 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000896 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000897 }
898 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
899 MVT::i32);
900 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000901 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000902
Evan Chenga8e29892007-01-19 07:51:42 +0000903 Base = N;
904 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000905 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000906 return true;
907}
908
Bob Wilson665814b2010-11-01 23:40:51 +0000909bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
910 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000911 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000912
913 unsigned Alignment = 0;
914 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
915 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
916 // The maximum alignment is equal to the memory size being referenced.
917 unsigned LSNAlign = LSN->getAlignment();
918 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000919 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000920 Alignment = MemSize;
921 } else {
922 // All other uses of addrmode6 are for intrinsics. For now just record
923 // the raw alignment value; it will be refined later based on the legal
924 // alignment operands for the intrinsic.
925 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
926 }
927
928 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000929 return true;
930}
931
Bob Wilsonda525062011-02-25 06:42:42 +0000932bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
933 SDValue &Offset) {
934 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
935 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
936 if (AM != ISD::POST_INC)
937 return false;
938 Offset = N;
939 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
940 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
941 Offset = CurDAG->getRegister(0, MVT::i32);
942 }
943 return true;
944}
945
Chris Lattner52a261b2010-09-21 20:31:19 +0000946bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000947 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000948 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
949 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000950 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000951 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
952 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000953 return true;
954 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000955
Evan Chenga8e29892007-01-19 07:51:42 +0000956 return false;
957}
958
Bill Wendlingf4caf692010-12-14 03:36:38 +0000959
960//===----------------------------------------------------------------------===//
961// Thumb Addressing Modes
962//===----------------------------------------------------------------------===//
963
Chris Lattner52a261b2010-09-21 20:31:19 +0000964bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000965 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000966 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000967 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000968 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000969 return false;
970
971 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000972 return true;
973 }
974
Evan Chenga8e29892007-01-19 07:51:42 +0000975 Base = N.getOperand(0);
976 Offset = N.getOperand(1);
977 return true;
978}
979
Evan Cheng79d43262007-01-24 02:21:22 +0000980bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000981ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
982 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000983 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000984 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000985 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000986 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000987
Evan Cheng012f2d92007-01-24 08:53:17 +0000988 if (N.getOpcode() == ARMISD::Wrapper &&
989 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
990 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000991 }
992
Chris Lattner0a9481f2011-02-13 22:25:43 +0000993 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000994 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000995
Evan Chengad0e4652007-02-06 00:22:06 +0000996 // Thumb does not have [sp, r] address mode.
997 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
998 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
999 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001000 (RHSR && RHSR->getReg() == ARM::SP))
1001 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001002
Daniel Dunbarec91d522011-01-19 15:12:16 +00001003 // FIXME: Why do we explicitly check for a match here and then return false?
1004 // Presumably to allow something else to match, but shouldn't this be
1005 // documented?
1006 int RHSC;
1007 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1008 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001009
1010 Base = N.getOperand(0);
1011 Offset = N.getOperand(1);
1012 return true;
1013}
1014
1015bool
1016ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1017 SDValue &Base,
1018 SDValue &Offset) {
1019 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1020}
1021
1022bool
1023ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1024 SDValue &Base,
1025 SDValue &Offset) {
1026 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1027}
1028
1029bool
1030ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1031 SDValue &Base,
1032 SDValue &Offset) {
1033 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1034}
1035
1036bool
1037ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1038 SDValue &Base, SDValue &OffImm) {
1039 if (Scale == 4) {
1040 SDValue TmpBase, TmpOffImm;
1041 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1042 return false; // We want to select tLDRspi / tSTRspi instead.
1043
1044 if (N.getOpcode() == ARMISD::Wrapper &&
1045 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1046 return false; // We want to select tLDRpci instead.
1047 }
1048
Chris Lattner0a9481f2011-02-13 22:25:43 +00001049 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001050 if (N.getOpcode() == ARMISD::Wrapper &&
1051 !(Subtarget->useMovt() &&
1052 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1053 Base = N.getOperand(0);
1054 } else {
1055 Base = N;
1056 }
1057
Owen Anderson825b72b2009-08-11 20:47:22 +00001058 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001059 return true;
1060 }
1061
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001062 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1063 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1064 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1065 (RHSR && RHSR->getReg() == ARM::SP)) {
1066 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1067 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1068 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1069 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1070
1071 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1072 if (LHSC != 0 || RHSC != 0) return false;
1073
1074 Base = N;
1075 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1076 return true;
1077 }
1078
Evan Chenga8e29892007-01-19 07:51:42 +00001079 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001080 int RHSC;
1081 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1082 Base = N.getOperand(0);
1083 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1084 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001085 }
1086
Evan Chengc38f2bc2007-01-23 22:59:13 +00001087 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001088 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001089 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001090}
1091
Bill Wendlingf4caf692010-12-14 03:36:38 +00001092bool
1093ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1094 SDValue &OffImm) {
1095 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001096}
1097
Bill Wendlingf4caf692010-12-14 03:36:38 +00001098bool
1099ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1100 SDValue &OffImm) {
1101 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001102}
1103
Bill Wendlingf4caf692010-12-14 03:36:38 +00001104bool
1105ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1106 SDValue &OffImm) {
1107 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001108}
1109
Chris Lattner52a261b2010-09-21 20:31:19 +00001110bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1111 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001112 if (N.getOpcode() == ISD::FrameIndex) {
1113 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1114 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001115 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001116 return true;
1117 }
Evan Cheng79d43262007-01-24 02:21:22 +00001118
Chris Lattner0a9481f2011-02-13 22:25:43 +00001119 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001120 return false;
1121
1122 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001123 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1124 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001125 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001126 int RHSC;
1127 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1128 Base = N.getOperand(0);
1129 if (Base.getOpcode() == ISD::FrameIndex) {
1130 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1131 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001132 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001133 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1134 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001135 }
1136 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001137
Evan Chenga8e29892007-01-19 07:51:42 +00001138 return false;
1139}
1140
Bill Wendlingf4caf692010-12-14 03:36:38 +00001141
1142//===----------------------------------------------------------------------===//
1143// Thumb 2 Addressing Modes
1144//===----------------------------------------------------------------------===//
1145
1146
Chris Lattner52a261b2010-09-21 20:31:19 +00001147bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001148 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001149 if (DisableShifterOp)
1150 return false;
1151
Evan Chengee04a6d2011-07-20 23:34:39 +00001152 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001153
1154 // Don't match base register only case. That is matched to a separate
1155 // lower complexity pattern with explicit register operand.
1156 if (ShOpcVal == ARM_AM::no_shift) return false;
1157
1158 BaseReg = N.getOperand(0);
1159 unsigned ShImmVal = 0;
1160 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1161 ShImmVal = RHS->getZExtValue() & 31;
1162 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1163 return true;
1164 }
1165
1166 return false;
1167}
1168
Chris Lattner52a261b2010-09-21 20:31:19 +00001169bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001170 SDValue &Base, SDValue &OffImm) {
1171 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001172
Evan Cheng3a214252009-08-11 08:52:18 +00001173 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001174 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1175 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001176 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001177 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001178 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1179 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001180 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001181 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001182 }
Owen Anderson099e5552011-03-18 19:46:58 +00001183
Chris Lattner0a9481f2011-02-13 22:25:43 +00001184 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001185 !(Subtarget->useMovt() &&
1186 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001187 Base = N.getOperand(0);
1188 if (Base.getOpcode() == ISD::TargetConstantPool)
1189 return false; // We want to select t2LDRpci instead.
1190 } else
1191 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001192 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001193 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001194 }
Evan Cheng055b0312009-06-29 07:51:04 +00001195
1196 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001197 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001198 // Let t2LDRi8 handle (R - imm8).
1199 return false;
1200
Evan Cheng055b0312009-06-29 07:51:04 +00001201 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001202 if (N.getOpcode() == ISD::SUB)
1203 RHSC = -RHSC;
1204
1205 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001206 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001207 if (Base.getOpcode() == ISD::FrameIndex) {
1208 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1209 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1210 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001211 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001212 return true;
1213 }
1214 }
1215
Evan Cheng3a214252009-08-11 08:52:18 +00001216 // Base only.
1217 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001218 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001219 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001220}
1221
Chris Lattner52a261b2010-09-21 20:31:19 +00001222bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001223 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001224 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001225 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1226 !CurDAG->isBaseWithConstantOffset(N))
1227 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001228
Chris Lattner0a9481f2011-02-13 22:25:43 +00001229 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1230 int RHSC = (int)RHS->getSExtValue();
1231 if (N.getOpcode() == ISD::SUB)
1232 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001233
Chris Lattner0a9481f2011-02-13 22:25:43 +00001234 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1235 Base = N.getOperand(0);
1236 if (Base.getOpcode() == ISD::FrameIndex) {
1237 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1238 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001239 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001240 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1241 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001242 }
1243 }
1244
1245 return false;
1246}
1247
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001248bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001249 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001250 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001251 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1252 ? cast<LoadSDNode>(Op)->getAddressingMode()
1253 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001254 int RHSC;
1255 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1256 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1257 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1258 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1259 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001260 }
1261
1262 return false;
1263}
1264
Chris Lattner52a261b2010-09-21 20:31:19 +00001265bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001266 SDValue &Base,
1267 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001268 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001269 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001270 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001271
Evan Cheng3a214252009-08-11 08:52:18 +00001272 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1273 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1274 int RHSC = (int)RHS->getZExtValue();
1275 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1276 return false;
1277 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001278 return false;
1279 }
1280
Evan Cheng055b0312009-06-29 07:51:04 +00001281 // Look for (R + R) or (R + (R << [1,2,3])).
1282 unsigned ShAmt = 0;
1283 Base = N.getOperand(0);
1284 OffReg = N.getOperand(1);
1285
1286 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001287 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001288 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001289 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001290 if (ShOpcVal == ARM_AM::lsl)
1291 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001292 }
1293
Evan Cheng055b0312009-06-29 07:51:04 +00001294 if (ShOpcVal == ARM_AM::lsl) {
1295 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1296 // it.
1297 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1298 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001299 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1300 OffReg = OffReg.getOperand(0);
1301 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001302 ShAmt = 0;
1303 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001304 }
Evan Cheng055b0312009-06-29 07:51:04 +00001305 } else {
1306 ShOpcVal = ARM_AM::no_shift;
1307 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001308 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001309
Owen Anderson825b72b2009-08-11 20:47:22 +00001310 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001311
1312 return true;
1313}
1314
1315//===--------------------------------------------------------------------===//
1316
Evan Chengee568cf2007-07-05 07:15:27 +00001317/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001318static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001319 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001320}
1321
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001322SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1323 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001324 ISD::MemIndexedMode AM = LD->getAddressingMode();
1325 if (AM == ISD::UNINDEXED)
1326 return NULL;
1327
Owen Andersone50ed302009-08-10 22:56:29 +00001328 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001329 SDValue Offset, AMOpc;
1330 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1331 unsigned Opcode = 0;
1332 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001333 if (LoadedVT == MVT::i32 && isPre &&
1334 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1335 Opcode = ARM::LDR_PRE_IMM;
1336 Match = true;
1337 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001338 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001339 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001340 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001341 } else if (LoadedVT == MVT::i32 &&
1342 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001343 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001344 Match = true;
1345
Owen Anderson825b72b2009-08-11 20:47:22 +00001346 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001347 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001348 Match = true;
1349 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1350 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1351 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001352 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001353 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001354 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001355 Match = true;
1356 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1357 }
1358 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001359 if (isPre &&
1360 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001361 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001362 Opcode = ARM::LDRB_PRE_IMM;
1363 } else if (!isPre &&
1364 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1365 Match = true;
1366 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001367 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1368 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001369 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001370 }
1371 }
1372 }
1373
1374 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001375 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1376 SDValue Chain = LD->getChain();
1377 SDValue Base = LD->getBasePtr();
1378 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1379 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001380 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1381 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001382 } else {
1383 SDValue Chain = LD->getChain();
1384 SDValue Base = LD->getBasePtr();
1385 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1386 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001387 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1388 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001389 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001390 }
1391
1392 return NULL;
1393}
1394
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001395SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1396 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001397 ISD::MemIndexedMode AM = LD->getAddressingMode();
1398 if (AM == ISD::UNINDEXED)
1399 return NULL;
1400
Owen Andersone50ed302009-08-10 22:56:29 +00001401 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001402 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001403 SDValue Offset;
1404 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1405 unsigned Opcode = 0;
1406 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001407 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001408 switch (LoadedVT.getSimpleVT().SimpleTy) {
1409 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001410 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1411 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001412 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001413 if (isSExtLd)
1414 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1415 else
1416 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001417 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001418 case MVT::i8:
1419 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001420 if (isSExtLd)
1421 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1422 else
1423 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001424 break;
1425 default:
1426 return NULL;
1427 }
1428 Match = true;
1429 }
1430
1431 if (Match) {
1432 SDValue Chain = LD->getChain();
1433 SDValue Base = LD->getBasePtr();
1434 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001435 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001436 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001437 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001438 }
1439
1440 return NULL;
1441}
1442
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001443/// PairSRegs - Form a D register from a pair of S registers.
1444///
1445SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1446 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001447 SDValue RegClass =
1448 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001449 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1450 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001451 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1452 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001453}
1454
Evan Cheng603afbf2010-05-10 17:34:18 +00001455/// PairDRegs - Form a quad register from a pair of D registers.
1456///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001457SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1458 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001459 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001460 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1461 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001462 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1463 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001464}
1465
Evan Cheng7f687192010-05-14 00:21:45 +00001466/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001467///
1468SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1469 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001470 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001471 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1472 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001473 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1474 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001475}
1476
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001477/// QuadSRegs - Form 4 consecutive S registers.
1478///
1479SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1480 SDValue V2, SDValue V3) {
1481 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001482 SDValue RegClass =
1483 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001484 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1485 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1486 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1487 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001488 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1489 V2, SubReg2, V3, SubReg3 };
1490 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001491}
1492
Evan Cheng7f687192010-05-14 00:21:45 +00001493/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001494///
1495SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1496 SDValue V2, SDValue V3) {
1497 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001498 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001499 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1500 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1501 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1502 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001503 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1504 V2, SubReg2, V3, SubReg3 };
1505 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001506}
1507
Evan Cheng8f6de382010-05-16 03:27:48 +00001508/// QuadQRegs - Form 4 consecutive Q registers.
1509///
1510SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1511 SDValue V2, SDValue V3) {
1512 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001513 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001514 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1515 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1516 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1517 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001518 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1519 V2, SubReg2, V3, SubReg3 };
1520 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001521}
1522
Bob Wilson2a6e6162010-09-23 23:42:37 +00001523/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1524/// of a NEON VLD or VST instruction. The supported values depend on the
1525/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001526SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1527 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001528 unsigned NumRegs = NumVecs;
1529 if (!is64BitVector && NumVecs < 3)
1530 NumRegs *= 2;
1531
Bob Wilson665814b2010-11-01 23:40:51 +00001532 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001533 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001534 Alignment = 32;
1535 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1536 Alignment = 16;
1537 else if (Alignment >= 8)
1538 Alignment = 8;
1539 else
1540 Alignment = 0;
1541
1542 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001543}
1544
Jim Grosbach10b90a92011-10-24 21:45:13 +00001545// Get the register stride update opcode of a VLD/VST instruction that
1546// is otherwise equivalent to the given fixed stride updating instruction.
1547static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1548 switch (Opc) {
1549 default: break;
1550 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1551 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1552 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1553 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1554 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1555 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1556 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1557 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001558
1559 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1560 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1561 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1562 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1563 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1564 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1565 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1566 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001567 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001568 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001569
Jim Grosbach28f08c92012-03-05 19:33:30 +00001570 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1571 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1572 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001573 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1574 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1575 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1576
Jim Grosbach28f08c92012-03-05 19:33:30 +00001577 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1578 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1579 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001580 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1581 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1582 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001583
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001584 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1585 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1586 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001587 }
1588 return Opc; // If not one we handle, return it unchanged.
1589}
1590
Bob Wilson1c3ef902011-02-07 17:43:21 +00001591SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001592 const uint16_t *DOpcodes,
1593 const uint16_t *QOpcodes0,
1594 const uint16_t *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001595 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001596 DebugLoc dl = N->getDebugLoc();
1597
Bob Wilson226036e2010-03-20 22:13:40 +00001598 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001599 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1600 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001601 return NULL;
1602
1603 SDValue Chain = N->getOperand(0);
1604 EVT VT = N->getValueType(0);
1605 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001606 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001607
Bob Wilson3e36f132009-10-14 17:28:52 +00001608 unsigned OpcodeIndex;
1609 switch (VT.getSimpleVT().SimpleTy) {
1610 default: llvm_unreachable("unhandled vld type");
1611 // Double-register operations:
1612 case MVT::v8i8: OpcodeIndex = 0; break;
1613 case MVT::v4i16: OpcodeIndex = 1; break;
1614 case MVT::v2f32:
1615 case MVT::v2i32: OpcodeIndex = 2; break;
1616 case MVT::v1i64: OpcodeIndex = 3; break;
1617 // Quad-register operations:
1618 case MVT::v16i8: OpcodeIndex = 0; break;
1619 case MVT::v8i16: OpcodeIndex = 1; break;
1620 case MVT::v4f32:
1621 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001622 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001623 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001624 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001625 }
1626
Bob Wilsonf5721912010-09-03 18:16:02 +00001627 EVT ResTy;
1628 if (NumVecs == 1)
1629 ResTy = VT;
1630 else {
1631 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1632 if (!is64BitVector)
1633 ResTyElts *= 2;
1634 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1635 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001636 std::vector<EVT> ResTys;
1637 ResTys.push_back(ResTy);
1638 if (isUpdating)
1639 ResTys.push_back(MVT::i32);
1640 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001641
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001642 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001643 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001644 SDNode *VLd;
1645 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001646
Bob Wilson1c3ef902011-02-07 17:43:21 +00001647 // Double registers and VLD1/VLD2 quad registers are directly supported.
1648 if (is64BitVector || NumVecs <= 2) {
1649 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1650 QOpcodes0[OpcodeIndex]);
1651 Ops.push_back(MemAddr);
1652 Ops.push_back(Align);
1653 if (isUpdating) {
1654 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001655 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001656 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001657 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001658 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001659 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001660 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001661 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001662 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001663 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001664 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001665 Ops.push_back(Pred);
1666 Ops.push_back(Reg0);
1667 Ops.push_back(Chain);
1668 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001669
Bob Wilson3e36f132009-10-14 17:28:52 +00001670 } else {
1671 // Otherwise, quad registers are loaded with two separate instructions,
1672 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001673 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001674
Bob Wilson1c3ef902011-02-07 17:43:21 +00001675 // Load the even subregs. This is always an updating load, so that it
1676 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001677 SDValue ImplDef =
1678 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1679 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001680 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1681 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001682 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001683
Bob Wilson24f995d2009-10-14 18:32:29 +00001684 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001685 Ops.push_back(SDValue(VLdA, 1));
1686 Ops.push_back(Align);
1687 if (isUpdating) {
1688 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1689 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1690 "only constant post-increment update allowed for VLD3/4");
1691 (void)Inc;
1692 Ops.push_back(Reg0);
1693 }
1694 Ops.push_back(SDValue(VLdA, 0));
1695 Ops.push_back(Pred);
1696 Ops.push_back(Reg0);
1697 Ops.push_back(Chain);
1698 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1699 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001700 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001701
Evan Chengb58a3402011-04-19 00:04:03 +00001702 // Transfer memoperands.
1703 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1704 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1705 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1706
Bob Wilson1c3ef902011-02-07 17:43:21 +00001707 if (NumVecs == 1)
1708 return VLd;
1709
1710 // Extract out the subregisters.
1711 SDValue SuperReg = SDValue(VLd, 0);
1712 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1713 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1714 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1715 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1716 ReplaceUses(SDValue(N, Vec),
1717 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1718 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1719 if (isUpdating)
1720 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001721 return NULL;
1722}
1723
Bob Wilson1c3ef902011-02-07 17:43:21 +00001724SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001725 const uint16_t *DOpcodes,
1726 const uint16_t *QOpcodes0,
1727 const uint16_t *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001728 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001729 DebugLoc dl = N->getDebugLoc();
1730
Bob Wilson226036e2010-03-20 22:13:40 +00001731 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001732 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1733 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1734 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001735 return NULL;
1736
Evan Chengb58a3402011-04-19 00:04:03 +00001737 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1738 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1739
Bob Wilson24f995d2009-10-14 18:32:29 +00001740 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001741 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001742 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001743 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001744
Bob Wilson24f995d2009-10-14 18:32:29 +00001745 unsigned OpcodeIndex;
1746 switch (VT.getSimpleVT().SimpleTy) {
1747 default: llvm_unreachable("unhandled vst type");
1748 // Double-register operations:
1749 case MVT::v8i8: OpcodeIndex = 0; break;
1750 case MVT::v4i16: OpcodeIndex = 1; break;
1751 case MVT::v2f32:
1752 case MVT::v2i32: OpcodeIndex = 2; break;
1753 case MVT::v1i64: OpcodeIndex = 3; break;
1754 // Quad-register operations:
1755 case MVT::v16i8: OpcodeIndex = 0; break;
1756 case MVT::v8i16: OpcodeIndex = 1; break;
1757 case MVT::v4f32:
1758 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001759 case MVT::v2i64: OpcodeIndex = 3;
1760 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1761 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001762 }
1763
Bob Wilson1c3ef902011-02-07 17:43:21 +00001764 std::vector<EVT> ResTys;
1765 if (isUpdating)
1766 ResTys.push_back(MVT::i32);
1767 ResTys.push_back(MVT::Other);
1768
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001769 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001770 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001771 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001772
Bob Wilson1c3ef902011-02-07 17:43:21 +00001773 // Double registers and VST1/VST2 quad registers are directly supported.
1774 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001775 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001776 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001777 SrcReg = N->getOperand(Vec0Idx);
1778 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001779 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001780 SDValue V0 = N->getOperand(Vec0Idx + 0);
1781 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001782 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001783 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001784 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001785 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001786 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001787 // an undef.
1788 SDValue V3 = (NumVecs == 3)
1789 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001791 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001792 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001793 } else {
1794 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001795 SDValue Q0 = N->getOperand(Vec0Idx);
1796 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001797 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001798 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001799
1800 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1801 QOpcodes0[OpcodeIndex]);
1802 Ops.push_back(MemAddr);
1803 Ops.push_back(Align);
1804 if (isUpdating) {
1805 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001806 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001807 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001808 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001809 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1810 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1811 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001812 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001813 !isa<ConstantSDNode>(Inc.getNode()))
1814 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001815 }
1816 Ops.push_back(SrcReg);
1817 Ops.push_back(Pred);
1818 Ops.push_back(Reg0);
1819 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001820 SDNode *VSt =
1821 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1822
1823 // Transfer memoperands.
1824 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1825
1826 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001827 }
1828
1829 // Otherwise, quad registers are stored with two separate instructions,
1830 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001831
Bob Wilson07f6e802010-06-16 21:34:01 +00001832 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001833 SDValue V0 = N->getOperand(Vec0Idx + 0);
1834 SDValue V1 = N->getOperand(Vec0Idx + 1);
1835 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001836 SDValue V3 = (NumVecs == 3)
1837 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001838 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001839 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001840
Bob Wilson1c3ef902011-02-07 17:43:21 +00001841 // Store the even D registers. This is always an updating store, so that it
1842 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001843 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1844 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1845 MemAddr.getValueType(),
1846 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001847 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001848 Chain = SDValue(VStA, 1);
1849
1850 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001851 Ops.push_back(SDValue(VStA, 0));
1852 Ops.push_back(Align);
1853 if (isUpdating) {
1854 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1855 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1856 "only constant post-increment update allowed for VST3/4");
1857 (void)Inc;
1858 Ops.push_back(Reg0);
1859 }
1860 Ops.push_back(RegSeq);
1861 Ops.push_back(Pred);
1862 Ops.push_back(Reg0);
1863 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001864 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1865 Ops.data(), Ops.size());
1866 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1867 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001868}
1869
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001870SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001871 bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001872 const uint16_t *DOpcodes,
1873 const uint16_t *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001874 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001875 DebugLoc dl = N->getDebugLoc();
1876
Bob Wilson226036e2010-03-20 22:13:40 +00001877 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001878 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1879 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1880 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001881 return NULL;
1882
Evan Chengb58a3402011-04-19 00:04:03 +00001883 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1884 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1885
Bob Wilsona7c397c2009-10-14 16:19:03 +00001886 SDValue Chain = N->getOperand(0);
1887 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001888 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1889 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001890 bool is64BitVector = VT.is64BitVector();
1891
Bob Wilson665814b2010-11-01 23:40:51 +00001892 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001893 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001894 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001895 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1896 if (Alignment > NumBytes)
1897 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001898 if (Alignment < 8 && Alignment < NumBytes)
1899 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001900 // Alignment must be a power of two; make sure of that.
1901 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001902 if (Alignment == 1)
1903 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001904 }
Bob Wilson665814b2010-11-01 23:40:51 +00001905 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001906
Bob Wilsona7c397c2009-10-14 16:19:03 +00001907 unsigned OpcodeIndex;
1908 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001909 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001910 // Double-register operations:
1911 case MVT::v8i8: OpcodeIndex = 0; break;
1912 case MVT::v4i16: OpcodeIndex = 1; break;
1913 case MVT::v2f32:
1914 case MVT::v2i32: OpcodeIndex = 2; break;
1915 // Quad-register operations:
1916 case MVT::v8i16: OpcodeIndex = 0; break;
1917 case MVT::v4f32:
1918 case MVT::v4i32: OpcodeIndex = 1; break;
1919 }
1920
Bob Wilson1c3ef902011-02-07 17:43:21 +00001921 std::vector<EVT> ResTys;
1922 if (IsLoad) {
1923 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1924 if (!is64BitVector)
1925 ResTyElts *= 2;
1926 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1927 MVT::i64, ResTyElts));
1928 }
1929 if (isUpdating)
1930 ResTys.push_back(MVT::i32);
1931 ResTys.push_back(MVT::Other);
1932
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001933 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001934 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001935
Bob Wilson1c3ef902011-02-07 17:43:21 +00001936 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001937 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001938 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001939 if (isUpdating) {
1940 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1941 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1942 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001943
Bob Wilson8466fa12010-09-13 23:01:35 +00001944 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001945 SDValue V0 = N->getOperand(Vec0Idx + 0);
1946 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001947 if (NumVecs == 2) {
1948 if (is64BitVector)
1949 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1950 else
1951 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001952 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001953 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001954 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001955 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1956 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001957 if (is64BitVector)
1958 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1959 else
1960 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001961 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001962 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001963 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001964 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001965 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001966 Ops.push_back(Chain);
1967
Bob Wilson1c3ef902011-02-07 17:43:21 +00001968 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1969 QOpcodes[OpcodeIndex]);
1970 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1971 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001972 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001973 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001974 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001975
Bob Wilson8466fa12010-09-13 23:01:35 +00001976 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001977 SuperReg = SDValue(VLdLn, 0);
1978 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1979 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1980 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001981 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1982 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001983 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1984 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1985 if (isUpdating)
1986 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001987 return NULL;
1988}
1989
Bob Wilson1c3ef902011-02-07 17:43:21 +00001990SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper51f50c12012-05-24 05:17:00 +00001991 unsigned NumVecs,
1992 const uint16_t *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001993 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1994 DebugLoc dl = N->getDebugLoc();
1995
1996 SDValue MemAddr, Align;
1997 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1998 return NULL;
1999
Evan Chengb58a3402011-04-19 00:04:03 +00002000 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2001 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2002
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002003 SDValue Chain = N->getOperand(0);
2004 EVT VT = N->getValueType(0);
2005
2006 unsigned Alignment = 0;
2007 if (NumVecs != 3) {
2008 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2009 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2010 if (Alignment > NumBytes)
2011 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002012 if (Alignment < 8 && Alignment < NumBytes)
2013 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002014 // Alignment must be a power of two; make sure of that.
2015 Alignment = (Alignment & -Alignment);
2016 if (Alignment == 1)
2017 Alignment = 0;
2018 }
2019 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2020
2021 unsigned OpcodeIndex;
2022 switch (VT.getSimpleVT().SimpleTy) {
2023 default: llvm_unreachable("unhandled vld-dup type");
2024 case MVT::v8i8: OpcodeIndex = 0; break;
2025 case MVT::v4i16: OpcodeIndex = 1; break;
2026 case MVT::v2f32:
2027 case MVT::v2i32: OpcodeIndex = 2; break;
2028 }
2029
2030 SDValue Pred = getAL(CurDAG);
2031 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2032 SDValue SuperReg;
2033 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002034 SmallVector<SDValue, 6> Ops;
2035 Ops.push_back(MemAddr);
2036 Ops.push_back(Align);
2037 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002038 // fixed-stride update instructions don't have an explicit writeback
2039 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002040 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002041 if (!isa<ConstantSDNode>(Inc.getNode()))
2042 Ops.push_back(Inc);
2043 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2044 else if (NumVecs > 2)
2045 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002046 }
2047 Ops.push_back(Pred);
2048 Ops.push_back(Reg0);
2049 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002050
2051 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002052 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002053 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002054 if (isUpdating)
2055 ResTys.push_back(MVT::i32);
2056 ResTys.push_back(MVT::Other);
2057 SDNode *VLdDup =
2058 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002059 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002060 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002061
2062 // Extract the subregisters.
2063 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2064 unsigned SubIdx = ARM::dsub_0;
2065 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2066 ReplaceUses(SDValue(N, Vec),
2067 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002068 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2069 if (isUpdating)
2070 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002071 return NULL;
2072}
2073
Bob Wilson78dfbc32010-07-07 00:08:54 +00002074SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2075 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002076 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2077 DebugLoc dl = N->getDebugLoc();
2078 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002079 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002080
2081 // Form a REG_SEQUENCE to force register allocation.
2082 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002083 SDValue V0 = N->getOperand(FirstTblReg + 0);
2084 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002085 if (NumVecs == 2)
2086 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2087 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002088 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002089 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002090 // an undef.
2091 SDValue V3 = (NumVecs == 3)
2092 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002093 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002094 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2095 }
2096
Bob Wilson78dfbc32010-07-07 00:08:54 +00002097 SmallVector<SDValue, 6> Ops;
2098 if (IsExt)
2099 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002100 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002101 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002102 Ops.push_back(getAL(CurDAG)); // predicate
2103 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002104 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002105}
2106
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002107SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002108 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002109 if (!Subtarget->hasV6T2Ops())
2110 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002111
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002112 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2113 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2114
2115
2116 // For unsigned extracts, check for a shift right and mask
2117 unsigned And_imm = 0;
2118 if (N->getOpcode() == ISD::AND) {
2119 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2120
2121 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2122 if (And_imm & (And_imm + 1))
2123 return NULL;
2124
2125 unsigned Srl_imm = 0;
2126 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2127 Srl_imm)) {
2128 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2129
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002130 // Note: The width operand is encoded as width-1.
2131 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002132 unsigned LSB = Srl_imm;
2133 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2134 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2135 CurDAG->getTargetConstant(LSB, MVT::i32),
2136 CurDAG->getTargetConstant(Width, MVT::i32),
2137 getAL(CurDAG), Reg0 };
2138 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2139 }
2140 }
2141 return NULL;
2142 }
2143
2144 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002145 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002146 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002147 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2148 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002149 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002150 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002151 // Note: The width operand is encoded as width-1.
2152 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002153 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002154 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002155 return NULL;
2156 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002157 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002158 CurDAG->getTargetConstant(LSB, MVT::i32),
2159 CurDAG->getTargetConstant(Width, MVT::i32),
2160 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002161 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002162 }
2163 }
2164 return NULL;
2165}
2166
Evan Cheng9ef48352009-11-20 00:54:03 +00002167SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002168SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002169 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2170 SDValue CPTmp0;
2171 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002172 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002173 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2174 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2175 unsigned Opc = 0;
2176 switch (SOShOp) {
2177 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2178 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2179 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2180 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2181 default:
2182 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng9ef48352009-11-20 00:54:03 +00002183 }
2184 SDValue SOShImm =
2185 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2186 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2187 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002188 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002189 }
2190 return 0;
2191}
2192
2193SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002194SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002195 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2196 SDValue CPTmp0;
2197 SDValue CPTmp1;
2198 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002199 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002200 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002201 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2202 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002203 }
2204
2205 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2206 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2207 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2208 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002209 }
2210 return 0;
2211}
2212
2213SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002214SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002215 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002216 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002217 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002218 return 0;
2219
Evan Cheng63f35442010-11-13 02:25:14 +00002220 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002221 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002222 if (is_t2_so_imm(TrueImm)) {
2223 Opc = ARM::t2MOVCCi;
2224 } else if (TrueImm <= 0xffff) {
2225 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002226 } else if (is_t2_so_imm_not(TrueImm)) {
2227 TrueImm = ~TrueImm;
2228 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002229 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002230 // Large immediate.
2231 Opc = ARM::t2MOVCCi32imm;
2232 }
2233
2234 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002235 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002236 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2237 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002238 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002239 }
Evan Cheng63f35442010-11-13 02:25:14 +00002240
Evan Cheng9ef48352009-11-20 00:54:03 +00002241 return 0;
2242}
2243
2244SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002245SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002246 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002247 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2248 if (!T)
2249 return 0;
2250
Evan Cheng63f35442010-11-13 02:25:14 +00002251 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002252 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002253 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002254 if (isSoImm) {
2255 Opc = ARM::MOVCCi;
2256 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2257 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002258 } else if (is_so_imm_not(TrueImm)) {
2259 TrueImm = ~TrueImm;
2260 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002261 } else if (TrueVal.getNode()->hasOneUse() &&
2262 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002263 // Large immediate.
2264 Opc = ARM::MOVCCi32imm;
2265 }
2266
2267 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002268 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002269 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2270 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002271 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002272 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002273
Evan Cheng9ef48352009-11-20 00:54:03 +00002274 return 0;
2275}
2276
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002277SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2278 EVT VT = N->getValueType(0);
2279 SDValue FalseVal = N->getOperand(0);
2280 SDValue TrueVal = N->getOperand(1);
2281 SDValue CC = N->getOperand(2);
2282 SDValue CCR = N->getOperand(3);
2283 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002284 assert(CC.getOpcode() == ISD::Constant);
2285 assert(CCR.getOpcode() == ISD::Register);
2286 ARMCC::CondCodes CCVal =
2287 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002288
2289 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2290 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2291 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2292 // Pattern complexity = 18 cost = 1 size = 0
Evan Cheng07ba9062009-11-19 21:45:22 +00002293 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002294 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002295 CCVal, CCR, InFlag);
2296 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002297 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002298 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2299 if (Res)
2300 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002301 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002302 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002303 CCVal, CCR, InFlag);
2304 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002305 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002306 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2307 if (Res)
2308 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002309 }
2310
2311 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002312 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002313 // (imm:i32):$cc)
2314 // Emits: (MOVCCi:i32 GPR:i32:$false,
2315 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2316 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002317 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002318 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002319 CCVal, CCR, InFlag);
2320 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002321 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002322 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2323 if (Res)
2324 return Res;
2325 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002326 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002327 CCVal, CCR, InFlag);
2328 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002329 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002330 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2331 if (Res)
2332 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002333 }
2334 }
2335
2336 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2337 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2338 // Pattern complexity = 6 cost = 1 size = 0
2339 //
2340 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2341 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2342 // Pattern complexity = 6 cost = 11 size = 0
2343 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002344 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002345 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2346 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002347 unsigned Opc = 0;
2348 switch (VT.getSimpleVT().SimpleTy) {
Craig Topperbc219812012-02-07 02:50:20 +00002349 default: llvm_unreachable("Illegal conditional move type!");
Evan Cheng07ba9062009-11-19 21:45:22 +00002350 case MVT::i32:
2351 Opc = Subtarget->isThumb()
2352 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2353 : ARM::MOVCCr;
2354 break;
2355 case MVT::f32:
2356 Opc = ARM::VMOVScc;
2357 break;
2358 case MVT::f64:
2359 Opc = ARM::VMOVDcc;
2360 break;
2361 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002362 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002363}
2364
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002365/// Target-specific DAG combining for ISD::XOR.
2366/// Target-independent combining lowers SELECT_CC nodes of the form
2367/// select_cc setg[ge] X, 0, X, -X
2368/// select_cc setgt X, -1, X, -X
2369/// select_cc setl[te] X, 0, -X, X
2370/// select_cc setlt X, 1, -X, X
2371/// which represent Integer ABS into:
2372/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2373/// ARM instruction selection detects the latter and matches it to
2374/// ARM::ABS or ARM::t2ABS machine node.
2375SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2376 SDValue XORSrc0 = N->getOperand(0);
2377 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002378 EVT VT = N->getValueType(0);
2379
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002380 if (Subtarget->isThumb1Only())
2381 return NULL;
2382
Jim Grosbach27690282012-08-01 20:33:00 +00002383 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002384 return NULL;
2385
2386 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2387 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2388 SDValue SRASrc0 = XORSrc1.getOperand(0);
2389 SDValue SRASrc1 = XORSrc1.getOperand(1);
2390 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2391 EVT XType = SRASrc0.getValueType();
2392 unsigned Size = XType.getSizeInBits() - 1;
2393
Jim Grosbach27690282012-08-01 20:33:00 +00002394 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2395 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002396 Size == SRAConstant->getZExtValue()) {
Jim Grosbach27690282012-08-01 20:33:00 +00002397 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002398 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2399 }
2400
2401 return NULL;
2402}
2403
Evan Chengde8aa4e2010-05-05 18:28:36 +00002404SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2405 // The only time a CONCAT_VECTORS operation can have legal types is when
2406 // two 64-bit vectors are concatenated to a 128-bit vector.
2407 EVT VT = N->getValueType(0);
2408 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2409 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002410 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002411}
2412
Eli Friedman2bdffe42011-08-31 00:31:29 +00002413SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002414 SmallVector<SDValue, 6> Ops;
2415 Ops.push_back(Node->getOperand(1)); // Ptr
2416 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2417 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002418 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002419 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2420 Ops.push_back(Node->getOperand(5)); // High part of Val2
2421 }
2422 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002423 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2424 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002425 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002426 MVT::i32, MVT::i32, MVT::Other,
2427 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002428 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2429 return ResNode;
2430}
2431
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002432SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002433 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002434
Dan Gohmane8be6c62008-07-17 19:10:17 +00002435 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002436 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002437
2438 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002439 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002440 case ISD::XOR: {
2441 // Select special operations if XOR node forms integer ABS pattern
2442 SDNode *ResNode = SelectABSOp(N);
2443 if (ResNode)
2444 return ResNode;
2445 // Other cases are autogenerated.
2446 break;
2447 }
Evan Chenga8e29892007-01-19 07:51:42 +00002448 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002449 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002450 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002451 if (Subtarget->hasThumb2())
2452 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2453 // be done with MOV + MOVT, at worst.
2454 UseCP = 0;
2455 else {
2456 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002457 UseCP = (Val > 255 && // MOV
2458 ~Val > 255 && // MOV + MVN
2459 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002460 } else
2461 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2462 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2463 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2464 }
2465
Evan Chenga8e29892007-01-19 07:51:42 +00002466 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002467 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002468 CurDAG->getTargetConstantPool(ConstantInt::get(
2469 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002470 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002471
2472 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002473 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002474 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002475 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002476 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002477 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002478 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002479 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002480 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002481 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002482 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002483 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002484 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002485 CurDAG->getEntryNode()
2486 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002487 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002488 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002489 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002490 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002491 return NULL;
2492 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002493
Evan Chenga8e29892007-01-19 07:51:42 +00002494 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002495 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002496 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002497 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002498 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002499 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002500 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002501 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002502 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2503 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2504 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002505 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002506 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2507 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002508 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2509 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2510 CurDAG->getRegister(0, MVT::i32) };
2511 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002512 }
Evan Chenga8e29892007-01-19 07:51:42 +00002513 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002514 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002515 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002516 return I;
2517 break;
2518 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002519 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002520 return I;
2521 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002522 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002523 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002524 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002525 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002526 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002527 if (!RHSV) break;
2528 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002529 unsigned ShImm = Log2_32(RHSV-1);
2530 if (ShImm >= 32)
2531 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002532 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002533 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002534 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2535 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002536 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002537 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002538 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002539 } else {
2540 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002541 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002542 }
Evan Chenga8e29892007-01-19 07:51:42 +00002543 }
2544 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002545 unsigned ShImm = Log2_32(RHSV+1);
2546 if (ShImm >= 32)
2547 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002548 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002549 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002550 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2551 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002552 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002553 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2554 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002555 } else {
2556 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002557 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002558 }
Evan Chenga8e29892007-01-19 07:51:42 +00002559 }
2560 }
2561 break;
Evan Cheng20956592009-10-21 08:15:52 +00002562 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002563 // Check for unsigned bitfield extract
2564 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2565 return I;
2566
Evan Cheng20956592009-10-21 08:15:52 +00002567 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2568 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2569 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2570 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2571 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002572 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002573 if (VT != MVT::i32)
2574 break;
2575 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2576 ? ARM::t2MOVTi16
2577 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2578 if (!Opc)
2579 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002580 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002581 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2582 if (!N1C)
2583 break;
2584 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2585 SDValue N2 = N0.getOperand(1);
2586 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2587 if (!N2C)
2588 break;
2589 unsigned N1CVal = N1C->getZExtValue();
2590 unsigned N2CVal = N2C->getZExtValue();
2591 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2592 (N1CVal & 0xffffU) == 0xffffU &&
2593 (N2CVal & 0xffffU) == 0x0U) {
2594 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2595 MVT::i32);
2596 SDValue Ops[] = { N0.getOperand(0), Imm16,
2597 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2598 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2599 }
2600 }
2601 break;
2602 }
Jim Grosbache5165492009-11-09 00:11:35 +00002603 case ARMISD::VMOVRRD:
2604 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002605 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002606 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002607 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002608 if (Subtarget->isThumb1Only())
2609 break;
2610 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002611 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002612 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2613 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002614 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002615 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002616 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002617 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2618 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002619 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2620 ARM::UMULL : ARM::UMULLv5,
2621 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002622 }
Evan Chengee568cf2007-07-05 07:15:27 +00002623 }
Dan Gohman525178c2007-10-08 18:33:35 +00002624 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002625 if (Subtarget->isThumb1Only())
2626 break;
2627 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002628 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002629 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002630 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002631 } else {
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),
2634 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002635 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2636 ARM::SMULL : ARM::SMULLv5,
2637 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002638 }
Evan Chengee568cf2007-07-05 07:15:27 +00002639 }
Evan Chenga8e29892007-01-19 07:51:42 +00002640 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002641 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002642 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002643 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002644 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002645 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002646 if (ResNode)
2647 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002648 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002649 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002650 }
Evan Chengee568cf2007-07-05 07:15:27 +00002651 case ARMISD::BRCOND: {
2652 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2653 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2654 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002655
Evan Chengee568cf2007-07-05 07:15:27 +00002656 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2657 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2658 // Pattern complexity = 6 cost = 1 size = 0
2659
David Goodwin5e47a9a2009-06-30 18:04:13 +00002660 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2661 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2662 // Pattern complexity = 6 cost = 1 size = 0
2663
Jim Grosbach764ab522009-08-11 15:33:49 +00002664 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002665 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002666 SDValue Chain = N->getOperand(0);
2667 SDValue N1 = N->getOperand(1);
2668 SDValue N2 = N->getOperand(2);
2669 SDValue N3 = N->getOperand(3);
2670 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002671 assert(N1.getOpcode() == ISD::BasicBlock);
2672 assert(N2.getOpcode() == ISD::Constant);
2673 assert(N3.getOpcode() == ISD::Register);
2674
Dan Gohman475871a2008-07-27 21:46:04 +00002675 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002676 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002677 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002678 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002679 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002680 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002681 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002682 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002683 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002684 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002685 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002686 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002687 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002688 return NULL;
2689 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002690 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002691 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002692 case ARMISD::VZIP: {
2693 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002694 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002695 switch (VT.getSimpleVT().SimpleTy) {
2696 default: return NULL;
2697 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2698 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2699 case MVT::v2f32:
Jim Grosbach6073b302012-04-11 16:53:25 +00002700 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2701 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002702 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2703 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2704 case MVT::v4f32:
2705 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2706 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002707 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002708 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2709 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2710 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002711 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002712 case ARMISD::VUZP: {
2713 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002714 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002715 switch (VT.getSimpleVT().SimpleTy) {
2716 default: return NULL;
2717 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2718 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2719 case MVT::v2f32:
Jim Grosbach18355472012-04-11 17:40:18 +00002720 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2721 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002722 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2723 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2724 case MVT::v4f32:
2725 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2726 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002727 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002728 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2729 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2730 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002731 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002732 case ARMISD::VTRN: {
2733 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002734 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002735 switch (VT.getSimpleVT().SimpleTy) {
2736 default: return NULL;
2737 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2738 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2739 case MVT::v2f32:
2740 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2741 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2742 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2743 case MVT::v4f32:
2744 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2745 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002746 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002747 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2748 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2749 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002750 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002751 case ARMISD::BUILD_VECTOR: {
2752 EVT VecVT = N->getValueType(0);
2753 EVT EltVT = VecVT.getVectorElementType();
2754 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002755 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002756 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2757 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2758 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002759 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002760 if (NumElts == 2)
2761 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2762 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2763 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2764 N->getOperand(2), N->getOperand(3));
2765 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002766
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002767 case ARMISD::VLD2DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002768 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2769 ARM::VLD2DUPd32 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002770 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002771 }
2772
Bob Wilson86c6d802010-11-29 19:35:29 +00002773 case ARMISD::VLD3DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002774 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2775 ARM::VLD3DUPd16Pseudo,
2776 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002777 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002778 }
2779
Bob Wilson6c4c9822010-11-30 00:00:35 +00002780 case ARMISD::VLD4DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002781 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2782 ARM::VLD4DUPd16Pseudo,
2783 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002784 return SelectVLDDup(N, false, 4, Opcodes);
2785 }
2786
2787 case ARMISD::VLD2DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002788 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2789 ARM::VLD2DUPd16wb_fixed,
2790 ARM::VLD2DUPd32wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002791 return SelectVLDDup(N, true, 2, Opcodes);
2792 }
2793
2794 case ARMISD::VLD3DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002795 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2796 ARM::VLD3DUPd16Pseudo_UPD,
2797 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002798 return SelectVLDDup(N, true, 3, Opcodes);
2799 }
2800
2801 case ARMISD::VLD4DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002802 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2803 ARM::VLD4DUPd16Pseudo_UPD,
2804 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002805 return SelectVLDDup(N, true, 4, Opcodes);
2806 }
2807
2808 case ARMISD::VLD1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002809 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2810 ARM::VLD1d16wb_fixed,
2811 ARM::VLD1d32wb_fixed,
2812 ARM::VLD1d64wb_fixed };
2813 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2814 ARM::VLD1q16wb_fixed,
2815 ARM::VLD1q32wb_fixed,
2816 ARM::VLD1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002817 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2818 }
2819
2820 case ARMISD::VLD2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002821 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2822 ARM::VLD2d16wb_fixed,
2823 ARM::VLD2d32wb_fixed,
2824 ARM::VLD1q64wb_fixed};
2825 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2826 ARM::VLD2q16PseudoWB_fixed,
2827 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002828 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2829 }
2830
2831 case ARMISD::VLD3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002832 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2833 ARM::VLD3d16Pseudo_UPD,
2834 ARM::VLD3d32Pseudo_UPD,
2835 ARM::VLD1q64wb_fixed};
2836 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2837 ARM::VLD3q16Pseudo_UPD,
2838 ARM::VLD3q32Pseudo_UPD };
2839 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2840 ARM::VLD3q16oddPseudo_UPD,
2841 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002842 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2843 }
2844
2845 case ARMISD::VLD4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002846 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2847 ARM::VLD4d16Pseudo_UPD,
2848 ARM::VLD4d32Pseudo_UPD,
2849 ARM::VLD1q64wb_fixed};
2850 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2851 ARM::VLD4q16Pseudo_UPD,
2852 ARM::VLD4q32Pseudo_UPD };
2853 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2854 ARM::VLD4q16oddPseudo_UPD,
2855 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002856 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2857 }
2858
2859 case ARMISD::VLD2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002860 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2861 ARM::VLD2LNd16Pseudo_UPD,
2862 ARM::VLD2LNd32Pseudo_UPD };
2863 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2864 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002865 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2866 }
2867
2868 case ARMISD::VLD3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002869 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2870 ARM::VLD3LNd16Pseudo_UPD,
2871 ARM::VLD3LNd32Pseudo_UPD };
2872 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2873 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002874 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2875 }
2876
2877 case ARMISD::VLD4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002878 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2879 ARM::VLD4LNd16Pseudo_UPD,
2880 ARM::VLD4LNd32Pseudo_UPD };
2881 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2882 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002883 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2884 }
2885
2886 case ARMISD::VST1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002887 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2888 ARM::VST1d16wb_fixed,
2889 ARM::VST1d32wb_fixed,
2890 ARM::VST1d64wb_fixed };
2891 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2892 ARM::VST1q16wb_fixed,
2893 ARM::VST1q32wb_fixed,
2894 ARM::VST1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002895 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2896 }
2897
2898 case ARMISD::VST2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002899 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2900 ARM::VST2d16wb_fixed,
2901 ARM::VST2d32wb_fixed,
2902 ARM::VST1q64wb_fixed};
2903 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2904 ARM::VST2q16PseudoWB_fixed,
2905 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002906 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2907 }
2908
2909 case ARMISD::VST3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002910 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2911 ARM::VST3d16Pseudo_UPD,
2912 ARM::VST3d32Pseudo_UPD,
2913 ARM::VST1d64TPseudoWB_fixed};
2914 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2915 ARM::VST3q16Pseudo_UPD,
2916 ARM::VST3q32Pseudo_UPD };
2917 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2918 ARM::VST3q16oddPseudo_UPD,
2919 ARM::VST3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002920 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2921 }
2922
2923 case ARMISD::VST4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002924 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2925 ARM::VST4d16Pseudo_UPD,
2926 ARM::VST4d32Pseudo_UPD,
2927 ARM::VST1d64QPseudoWB_fixed};
2928 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2929 ARM::VST4q16Pseudo_UPD,
2930 ARM::VST4q32Pseudo_UPD };
2931 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2932 ARM::VST4q16oddPseudo_UPD,
2933 ARM::VST4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002934 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2935 }
2936
2937 case ARMISD::VST2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002938 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2939 ARM::VST2LNd16Pseudo_UPD,
2940 ARM::VST2LNd32Pseudo_UPD };
2941 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2942 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002943 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2944 }
2945
2946 case ARMISD::VST3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002947 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2948 ARM::VST3LNd16Pseudo_UPD,
2949 ARM::VST3LNd32Pseudo_UPD };
2950 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2951 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002952 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2953 }
2954
2955 case ARMISD::VST4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002956 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2957 ARM::VST4LNd16Pseudo_UPD,
2958 ARM::VST4LNd32Pseudo_UPD };
2959 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2960 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002961 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002962 }
2963
Bob Wilson31fb12f2009-08-26 17:39:53 +00002964 case ISD::INTRINSIC_VOID:
2965 case ISD::INTRINSIC_W_CHAIN: {
2966 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002967 switch (IntNo) {
2968 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002969 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002970
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002971 case Intrinsic::arm_ldrexd: {
2972 SDValue MemAddr = N->getOperand(2);
2973 DebugLoc dl = N->getDebugLoc();
2974 SDValue Chain = N->getOperand(0);
2975
2976 unsigned NewOpc = ARM::LDREXD;
2977 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2978 NewOpc = ARM::t2LDREXD;
2979
2980 // arm_ldrexd returns a i64 value in {i32, i32}
2981 std::vector<EVT> ResTys;
2982 ResTys.push_back(MVT::i32);
2983 ResTys.push_back(MVT::i32);
2984 ResTys.push_back(MVT::Other);
2985
2986 // place arguments in the right order
2987 SmallVector<SDValue, 7> Ops;
2988 Ops.push_back(MemAddr);
2989 Ops.push_back(getAL(CurDAG));
2990 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2991 Ops.push_back(Chain);
2992 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2993 Ops.size());
2994 // Transfer memoperands.
2995 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2996 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2997 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2998
2999 // Until there's support for specifing explicit register constraints
3000 // like the use of even/odd register pair, hardcode ldrexd to always
3001 // use the pair [R0, R1] to hold the load result.
3002 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3003 SDValue(Ld, 0), SDValue(0,0));
3004 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3005 SDValue(Ld, 1), Chain.getValue(1));
3006
3007 // Remap uses.
3008 SDValue Glue = Chain.getValue(1);
3009 if (!SDValue(N, 0).use_empty()) {
3010 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3011 ARM::R0, MVT::i32, Glue);
3012 Glue = Result.getValue(2);
3013 ReplaceUses(SDValue(N, 0), Result);
3014 }
3015 if (!SDValue(N, 1).use_empty()) {
3016 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3017 ARM::R1, MVT::i32, Glue);
3018 Glue = Result.getValue(2);
3019 ReplaceUses(SDValue(N, 1), Result);
3020 }
3021
3022 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3023 return NULL;
3024 }
3025
3026 case Intrinsic::arm_strexd: {
3027 DebugLoc dl = N->getDebugLoc();
3028 SDValue Chain = N->getOperand(0);
3029 SDValue Val0 = N->getOperand(2);
3030 SDValue Val1 = N->getOperand(3);
3031 SDValue MemAddr = N->getOperand(4);
3032
3033 // Until there's support for specifing explicit register constraints
3034 // like the use of even/odd register pair, hardcode strexd to always
3035 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3036 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3037 SDValue(0, 0));
3038 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3039
3040 SDValue Glue = Chain.getValue(1);
3041 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3042 ARM::R2, MVT::i32, Glue);
3043 Glue = Val0.getValue(1);
3044 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3045 ARM::R3, MVT::i32, Glue);
3046
3047 // Store exclusive double return a i32 value which is the return status
3048 // of the issued store.
3049 std::vector<EVT> ResTys;
3050 ResTys.push_back(MVT::i32);
3051 ResTys.push_back(MVT::Other);
3052
3053 // place arguments in the right order
3054 SmallVector<SDValue, 7> Ops;
3055 Ops.push_back(Val0);
3056 Ops.push_back(Val1);
3057 Ops.push_back(MemAddr);
3058 Ops.push_back(getAL(CurDAG));
3059 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3060 Ops.push_back(Chain);
3061
3062 unsigned NewOpc = ARM::STREXD;
3063 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3064 NewOpc = ARM::t2STREXD;
3065
3066 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3067 Ops.size());
3068 // Transfer memoperands.
3069 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3070 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3071 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3072
3073 return St;
3074 }
3075
Bob Wilson621f1952010-03-23 05:25:43 +00003076 case Intrinsic::arm_neon_vld1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003077 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3078 ARM::VLD1d32, ARM::VLD1d64 };
3079 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3080 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003081 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003082 }
3083
Bob Wilson31fb12f2009-08-26 17:39:53 +00003084 case Intrinsic::arm_neon_vld2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003085 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3086 ARM::VLD2d32, ARM::VLD1q64 };
3087 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3088 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003089 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003090 }
3091
3092 case Intrinsic::arm_neon_vld3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003093 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3094 ARM::VLD3d16Pseudo,
3095 ARM::VLD3d32Pseudo,
3096 ARM::VLD1d64TPseudo };
3097 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3098 ARM::VLD3q16Pseudo_UPD,
3099 ARM::VLD3q32Pseudo_UPD };
3100 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3101 ARM::VLD3q16oddPseudo,
3102 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003103 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003104 }
3105
3106 case Intrinsic::arm_neon_vld4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003107 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3108 ARM::VLD4d16Pseudo,
3109 ARM::VLD4d32Pseudo,
3110 ARM::VLD1d64QPseudo };
3111 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3112 ARM::VLD4q16Pseudo_UPD,
3113 ARM::VLD4q32Pseudo_UPD };
3114 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3115 ARM::VLD4q16oddPseudo,
3116 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003117 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003118 }
3119
Bob Wilson243fcc52009-09-01 04:26:28 +00003120 case Intrinsic::arm_neon_vld2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003121 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3122 ARM::VLD2LNd16Pseudo,
3123 ARM::VLD2LNd32Pseudo };
3124 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3125 ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003126 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003127 }
3128
3129 case Intrinsic::arm_neon_vld3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003130 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3131 ARM::VLD3LNd16Pseudo,
3132 ARM::VLD3LNd32Pseudo };
3133 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3134 ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003135 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003136 }
3137
3138 case Intrinsic::arm_neon_vld4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003139 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3140 ARM::VLD4LNd16Pseudo,
3141 ARM::VLD4LNd32Pseudo };
3142 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3143 ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003144 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003145 }
3146
Bob Wilson11d98992010-03-23 06:20:33 +00003147 case Intrinsic::arm_neon_vst1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003148 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3149 ARM::VST1d32, ARM::VST1d64 };
3150 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3151 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003152 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003153 }
3154
Bob Wilson31fb12f2009-08-26 17:39:53 +00003155 case Intrinsic::arm_neon_vst2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003156 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3157 ARM::VST2d32, ARM::VST1q64 };
3158 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3159 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003160 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003161 }
3162
3163 case Intrinsic::arm_neon_vst3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003164 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3165 ARM::VST3d16Pseudo,
3166 ARM::VST3d32Pseudo,
3167 ARM::VST1d64TPseudo };
3168 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3169 ARM::VST3q16Pseudo_UPD,
3170 ARM::VST3q32Pseudo_UPD };
3171 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3172 ARM::VST3q16oddPseudo,
3173 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003174 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003175 }
3176
3177 case Intrinsic::arm_neon_vst4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003178 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3179 ARM::VST4d16Pseudo,
3180 ARM::VST4d32Pseudo,
3181 ARM::VST1d64QPseudo };
3182 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3183 ARM::VST4q16Pseudo_UPD,
3184 ARM::VST4q32Pseudo_UPD };
3185 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3186 ARM::VST4q16oddPseudo,
3187 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003188 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003189 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003190
3191 case Intrinsic::arm_neon_vst2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003192 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3193 ARM::VST2LNd16Pseudo,
3194 ARM::VST2LNd32Pseudo };
3195 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3196 ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003197 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003198 }
3199
3200 case Intrinsic::arm_neon_vst3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003201 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3202 ARM::VST3LNd16Pseudo,
3203 ARM::VST3LNd32Pseudo };
3204 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3205 ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003206 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003207 }
3208
3209 case Intrinsic::arm_neon_vst4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003210 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3211 ARM::VST4LNd16Pseudo,
3212 ARM::VST4LNd32Pseudo };
3213 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3214 ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003215 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003216 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003217 }
Bob Wilson429009b2010-05-06 16:05:26 +00003218 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003219 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003220
Bob Wilsond491d6e2010-07-06 23:36:25 +00003221 case ISD::INTRINSIC_WO_CHAIN: {
3222 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3223 switch (IntNo) {
3224 default:
3225 break;
3226
3227 case Intrinsic::arm_neon_vtbl2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003228 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003229 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003230 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003231 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003232 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003233
3234 case Intrinsic::arm_neon_vtbx2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003235 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003236 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003237 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003238 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003239 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003240 }
3241 break;
3242 }
3243
Bill Wendling69a05a72011-03-14 23:02:38 +00003244 case ARMISD::VTBL1: {
3245 DebugLoc dl = N->getDebugLoc();
3246 EVT VT = N->getValueType(0);
3247 SmallVector<SDValue, 6> Ops;
3248
3249 Ops.push_back(N->getOperand(0));
3250 Ops.push_back(N->getOperand(1));
3251 Ops.push_back(getAL(CurDAG)); // Predicate
3252 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3253 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3254 }
3255 case ARMISD::VTBL2: {
3256 DebugLoc dl = N->getDebugLoc();
3257 EVT VT = N->getValueType(0);
3258
3259 // Form a REG_SEQUENCE to force register allocation.
3260 SDValue V0 = N->getOperand(0);
3261 SDValue V1 = N->getOperand(1);
3262 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3263
3264 SmallVector<SDValue, 6> Ops;
3265 Ops.push_back(RegSeq);
3266 Ops.push_back(N->getOperand(2));
3267 Ops.push_back(getAL(CurDAG)); // Predicate
3268 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Jim Grosbach28f08c92012-03-05 19:33:30 +00003269 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT,
Bill Wendling69a05a72011-03-14 23:02:38 +00003270 Ops.data(), Ops.size());
3271 }
3272
Bob Wilson429009b2010-05-06 16:05:26 +00003273 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003274 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003275
3276 case ARMISD::ATOMOR64_DAG:
3277 return SelectAtomic64(N, ARM::ATOMOR6432);
3278 case ARMISD::ATOMXOR64_DAG:
3279 return SelectAtomic64(N, ARM::ATOMXOR6432);
3280 case ARMISD::ATOMADD64_DAG:
3281 return SelectAtomic64(N, ARM::ATOMADD6432);
3282 case ARMISD::ATOMSUB64_DAG:
3283 return SelectAtomic64(N, ARM::ATOMSUB6432);
3284 case ARMISD::ATOMNAND64_DAG:
3285 return SelectAtomic64(N, ARM::ATOMNAND6432);
3286 case ARMISD::ATOMAND64_DAG:
3287 return SelectAtomic64(N, ARM::ATOMAND6432);
3288 case ARMISD::ATOMSWAP64_DAG:
3289 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003290 case ARMISD::ATOMCMPXCHG64_DAG:
3291 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003292 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003293
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003294 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003295}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003296
Bob Wilson224c2442009-05-19 05:53:42 +00003297bool ARMDAGToDAGISel::
3298SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3299 std::vector<SDValue> &OutOps) {
3300 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003301 // Require the address to be in a register. That is safe for all ARM
3302 // variants and it is hard to do anything much smarter without knowing
3303 // how the operand is used.
3304 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003305 return false;
3306}
3307
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003308/// createARMISelDag - This pass converts a legalized DAG into a
3309/// ARM-specific DAG, ready for instruction scheduling.
3310///
Bob Wilson522ce972009-09-28 14:30:20 +00003311FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3312 CodeGenOpt::Level OptLevel) {
3313 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003314}