blob: 0626240333dabd297d4aa97c4f743d2eafe84243 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000107 }
108
Jim Grosbach3e556122010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach82891622010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
Owen Anderson793e7962011-07-26 20:54:26 +0000132 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
133 SDValue &Offset, SDValue &Opc);
134 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000135 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000136 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
137 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000138 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000139 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000141 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000142 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000143 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000144 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000145 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000146 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000147
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000148 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000152 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
153 unsigned Scale);
154 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
155 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
156 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
157 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
158 SDValue &OffImm);
159 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
160 SDValue &OffImm);
161 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
162 SDValue &OffImm);
163 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
164 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000165 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000166
Bill Wendlingf4caf692010-12-14 03:36:38 +0000167 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000168 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000169 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
171 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000172 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000173 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000174 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000176 SDValue &OffReg, SDValue &ShImm);
177
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 inline bool is_so_imm(unsigned Imm) const {
179 return ARM_AM::getSOImmVal(Imm) != -1;
180 }
181
182 inline bool is_so_imm_not(unsigned Imm) const {
183 return ARM_AM::getSOImmVal(~Imm) != -1;
184 }
185
186 inline bool is_t2_so_imm(unsigned Imm) const {
187 return ARM_AM::getT2SOImmVal(Imm) != -1;
188 }
189
190 inline bool is_t2_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getT2SOImmVal(~Imm) != -1;
192 }
193
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000194 // Include the pieces autogenerated from the target description.
195#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000196
197private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000198 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
199 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000200 SDNode *SelectARMIndexedLoad(SDNode *N);
201 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000202
Bob Wilson621f1952010-03-23 05:25:43 +0000203 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
204 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000205 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000207 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
208 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000209 unsigned *QOpcodes0, unsigned *QOpcodes1);
210
Bob Wilson24f995d2009-10-14 18:32:29 +0000211 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000212 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000213 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000214 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000215 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
216 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000217 unsigned *QOpcodes0, unsigned *QOpcodes1);
218
Bob Wilson96493442009-10-14 16:46:45 +0000219 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000220 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000221 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000222 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
223 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000224 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000226 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
227 /// should be 2, 3 or 4. The opcode array specifies the instructions used
228 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000229 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
230 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231
Bob Wilson78dfbc32010-07-07 00:08:54 +0000232 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
233 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
234 /// generated to force the table registers to be consecutive.
235 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000236
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000237 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000238 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000239
Evan Cheng07ba9062009-11-19 21:45:22 +0000240 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000241 SDNode *SelectCMOVOp(SDNode *N);
242 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000243 ARMCC::CondCodes CCVal, SDValue CCR,
244 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000245 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000246 ARMCC::CondCodes CCVal, SDValue CCR,
247 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000248 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000251 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000254
Evan Chengde8aa4e2010-05-05 18:28:36 +0000255 SDNode *SelectConcatVector(SDNode *N);
256
Eli Friedman2bdffe42011-08-31 00:31:29 +0000257 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
258
Evan Chengaf4550f2009-07-02 01:23:32 +0000259 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
260 /// inline asm expressions.
261 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
262 char ConstraintCode,
263 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000264
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000265 // Form pairs of consecutive S, D, or Q registers.
266 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000267 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000268 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
269
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000270 // Form sequences of 4 consecutive S, D, or Q registers.
271 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000272 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000273 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000274
275 // Get the alignment operand for a NEON VLD or VST instruction.
276 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000277};
Evan Chenga8e29892007-01-19 07:51:42 +0000278}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000279
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000280/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
281/// operand. If so Imm will receive the 32-bit value.
282static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
283 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
284 Imm = cast<ConstantSDNode>(N)->getZExtValue();
285 return true;
286 }
287 return false;
288}
289
290// isInt32Immediate - This method tests to see if a constant operand.
291// If so Imm will receive the 32 bit value.
292static bool isInt32Immediate(SDValue N, unsigned &Imm) {
293 return isInt32Immediate(N.getNode(), Imm);
294}
295
296// isOpcWithIntImmediate - This method tests to see if the node is a specific
297// opcode and that it has a immediate integer right operand.
298// If so Imm will receive the 32 bit value.
299static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
300 return N->getOpcode() == Opc &&
301 isInt32Immediate(N->getOperand(1).getNode(), Imm);
302}
303
Daniel Dunbarec91d522011-01-19 15:12:16 +0000304/// \brief Check whether a particular node is a constant value representable as
305/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
306///
307/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000308static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbarec91d522011-01-19 15:12:16 +0000309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000311 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbarec91d522011-01-19 15:12:16 +0000312
313 // Check that this is a constant.
314 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
315 if (!C)
316 return false;
317
318 ScaledConstant = (int) C->getZExtValue();
319 if ((ScaledConstant % Scale) != 0)
320 return false;
321
322 ScaledConstant /= Scale;
323 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
324}
325
Evan Cheng48575f62010-12-05 22:04:16 +0000326/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
327/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
328/// least on current ARM implementations) which should be avoidded.
329bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
330 if (OptLevel == CodeGenOpt::None)
331 return true;
332
333 if (!CheckVMLxHazard)
334 return true;
335
336 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
337 return true;
338
339 if (!N->hasOneUse())
340 return false;
341
342 SDNode *Use = *N->use_begin();
343 if (Use->getOpcode() == ISD::CopyToReg)
344 return true;
345 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000346 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
347 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000348 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000349 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000350 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
351 return true;
352 // vmlx feeding into another vmlx. We actually want to unfold
353 // the use later in the MLxExpansion pass. e.g.
354 // vmla
355 // vmla (stall 8 cycles)
356 //
357 // vmul (5 cycles)
358 // vadd (5 cycles)
359 // vmla
360 // This adds up to about 18 - 19 cycles.
361 //
362 // vmla
363 // vmul (stall 4 cycles)
364 // vadd adds up to about 14 cycles.
365 return TII->isFpMLxInstruction(Opcode);
366 }
367
368 return false;
369}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000370
Evan Chengf40deed2010-10-27 23:41:30 +0000371bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
372 ARM_AM::ShiftOpc ShOpcVal,
373 unsigned ShAmt) {
374 if (!Subtarget->isCortexA9())
375 return true;
376 if (Shift.hasOneUse())
377 return true;
378 // R << 2 is free.
379 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
380}
381
Owen Anderson92a20222011-07-21 18:54:16 +0000382bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000383 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000384 SDValue &Opc,
385 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000386 if (DisableShifterOp)
387 return false;
388
Evan Chengee04a6d2011-07-20 23:34:39 +0000389 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000390
391 // Don't match base register only case. That is matched to a separate
392 // lower complexity pattern with explicit register operand.
393 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000394
Evan Cheng055b0312009-06-29 07:51:04 +0000395 BaseReg = N.getOperand(0);
396 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000397 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
398 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000399 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000400 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
401 MVT::i32);
402 return true;
403}
404
Owen Anderson92a20222011-07-21 18:54:16 +0000405bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
406 SDValue &BaseReg,
407 SDValue &ShReg,
408 SDValue &Opc,
409 bool CheckProfitability) {
410 if (DisableShifterOp)
411 return false;
412
413 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
414
415 // Don't match base register only case. That is matched to a separate
416 // lower complexity pattern with explicit register operand.
417 if (ShOpcVal == ARM_AM::no_shift) return false;
418
419 BaseReg = N.getOperand(0);
420 unsigned ShImmVal = 0;
421 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
422 if (RHS) return false;
423
424 ShReg = N.getOperand(1);
425 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
426 return false;
427 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
428 MVT::i32);
429 return true;
430}
431
432
Jim Grosbach3e556122010-10-26 22:37:02 +0000433bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
434 SDValue &Base,
435 SDValue &OffImm) {
436 // Match simple R + imm12 operands.
437
438 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000439 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
440 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000441 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000442 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000443 int FI = cast<FrameIndexSDNode>(N)->getIndex();
444 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
445 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
446 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000447 }
Owen Anderson099e5552011-03-18 19:46:58 +0000448
Chris Lattner0a9481f2011-02-13 22:25:43 +0000449 if (N.getOpcode() == ARMISD::Wrapper &&
450 !(Subtarget->useMovt() &&
451 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000452 Base = N.getOperand(0);
453 } else
454 Base = N;
455 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
456 return true;
457 }
458
459 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
460 int RHSC = (int)RHS->getZExtValue();
461 if (N.getOpcode() == ISD::SUB)
462 RHSC = -RHSC;
463
464 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
465 Base = N.getOperand(0);
466 if (Base.getOpcode() == ISD::FrameIndex) {
467 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
468 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
469 }
470 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
471 return true;
472 }
473 }
474
475 // Base only.
476 Base = N;
477 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
478 return true;
479}
480
481
482
483bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
484 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000485 if (N.getOpcode() == ISD::MUL &&
486 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000487 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
488 // X * [3,5,9] -> X + X * [2,4,8] etc.
489 int RHSC = (int)RHS->getZExtValue();
490 if (RHSC & 1) {
491 RHSC = RHSC & ~1;
492 ARM_AM::AddrOpc AddSub = ARM_AM::add;
493 if (RHSC < 0) {
494 AddSub = ARM_AM::sub;
495 RHSC = - RHSC;
496 }
497 if (isPowerOf2_32(RHSC)) {
498 unsigned ShAmt = Log2_32(RHSC);
499 Base = Offset = N.getOperand(0);
500 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
501 ARM_AM::lsl),
502 MVT::i32);
503 return true;
504 }
505 }
506 }
507 }
508
Chris Lattner0a9481f2011-02-13 22:25:43 +0000509 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
510 // ISD::OR that is equivalent to an ISD::ADD.
511 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000512 return false;
513
514 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000515 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000516 int RHSC;
517 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
518 -0x1000+1, 0x1000, RHSC)) // 12 bits.
519 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000520 }
521
522 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000523 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000524 ARM_AM::ShiftOpc ShOpcVal =
525 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000526 unsigned ShAmt = 0;
527
528 Base = N.getOperand(0);
529 Offset = N.getOperand(1);
530
531 if (ShOpcVal != ARM_AM::no_shift) {
532 // Check to see if the RHS of the shift is a constant, if not, we can't fold
533 // it.
534 if (ConstantSDNode *Sh =
535 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
536 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000537 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
538 Offset = N.getOperand(1).getOperand(0);
539 else {
540 ShAmt = 0;
541 ShOpcVal = ARM_AM::no_shift;
542 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000543 } else {
544 ShOpcVal = ARM_AM::no_shift;
545 }
546 }
547
548 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000549 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000550 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000551 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000552 if (ShOpcVal != ARM_AM::no_shift) {
553 // Check to see if the RHS of the shift is a constant, if not, we can't
554 // fold it.
555 if (ConstantSDNode *Sh =
556 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
557 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000558 if (!Subtarget->isCortexA9() ||
559 (N.hasOneUse() &&
560 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
561 Offset = N.getOperand(0).getOperand(0);
562 Base = N.getOperand(1);
563 } else {
564 ShAmt = 0;
565 ShOpcVal = ARM_AM::no_shift;
566 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000567 } else {
568 ShOpcVal = ARM_AM::no_shift;
569 }
570 }
571 }
572
573 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
574 MVT::i32);
575 return true;
576}
577
578
579
580
581//-----
582
Jim Grosbach82891622010-09-29 19:03:54 +0000583AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
584 SDValue &Base,
585 SDValue &Offset,
586 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000587 if (N.getOpcode() == ISD::MUL &&
588 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000589 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
590 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000591 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000592 if (RHSC & 1) {
593 RHSC = RHSC & ~1;
594 ARM_AM::AddrOpc AddSub = ARM_AM::add;
595 if (RHSC < 0) {
596 AddSub = ARM_AM::sub;
597 RHSC = - RHSC;
598 }
599 if (isPowerOf2_32(RHSC)) {
600 unsigned ShAmt = Log2_32(RHSC);
601 Base = Offset = N.getOperand(0);
602 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
603 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000605 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000606 }
607 }
608 }
609 }
610
Chris Lattner0a9481f2011-02-13 22:25:43 +0000611 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
612 // ISD::OR that is equivalent to an ADD.
613 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000614 Base = N;
615 if (N.getOpcode() == ISD::FrameIndex) {
616 int FI = cast<FrameIndexSDNode>(N)->getIndex();
617 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000618 } else if (N.getOpcode() == ARMISD::Wrapper &&
619 !(Subtarget->useMovt() &&
620 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000621 Base = N.getOperand(0);
622 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000623 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000624 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
625 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000626 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000627 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000628 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000629
Evan Chenga8e29892007-01-19 07:51:42 +0000630 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000631 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000632 int RHSC;
633 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
634 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
635 Base = N.getOperand(0);
636 if (Base.getOpcode() == ISD::FrameIndex) {
637 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
638 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000639 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000640 Offset = CurDAG->getRegister(0, MVT::i32);
641
642 ARM_AM::AddrOpc AddSub = ARM_AM::add;
643 if (RHSC < 0) {
644 AddSub = ARM_AM::sub;
645 RHSC = - RHSC;
646 }
647 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
648 ARM_AM::no_shift),
649 MVT::i32);
650 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000651 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000652 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000653
Evan Chengf40deed2010-10-27 23:41:30 +0000654 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
655 // Compute R +/- (R << N) and reuse it.
656 Base = N;
657 Offset = CurDAG->getRegister(0, MVT::i32);
658 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
659 ARM_AM::no_shift),
660 MVT::i32);
661 return AM2_BASE;
662 }
663
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000664 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000665 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000666 ARM_AM::ShiftOpc ShOpcVal =
667 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000668 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000669
Evan Chenga8e29892007-01-19 07:51:42 +0000670 Base = N.getOperand(0);
671 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000672
Evan Chenga8e29892007-01-19 07:51:42 +0000673 if (ShOpcVal != ARM_AM::no_shift) {
674 // Check to see if the RHS of the shift is a constant, if not, we can't fold
675 // it.
676 if (ConstantSDNode *Sh =
677 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000678 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000679 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
680 Offset = N.getOperand(1).getOperand(0);
681 else {
682 ShAmt = 0;
683 ShOpcVal = ARM_AM::no_shift;
684 }
Evan Chenga8e29892007-01-19 07:51:42 +0000685 } else {
686 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000687 }
688 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000689
Evan Chenga8e29892007-01-19 07:51:42 +0000690 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000691 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000692 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000693 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000694 if (ShOpcVal != ARM_AM::no_shift) {
695 // Check to see if the RHS of the shift is a constant, if not, we can't
696 // fold it.
697 if (ConstantSDNode *Sh =
698 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000699 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000700 if (!Subtarget->isCortexA9() ||
701 (N.hasOneUse() &&
702 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
703 Offset = N.getOperand(0).getOperand(0);
704 Base = N.getOperand(1);
705 } else {
706 ShAmt = 0;
707 ShOpcVal = ARM_AM::no_shift;
708 }
Evan Chenga8e29892007-01-19 07:51:42 +0000709 } else {
710 ShOpcVal = ARM_AM::no_shift;
711 }
712 }
713 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000714
Evan Chenga8e29892007-01-19 07:51:42 +0000715 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000716 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000717 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000718}
719
Owen Anderson793e7962011-07-26 20:54:26 +0000720bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000721 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000722 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000723 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
724 ? cast<LoadSDNode>(Op)->getAddressingMode()
725 : cast<StoreSDNode>(Op)->getAddressingMode();
726 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
727 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000728 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000729 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
730 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000731
732 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000733 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000734 unsigned ShAmt = 0;
735 if (ShOpcVal != ARM_AM::no_shift) {
736 // Check to see if the RHS of the shift is a constant, if not, we can't fold
737 // it.
738 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000739 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000740 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
741 Offset = N.getOperand(0);
742 else {
743 ShAmt = 0;
744 ShOpcVal = ARM_AM::no_shift;
745 }
Evan Chenga8e29892007-01-19 07:51:42 +0000746 } else {
747 ShOpcVal = ARM_AM::no_shift;
748 }
749 }
750
751 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000752 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000753 return true;
754}
755
Owen Andersonc4e16de2011-08-29 20:16:50 +0000756bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
757 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000758 unsigned Opcode = Op->getOpcode();
759 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
760 ? cast<LoadSDNode>(Op)->getAddressingMode()
761 : cast<StoreSDNode>(Op)->getAddressingMode();
762 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
763 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000764 int Val;
765 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000766 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000767 Offset = CurDAG->getRegister(0, MVT::i32);
768 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
769 return true;
770 }
771
772 return false;
773}
774
775
Owen Anderson793e7962011-07-26 20:54:26 +0000776bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
777 SDValue &Offset, SDValue &Opc) {
778 unsigned Opcode = Op->getOpcode();
779 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
780 ? cast<LoadSDNode>(Op)->getAddressingMode()
781 : cast<StoreSDNode>(Op)->getAddressingMode();
782 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
783 ? ARM_AM::add : ARM_AM::sub;
784 int Val;
785 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
786 Offset = CurDAG->getRegister(0, MVT::i32);
787 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
788 ARM_AM::no_shift),
789 MVT::i32);
790 return true;
791 }
792
793 return false;
794}
795
Jim Grosbach19dec202011-08-05 20:35:44 +0000796bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
797 Base = N;
798 return true;
799}
Evan Chenga8e29892007-01-19 07:51:42 +0000800
Chris Lattner52a261b2010-09-21 20:31:19 +0000801bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000802 SDValue &Base, SDValue &Offset,
803 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000804 if (N.getOpcode() == ISD::SUB) {
805 // X - C is canonicalize to X + -C, no need to handle it here.
806 Base = N.getOperand(0);
807 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000808 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000809 return true;
810 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000811
Chris Lattner0a9481f2011-02-13 22:25:43 +0000812 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000813 Base = N;
814 if (N.getOpcode() == ISD::FrameIndex) {
815 int FI = cast<FrameIndexSDNode>(N)->getIndex();
816 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
817 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000818 Offset = CurDAG->getRegister(0, MVT::i32);
819 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000820 return true;
821 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000822
Evan Chenga8e29892007-01-19 07:51:42 +0000823 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000824 int RHSC;
825 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
826 -256 + 1, 256, RHSC)) { // 8 bits.
827 Base = N.getOperand(0);
828 if (Base.getOpcode() == ISD::FrameIndex) {
829 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
830 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000831 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000832 Offset = CurDAG->getRegister(0, MVT::i32);
833
834 ARM_AM::AddrOpc AddSub = ARM_AM::add;
835 if (RHSC < 0) {
836 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000837 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000838 }
839 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
840 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000841 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000842
Evan Chenga8e29892007-01-19 07:51:42 +0000843 Base = N.getOperand(0);
844 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000846 return true;
847}
848
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000849bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000850 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000851 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000852 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
853 ? cast<LoadSDNode>(Op)->getAddressingMode()
854 : cast<StoreSDNode>(Op)->getAddressingMode();
855 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
856 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000857 int Val;
858 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
859 Offset = CurDAG->getRegister(0, MVT::i32);
860 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
861 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000862 }
863
864 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000865 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000866 return true;
867}
868
Jim Grosbach3ab56582010-10-21 19:38:40 +0000869bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000870 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000871 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000872 Base = N;
873 if (N.getOpcode() == ISD::FrameIndex) {
874 int FI = cast<FrameIndexSDNode>(N)->getIndex();
875 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000876 } else if (N.getOpcode() == ARMISD::Wrapper &&
877 !(Subtarget->useMovt() &&
878 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000879 Base = N.getOperand(0);
880 }
881 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000882 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000883 return true;
884 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000885
Evan Chenga8e29892007-01-19 07:51:42 +0000886 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000887 int RHSC;
888 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
889 -256 + 1, 256, RHSC)) {
890 Base = N.getOperand(0);
891 if (Base.getOpcode() == ISD::FrameIndex) {
892 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
893 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000894 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000895
896 ARM_AM::AddrOpc AddSub = ARM_AM::add;
897 if (RHSC < 0) {
898 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000899 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000900 }
901 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
902 MVT::i32);
903 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000904 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000905
Evan Chenga8e29892007-01-19 07:51:42 +0000906 Base = N;
907 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000908 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000909 return true;
910}
911
Bob Wilson665814b2010-11-01 23:40:51 +0000912bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
913 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000914 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000915
916 unsigned Alignment = 0;
917 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
918 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
919 // The maximum alignment is equal to the memory size being referenced.
920 unsigned LSNAlign = LSN->getAlignment();
921 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
922 if (LSNAlign > MemSize && MemSize > 1)
923 Alignment = MemSize;
924 } else {
925 // All other uses of addrmode6 are for intrinsics. For now just record
926 // the raw alignment value; it will be refined later based on the legal
927 // alignment operands for the intrinsic.
928 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
929 }
930
931 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000932 return true;
933}
934
Bob Wilsonda525062011-02-25 06:42:42 +0000935bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
936 SDValue &Offset) {
937 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
938 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
939 if (AM != ISD::POST_INC)
940 return false;
941 Offset = N;
942 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
943 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
944 Offset = CurDAG->getRegister(0, MVT::i32);
945 }
946 return true;
947}
948
Chris Lattner52a261b2010-09-21 20:31:19 +0000949bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000950 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000951 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
952 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000953 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000954 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
955 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000956 return true;
957 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000958
Evan Chenga8e29892007-01-19 07:51:42 +0000959 return false;
960}
961
Bill Wendlingf4caf692010-12-14 03:36:38 +0000962
963//===----------------------------------------------------------------------===//
964// Thumb Addressing Modes
965//===----------------------------------------------------------------------===//
966
Chris Lattner52a261b2010-09-21 20:31:19 +0000967bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000968 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000969 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000970 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000971 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000972 return false;
973
974 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000975 return true;
976 }
977
Evan Chenga8e29892007-01-19 07:51:42 +0000978 Base = N.getOperand(0);
979 Offset = N.getOperand(1);
980 return true;
981}
982
Evan Cheng79d43262007-01-24 02:21:22 +0000983bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000984ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
985 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000986 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000987 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000988 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000989 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000990
Evan Cheng012f2d92007-01-24 08:53:17 +0000991 if (N.getOpcode() == ARMISD::Wrapper &&
992 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
993 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000994 }
995
Chris Lattner0a9481f2011-02-13 22:25:43 +0000996 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000997 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000998
Evan Chengad0e4652007-02-06 00:22:06 +0000999 // Thumb does not have [sp, r] address mode.
1000 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1001 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1002 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001003 (RHSR && RHSR->getReg() == ARM::SP))
1004 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001005
Daniel Dunbarec91d522011-01-19 15:12:16 +00001006 // FIXME: Why do we explicitly check for a match here and then return false?
1007 // Presumably to allow something else to match, but shouldn't this be
1008 // documented?
1009 int RHSC;
1010 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1011 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001012
1013 Base = N.getOperand(0);
1014 Offset = N.getOperand(1);
1015 return true;
1016}
1017
1018bool
1019ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1020 SDValue &Base,
1021 SDValue &Offset) {
1022 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1023}
1024
1025bool
1026ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1027 SDValue &Base,
1028 SDValue &Offset) {
1029 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1030}
1031
1032bool
1033ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1034 SDValue &Base,
1035 SDValue &Offset) {
1036 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1037}
1038
1039bool
1040ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1041 SDValue &Base, SDValue &OffImm) {
1042 if (Scale == 4) {
1043 SDValue TmpBase, TmpOffImm;
1044 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1045 return false; // We want to select tLDRspi / tSTRspi instead.
1046
1047 if (N.getOpcode() == ARMISD::Wrapper &&
1048 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1049 return false; // We want to select tLDRpci instead.
1050 }
1051
Chris Lattner0a9481f2011-02-13 22:25:43 +00001052 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001053 if (N.getOpcode() == ARMISD::Wrapper &&
1054 !(Subtarget->useMovt() &&
1055 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1056 Base = N.getOperand(0);
1057 } else {
1058 Base = N;
1059 }
1060
Owen Anderson825b72b2009-08-11 20:47:22 +00001061 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001062 return true;
1063 }
1064
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001065 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1066 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1067 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1068 (RHSR && RHSR->getReg() == ARM::SP)) {
1069 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1070 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1071 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1072 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1073
1074 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1075 if (LHSC != 0 || RHSC != 0) return false;
1076
1077 Base = N;
1078 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1079 return true;
1080 }
1081
Evan Chenga8e29892007-01-19 07:51:42 +00001082 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001083 int RHSC;
1084 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1085 Base = N.getOperand(0);
1086 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1087 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001088 }
1089
Evan Chengc38f2bc2007-01-23 22:59:13 +00001090 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001091 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001092 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001093}
1094
Bill Wendlingf4caf692010-12-14 03:36:38 +00001095bool
1096ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1097 SDValue &OffImm) {
1098 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001099}
1100
Bill Wendlingf4caf692010-12-14 03:36:38 +00001101bool
1102ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1103 SDValue &OffImm) {
1104 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001105}
1106
Bill Wendlingf4caf692010-12-14 03:36:38 +00001107bool
1108ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1109 SDValue &OffImm) {
1110 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001111}
1112
Chris Lattner52a261b2010-09-21 20:31:19 +00001113bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1114 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001115 if (N.getOpcode() == ISD::FrameIndex) {
1116 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1117 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001118 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001119 return true;
1120 }
Evan Cheng79d43262007-01-24 02:21:22 +00001121
Chris Lattner0a9481f2011-02-13 22:25:43 +00001122 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001123 return false;
1124
1125 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001126 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1127 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001128 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001129 int RHSC;
1130 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1131 Base = N.getOperand(0);
1132 if (Base.getOpcode() == ISD::FrameIndex) {
1133 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1134 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001135 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001136 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1137 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001138 }
1139 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001140
Evan Chenga8e29892007-01-19 07:51:42 +00001141 return false;
1142}
1143
Bill Wendlingf4caf692010-12-14 03:36:38 +00001144
1145//===----------------------------------------------------------------------===//
1146// Thumb 2 Addressing Modes
1147//===----------------------------------------------------------------------===//
1148
1149
Chris Lattner52a261b2010-09-21 20:31:19 +00001150bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001151 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001152 if (DisableShifterOp)
1153 return false;
1154
Evan Chengee04a6d2011-07-20 23:34:39 +00001155 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001156
1157 // Don't match base register only case. That is matched to a separate
1158 // lower complexity pattern with explicit register operand.
1159 if (ShOpcVal == ARM_AM::no_shift) return false;
1160
1161 BaseReg = N.getOperand(0);
1162 unsigned ShImmVal = 0;
1163 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1164 ShImmVal = RHS->getZExtValue() & 31;
1165 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1166 return true;
1167 }
1168
1169 return false;
1170}
1171
Chris Lattner52a261b2010-09-21 20:31:19 +00001172bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001173 SDValue &Base, SDValue &OffImm) {
1174 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001175
Evan Cheng3a214252009-08-11 08:52:18 +00001176 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001177 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1178 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001179 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001180 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001181 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1182 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001183 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001184 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001185 }
Owen Anderson099e5552011-03-18 19:46:58 +00001186
Chris Lattner0a9481f2011-02-13 22:25:43 +00001187 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001188 !(Subtarget->useMovt() &&
1189 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001190 Base = N.getOperand(0);
1191 if (Base.getOpcode() == ISD::TargetConstantPool)
1192 return false; // We want to select t2LDRpci instead.
1193 } else
1194 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001195 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001196 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001197 }
Evan Cheng055b0312009-06-29 07:51:04 +00001198
1199 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001200 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001201 // Let t2LDRi8 handle (R - imm8).
1202 return false;
1203
Evan Cheng055b0312009-06-29 07:51:04 +00001204 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001205 if (N.getOpcode() == ISD::SUB)
1206 RHSC = -RHSC;
1207
1208 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001209 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001210 if (Base.getOpcode() == ISD::FrameIndex) {
1211 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1212 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1213 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001214 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001215 return true;
1216 }
1217 }
1218
Evan Cheng3a214252009-08-11 08:52:18 +00001219 // Base only.
1220 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001221 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001222 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001223}
1224
Chris Lattner52a261b2010-09-21 20:31:19 +00001225bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001226 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001227 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001228 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1229 !CurDAG->isBaseWithConstantOffset(N))
1230 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001231
Chris Lattner0a9481f2011-02-13 22:25:43 +00001232 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1233 int RHSC = (int)RHS->getSExtValue();
1234 if (N.getOpcode() == ISD::SUB)
1235 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001236
Chris Lattner0a9481f2011-02-13 22:25:43 +00001237 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1238 Base = N.getOperand(0);
1239 if (Base.getOpcode() == ISD::FrameIndex) {
1240 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1241 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001242 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001243 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1244 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001245 }
1246 }
1247
1248 return false;
1249}
1250
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001251bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001252 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001253 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001254 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1255 ? cast<LoadSDNode>(Op)->getAddressingMode()
1256 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001257 int RHSC;
1258 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1259 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1260 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1261 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1262 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001263 }
1264
1265 return false;
1266}
1267
Chris Lattner52a261b2010-09-21 20:31:19 +00001268bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001269 SDValue &Base,
1270 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001271 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001272 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001273 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001274
Evan Cheng3a214252009-08-11 08:52:18 +00001275 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1276 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1277 int RHSC = (int)RHS->getZExtValue();
1278 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1279 return false;
1280 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001281 return false;
1282 }
1283
Evan Cheng055b0312009-06-29 07:51:04 +00001284 // Look for (R + R) or (R + (R << [1,2,3])).
1285 unsigned ShAmt = 0;
1286 Base = N.getOperand(0);
1287 OffReg = N.getOperand(1);
1288
1289 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001290 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001291 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001292 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001293 if (ShOpcVal == ARM_AM::lsl)
1294 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001295 }
1296
Evan Cheng055b0312009-06-29 07:51:04 +00001297 if (ShOpcVal == ARM_AM::lsl) {
1298 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1299 // it.
1300 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1301 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001302 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1303 OffReg = OffReg.getOperand(0);
1304 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001305 ShAmt = 0;
1306 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001307 }
Evan Cheng055b0312009-06-29 07:51:04 +00001308 } else {
1309 ShOpcVal = ARM_AM::no_shift;
1310 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001311 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001312
Owen Anderson825b72b2009-08-11 20:47:22 +00001313 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001314
1315 return true;
1316}
1317
1318//===--------------------------------------------------------------------===//
1319
Evan Chengee568cf2007-07-05 07:15:27 +00001320/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001321static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001322 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001323}
1324
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001325SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1326 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001327 ISD::MemIndexedMode AM = LD->getAddressingMode();
1328 if (AM == ISD::UNINDEXED)
1329 return NULL;
1330
Owen Andersone50ed302009-08-10 22:56:29 +00001331 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001332 SDValue Offset, AMOpc;
1333 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1334 unsigned Opcode = 0;
1335 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001336 if (LoadedVT == MVT::i32 && isPre &&
1337 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1338 Opcode = ARM::LDR_PRE_IMM;
1339 Match = true;
1340 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001341 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001342 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001343 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001344 } else if (LoadedVT == MVT::i32 &&
1345 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001346 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001347 Match = true;
1348
Owen Anderson825b72b2009-08-11 20:47:22 +00001349 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001350 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001351 Match = true;
1352 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1353 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1354 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001355 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001356 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001357 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001358 Match = true;
1359 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1360 }
1361 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001362 if (isPre &&
1363 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001364 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001365 Opcode = ARM::LDRB_PRE_IMM;
1366 } else if (!isPre &&
1367 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1368 Match = true;
1369 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001370 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1371 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001372 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001373 }
1374 }
1375 }
1376
1377 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001378 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1379 SDValue Chain = LD->getChain();
1380 SDValue Base = LD->getBasePtr();
1381 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1382 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001383 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1384 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001385 } else {
1386 SDValue Chain = LD->getChain();
1387 SDValue Base = LD->getBasePtr();
1388 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1389 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001390 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1391 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001392 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001393 }
1394
1395 return NULL;
1396}
1397
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001398SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1399 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001400 ISD::MemIndexedMode AM = LD->getAddressingMode();
1401 if (AM == ISD::UNINDEXED)
1402 return NULL;
1403
Owen Andersone50ed302009-08-10 22:56:29 +00001404 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001405 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001406 SDValue Offset;
1407 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1408 unsigned Opcode = 0;
1409 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001410 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001411 switch (LoadedVT.getSimpleVT().SimpleTy) {
1412 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001413 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1414 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001415 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001416 if (isSExtLd)
1417 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1418 else
1419 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001420 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001421 case MVT::i8:
1422 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001423 if (isSExtLd)
1424 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1425 else
1426 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001427 break;
1428 default:
1429 return NULL;
1430 }
1431 Match = true;
1432 }
1433
1434 if (Match) {
1435 SDValue Chain = LD->getChain();
1436 SDValue Base = LD->getBasePtr();
1437 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001438 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001439 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001440 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001441 }
1442
1443 return NULL;
1444}
1445
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001446/// PairSRegs - Form a D register from a pair of S registers.
1447///
1448SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1449 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001450 SDValue RegClass =
1451 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001452 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1453 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001454 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1455 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001456}
1457
Evan Cheng603afbf2010-05-10 17:34:18 +00001458/// PairDRegs - Form a quad register from a pair of D registers.
1459///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001460SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1461 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001462 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001463 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1464 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001465 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1466 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001467}
1468
Evan Cheng7f687192010-05-14 00:21:45 +00001469/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001470///
1471SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1472 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001473 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001474 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1475 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001476 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1477 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001478}
1479
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001480/// QuadSRegs - Form 4 consecutive S registers.
1481///
1482SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1483 SDValue V2, SDValue V3) {
1484 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001485 SDValue RegClass =
1486 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001487 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1488 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1489 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1490 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001491 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1492 V2, SubReg2, V3, SubReg3 };
1493 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001494}
1495
Evan Cheng7f687192010-05-14 00:21:45 +00001496/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001497///
1498SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1499 SDValue V2, SDValue V3) {
1500 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001501 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001502 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1503 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1504 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1505 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001506 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1507 V2, SubReg2, V3, SubReg3 };
1508 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001509}
1510
Evan Cheng8f6de382010-05-16 03:27:48 +00001511/// QuadQRegs - Form 4 consecutive Q registers.
1512///
1513SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1514 SDValue V2, SDValue V3) {
1515 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001516 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001517 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1518 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1519 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1520 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001521 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1522 V2, SubReg2, V3, SubReg3 };
1523 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001524}
1525
Bob Wilson2a6e6162010-09-23 23:42:37 +00001526/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1527/// of a NEON VLD or VST instruction. The supported values depend on the
1528/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001529SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1530 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001531 unsigned NumRegs = NumVecs;
1532 if (!is64BitVector && NumVecs < 3)
1533 NumRegs *= 2;
1534
Bob Wilson665814b2010-11-01 23:40:51 +00001535 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001536 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001537 Alignment = 32;
1538 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1539 Alignment = 16;
1540 else if (Alignment >= 8)
1541 Alignment = 8;
1542 else
1543 Alignment = 0;
1544
1545 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001546}
1547
Bob Wilson1c3ef902011-02-07 17:43:21 +00001548SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001549 unsigned *DOpcodes, unsigned *QOpcodes0,
1550 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001551 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001552 DebugLoc dl = N->getDebugLoc();
1553
Bob Wilson226036e2010-03-20 22:13:40 +00001554 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001555 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1556 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001557 return NULL;
1558
1559 SDValue Chain = N->getOperand(0);
1560 EVT VT = N->getValueType(0);
1561 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001562 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001563
Bob Wilson3e36f132009-10-14 17:28:52 +00001564 unsigned OpcodeIndex;
1565 switch (VT.getSimpleVT().SimpleTy) {
1566 default: llvm_unreachable("unhandled vld type");
1567 // Double-register operations:
1568 case MVT::v8i8: OpcodeIndex = 0; break;
1569 case MVT::v4i16: OpcodeIndex = 1; break;
1570 case MVT::v2f32:
1571 case MVT::v2i32: OpcodeIndex = 2; break;
1572 case MVT::v1i64: OpcodeIndex = 3; break;
1573 // Quad-register operations:
1574 case MVT::v16i8: OpcodeIndex = 0; break;
1575 case MVT::v8i16: OpcodeIndex = 1; break;
1576 case MVT::v4f32:
1577 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001578 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001579 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001580 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001581 }
1582
Bob Wilsonf5721912010-09-03 18:16:02 +00001583 EVT ResTy;
1584 if (NumVecs == 1)
1585 ResTy = VT;
1586 else {
1587 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1588 if (!is64BitVector)
1589 ResTyElts *= 2;
1590 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1591 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001592 std::vector<EVT> ResTys;
1593 ResTys.push_back(ResTy);
1594 if (isUpdating)
1595 ResTys.push_back(MVT::i32);
1596 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001597
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001598 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001599 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001600 SDNode *VLd;
1601 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001602
Bob Wilson1c3ef902011-02-07 17:43:21 +00001603 // Double registers and VLD1/VLD2 quad registers are directly supported.
1604 if (is64BitVector || NumVecs <= 2) {
1605 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1606 QOpcodes0[OpcodeIndex]);
1607 Ops.push_back(MemAddr);
1608 Ops.push_back(Align);
1609 if (isUpdating) {
1610 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1611 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001612 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001613 Ops.push_back(Pred);
1614 Ops.push_back(Reg0);
1615 Ops.push_back(Chain);
1616 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001617
Bob Wilson3e36f132009-10-14 17:28:52 +00001618 } else {
1619 // Otherwise, quad registers are loaded with two separate instructions,
1620 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001621 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001622
Bob Wilson1c3ef902011-02-07 17:43:21 +00001623 // Load the even subregs. This is always an updating load, so that it
1624 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001625 SDValue ImplDef =
1626 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1627 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001628 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1629 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001630 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001631
Bob Wilson24f995d2009-10-14 18:32:29 +00001632 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001633 Ops.push_back(SDValue(VLdA, 1));
1634 Ops.push_back(Align);
1635 if (isUpdating) {
1636 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1637 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1638 "only constant post-increment update allowed for VLD3/4");
1639 (void)Inc;
1640 Ops.push_back(Reg0);
1641 }
1642 Ops.push_back(SDValue(VLdA, 0));
1643 Ops.push_back(Pred);
1644 Ops.push_back(Reg0);
1645 Ops.push_back(Chain);
1646 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1647 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001648 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001649
Evan Chengb58a3402011-04-19 00:04:03 +00001650 // Transfer memoperands.
1651 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1652 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1653 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1654
Bob Wilson1c3ef902011-02-07 17:43:21 +00001655 if (NumVecs == 1)
1656 return VLd;
1657
1658 // Extract out the subregisters.
1659 SDValue SuperReg = SDValue(VLd, 0);
1660 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1661 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1662 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1663 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1664 ReplaceUses(SDValue(N, Vec),
1665 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1666 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1667 if (isUpdating)
1668 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001669 return NULL;
1670}
1671
Bob Wilson1c3ef902011-02-07 17:43:21 +00001672SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001673 unsigned *DOpcodes, unsigned *QOpcodes0,
1674 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001675 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001676 DebugLoc dl = N->getDebugLoc();
1677
Bob Wilson226036e2010-03-20 22:13:40 +00001678 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001679 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1680 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1681 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001682 return NULL;
1683
Evan Chengb58a3402011-04-19 00:04:03 +00001684 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1685 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1686
Bob Wilson24f995d2009-10-14 18:32:29 +00001687 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001688 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001689 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001690 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001691
Bob Wilson24f995d2009-10-14 18:32:29 +00001692 unsigned OpcodeIndex;
1693 switch (VT.getSimpleVT().SimpleTy) {
1694 default: llvm_unreachable("unhandled vst type");
1695 // Double-register operations:
1696 case MVT::v8i8: OpcodeIndex = 0; break;
1697 case MVT::v4i16: OpcodeIndex = 1; break;
1698 case MVT::v2f32:
1699 case MVT::v2i32: OpcodeIndex = 2; break;
1700 case MVT::v1i64: OpcodeIndex = 3; break;
1701 // Quad-register operations:
1702 case MVT::v16i8: OpcodeIndex = 0; break;
1703 case MVT::v8i16: OpcodeIndex = 1; break;
1704 case MVT::v4f32:
1705 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001706 case MVT::v2i64: OpcodeIndex = 3;
1707 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1708 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001709 }
1710
Bob Wilson1c3ef902011-02-07 17:43:21 +00001711 std::vector<EVT> ResTys;
1712 if (isUpdating)
1713 ResTys.push_back(MVT::i32);
1714 ResTys.push_back(MVT::Other);
1715
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001716 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001717 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001718 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001719
Bob Wilson1c3ef902011-02-07 17:43:21 +00001720 // Double registers and VST1/VST2 quad registers are directly supported.
1721 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001722 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001723 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001724 SrcReg = N->getOperand(Vec0Idx);
1725 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001726 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001727 SDValue V0 = N->getOperand(Vec0Idx + 0);
1728 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001729 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001730 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001731 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001732 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001733 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001734 // an undef.
1735 SDValue V3 = (NumVecs == 3)
1736 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001737 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001738 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001739 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001740 } else {
1741 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001742 SDValue Q0 = N->getOperand(Vec0Idx);
1743 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001744 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001745 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001746
1747 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1748 QOpcodes0[OpcodeIndex]);
1749 Ops.push_back(MemAddr);
1750 Ops.push_back(Align);
1751 if (isUpdating) {
1752 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1753 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1754 }
1755 Ops.push_back(SrcReg);
1756 Ops.push_back(Pred);
1757 Ops.push_back(Reg0);
1758 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001759 SDNode *VSt =
1760 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1761
1762 // Transfer memoperands.
1763 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1764
1765 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001766 }
1767
1768 // Otherwise, quad registers are stored with two separate instructions,
1769 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001770
Bob Wilson07f6e802010-06-16 21:34:01 +00001771 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001772 SDValue V0 = N->getOperand(Vec0Idx + 0);
1773 SDValue V1 = N->getOperand(Vec0Idx + 1);
1774 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001775 SDValue V3 = (NumVecs == 3)
1776 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001777 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001778 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001779
Bob Wilson1c3ef902011-02-07 17:43:21 +00001780 // Store the even D registers. This is always an updating store, so that it
1781 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001782 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1783 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1784 MemAddr.getValueType(),
1785 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001786 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001787 Chain = SDValue(VStA, 1);
1788
1789 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001790 Ops.push_back(SDValue(VStA, 0));
1791 Ops.push_back(Align);
1792 if (isUpdating) {
1793 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1794 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1795 "only constant post-increment update allowed for VST3/4");
1796 (void)Inc;
1797 Ops.push_back(Reg0);
1798 }
1799 Ops.push_back(RegSeq);
1800 Ops.push_back(Pred);
1801 Ops.push_back(Reg0);
1802 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001803 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1804 Ops.data(), Ops.size());
1805 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1806 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001807}
1808
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001809SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001810 bool isUpdating, unsigned NumVecs,
1811 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001812 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001813 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001814 DebugLoc dl = N->getDebugLoc();
1815
Bob Wilson226036e2010-03-20 22:13:40 +00001816 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001817 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1818 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1819 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001820 return NULL;
1821
Evan Chengb58a3402011-04-19 00:04:03 +00001822 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1823 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1824
Bob Wilsona7c397c2009-10-14 16:19:03 +00001825 SDValue Chain = N->getOperand(0);
1826 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001827 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1828 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001829 bool is64BitVector = VT.is64BitVector();
1830
Bob Wilson665814b2010-11-01 23:40:51 +00001831 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001832 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001833 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001834 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1835 if (Alignment > NumBytes)
1836 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001837 if (Alignment < 8 && Alignment < NumBytes)
1838 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001839 // Alignment must be a power of two; make sure of that.
1840 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001841 if (Alignment == 1)
1842 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001843 }
Bob Wilson665814b2010-11-01 23:40:51 +00001844 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001845
Bob Wilsona7c397c2009-10-14 16:19:03 +00001846 unsigned OpcodeIndex;
1847 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001848 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001849 // Double-register operations:
1850 case MVT::v8i8: OpcodeIndex = 0; break;
1851 case MVT::v4i16: OpcodeIndex = 1; break;
1852 case MVT::v2f32:
1853 case MVT::v2i32: OpcodeIndex = 2; break;
1854 // Quad-register operations:
1855 case MVT::v8i16: OpcodeIndex = 0; break;
1856 case MVT::v4f32:
1857 case MVT::v4i32: OpcodeIndex = 1; break;
1858 }
1859
Bob Wilson1c3ef902011-02-07 17:43:21 +00001860 std::vector<EVT> ResTys;
1861 if (IsLoad) {
1862 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1863 if (!is64BitVector)
1864 ResTyElts *= 2;
1865 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1866 MVT::i64, ResTyElts));
1867 }
1868 if (isUpdating)
1869 ResTys.push_back(MVT::i32);
1870 ResTys.push_back(MVT::Other);
1871
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001872 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001873 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001874
Bob Wilson1c3ef902011-02-07 17:43:21 +00001875 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001876 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001877 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001878 if (isUpdating) {
1879 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1880 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1881 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001882
Bob Wilson8466fa12010-09-13 23:01:35 +00001883 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 SDValue V0 = N->getOperand(Vec0Idx + 0);
1885 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001886 if (NumVecs == 2) {
1887 if (is64BitVector)
1888 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1889 else
1890 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001891 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001892 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001893 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001894 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1895 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001896 if (is64BitVector)
1897 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1898 else
1899 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001900 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001901 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001902 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001903 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001904 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001905 Ops.push_back(Chain);
1906
Bob Wilson1c3ef902011-02-07 17:43:21 +00001907 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1908 QOpcodes[OpcodeIndex]);
1909 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1910 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001911 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001912 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001913 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001914
Bob Wilson8466fa12010-09-13 23:01:35 +00001915 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001916 SuperReg = SDValue(VLdLn, 0);
1917 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1918 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1919 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001920 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1921 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001922 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1923 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1924 if (isUpdating)
1925 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001926 return NULL;
1927}
1928
Bob Wilson1c3ef902011-02-07 17:43:21 +00001929SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
1930 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001931 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1932 DebugLoc dl = N->getDebugLoc();
1933
1934 SDValue MemAddr, Align;
1935 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1936 return NULL;
1937
Evan Chengb58a3402011-04-19 00:04:03 +00001938 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1939 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1940
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001941 SDValue Chain = N->getOperand(0);
1942 EVT VT = N->getValueType(0);
1943
1944 unsigned Alignment = 0;
1945 if (NumVecs != 3) {
1946 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1947 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1948 if (Alignment > NumBytes)
1949 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001950 if (Alignment < 8 && Alignment < NumBytes)
1951 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001952 // Alignment must be a power of two; make sure of that.
1953 Alignment = (Alignment & -Alignment);
1954 if (Alignment == 1)
1955 Alignment = 0;
1956 }
1957 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1958
1959 unsigned OpcodeIndex;
1960 switch (VT.getSimpleVT().SimpleTy) {
1961 default: llvm_unreachable("unhandled vld-dup type");
1962 case MVT::v8i8: OpcodeIndex = 0; break;
1963 case MVT::v4i16: OpcodeIndex = 1; break;
1964 case MVT::v2f32:
1965 case MVT::v2i32: OpcodeIndex = 2; break;
1966 }
1967
1968 SDValue Pred = getAL(CurDAG);
1969 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1970 SDValue SuperReg;
1971 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00001972 SmallVector<SDValue, 6> Ops;
1973 Ops.push_back(MemAddr);
1974 Ops.push_back(Align);
1975 if (isUpdating) {
1976 SDValue Inc = N->getOperand(2);
1977 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1978 }
1979 Ops.push_back(Pred);
1980 Ops.push_back(Reg0);
1981 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001982
1983 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001984 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00001985 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00001986 if (isUpdating)
1987 ResTys.push_back(MVT::i32);
1988 ResTys.push_back(MVT::Other);
1989 SDNode *VLdDup =
1990 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001991 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001992 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001993
1994 // Extract the subregisters.
1995 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1996 unsigned SubIdx = ARM::dsub_0;
1997 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1998 ReplaceUses(SDValue(N, Vec),
1999 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002000 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2001 if (isUpdating)
2002 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002003 return NULL;
2004}
2005
Bob Wilson78dfbc32010-07-07 00:08:54 +00002006SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2007 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002008 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2009 DebugLoc dl = N->getDebugLoc();
2010 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002011 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002012
2013 // Form a REG_SEQUENCE to force register allocation.
2014 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002015 SDValue V0 = N->getOperand(FirstTblReg + 0);
2016 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002017 if (NumVecs == 2)
2018 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2019 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002020 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002021 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002022 // an undef.
2023 SDValue V3 = (NumVecs == 3)
2024 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002025 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002026 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2027 }
2028
Bob Wilson78dfbc32010-07-07 00:08:54 +00002029 SmallVector<SDValue, 6> Ops;
2030 if (IsExt)
2031 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002032 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002033 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002034 Ops.push_back(getAL(CurDAG)); // predicate
2035 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002036 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002037}
2038
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002039SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002040 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002041 if (!Subtarget->hasV6T2Ops())
2042 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002043
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002044 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2045 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2046
2047
2048 // For unsigned extracts, check for a shift right and mask
2049 unsigned And_imm = 0;
2050 if (N->getOpcode() == ISD::AND) {
2051 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2052
2053 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2054 if (And_imm & (And_imm + 1))
2055 return NULL;
2056
2057 unsigned Srl_imm = 0;
2058 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2059 Srl_imm)) {
2060 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2061
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002062 // Note: The width operand is encoded as width-1.
2063 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002064 unsigned LSB = Srl_imm;
2065 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2066 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2067 CurDAG->getTargetConstant(LSB, MVT::i32),
2068 CurDAG->getTargetConstant(Width, MVT::i32),
2069 getAL(CurDAG), Reg0 };
2070 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2071 }
2072 }
2073 return NULL;
2074 }
2075
2076 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002077 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002078 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002079 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2080 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002081 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002082 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002083 // Note: The width operand is encoded as width-1.
2084 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002085 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002086 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002087 return NULL;
2088 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002089 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002090 CurDAG->getTargetConstant(LSB, MVT::i32),
2091 CurDAG->getTargetConstant(Width, MVT::i32),
2092 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002093 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002094 }
2095 }
2096 return NULL;
2097}
2098
Evan Cheng9ef48352009-11-20 00:54:03 +00002099SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002100SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002101 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2102 SDValue CPTmp0;
2103 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002104 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002105 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2106 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2107 unsigned Opc = 0;
2108 switch (SOShOp) {
2109 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2110 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2111 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2112 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2113 default:
2114 llvm_unreachable("Unknown so_reg opcode!");
2115 break;
2116 }
2117 SDValue SOShImm =
2118 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2119 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2120 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002121 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002122 }
2123 return 0;
2124}
2125
2126SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002127SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002128 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2129 SDValue CPTmp0;
2130 SDValue CPTmp1;
2131 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002132 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002133 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002134 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2135 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002136 }
2137
2138 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2139 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2140 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2141 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002142 }
2143 return 0;
2144}
2145
2146SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002147SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002148 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002149 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002150 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002151 return 0;
2152
Evan Cheng63f35442010-11-13 02:25:14 +00002153 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002154 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002155 if (is_t2_so_imm(TrueImm)) {
2156 Opc = ARM::t2MOVCCi;
2157 } else if (TrueImm <= 0xffff) {
2158 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002159 } else if (is_t2_so_imm_not(TrueImm)) {
2160 TrueImm = ~TrueImm;
2161 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002162 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002163 // Large immediate.
2164 Opc = ARM::t2MOVCCi32imm;
2165 }
2166
2167 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002168 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002169 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2170 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002171 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002172 }
Evan Cheng63f35442010-11-13 02:25:14 +00002173
Evan Cheng9ef48352009-11-20 00:54:03 +00002174 return 0;
2175}
2176
2177SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002178SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002179 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002180 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2181 if (!T)
2182 return 0;
2183
Evan Cheng63f35442010-11-13 02:25:14 +00002184 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002185 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002186 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002187 if (isSoImm) {
2188 Opc = ARM::MOVCCi;
2189 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2190 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002191 } else if (is_so_imm_not(TrueImm)) {
2192 TrueImm = ~TrueImm;
2193 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002194 } else if (TrueVal.getNode()->hasOneUse() &&
2195 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002196 // Large immediate.
2197 Opc = ARM::MOVCCi32imm;
2198 }
2199
2200 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002201 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002202 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2203 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002204 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002205 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002206
Evan Cheng9ef48352009-11-20 00:54:03 +00002207 return 0;
2208}
2209
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002210SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2211 EVT VT = N->getValueType(0);
2212 SDValue FalseVal = N->getOperand(0);
2213 SDValue TrueVal = N->getOperand(1);
2214 SDValue CC = N->getOperand(2);
2215 SDValue CCR = N->getOperand(3);
2216 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002217 assert(CC.getOpcode() == ISD::Constant);
2218 assert(CCR.getOpcode() == ISD::Register);
2219 ARMCC::CondCodes CCVal =
2220 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002221
2222 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2223 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2224 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2225 // Pattern complexity = 18 cost = 1 size = 0
2226 SDValue CPTmp0;
2227 SDValue CPTmp1;
2228 SDValue CPTmp2;
2229 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002230 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002231 CCVal, CCR, InFlag);
2232 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002233 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002234 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2235 if (Res)
2236 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002237 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002238 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002239 CCVal, CCR, InFlag);
2240 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002241 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002242 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2243 if (Res)
2244 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002245 }
2246
2247 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002248 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002249 // (imm:i32):$cc)
2250 // Emits: (MOVCCi:i32 GPR:i32:$false,
2251 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2252 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002253 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002254 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002255 CCVal, CCR, InFlag);
2256 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002257 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002258 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2259 if (Res)
2260 return Res;
2261 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002262 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002263 CCVal, CCR, InFlag);
2264 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002265 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002266 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2267 if (Res)
2268 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002269 }
2270 }
2271
2272 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2273 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2274 // Pattern complexity = 6 cost = 1 size = 0
2275 //
2276 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2277 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2278 // Pattern complexity = 6 cost = 11 size = 0
2279 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002280 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002281 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2282 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002283 unsigned Opc = 0;
2284 switch (VT.getSimpleVT().SimpleTy) {
2285 default: assert(false && "Illegal conditional move type!");
2286 break;
2287 case MVT::i32:
2288 Opc = Subtarget->isThumb()
2289 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2290 : ARM::MOVCCr;
2291 break;
2292 case MVT::f32:
2293 Opc = ARM::VMOVScc;
2294 break;
2295 case MVT::f64:
2296 Opc = ARM::VMOVDcc;
2297 break;
2298 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002299 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002300}
2301
Evan Chengde8aa4e2010-05-05 18:28:36 +00002302SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2303 // The only time a CONCAT_VECTORS operation can have legal types is when
2304 // two 64-bit vectors are concatenated to a 128-bit vector.
2305 EVT VT = N->getValueType(0);
2306 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2307 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002308 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002309}
2310
Eli Friedman2bdffe42011-08-31 00:31:29 +00002311SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002312 SmallVector<SDValue, 6> Ops;
2313 Ops.push_back(Node->getOperand(1)); // Ptr
2314 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2315 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002316 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002317 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2318 Ops.push_back(Node->getOperand(5)); // High part of Val2
2319 }
2320 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002321 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2322 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002323 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002324 MVT::i32, MVT::i32, MVT::Other,
2325 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002326 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2327 return ResNode;
2328}
2329
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002330SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002331 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002332
Dan Gohmane8be6c62008-07-17 19:10:17 +00002333 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002334 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002335
2336 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002337 default: break;
2338 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002339 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002340 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002341 if (Subtarget->hasThumb2())
2342 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2343 // be done with MOV + MOVT, at worst.
2344 UseCP = 0;
2345 else {
2346 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002347 UseCP = (Val > 255 && // MOV
2348 ~Val > 255 && // MOV + MVN
2349 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002350 } else
2351 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2352 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2353 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2354 }
2355
Evan Chenga8e29892007-01-19 07:51:42 +00002356 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002357 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002358 CurDAG->getTargetConstantPool(ConstantInt::get(
2359 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002360 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002361
2362 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002363 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002364 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002365 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002366 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002367 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002368 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002369 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002370 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002371 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002372 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002373 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002374 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002375 CurDAG->getEntryNode()
2376 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002377 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002378 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002379 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002380 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002381 return NULL;
2382 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002383
Evan Chenga8e29892007-01-19 07:51:42 +00002384 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002385 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002386 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002387 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002388 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002389 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002390 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002391 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002392 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2393 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2394 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002395 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002396 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2397 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002398 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2399 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2400 CurDAG->getRegister(0, MVT::i32) };
2401 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002402 }
Evan Chenga8e29892007-01-19 07:51:42 +00002403 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002404 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002405 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002406 return I;
2407 break;
2408 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002409 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002410 return I;
2411 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002412 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002413 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002414 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002415 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002416 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002417 if (!RHSV) break;
2418 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002419 unsigned ShImm = Log2_32(RHSV-1);
2420 if (ShImm >= 32)
2421 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002422 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002423 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002424 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2425 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002426 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002427 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002428 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002429 } else {
2430 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002431 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002432 }
Evan Chenga8e29892007-01-19 07:51:42 +00002433 }
2434 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002435 unsigned ShImm = Log2_32(RHSV+1);
2436 if (ShImm >= 32)
2437 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002438 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002439 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002440 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2441 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002442 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002443 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2444 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002445 } else {
2446 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002447 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002448 }
Evan Chenga8e29892007-01-19 07:51:42 +00002449 }
2450 }
2451 break;
Evan Cheng20956592009-10-21 08:15:52 +00002452 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002453 // Check for unsigned bitfield extract
2454 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2455 return I;
2456
Evan Cheng20956592009-10-21 08:15:52 +00002457 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2458 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2459 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2460 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2461 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002462 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002463 if (VT != MVT::i32)
2464 break;
2465 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2466 ? ARM::t2MOVTi16
2467 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2468 if (!Opc)
2469 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002470 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002471 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2472 if (!N1C)
2473 break;
2474 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2475 SDValue N2 = N0.getOperand(1);
2476 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2477 if (!N2C)
2478 break;
2479 unsigned N1CVal = N1C->getZExtValue();
2480 unsigned N2CVal = N2C->getZExtValue();
2481 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2482 (N1CVal & 0xffffU) == 0xffffU &&
2483 (N2CVal & 0xffffU) == 0x0U) {
2484 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2485 MVT::i32);
2486 SDValue Ops[] = { N0.getOperand(0), Imm16,
2487 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2488 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2489 }
2490 }
2491 break;
2492 }
Jim Grosbache5165492009-11-09 00:11:35 +00002493 case ARMISD::VMOVRRD:
2494 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002495 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002496 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002497 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002498 if (Subtarget->isThumb1Only())
2499 break;
2500 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002501 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002502 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2503 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002504 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002505 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002506 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002507 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2508 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002509 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2510 ARM::UMULL : ARM::UMULLv5,
2511 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002512 }
Evan Chengee568cf2007-07-05 07:15:27 +00002513 }
Dan Gohman525178c2007-10-08 18:33:35 +00002514 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002515 if (Subtarget->isThumb1Only())
2516 break;
2517 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002518 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002519 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002520 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002521 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002522 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002523 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2524 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002525 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2526 ARM::SMULL : ARM::SMULLv5,
2527 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002528 }
Evan Chengee568cf2007-07-05 07:15:27 +00002529 }
Evan Chenga8e29892007-01-19 07:51:42 +00002530 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002531 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002532 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002533 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002534 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002535 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002536 if (ResNode)
2537 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002538 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002539 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002540 }
Evan Chengee568cf2007-07-05 07:15:27 +00002541 case ARMISD::BRCOND: {
2542 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2543 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2544 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002545
Evan Chengee568cf2007-07-05 07:15:27 +00002546 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2547 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2548 // Pattern complexity = 6 cost = 1 size = 0
2549
David Goodwin5e47a9a2009-06-30 18:04:13 +00002550 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2551 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2552 // Pattern complexity = 6 cost = 1 size = 0
2553
Jim Grosbach764ab522009-08-11 15:33:49 +00002554 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002555 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002556 SDValue Chain = N->getOperand(0);
2557 SDValue N1 = N->getOperand(1);
2558 SDValue N2 = N->getOperand(2);
2559 SDValue N3 = N->getOperand(3);
2560 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002561 assert(N1.getOpcode() == ISD::BasicBlock);
2562 assert(N2.getOpcode() == ISD::Constant);
2563 assert(N3.getOpcode() == ISD::Register);
2564
Dan Gohman475871a2008-07-27 21:46:04 +00002565 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002566 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002567 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002568 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002569 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002570 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002571 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002572 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002573 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002574 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002575 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002576 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002577 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002578 return NULL;
2579 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002580 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002581 return SelectCMOVOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002582 case ARMISD::VZIP: {
2583 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002584 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002585 switch (VT.getSimpleVT().SimpleTy) {
2586 default: return NULL;
2587 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2588 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2589 case MVT::v2f32:
2590 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2591 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2592 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2593 case MVT::v4f32:
2594 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2595 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002596 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002597 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2598 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2599 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002600 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002601 case ARMISD::VUZP: {
2602 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002603 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002604 switch (VT.getSimpleVT().SimpleTy) {
2605 default: return NULL;
2606 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2607 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2608 case MVT::v2f32:
2609 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2610 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2611 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2612 case MVT::v4f32:
2613 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2614 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002615 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002616 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2617 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2618 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002619 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002620 case ARMISD::VTRN: {
2621 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002622 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002623 switch (VT.getSimpleVT().SimpleTy) {
2624 default: return NULL;
2625 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2626 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2627 case MVT::v2f32:
2628 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2629 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2630 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2631 case MVT::v4f32:
2632 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2633 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002634 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002635 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2636 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2637 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002638 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002639 case ARMISD::BUILD_VECTOR: {
2640 EVT VecVT = N->getValueType(0);
2641 EVT EltVT = VecVT.getVectorElementType();
2642 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002643 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002644 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2645 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2646 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002647 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002648 if (NumElts == 2)
2649 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2650 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2651 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2652 N->getOperand(2), N->getOperand(3));
2653 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002654
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002655 case ARMISD::VLD2DUP: {
2656 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2657 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002658 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002659 }
2660
Bob Wilson86c6d802010-11-29 19:35:29 +00002661 case ARMISD::VLD3DUP: {
2662 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2663 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002664 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002665 }
2666
Bob Wilson6c4c9822010-11-30 00:00:35 +00002667 case ARMISD::VLD4DUP: {
2668 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2669 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002670 return SelectVLDDup(N, false, 4, Opcodes);
2671 }
2672
2673 case ARMISD::VLD2DUP_UPD: {
2674 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo_UPD, ARM::VLD2DUPd16Pseudo_UPD,
2675 ARM::VLD2DUPd32Pseudo_UPD };
2676 return SelectVLDDup(N, true, 2, Opcodes);
2677 }
2678
2679 case ARMISD::VLD3DUP_UPD: {
2680 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2681 ARM::VLD3DUPd32Pseudo_UPD };
2682 return SelectVLDDup(N, true, 3, Opcodes);
2683 }
2684
2685 case ARMISD::VLD4DUP_UPD: {
2686 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2687 ARM::VLD4DUPd32Pseudo_UPD };
2688 return SelectVLDDup(N, true, 4, Opcodes);
2689 }
2690
2691 case ARMISD::VLD1_UPD: {
2692 unsigned DOpcodes[] = { ARM::VLD1d8_UPD, ARM::VLD1d16_UPD,
2693 ARM::VLD1d32_UPD, ARM::VLD1d64_UPD };
2694 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q16Pseudo_UPD,
2695 ARM::VLD1q32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2696 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2697 }
2698
2699 case ARMISD::VLD2_UPD: {
2700 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d16Pseudo_UPD,
2701 ARM::VLD2d32Pseudo_UPD, ARM::VLD1q64Pseudo_UPD };
2702 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q16Pseudo_UPD,
2703 ARM::VLD2q32Pseudo_UPD };
2704 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2705 }
2706
2707 case ARMISD::VLD3_UPD: {
2708 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
2709 ARM::VLD3d32Pseudo_UPD, ARM::VLD1d64TPseudo_UPD };
2710 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2711 ARM::VLD3q16Pseudo_UPD,
2712 ARM::VLD3q32Pseudo_UPD };
2713 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2714 ARM::VLD3q16oddPseudo_UPD,
2715 ARM::VLD3q32oddPseudo_UPD };
2716 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2717 }
2718
2719 case ARMISD::VLD4_UPD: {
2720 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
2721 ARM::VLD4d32Pseudo_UPD, ARM::VLD1d64QPseudo_UPD };
2722 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2723 ARM::VLD4q16Pseudo_UPD,
2724 ARM::VLD4q32Pseudo_UPD };
2725 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2726 ARM::VLD4q16oddPseudo_UPD,
2727 ARM::VLD4q32oddPseudo_UPD };
2728 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2729 }
2730
2731 case ARMISD::VLD2LN_UPD: {
2732 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2733 ARM::VLD2LNd32Pseudo_UPD };
2734 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2735 ARM::VLD2LNq32Pseudo_UPD };
2736 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2737 }
2738
2739 case ARMISD::VLD3LN_UPD: {
2740 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2741 ARM::VLD3LNd32Pseudo_UPD };
2742 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2743 ARM::VLD3LNq32Pseudo_UPD };
2744 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2745 }
2746
2747 case ARMISD::VLD4LN_UPD: {
2748 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
2749 ARM::VLD4LNd32Pseudo_UPD };
2750 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2751 ARM::VLD4LNq32Pseudo_UPD };
2752 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2753 }
2754
2755 case ARMISD::VST1_UPD: {
2756 unsigned DOpcodes[] = { ARM::VST1d8_UPD, ARM::VST1d16_UPD,
2757 ARM::VST1d32_UPD, ARM::VST1d64_UPD };
2758 unsigned QOpcodes[] = { ARM::VST1q8Pseudo_UPD, ARM::VST1q16Pseudo_UPD,
2759 ARM::VST1q32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2760 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2761 }
2762
2763 case ARMISD::VST2_UPD: {
2764 unsigned DOpcodes[] = { ARM::VST2d8Pseudo_UPD, ARM::VST2d16Pseudo_UPD,
2765 ARM::VST2d32Pseudo_UPD, ARM::VST1q64Pseudo_UPD };
2766 unsigned QOpcodes[] = { ARM::VST2q8Pseudo_UPD, ARM::VST2q16Pseudo_UPD,
2767 ARM::VST2q32Pseudo_UPD };
2768 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2769 }
2770
2771 case ARMISD::VST3_UPD: {
2772 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
2773 ARM::VST3d32Pseudo_UPD, ARM::VST1d64TPseudo_UPD };
2774 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2775 ARM::VST3q16Pseudo_UPD,
2776 ARM::VST3q32Pseudo_UPD };
2777 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2778 ARM::VST3q16oddPseudo_UPD,
2779 ARM::VST3q32oddPseudo_UPD };
2780 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2781 }
2782
2783 case ARMISD::VST4_UPD: {
2784 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
2785 ARM::VST4d32Pseudo_UPD, ARM::VST1d64QPseudo_UPD };
2786 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2787 ARM::VST4q16Pseudo_UPD,
2788 ARM::VST4q32Pseudo_UPD };
2789 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2790 ARM::VST4q16oddPseudo_UPD,
2791 ARM::VST4q32oddPseudo_UPD };
2792 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2793 }
2794
2795 case ARMISD::VST2LN_UPD: {
2796 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
2797 ARM::VST2LNd32Pseudo_UPD };
2798 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2799 ARM::VST2LNq32Pseudo_UPD };
2800 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2801 }
2802
2803 case ARMISD::VST3LN_UPD: {
2804 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
2805 ARM::VST3LNd32Pseudo_UPD };
2806 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2807 ARM::VST3LNq32Pseudo_UPD };
2808 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2809 }
2810
2811 case ARMISD::VST4LN_UPD: {
2812 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
2813 ARM::VST4LNd32Pseudo_UPD };
2814 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2815 ARM::VST4LNq32Pseudo_UPD };
2816 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00002817 }
2818
Bob Wilson31fb12f2009-08-26 17:39:53 +00002819 case ISD::INTRINSIC_VOID:
2820 case ISD::INTRINSIC_W_CHAIN: {
2821 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002822 switch (IntNo) {
2823 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002824 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002825
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002826 case Intrinsic::arm_ldrexd: {
2827 SDValue MemAddr = N->getOperand(2);
2828 DebugLoc dl = N->getDebugLoc();
2829 SDValue Chain = N->getOperand(0);
2830
2831 unsigned NewOpc = ARM::LDREXD;
2832 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2833 NewOpc = ARM::t2LDREXD;
2834
2835 // arm_ldrexd returns a i64 value in {i32, i32}
2836 std::vector<EVT> ResTys;
2837 ResTys.push_back(MVT::i32);
2838 ResTys.push_back(MVT::i32);
2839 ResTys.push_back(MVT::Other);
2840
2841 // place arguments in the right order
2842 SmallVector<SDValue, 7> Ops;
2843 Ops.push_back(MemAddr);
2844 Ops.push_back(getAL(CurDAG));
2845 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2846 Ops.push_back(Chain);
2847 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2848 Ops.size());
2849 // Transfer memoperands.
2850 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2851 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2852 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2853
2854 // Until there's support for specifing explicit register constraints
2855 // like the use of even/odd register pair, hardcode ldrexd to always
2856 // use the pair [R0, R1] to hold the load result.
2857 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
2858 SDValue(Ld, 0), SDValue(0,0));
2859 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
2860 SDValue(Ld, 1), Chain.getValue(1));
2861
2862 // Remap uses.
2863 SDValue Glue = Chain.getValue(1);
2864 if (!SDValue(N, 0).use_empty()) {
2865 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2866 ARM::R0, MVT::i32, Glue);
2867 Glue = Result.getValue(2);
2868 ReplaceUses(SDValue(N, 0), Result);
2869 }
2870 if (!SDValue(N, 1).use_empty()) {
2871 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2872 ARM::R1, MVT::i32, Glue);
2873 Glue = Result.getValue(2);
2874 ReplaceUses(SDValue(N, 1), Result);
2875 }
2876
2877 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
2878 return NULL;
2879 }
2880
2881 case Intrinsic::arm_strexd: {
2882 DebugLoc dl = N->getDebugLoc();
2883 SDValue Chain = N->getOperand(0);
2884 SDValue Val0 = N->getOperand(2);
2885 SDValue Val1 = N->getOperand(3);
2886 SDValue MemAddr = N->getOperand(4);
2887
2888 // Until there's support for specifing explicit register constraints
2889 // like the use of even/odd register pair, hardcode strexd to always
2890 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
2891 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
2892 SDValue(0, 0));
2893 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
2894
2895 SDValue Glue = Chain.getValue(1);
2896 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2897 ARM::R2, MVT::i32, Glue);
2898 Glue = Val0.getValue(1);
2899 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
2900 ARM::R3, MVT::i32, Glue);
2901
2902 // Store exclusive double return a i32 value which is the return status
2903 // of the issued store.
2904 std::vector<EVT> ResTys;
2905 ResTys.push_back(MVT::i32);
2906 ResTys.push_back(MVT::Other);
2907
2908 // place arguments in the right order
2909 SmallVector<SDValue, 7> Ops;
2910 Ops.push_back(Val0);
2911 Ops.push_back(Val1);
2912 Ops.push_back(MemAddr);
2913 Ops.push_back(getAL(CurDAG));
2914 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2915 Ops.push_back(Chain);
2916
2917 unsigned NewOpc = ARM::STREXD;
2918 if (Subtarget->isThumb() && Subtarget->hasThumb2())
2919 NewOpc = ARM::t2STREXD;
2920
2921 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
2922 Ops.size());
2923 // Transfer memoperands.
2924 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2925 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2926 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
2927
2928 return St;
2929 }
2930
Bob Wilson621f1952010-03-23 05:25:43 +00002931 case Intrinsic::arm_neon_vld1: {
2932 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2933 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002934 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2935 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002936 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00002937 }
2938
Bob Wilson31fb12f2009-08-26 17:39:53 +00002939 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002940 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2941 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2942 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2943 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002944 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002945 }
2946
2947 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002948 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2949 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2950 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2951 ARM::VLD3q16Pseudo_UPD,
2952 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002953 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
2954 ARM::VLD3q16oddPseudo,
2955 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002956 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002957 }
2958
2959 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002960 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2961 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2962 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2963 ARM::VLD4q16Pseudo_UPD,
2964 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00002965 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
2966 ARM::VLD4q16oddPseudo,
2967 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002968 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002969 }
2970
Bob Wilson243fcc52009-09-01 04:26:28 +00002971 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002972 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2973 ARM::VLD2LNd32Pseudo };
2974 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002975 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002976 }
2977
2978 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002979 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2980 ARM::VLD3LNd32Pseudo };
2981 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002982 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002983 }
2984
2985 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002986 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2987 ARM::VLD4LNd32Pseudo };
2988 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002989 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002990 }
2991
Bob Wilson11d98992010-03-23 06:20:33 +00002992 case Intrinsic::arm_neon_vst1: {
2993 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2994 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002995 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2996 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002997 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00002998 }
2999
Bob Wilson31fb12f2009-08-26 17:39:53 +00003000 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003001 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
3002 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
3003 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3004 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003005 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003006 }
3007
3008 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00003009 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
3010 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
3011 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3012 ARM::VST3q16Pseudo_UPD,
3013 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003014 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
3015 ARM::VST3q16oddPseudo,
3016 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003017 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003018 }
3019
3020 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00003021 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00003022 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00003023 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3024 ARM::VST4q16Pseudo_UPD,
3025 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003026 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
3027 ARM::VST4q16oddPseudo,
3028 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003029 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003030 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003031
3032 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003033 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
3034 ARM::VST2LNd32Pseudo };
3035 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003036 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003037 }
3038
3039 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003040 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
3041 ARM::VST3LNd32Pseudo };
3042 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003043 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003044 }
3045
3046 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003047 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3048 ARM::VST4LNd32Pseudo };
3049 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003050 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003051 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003052 }
Bob Wilson429009b2010-05-06 16:05:26 +00003053 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003054 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003055
Bob Wilsond491d6e2010-07-06 23:36:25 +00003056 case ISD::INTRINSIC_WO_CHAIN: {
3057 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3058 switch (IntNo) {
3059 default:
3060 break;
3061
3062 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003063 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003064 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003065 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003066 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003067 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003068
3069 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003070 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003071 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003072 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003073 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003074 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003075 }
3076 break;
3077 }
3078
Bill Wendling69a05a72011-03-14 23:02:38 +00003079 case ARMISD::VTBL1: {
3080 DebugLoc dl = N->getDebugLoc();
3081 EVT VT = N->getValueType(0);
3082 SmallVector<SDValue, 6> Ops;
3083
3084 Ops.push_back(N->getOperand(0));
3085 Ops.push_back(N->getOperand(1));
3086 Ops.push_back(getAL(CurDAG)); // Predicate
3087 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3088 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3089 }
3090 case ARMISD::VTBL2: {
3091 DebugLoc dl = N->getDebugLoc();
3092 EVT VT = N->getValueType(0);
3093
3094 // Form a REG_SEQUENCE to force register allocation.
3095 SDValue V0 = N->getOperand(0);
3096 SDValue V1 = N->getOperand(1);
3097 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3098
3099 SmallVector<SDValue, 6> Ops;
3100 Ops.push_back(RegSeq);
3101 Ops.push_back(N->getOperand(2));
3102 Ops.push_back(getAL(CurDAG)); // Predicate
3103 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3104 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3105 Ops.data(), Ops.size());
3106 }
3107
Bob Wilson429009b2010-05-06 16:05:26 +00003108 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003109 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003110
3111 case ARMISD::ATOMOR64_DAG:
3112 return SelectAtomic64(N, ARM::ATOMOR6432);
3113 case ARMISD::ATOMXOR64_DAG:
3114 return SelectAtomic64(N, ARM::ATOMXOR6432);
3115 case ARMISD::ATOMADD64_DAG:
3116 return SelectAtomic64(N, ARM::ATOMADD6432);
3117 case ARMISD::ATOMSUB64_DAG:
3118 return SelectAtomic64(N, ARM::ATOMSUB6432);
3119 case ARMISD::ATOMNAND64_DAG:
3120 return SelectAtomic64(N, ARM::ATOMNAND6432);
3121 case ARMISD::ATOMAND64_DAG:
3122 return SelectAtomic64(N, ARM::ATOMAND6432);
3123 case ARMISD::ATOMSWAP64_DAG:
3124 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003125 case ARMISD::ATOMCMPXCHG64_DAG:
3126 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003127 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003128
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003129 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003130}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003131
Bob Wilson224c2442009-05-19 05:53:42 +00003132bool ARMDAGToDAGISel::
3133SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3134 std::vector<SDValue> &OutOps) {
3135 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003136 // Require the address to be in a register. That is safe for all ARM
3137 // variants and it is hard to do anything much smarter without knowing
3138 // how the operand is used.
3139 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003140 return false;
3141}
3142
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003143/// createARMISelDag - This pass converts a legalized DAG into a
3144/// ARM-specific DAG, ready for instruction scheduling.
3145///
Bob Wilson522ce972009-09-28 14:30:20 +00003146FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3147 CodeGenOpt::Level OptLevel) {
3148 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003149}