blob: c2dbcb9750ced4bb70dc2d930789aa2b36a38709 [file] [log] [blame]
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Espindolaffdc24b2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesend679ff72010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chenga20cde32011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
Weiming Zhaoc5987002013-02-14 18:10:21 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000023#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000025#include "llvm/IR/CallingConv.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DerivedTypes.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/LLVMContext.h"
Evan Cheng8e6b40a2010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner1770fb82008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Target/TargetLowering.h"
37#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000038
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000039using namespace llvm;
40
Evan Cheng59069ec2010-07-30 23:33:54 +000041static cl::opt<bool>
42DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
44 cl::init(false));
45
Evan Cheng62c7b5b2010-12-05 22:04:16 +000046static cl::opt<bool>
47CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000049 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000050
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000051//===--------------------------------------------------------------------===//
52/// ARMDAGToDAGISel - ARM specific code to select ARM machine
53/// instructions for SelectionDAG operations.
54///
55namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000056
57enum AddrMode2Type {
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
60};
61
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000062class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikov99152f32009-06-26 21:28:53 +000063 ARMBaseTargetMachine &TM;
Evan Chengbc0d0ec2008-09-18 07:24:33 +000064
Evan Cheng10043e22007-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 Espindolaffdc24b2006-05-14 22:18:28 +000069public:
Bob Wilson2dd957f2009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng62c7b5b2010-12-05 22:04:16 +000073 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000074 }
75
Evan Cheng10043e22007-01-19 07:51:42 +000076 virtual const char *getPassName() const {
77 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000078 }
79
Evan Chengeae6d2c2012-12-19 20:16:09 +000080 virtual void PreprocessISelDAG();
81
Bob Wilson4facd962009-10-08 18:51:31 +000082 /// getI32Imm - Return a target constant of type i32 with the specified
83 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000084 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000085 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000086 }
87
Dan Gohmanea6f91f2010-01-05 01:24:18 +000088 SDNode *Select(SDNode *N);
Evan Cheng5e73ff22010-02-15 19:41:07 +000089
Evan Cheng62c7b5b2010-12-05 22:04:16 +000090
91 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000092 bool isShifterOpProfitable(const SDValue &Shift,
93 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000094 bool SelectRegShifterOperand(SDValue N, SDValue &A,
95 SDValue &B, SDValue &C,
96 bool CheckProfitability = true);
97 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +000098 SDValue &B, bool CheckProfitability = true);
99 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000100 SDValue &B, SDValue &C) {
101 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000102 return SelectRegShifterOperand(N, A, B, C, false);
103 }
104 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
105 SDValue &B) {
106 // Don't apply the profitability check
107 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000108 }
109
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000110 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
111 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
112
Jim Grosbach08605202010-09-29 19:03:54 +0000113 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
114 SDValue &Offset, SDValue &Opc);
115 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
116 SDValue &Opc) {
117 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
118 }
119
120 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
121 SDValue &Opc) {
122 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
123 }
124
125 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
126 SDValue &Opc) {
127 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000128// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000129 // This always matches one way or another.
130 return true;
131 }
132
Tim Northover42180442013-08-22 09:57:11 +0000133 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
134 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
135 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
136 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
137 return true;
138 }
139
Owen Anderson2aedba62011-07-26 20:54:26 +0000140 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
141 SDValue &Offset, SDValue &Opc);
142 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000143 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000144 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
145 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000146 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000147 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000148 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000149 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000150 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000151 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000152 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000153 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000154 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000155
Evan Chengdfce83c2011-01-17 08:03:18 +0000156 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000157
Bill Wendling092a7bd2010-12-14 03:36:38 +0000158 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000159 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000160 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
161 unsigned Scale);
162 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
163 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
164 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
165 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
166 SDValue &OffImm);
167 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
168 SDValue &OffImm);
169 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
170 SDValue &OffImm);
171 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
172 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000173 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000174
Bill Wendling092a7bd2010-12-14 03:36:38 +0000175 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000176 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000177 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000178 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
179 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000180 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000181 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000182 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000183 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000184 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000185 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000186
Evan Cheng0fc80842010-11-12 22:42:47 +0000187 inline bool is_so_imm(unsigned Imm) const {
188 return ARM_AM::getSOImmVal(Imm) != -1;
189 }
190
191 inline bool is_so_imm_not(unsigned Imm) const {
192 return ARM_AM::getSOImmVal(~Imm) != -1;
193 }
194
195 inline bool is_t2_so_imm(unsigned Imm) const {
196 return ARM_AM::getT2SOImmVal(Imm) != -1;
197 }
198
199 inline bool is_t2_so_imm_not(unsigned Imm) const {
200 return ARM_AM::getT2SOImmVal(~Imm) != -1;
201 }
202
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000203 // Include the pieces autogenerated from the target description.
204#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000205
206private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000207 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
208 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000209 SDNode *SelectARMIndexedLoad(SDNode *N);
210 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000211
Bob Wilson340861d2010-03-23 05:25:43 +0000212 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
213 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000214 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000215 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000216 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000217 const uint16_t *DOpcodes,
218 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000219
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000220 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000221 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000222 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000223 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000224 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000225 const uint16_t *DOpcodes,
226 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000227
Bob Wilson93117bc2009-10-14 16:46:45 +0000228 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000229 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000230 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000231 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
232 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000233 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000234
Bob Wilson2d790df2010-11-28 06:51:26 +0000235 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
236 /// should be 2, 3 or 4. The opcode array specifies the instructions used
237 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000238 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000239 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000240
Bob Wilson5bc8a792010-07-07 00:08:54 +0000241 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
242 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
243 /// generated to force the table registers to be consecutive.
244 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000245
Sandeep Patel7460e082009-10-13 20:25:58 +0000246 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000247 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000248
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000249 // Select special operations if node forms integer ABS pattern
250 SDNode *SelectABSOp(SDNode *N);
251
Weiming Zhaoc5987002013-02-14 18:10:21 +0000252 SDNode *SelectInlineAsm(SDNode *N);
253
Evan Chengd85631e2010-05-05 18:28:36 +0000254 SDNode *SelectConcatVector(SDNode *N);
255
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +0000256 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
257
Evan Chengd9c55362009-07-02 01:23:32 +0000258 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
259 /// inline asm expressions.
260 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
261 char ConstraintCode,
262 std::vector<SDValue> &OutOps);
Bob Wilsone6b778d2009-10-06 22:01:59 +0000263
Weiming Zhao95782222012-11-17 00:23:35 +0000264 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000265 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000266 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
267 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
268 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000269
Bob Wilsond8a9a042010-06-04 00:04:02 +0000270 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000271 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
272 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
273 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-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 Espindolaffdc24b2006-05-14 22:18:28 +0000277};
Evan Cheng10043e22007-01-19 07:51:42 +0000278}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000279
Sandeep Patel423e42b2009-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 Dunbare0cd9ac2011-01-19 15:12:16 +0000304/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000305/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000306///
307/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000308static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000311 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-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 Chengeae6d2c2012-12-19 20:16:09 +0000326void ARMDAGToDAGISel::PreprocessISelDAG() {
327 if (!Subtarget->hasV6T2Ops())
328 return;
329
330 bool isThumb2 = Subtarget->isThumb();
331 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
332 E = CurDAG->allnodes_end(); I != E; ) {
333 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
334
335 if (N->getOpcode() != ISD::ADD)
336 continue;
337
338 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
339 // leading zeros, followed by consecutive set bits, followed by 1 or 2
340 // trailing zeros, e.g. 1020.
341 // Transform the expression to
342 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
343 // of trailing zeros of c2. The left shift would be folded as an shifter
344 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
345 // node (UBFX).
346
347 SDValue N0 = N->getOperand(0);
348 SDValue N1 = N->getOperand(1);
349 unsigned And_imm = 0;
350 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
351 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
352 std::swap(N0, N1);
353 }
354 if (!And_imm)
355 continue;
356
357 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000358 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000359 if (TZ != 1 && TZ != 2)
360 // Be conservative here. Shifter operands aren't always free. e.g. On
361 // Swift, left shifter operand of 1 / 2 for free but others are not.
362 // e.g.
363 // ubfx r3, r1, #16, #8
364 // ldr.w r3, [r0, r3, lsl #2]
365 // vs.
366 // mov.w r9, #1020
367 // and.w r2, r9, r1, lsr #14
368 // ldr r2, [r0, r2]
369 continue;
370 And_imm >>= TZ;
371 if (And_imm & (And_imm + 1))
372 continue;
373
374 // Look for (and (srl X, c1), c2).
375 SDValue Srl = N1.getOperand(0);
376 unsigned Srl_imm = 0;
377 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
378 (Srl_imm <= 2))
379 continue;
380
381 // Make sure first operand is not a shifter operand which would prevent
382 // folding of the left shift.
383 SDValue CPTmp0;
384 SDValue CPTmp1;
385 SDValue CPTmp2;
386 if (isThumb2) {
387 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
388 continue;
389 } else {
390 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
391 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
392 continue;
393 }
394
395 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000396 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000397 Srl.getOperand(0),
398 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000399 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000400 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000401 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000402 N1, CurDAG->getConstant(TZ, MVT::i32));
403 CurDAG->UpdateNodeOperands(N, N0, N1);
404 }
405}
406
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000407/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
408/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
409/// least on current ARM implementations) which should be avoidded.
410bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
411 if (OptLevel == CodeGenOpt::None)
412 return true;
413
414 if (!CheckVMLxHazard)
415 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000416
Silviu Baranga91ddaa12013-07-29 09:25:50 +0000417 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9() &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000418 !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000419 return true;
420
421 if (!N->hasOneUse())
422 return false;
423
424 SDNode *Use = *N->use_begin();
425 if (Use->getOpcode() == ISD::CopyToReg)
426 return true;
427 if (Use->isMachineOpcode()) {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000428 const ARMBaseInstrInfo *TII =
429 static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
430
Evan Cheng6cc775f2011-06-28 19:10:37 +0000431 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
432 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000433 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000434 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000435 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
436 return true;
437 // vmlx feeding into another vmlx. We actually want to unfold
438 // the use later in the MLxExpansion pass. e.g.
439 // vmla
440 // vmla (stall 8 cycles)
441 //
442 // vmul (5 cycles)
443 // vadd (5 cycles)
444 // vmla
445 // This adds up to about 18 - 19 cycles.
446 //
447 // vmla
448 // vmul (stall 4 cycles)
449 // vadd adds up to about 14 cycles.
450 return TII->isFpMLxInstruction(Opcode);
451 }
452
453 return false;
454}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000455
Evan Cheng59bbc542010-10-27 23:41:30 +0000456bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
457 ARM_AM::ShiftOpc ShOpcVal,
458 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000459 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000460 return true;
461 if (Shift.hasOneUse())
462 return true;
463 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000464 return ShOpcVal == ARM_AM::lsl &&
465 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000466}
467
Owen Andersonb595ed02011-07-21 18:54:16 +0000468bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000469 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000470 SDValue &Opc,
471 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000472 if (DisableShifterOp)
473 return false;
474
Evan Chenga20cde32011-07-20 23:34:39 +0000475 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000476
477 // Don't match base register only case. That is matched to a separate
478 // lower complexity pattern with explicit register operand.
479 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000480
Evan Chengb23b50d2009-06-29 07:51:04 +0000481 BaseReg = N.getOperand(0);
482 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000483 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
484 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000485 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000486 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
487 MVT::i32);
488 return true;
489}
490
Owen Andersonb595ed02011-07-21 18:54:16 +0000491bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
492 SDValue &BaseReg,
493 SDValue &ShReg,
494 SDValue &Opc,
495 bool CheckProfitability) {
496 if (DisableShifterOp)
497 return false;
498
499 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
500
501 // Don't match base register only case. That is matched to a separate
502 // lower complexity pattern with explicit register operand.
503 if (ShOpcVal == ARM_AM::no_shift) return false;
504
505 BaseReg = N.getOperand(0);
506 unsigned ShImmVal = 0;
507 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
508 if (RHS) return false;
509
510 ShReg = N.getOperand(1);
511 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
512 return false;
513 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
514 MVT::i32);
515 return true;
516}
517
518
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000519bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
520 SDValue &Base,
521 SDValue &OffImm) {
522 // Match simple R + imm12 operands.
523
524 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000525 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
526 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000527 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000528 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000529 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000530 Base = CurDAG->getTargetFrameIndex(FI,
531 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000532 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
533 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000534 }
Owen Anderson6d557452011-03-18 19:46:58 +0000535
Chris Lattner46c01a32011-02-13 22:25:43 +0000536 if (N.getOpcode() == ARMISD::Wrapper &&
537 !(Subtarget->useMovt() &&
538 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000539 Base = N.getOperand(0);
540 } else
541 Base = N;
542 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
543 return true;
544 }
545
546 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
547 int RHSC = (int)RHS->getZExtValue();
548 if (N.getOpcode() == ISD::SUB)
549 RHSC = -RHSC;
550
551 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
552 Base = N.getOperand(0);
553 if (Base.getOpcode() == ISD::FrameIndex) {
554 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000555 Base = CurDAG->getTargetFrameIndex(FI,
556 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000557 }
558 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
559 return true;
560 }
561 }
562
563 // Base only.
564 Base = N;
565 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
566 return true;
567}
568
569
570
571bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
572 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000573 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000574 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000575 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
576 // X * [3,5,9] -> X + X * [2,4,8] etc.
577 int RHSC = (int)RHS->getZExtValue();
578 if (RHSC & 1) {
579 RHSC = RHSC & ~1;
580 ARM_AM::AddrOpc AddSub = ARM_AM::add;
581 if (RHSC < 0) {
582 AddSub = ARM_AM::sub;
583 RHSC = - RHSC;
584 }
585 if (isPowerOf2_32(RHSC)) {
586 unsigned ShAmt = Log2_32(RHSC);
587 Base = Offset = N.getOperand(0);
588 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
589 ARM_AM::lsl),
590 MVT::i32);
591 return true;
592 }
593 }
594 }
595 }
596
Chris Lattner46c01a32011-02-13 22:25:43 +0000597 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
598 // ISD::OR that is equivalent to an ISD::ADD.
599 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000600 return false;
601
602 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000603 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000604 int RHSC;
605 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
606 -0x1000+1, 0x1000, RHSC)) // 12 bits.
607 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000608 }
609
610 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000611 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000612 ARM_AM::ShiftOpc ShOpcVal =
613 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000614 unsigned ShAmt = 0;
615
616 Base = N.getOperand(0);
617 Offset = N.getOperand(1);
618
619 if (ShOpcVal != ARM_AM::no_shift) {
620 // Check to see if the RHS of the shift is a constant, if not, we can't fold
621 // it.
622 if (ConstantSDNode *Sh =
623 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
624 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000625 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
626 Offset = N.getOperand(1).getOperand(0);
627 else {
628 ShAmt = 0;
629 ShOpcVal = ARM_AM::no_shift;
630 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000631 } else {
632 ShOpcVal = ARM_AM::no_shift;
633 }
634 }
635
636 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000637 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000638 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
639 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000640 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000641 if (ShOpcVal != ARM_AM::no_shift) {
642 // Check to see if the RHS of the shift is a constant, if not, we can't
643 // fold it.
644 if (ConstantSDNode *Sh =
645 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
646 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000647 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000648 Offset = N.getOperand(0).getOperand(0);
649 Base = N.getOperand(1);
650 } else {
651 ShAmt = 0;
652 ShOpcVal = ARM_AM::no_shift;
653 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000654 } else {
655 ShOpcVal = ARM_AM::no_shift;
656 }
657 }
658 }
659
660 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
661 MVT::i32);
662 return true;
663}
664
665
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000666//-----
667
Jim Grosbach08605202010-09-29 19:03:54 +0000668AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
669 SDValue &Base,
670 SDValue &Offset,
671 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000672 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000673 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000674 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
675 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000676 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000677 if (RHSC & 1) {
678 RHSC = RHSC & ~1;
679 ARM_AM::AddrOpc AddSub = ARM_AM::add;
680 if (RHSC < 0) {
681 AddSub = ARM_AM::sub;
682 RHSC = - RHSC;
683 }
684 if (isPowerOf2_32(RHSC)) {
685 unsigned ShAmt = Log2_32(RHSC);
686 Base = Offset = N.getOperand(0);
687 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
688 ARM_AM::lsl),
Owen Anderson9f944592009-08-11 20:47:22 +0000689 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000690 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000691 }
692 }
693 }
694 }
695
Chris Lattner46c01a32011-02-13 22:25:43 +0000696 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
697 // ISD::OR that is equivalent to an ADD.
698 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000699 Base = N;
700 if (N.getOpcode() == ISD::FrameIndex) {
701 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000702 Base = CurDAG->getTargetFrameIndex(FI,
703 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000704 } else if (N.getOpcode() == ARMISD::Wrapper &&
705 !(Subtarget->useMovt() &&
706 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000707 Base = N.getOperand(0);
708 }
Owen Anderson9f944592009-08-11 20:47:22 +0000709 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000710 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
711 ARM_AM::no_shift),
Owen Anderson9f944592009-08-11 20:47:22 +0000712 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000713 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000714 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000715
Evan Cheng10043e22007-01-19 07:51:42 +0000716 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000717 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000718 int RHSC;
719 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
720 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
721 Base = N.getOperand(0);
722 if (Base.getOpcode() == ISD::FrameIndex) {
723 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000724 Base = CurDAG->getTargetFrameIndex(FI,
725 getTargetLowering()->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000726 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000727 Offset = CurDAG->getRegister(0, MVT::i32);
728
729 ARM_AM::AddrOpc AddSub = ARM_AM::add;
730 if (RHSC < 0) {
731 AddSub = ARM_AM::sub;
732 RHSC = - RHSC;
733 }
734 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
735 ARM_AM::no_shift),
736 MVT::i32);
737 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000738 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000739 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000740
Bob Wilsone8a549c2012-09-29 21:43:49 +0000741 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000742 // Compute R +/- (R << N) and reuse it.
743 Base = N;
744 Offset = CurDAG->getRegister(0, MVT::i32);
745 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
746 ARM_AM::no_shift),
747 MVT::i32);
748 return AM2_BASE;
749 }
750
Johnny Chenb678a562009-10-27 17:25:15 +0000751 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000752 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000753 ARM_AM::ShiftOpc ShOpcVal =
754 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000755 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000756
Evan Cheng10043e22007-01-19 07:51:42 +0000757 Base = N.getOperand(0);
758 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000759
Evan Cheng10043e22007-01-19 07:51:42 +0000760 if (ShOpcVal != ARM_AM::no_shift) {
761 // Check to see if the RHS of the shift is a constant, if not, we can't fold
762 // it.
763 if (ConstantSDNode *Sh =
764 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000765 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000766 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
767 Offset = N.getOperand(1).getOperand(0);
768 else {
769 ShAmt = 0;
770 ShOpcVal = ARM_AM::no_shift;
771 }
Evan Cheng10043e22007-01-19 07:51:42 +0000772 } else {
773 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000774 }
775 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000776
Evan Cheng10043e22007-01-19 07:51:42 +0000777 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000778 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000779 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
780 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000781 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000782 if (ShOpcVal != ARM_AM::no_shift) {
783 // Check to see if the RHS of the shift is a constant, if not, we can't
784 // fold it.
785 if (ConstantSDNode *Sh =
786 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000787 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000788 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000789 Offset = N.getOperand(0).getOperand(0);
790 Base = N.getOperand(1);
791 } else {
792 ShAmt = 0;
793 ShOpcVal = ARM_AM::no_shift;
794 }
Evan Cheng10043e22007-01-19 07:51:42 +0000795 } else {
796 ShOpcVal = ARM_AM::no_shift;
797 }
798 }
799 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000800
Evan Cheng10043e22007-01-19 07:51:42 +0000801 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000802 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000803 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000804}
805
Owen Anderson2aedba62011-07-26 20:54:26 +0000806bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000807 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000808 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000809 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
810 ? cast<LoadSDNode>(Op)->getAddressingMode()
811 : cast<StoreSDNode>(Op)->getAddressingMode();
812 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
813 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000814 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000815 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
816 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000817
818 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000819 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000820 unsigned ShAmt = 0;
821 if (ShOpcVal != ARM_AM::no_shift) {
822 // Check to see if the RHS of the shift is a constant, if not, we can't fold
823 // it.
824 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000825 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000826 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
827 Offset = N.getOperand(0);
828 else {
829 ShAmt = 0;
830 ShOpcVal = ARM_AM::no_shift;
831 }
Evan Cheng10043e22007-01-19 07:51:42 +0000832 } else {
833 ShOpcVal = ARM_AM::no_shift;
834 }
835 }
836
837 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000838 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000839 return true;
840}
841
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000842bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
843 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000844 unsigned Opcode = Op->getOpcode();
845 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
846 ? cast<LoadSDNode>(Op)->getAddressingMode()
847 : cast<StoreSDNode>(Op)->getAddressingMode();
848 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
849 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000850 int Val;
851 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000852 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000853 Offset = CurDAG->getRegister(0, MVT::i32);
854 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
855 return true;
856 }
857
858 return false;
859}
860
861
Owen Anderson2aedba62011-07-26 20:54:26 +0000862bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
863 SDValue &Offset, SDValue &Opc) {
864 unsigned Opcode = Op->getOpcode();
865 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
866 ? cast<LoadSDNode>(Op)->getAddressingMode()
867 : cast<StoreSDNode>(Op)->getAddressingMode();
868 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
869 ? ARM_AM::add : ARM_AM::sub;
870 int Val;
871 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
872 Offset = CurDAG->getRegister(0, MVT::i32);
873 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
874 ARM_AM::no_shift),
875 MVT::i32);
876 return true;
877 }
878
879 return false;
880}
881
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000882bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
883 Base = N;
884 return true;
885}
Evan Cheng10043e22007-01-19 07:51:42 +0000886
Chris Lattner0e023ea2010-09-21 20:31:19 +0000887bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000888 SDValue &Base, SDValue &Offset,
889 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000890 if (N.getOpcode() == ISD::SUB) {
891 // X - C is canonicalize to X + -C, no need to handle it here.
892 Base = N.getOperand(0);
893 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000894 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000895 return true;
896 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000897
Chris Lattner46c01a32011-02-13 22:25:43 +0000898 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000899 Base = N;
900 if (N.getOpcode() == ISD::FrameIndex) {
901 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000902 Base = CurDAG->getTargetFrameIndex(FI,
903 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000904 }
Owen Anderson9f944592009-08-11 20:47:22 +0000905 Offset = CurDAG->getRegister(0, MVT::i32);
906 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000907 return true;
908 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000909
Evan Cheng10043e22007-01-19 07:51:42 +0000910 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000911 int RHSC;
912 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
913 -256 + 1, 256, RHSC)) { // 8 bits.
914 Base = N.getOperand(0);
915 if (Base.getOpcode() == ISD::FrameIndex) {
916 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000917 Base = CurDAG->getTargetFrameIndex(FI,
918 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000919 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000920 Offset = CurDAG->getRegister(0, MVT::i32);
921
922 ARM_AM::AddrOpc AddSub = ARM_AM::add;
923 if (RHSC < 0) {
924 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000925 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000926 }
927 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
928 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000929 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000930
Evan Cheng10043e22007-01-19 07:51:42 +0000931 Base = N.getOperand(0);
932 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000933 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000934 return true;
935}
936
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000937bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000938 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000939 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000940 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
941 ? cast<LoadSDNode>(Op)->getAddressingMode()
942 : cast<StoreSDNode>(Op)->getAddressingMode();
943 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
944 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000945 int Val;
946 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
947 Offset = CurDAG->getRegister(0, MVT::i32);
948 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
949 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000950 }
951
952 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000953 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000954 return true;
955}
956
Jim Grosbachd37f0712010-10-21 19:38:40 +0000957bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000958 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000959 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000960 Base = N;
961 if (N.getOpcode() == ISD::FrameIndex) {
962 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000963 Base = CurDAG->getTargetFrameIndex(FI,
964 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000965 } else if (N.getOpcode() == ARMISD::Wrapper &&
966 !(Subtarget->useMovt() &&
967 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000968 Base = N.getOperand(0);
969 }
970 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000971 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000972 return true;
973 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000974
Evan Cheng10043e22007-01-19 07:51:42 +0000975 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000976 int RHSC;
977 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
978 -256 + 1, 256, RHSC)) {
979 Base = N.getOperand(0);
980 if (Base.getOpcode() == ISD::FrameIndex) {
981 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000982 Base = CurDAG->getTargetFrameIndex(FI,
983 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000984 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000985
986 ARM_AM::AddrOpc AddSub = ARM_AM::add;
987 if (RHSC < 0) {
988 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000989 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000990 }
991 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
992 MVT::i32);
993 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000994 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000995
Evan Cheng10043e22007-01-19 07:51:42 +0000996 Base = N;
997 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000998 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000999 return true;
1000}
1001
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001002bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
1003 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +00001004 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001005
1006 unsigned Alignment = 0;
1007 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1008 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1009 // The maximum alignment is equal to the memory size being referenced.
1010 unsigned LSNAlign = LSN->getAlignment();
1011 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001012 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001013 Alignment = MemSize;
1014 } else {
1015 // All other uses of addrmode6 are for intrinsics. For now just record
1016 // the raw alignment value; it will be refined later based on the legal
1017 // alignment operands for the intrinsic.
1018 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1019 }
1020
1021 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001022 return true;
1023}
1024
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001025bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1026 SDValue &Offset) {
1027 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1028 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1029 if (AM != ISD::POST_INC)
1030 return false;
1031 Offset = N;
1032 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1033 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1034 Offset = CurDAG->getRegister(0, MVT::i32);
1035 }
1036 return true;
1037}
1038
Chris Lattner0e023ea2010-09-21 20:31:19 +00001039bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001040 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001041 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1042 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001043 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001044 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1045 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001046 return true;
1047 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001048
Evan Cheng10043e22007-01-19 07:51:42 +00001049 return false;
1050}
1051
Bill Wendling092a7bd2010-12-14 03:36:38 +00001052
1053//===----------------------------------------------------------------------===//
1054// Thumb Addressing Modes
1055//===----------------------------------------------------------------------===//
1056
Chris Lattner0e023ea2010-09-21 20:31:19 +00001057bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001058 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001059 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001060 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001061 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001062 return false;
1063
1064 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001065 return true;
1066 }
1067
Evan Cheng10043e22007-01-19 07:51:42 +00001068 Base = N.getOperand(0);
1069 Offset = N.getOperand(1);
1070 return true;
1071}
1072
Evan Cheng139edae2007-01-24 02:21:22 +00001073bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001074ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1075 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001076 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001077 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001078 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001079 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001080
Evan Cheng1526ba52007-01-24 08:53:17 +00001081 if (N.getOpcode() == ARMISD::Wrapper &&
1082 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1083 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001084 }
1085
Chris Lattner46c01a32011-02-13 22:25:43 +00001086 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001087 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001088
Evan Cheng650d0672007-02-06 00:22:06 +00001089 // Thumb does not have [sp, r] address mode.
1090 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1091 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1092 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001093 (RHSR && RHSR->getReg() == ARM::SP))
1094 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001095
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001096 // FIXME: Why do we explicitly check for a match here and then return false?
1097 // Presumably to allow something else to match, but shouldn't this be
1098 // documented?
1099 int RHSC;
1100 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1101 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001102
1103 Base = N.getOperand(0);
1104 Offset = N.getOperand(1);
1105 return true;
1106}
1107
1108bool
1109ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1110 SDValue &Base,
1111 SDValue &Offset) {
1112 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1113}
1114
1115bool
1116ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1117 SDValue &Base,
1118 SDValue &Offset) {
1119 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1120}
1121
1122bool
1123ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1124 SDValue &Base,
1125 SDValue &Offset) {
1126 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1127}
1128
1129bool
1130ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1131 SDValue &Base, SDValue &OffImm) {
1132 if (Scale == 4) {
1133 SDValue TmpBase, TmpOffImm;
1134 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1135 return false; // We want to select tLDRspi / tSTRspi instead.
1136
1137 if (N.getOpcode() == ARMISD::Wrapper &&
1138 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1139 return false; // We want to select tLDRpci instead.
1140 }
1141
Chris Lattner46c01a32011-02-13 22:25:43 +00001142 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001143 if (N.getOpcode() == ARMISD::Wrapper &&
1144 !(Subtarget->useMovt() &&
1145 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1146 Base = N.getOperand(0);
1147 } else {
1148 Base = N;
1149 }
1150
Owen Anderson9f944592009-08-11 20:47:22 +00001151 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001152 return true;
1153 }
1154
Bill Wendling832a5da2010-12-15 01:03:19 +00001155 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1156 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1157 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1158 (RHSR && RHSR->getReg() == ARM::SP)) {
1159 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1160 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1161 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1162 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1163
1164 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1165 if (LHSC != 0 || RHSC != 0) return false;
1166
1167 Base = N;
1168 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1169 return true;
1170 }
1171
Evan Cheng10043e22007-01-19 07:51:42 +00001172 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001173 int RHSC;
1174 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1175 Base = N.getOperand(0);
1176 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1177 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001178 }
1179
Evan Chengc0b73662007-01-23 22:59:13 +00001180 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001181 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001182 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001183}
1184
Bill Wendling092a7bd2010-12-14 03:36:38 +00001185bool
1186ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1187 SDValue &OffImm) {
1188 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001189}
1190
Bill Wendling092a7bd2010-12-14 03:36:38 +00001191bool
1192ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1193 SDValue &OffImm) {
1194 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001195}
1196
Bill Wendling092a7bd2010-12-14 03:36:38 +00001197bool
1198ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1199 SDValue &OffImm) {
1200 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001201}
1202
Chris Lattner0e023ea2010-09-21 20:31:19 +00001203bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1204 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001205 if (N.getOpcode() == ISD::FrameIndex) {
1206 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001207 Base = CurDAG->getTargetFrameIndex(FI,
1208 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001209 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001210 return true;
1211 }
Evan Cheng139edae2007-01-24 02:21:22 +00001212
Chris Lattner46c01a32011-02-13 22:25:43 +00001213 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001214 return false;
1215
1216 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001217 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1218 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001219 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001220 int RHSC;
1221 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1222 Base = N.getOperand(0);
1223 if (Base.getOpcode() == ISD::FrameIndex) {
1224 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001225 Base = CurDAG->getTargetFrameIndex(FI,
1226 getTargetLowering()->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001227 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001228 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1229 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001230 }
1231 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001232
Evan Cheng10043e22007-01-19 07:51:42 +00001233 return false;
1234}
1235
Bill Wendling092a7bd2010-12-14 03:36:38 +00001236
1237//===----------------------------------------------------------------------===//
1238// Thumb 2 Addressing Modes
1239//===----------------------------------------------------------------------===//
1240
1241
Chris Lattner0e023ea2010-09-21 20:31:19 +00001242bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001243 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001244 if (DisableShifterOp)
1245 return false;
1246
Evan Chenga20cde32011-07-20 23:34:39 +00001247 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001248
1249 // Don't match base register only case. That is matched to a separate
1250 // lower complexity pattern with explicit register operand.
1251 if (ShOpcVal == ARM_AM::no_shift) return false;
1252
1253 BaseReg = N.getOperand(0);
1254 unsigned ShImmVal = 0;
1255 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1256 ShImmVal = RHS->getZExtValue() & 31;
1257 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1258 return true;
1259 }
1260
1261 return false;
1262}
1263
Chris Lattner0e023ea2010-09-21 20:31:19 +00001264bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001265 SDValue &Base, SDValue &OffImm) {
1266 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001267
Evan Cheng36064672009-08-11 08:52:18 +00001268 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001269 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1270 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001271 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001272 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001273 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001274 Base = CurDAG->getTargetFrameIndex(FI,
1275 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001276 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001277 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001278 }
Owen Anderson6d557452011-03-18 19:46:58 +00001279
Chris Lattner46c01a32011-02-13 22:25:43 +00001280 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov25229082009-11-24 00:44:37 +00001281 !(Subtarget->useMovt() &&
1282 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng36064672009-08-11 08:52:18 +00001283 Base = N.getOperand(0);
1284 if (Base.getOpcode() == ISD::TargetConstantPool)
1285 return false; // We want to select t2LDRpci instead.
1286 } else
1287 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001288 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001289 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001290 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001291
1292 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001293 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001294 // Let t2LDRi8 handle (R - imm8).
1295 return false;
1296
Evan Chengb23b50d2009-06-29 07:51:04 +00001297 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001298 if (N.getOpcode() == ISD::SUB)
1299 RHSC = -RHSC;
1300
1301 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001302 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001303 if (Base.getOpcode() == ISD::FrameIndex) {
1304 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001305 Base = CurDAG->getTargetFrameIndex(FI,
1306 getTargetLowering()->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001307 }
Owen Anderson9f944592009-08-11 20:47:22 +00001308 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001309 return true;
1310 }
1311 }
1312
Evan Cheng36064672009-08-11 08:52:18 +00001313 // Base only.
1314 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001315 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001316 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001317}
1318
Chris Lattner0e023ea2010-09-21 20:31:19 +00001319bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001320 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001321 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001322 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1323 !CurDAG->isBaseWithConstantOffset(N))
1324 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001325
Chris Lattner46c01a32011-02-13 22:25:43 +00001326 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1327 int RHSC = (int)RHS->getSExtValue();
1328 if (N.getOpcode() == ISD::SUB)
1329 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001330
Chris Lattner46c01a32011-02-13 22:25:43 +00001331 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1332 Base = N.getOperand(0);
1333 if (Base.getOpcode() == ISD::FrameIndex) {
1334 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001335 Base = CurDAG->getTargetFrameIndex(FI,
1336 getTargetLowering()->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001337 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001338 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1339 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001340 }
1341 }
1342
1343 return false;
1344}
1345
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001346bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001347 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001348 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001349 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1350 ? cast<LoadSDNode>(Op)->getAddressingMode()
1351 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001352 int RHSC;
1353 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1354 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1355 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1356 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1357 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001358 }
1359
1360 return false;
1361}
1362
Chris Lattner0e023ea2010-09-21 20:31:19 +00001363bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001364 SDValue &Base,
1365 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001366 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001367 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001368 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001369
Evan Cheng36064672009-08-11 08:52:18 +00001370 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1371 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1372 int RHSC = (int)RHS->getZExtValue();
1373 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1374 return false;
1375 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001376 return false;
1377 }
1378
Evan Chengb23b50d2009-06-29 07:51:04 +00001379 // Look for (R + R) or (R + (R << [1,2,3])).
1380 unsigned ShAmt = 0;
1381 Base = N.getOperand(0);
1382 OffReg = N.getOperand(1);
1383
1384 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001385 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001386 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001387 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001388 if (ShOpcVal == ARM_AM::lsl)
1389 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001390 }
1391
Evan Chengb23b50d2009-06-29 07:51:04 +00001392 if (ShOpcVal == ARM_AM::lsl) {
1393 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1394 // it.
1395 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1396 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001397 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1398 OffReg = OffReg.getOperand(0);
1399 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001400 ShAmt = 0;
1401 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001402 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001403 } else {
1404 ShOpcVal = ARM_AM::no_shift;
1405 }
David Goodwinf3912052009-07-15 15:50:19 +00001406 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001407
Owen Anderson9f944592009-08-11 20:47:22 +00001408 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001409
1410 return true;
1411}
1412
Tim Northovera7ecd242013-07-16 09:46:55 +00001413bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1414 SDValue &OffImm) {
1415 // This *must* succeed since it's used for the irreplacable ldrex and strex
1416 // instructions.
1417 Base = N;
1418 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1419
1420 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1421 return true;
1422
1423 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1424 if (!RHS)
1425 return true;
1426
1427 uint32_t RHSC = (int)RHS->getZExtValue();
1428 if (RHSC > 1020 || RHSC % 4 != 0)
1429 return true;
1430
1431 Base = N.getOperand(0);
1432 if (Base.getOpcode() == ISD::FrameIndex) {
1433 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1434 Base = CurDAG->getTargetFrameIndex(FI, getTargetLowering()->getPointerTy());
1435 }
1436
1437 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1438 return true;
1439}
1440
Evan Chengb23b50d2009-06-29 07:51:04 +00001441//===--------------------------------------------------------------------===//
1442
Evan Cheng7e90b112007-07-05 07:15:27 +00001443/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001444static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001445 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001446}
1447
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001448SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1449 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001450 ISD::MemIndexedMode AM = LD->getAddressingMode();
1451 if (AM == ISD::UNINDEXED)
1452 return NULL;
1453
Owen Anderson53aa7a92009-08-10 22:56:29 +00001454 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001455 SDValue Offset, AMOpc;
1456 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1457 unsigned Opcode = 0;
1458 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001459 if (LoadedVT == MVT::i32 && isPre &&
1460 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1461 Opcode = ARM::LDR_PRE_IMM;
1462 Match = true;
1463 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001464 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001465 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001466 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001467 } else if (LoadedVT == MVT::i32 &&
1468 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001469 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001470 Match = true;
1471
Owen Anderson9f944592009-08-11 20:47:22 +00001472 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001473 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001474 Match = true;
1475 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1476 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1477 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001478 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001479 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001480 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001481 Match = true;
1482 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1483 }
1484 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001485 if (isPre &&
1486 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001487 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001488 Opcode = ARM::LDRB_PRE_IMM;
1489 } else if (!isPre &&
1490 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1491 Match = true;
1492 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001493 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1494 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001495 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001496 }
1497 }
1498 }
1499
1500 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001501 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1502 SDValue Chain = LD->getChain();
1503 SDValue Base = LD->getBasePtr();
1504 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1505 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001506 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001507 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001508 } else {
1509 SDValue Chain = LD->getChain();
1510 SDValue Base = LD->getBasePtr();
1511 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1512 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001513 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001514 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001515 }
Evan Chengd9c55362009-07-02 01:23:32 +00001516 }
1517
1518 return NULL;
1519}
1520
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001521SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1522 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001523 ISD::MemIndexedMode AM = LD->getAddressingMode();
1524 if (AM == ISD::UNINDEXED)
1525 return NULL;
1526
Owen Anderson53aa7a92009-08-10 22:56:29 +00001527 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001528 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001529 SDValue Offset;
1530 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1531 unsigned Opcode = 0;
1532 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001533 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001534 switch (LoadedVT.getSimpleVT().SimpleTy) {
1535 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001536 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1537 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001538 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001539 if (isSExtLd)
1540 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1541 else
1542 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001543 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001544 case MVT::i8:
1545 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001546 if (isSExtLd)
1547 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1548 else
1549 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001550 break;
1551 default:
1552 return NULL;
1553 }
1554 Match = true;
1555 }
1556
1557 if (Match) {
1558 SDValue Chain = LD->getChain();
1559 SDValue Base = LD->getBasePtr();
1560 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001561 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001562 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001563 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001564 }
1565
1566 return NULL;
1567}
1568
Weiming Zhao8f56f882012-11-16 21:55:34 +00001569/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1570SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001571 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001572 SDValue RegClass =
1573 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1574 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1575 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1576 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001577 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001578}
1579
Weiming Zhao95782222012-11-17 00:23:35 +00001580/// \brief Form a D register from a pair of S registers.
1581SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001582 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001583 SDValue RegClass =
1584 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001585 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1586 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001587 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001588 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001589}
1590
Weiming Zhao95782222012-11-17 00:23:35 +00001591/// \brief Form a quad register from a pair of D registers.
1592SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001593 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001594 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001595 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1596 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001597 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001598 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001599}
1600
Weiming Zhao95782222012-11-17 00:23:35 +00001601/// \brief Form 4 consecutive D registers from a pair of Q registers.
1602SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001603 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001604 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001605 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1606 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001607 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001608 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001609}
1610
Weiming Zhao95782222012-11-17 00:23:35 +00001611/// \brief Form 4 consecutive S registers.
1612SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001613 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001614 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001615 SDValue RegClass =
1616 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001617 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1618 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1619 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1620 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001621 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1622 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001623 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001624}
1625
Weiming Zhao95782222012-11-17 00:23:35 +00001626/// \brief Form 4 consecutive D registers.
1627SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001628 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001629 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001630 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001631 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1632 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1633 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1634 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001635 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1636 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001637 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001638}
1639
Weiming Zhao95782222012-11-17 00:23:35 +00001640/// \brief Form 4 consecutive Q registers.
1641SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001642 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001643 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001644 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001645 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1646 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1647 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1648 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001649 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1650 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001651 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001652}
1653
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001654/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1655/// of a NEON VLD or VST instruction. The supported values depend on the
1656/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001657SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1658 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001659 unsigned NumRegs = NumVecs;
1660 if (!is64BitVector && NumVecs < 3)
1661 NumRegs *= 2;
1662
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001663 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001664 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001665 Alignment = 32;
1666 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1667 Alignment = 16;
1668 else if (Alignment >= 8)
1669 Alignment = 8;
1670 else
1671 Alignment = 0;
1672
1673 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001674}
1675
Jim Grosbach2098cb12011-10-24 21:45:13 +00001676// Get the register stride update opcode of a VLD/VST instruction that
1677// is otherwise equivalent to the given fixed stride updating instruction.
1678static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1679 switch (Opc) {
1680 default: break;
1681 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1682 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1683 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1684 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1685 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1686 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1687 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1688 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001689
1690 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1691 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1692 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1693 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1694 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1695 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1696 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1697 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001698 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001699 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001700
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001701 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1702 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1703 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001704 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1705 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1706 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1707
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001708 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1709 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1710 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001711 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1712 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1713 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001714
Jim Grosbach13a292c2012-03-06 22:01:44 +00001715 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1716 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1717 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001718 }
1719 return Opc; // If not one we handle, return it unchanged.
1720}
1721
Bob Wilson06fce872011-02-07 17:43:21 +00001722SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001723 const uint16_t *DOpcodes,
1724 const uint16_t *QOpcodes0,
1725 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001726 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001727 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001728
Bob Wilsonae08a732010-03-20 22:13:40 +00001729 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001730 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1731 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson12b47992009-10-14 17:28:52 +00001732 return NULL;
1733
1734 SDValue Chain = N->getOperand(0);
1735 EVT VT = N->getValueType(0);
1736 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001737 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001738
Bob Wilson12b47992009-10-14 17:28:52 +00001739 unsigned OpcodeIndex;
1740 switch (VT.getSimpleVT().SimpleTy) {
1741 default: llvm_unreachable("unhandled vld type");
1742 // Double-register operations:
1743 case MVT::v8i8: OpcodeIndex = 0; break;
1744 case MVT::v4i16: OpcodeIndex = 1; break;
1745 case MVT::v2f32:
1746 case MVT::v2i32: OpcodeIndex = 2; break;
1747 case MVT::v1i64: OpcodeIndex = 3; break;
1748 // Quad-register operations:
1749 case MVT::v16i8: OpcodeIndex = 0; break;
1750 case MVT::v8i16: OpcodeIndex = 1; break;
1751 case MVT::v4f32:
1752 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001753 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001754 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001755 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001756 }
1757
Bob Wilson35fafca2010-09-03 18:16:02 +00001758 EVT ResTy;
1759 if (NumVecs == 1)
1760 ResTy = VT;
1761 else {
1762 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1763 if (!is64BitVector)
1764 ResTyElts *= 2;
1765 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1766 }
Bob Wilson06fce872011-02-07 17:43:21 +00001767 std::vector<EVT> ResTys;
1768 ResTys.push_back(ResTy);
1769 if (isUpdating)
1770 ResTys.push_back(MVT::i32);
1771 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001772
Evan Cheng3da64f762010-04-16 05:46:06 +00001773 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001774 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001775 SDNode *VLd;
1776 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001777
Bob Wilson06fce872011-02-07 17:43:21 +00001778 // Double registers and VLD1/VLD2 quad registers are directly supported.
1779 if (is64BitVector || NumVecs <= 2) {
1780 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1781 QOpcodes0[OpcodeIndex]);
1782 Ops.push_back(MemAddr);
1783 Ops.push_back(Align);
1784 if (isUpdating) {
1785 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001786 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001787 // case entirely when the rest are updated to that form, too.
Jim Grosbachd146a022011-12-09 21:28:25 +00001788 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001789 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbachd146a022011-12-09 21:28:25 +00001790 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001791 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001792 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001793 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001794 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001795 }
Bob Wilson06fce872011-02-07 17:43:21 +00001796 Ops.push_back(Pred);
1797 Ops.push_back(Reg0);
1798 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001799 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001800
Bob Wilson12b47992009-10-14 17:28:52 +00001801 } else {
1802 // Otherwise, quad registers are loaded with two separate instructions,
1803 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001804 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001805
Bob Wilson06fce872011-02-07 17:43:21 +00001806 // Load the even subregs. This is always an updating load, so that it
1807 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001808 SDValue ImplDef =
1809 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1810 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001811 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001812 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001813 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001814
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001815 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001816 Ops.push_back(SDValue(VLdA, 1));
1817 Ops.push_back(Align);
1818 if (isUpdating) {
1819 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1820 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1821 "only constant post-increment update allowed for VLD3/4");
1822 (void)Inc;
1823 Ops.push_back(Reg0);
1824 }
1825 Ops.push_back(SDValue(VLdA, 0));
1826 Ops.push_back(Pred);
1827 Ops.push_back(Reg0);
1828 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001829 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001830 }
Bob Wilson12b47992009-10-14 17:28:52 +00001831
Evan Cheng40791332011-04-19 00:04:03 +00001832 // Transfer memoperands.
1833 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1834 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1835 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1836
Bob Wilson06fce872011-02-07 17:43:21 +00001837 if (NumVecs == 1)
1838 return VLd;
1839
1840 // Extract out the subregisters.
1841 SDValue SuperReg = SDValue(VLd, 0);
1842 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1843 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1844 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1845 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1846 ReplaceUses(SDValue(N, Vec),
1847 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1848 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1849 if (isUpdating)
1850 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson12b47992009-10-14 17:28:52 +00001851 return NULL;
1852}
1853
Bob Wilson06fce872011-02-07 17:43:21 +00001854SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001855 const uint16_t *DOpcodes,
1856 const uint16_t *QOpcodes0,
1857 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001858 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001859 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001860
Bob Wilsonae08a732010-03-20 22:13:40 +00001861 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001862 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1863 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1864 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001865 return NULL;
1866
Evan Cheng40791332011-04-19 00:04:03 +00001867 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1868 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1869
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001870 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001871 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001872 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001873 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001874
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001875 unsigned OpcodeIndex;
1876 switch (VT.getSimpleVT().SimpleTy) {
1877 default: llvm_unreachable("unhandled vst type");
1878 // Double-register operations:
1879 case MVT::v8i8: OpcodeIndex = 0; break;
1880 case MVT::v4i16: OpcodeIndex = 1; break;
1881 case MVT::v2f32:
1882 case MVT::v2i32: OpcodeIndex = 2; break;
1883 case MVT::v1i64: OpcodeIndex = 3; break;
1884 // Quad-register operations:
1885 case MVT::v16i8: OpcodeIndex = 0; break;
1886 case MVT::v8i16: OpcodeIndex = 1; break;
1887 case MVT::v4f32:
1888 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001889 case MVT::v2i64: OpcodeIndex = 3;
1890 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1891 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001892 }
1893
Bob Wilson06fce872011-02-07 17:43:21 +00001894 std::vector<EVT> ResTys;
1895 if (isUpdating)
1896 ResTys.push_back(MVT::i32);
1897 ResTys.push_back(MVT::Other);
1898
Evan Cheng3da64f762010-04-16 05:46:06 +00001899 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001900 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001901 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001902
Bob Wilson06fce872011-02-07 17:43:21 +00001903 // Double registers and VST1/VST2 quad registers are directly supported.
1904 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001905 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001906 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001907 SrcReg = N->getOperand(Vec0Idx);
1908 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001909 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001910 SDValue V0 = N->getOperand(Vec0Idx + 0);
1911 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001912 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001913 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001914 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001915 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001916 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001917 // an undef.
1918 SDValue V3 = (NumVecs == 3)
1919 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001920 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001921 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001922 }
Bob Wilson950882b2010-08-28 05:12:57 +00001923 } else {
1924 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001925 SDValue Q0 = N->getOperand(Vec0Idx);
1926 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001927 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001928 }
Bob Wilson06fce872011-02-07 17:43:21 +00001929
1930 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1931 QOpcodes0[OpcodeIndex]);
1932 Ops.push_back(MemAddr);
1933 Ops.push_back(Align);
1934 if (isUpdating) {
1935 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001936 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001937 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001938 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001939 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1940 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1941 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001942 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001943 !isa<ConstantSDNode>(Inc.getNode()))
1944 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson06fce872011-02-07 17:43:21 +00001945 }
1946 Ops.push_back(SrcReg);
1947 Ops.push_back(Pred);
1948 Ops.push_back(Reg0);
1949 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001950 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001951
1952 // Transfer memoperands.
1953 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1954
1955 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001956 }
1957
1958 // Otherwise, quad registers are stored with two separate instructions,
1959 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00001960
Bob Wilson01ac8f92010-06-16 21:34:01 +00001961 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00001962 SDValue V0 = N->getOperand(Vec0Idx + 0);
1963 SDValue V1 = N->getOperand(Vec0Idx + 1);
1964 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00001965 SDValue V3 = (NumVecs == 3)
1966 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001967 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001968 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001969
Bob Wilson06fce872011-02-07 17:43:21 +00001970 // Store the even D registers. This is always an updating store, so that it
1971 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00001972 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1973 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1974 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00001975 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00001976 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001977 Chain = SDValue(VStA, 1);
1978
1979 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00001980 Ops.push_back(SDValue(VStA, 0));
1981 Ops.push_back(Align);
1982 if (isUpdating) {
1983 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1984 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1985 "only constant post-increment update allowed for VST3/4");
1986 (void)Inc;
1987 Ops.push_back(Reg0);
1988 }
1989 Ops.push_back(RegSeq);
1990 Ops.push_back(Pred);
1991 Ops.push_back(Reg0);
1992 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00001993 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00001994 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001995 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1996 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001997}
1998
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001999SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00002000 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00002001 const uint16_t *DOpcodes,
2002 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002003 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002004 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002005
Bob Wilsonae08a732010-03-20 22:13:40 +00002006 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002007 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2008 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2009 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson4145e3a2009-10-14 16:19:03 +00002010 return NULL;
2011
Evan Cheng40791332011-04-19 00:04:03 +00002012 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2013 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2014
Bob Wilson4145e3a2009-10-14 16:19:03 +00002015 SDValue Chain = N->getOperand(0);
2016 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002017 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2018 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002019 bool is64BitVector = VT.is64BitVector();
2020
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002021 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002022 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002023 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002024 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2025 if (Alignment > NumBytes)
2026 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002027 if (Alignment < 8 && Alignment < NumBytes)
2028 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002029 // Alignment must be a power of two; make sure of that.
2030 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002031 if (Alignment == 1)
2032 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002033 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002034 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002035
Bob Wilson4145e3a2009-10-14 16:19:03 +00002036 unsigned OpcodeIndex;
2037 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002038 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002039 // Double-register operations:
2040 case MVT::v8i8: OpcodeIndex = 0; break;
2041 case MVT::v4i16: OpcodeIndex = 1; break;
2042 case MVT::v2f32:
2043 case MVT::v2i32: OpcodeIndex = 2; break;
2044 // Quad-register operations:
2045 case MVT::v8i16: OpcodeIndex = 0; break;
2046 case MVT::v4f32:
2047 case MVT::v4i32: OpcodeIndex = 1; break;
2048 }
2049
Bob Wilson06fce872011-02-07 17:43:21 +00002050 std::vector<EVT> ResTys;
2051 if (IsLoad) {
2052 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2053 if (!is64BitVector)
2054 ResTyElts *= 2;
2055 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2056 MVT::i64, ResTyElts));
2057 }
2058 if (isUpdating)
2059 ResTys.push_back(MVT::i32);
2060 ResTys.push_back(MVT::Other);
2061
Evan Cheng3da64f762010-04-16 05:46:06 +00002062 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002063 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002064
Bob Wilson06fce872011-02-07 17:43:21 +00002065 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002066 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002067 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002068 if (isUpdating) {
2069 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2070 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2071 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002072
Bob Wilsond5c57a52010-09-13 23:01:35 +00002073 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002074 SDValue V0 = N->getOperand(Vec0Idx + 0);
2075 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002076 if (NumVecs == 2) {
2077 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002078 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002079 else
Weiming Zhao95782222012-11-17 00:23:35 +00002080 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002081 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002082 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002083 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002084 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2085 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002086 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002087 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002088 else
Weiming Zhao95782222012-11-17 00:23:35 +00002089 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002090 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002091 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002092 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002093 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002094 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002095 Ops.push_back(Chain);
2096
Bob Wilson06fce872011-02-07 17:43:21 +00002097 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2098 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002099 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002100 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002101 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002102 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002103
Bob Wilsond5c57a52010-09-13 23:01:35 +00002104 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002105 SuperReg = SDValue(VLdLn, 0);
2106 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2107 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2108 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002109 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2110 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002111 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2112 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2113 if (isUpdating)
2114 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilson4145e3a2009-10-14 16:19:03 +00002115 return NULL;
2116}
2117
Bob Wilson06fce872011-02-07 17:43:21 +00002118SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002119 unsigned NumVecs,
2120 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002121 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002122 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002123
2124 SDValue MemAddr, Align;
2125 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2126 return NULL;
2127
Evan Cheng40791332011-04-19 00:04:03 +00002128 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2129 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2130
Bob Wilson2d790df2010-11-28 06:51:26 +00002131 SDValue Chain = N->getOperand(0);
2132 EVT VT = N->getValueType(0);
2133
2134 unsigned Alignment = 0;
2135 if (NumVecs != 3) {
2136 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2137 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2138 if (Alignment > NumBytes)
2139 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002140 if (Alignment < 8 && Alignment < NumBytes)
2141 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002142 // Alignment must be a power of two; make sure of that.
2143 Alignment = (Alignment & -Alignment);
2144 if (Alignment == 1)
2145 Alignment = 0;
2146 }
2147 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2148
2149 unsigned OpcodeIndex;
2150 switch (VT.getSimpleVT().SimpleTy) {
2151 default: llvm_unreachable("unhandled vld-dup type");
2152 case MVT::v8i8: OpcodeIndex = 0; break;
2153 case MVT::v4i16: OpcodeIndex = 1; break;
2154 case MVT::v2f32:
2155 case MVT::v2i32: OpcodeIndex = 2; break;
2156 }
2157
2158 SDValue Pred = getAL(CurDAG);
2159 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2160 SDValue SuperReg;
2161 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002162 SmallVector<SDValue, 6> Ops;
2163 Ops.push_back(MemAddr);
2164 Ops.push_back(Align);
2165 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002166 // fixed-stride update instructions don't have an explicit writeback
2167 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002168 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002169 if (!isa<ConstantSDNode>(Inc.getNode()))
2170 Ops.push_back(Inc);
2171 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2172 else if (NumVecs > 2)
2173 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002174 }
2175 Ops.push_back(Pred);
2176 Ops.push_back(Reg0);
2177 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002178
2179 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002180 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002181 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002182 if (isUpdating)
2183 ResTys.push_back(MVT::i32);
2184 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002185 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002186 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002187 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002188
2189 // Extract the subregisters.
2190 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2191 unsigned SubIdx = ARM::dsub_0;
2192 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2193 ReplaceUses(SDValue(N, Vec),
2194 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002195 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2196 if (isUpdating)
2197 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilson2d790df2010-11-28 06:51:26 +00002198 return NULL;
2199}
2200
Bob Wilson5bc8a792010-07-07 00:08:54 +00002201SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2202 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002203 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002204 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002205 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002206 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002207
2208 // Form a REG_SEQUENCE to force register allocation.
2209 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002210 SDValue V0 = N->getOperand(FirstTblReg + 0);
2211 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002212 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002213 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002214 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002215 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002216 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002217 // an undef.
2218 SDValue V3 = (NumVecs == 3)
2219 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002220 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002221 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002222 }
2223
Bob Wilson5bc8a792010-07-07 00:08:54 +00002224 SmallVector<SDValue, 6> Ops;
2225 if (IsExt)
2226 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002227 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002228 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002229 Ops.push_back(getAL(CurDAG)); // predicate
2230 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002231 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002232}
2233
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002234SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002235 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002236 if (!Subtarget->hasV6T2Ops())
2237 return NULL;
Bob Wilson93117bc2009-10-14 16:46:45 +00002238
Evan Chengeae6d2c2012-12-19 20:16:09 +00002239 unsigned Opc = isSigned
2240 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002241 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2242
Jim Grosbach825cb292010-04-22 23:24:18 +00002243 // For unsigned extracts, check for a shift right and mask
2244 unsigned And_imm = 0;
2245 if (N->getOpcode() == ISD::AND) {
2246 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2247
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002248 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002249 if (And_imm & (And_imm + 1))
2250 return NULL;
2251
2252 unsigned Srl_imm = 0;
2253 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2254 Srl_imm)) {
2255 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2256
Jim Grosbach03f56d92011-07-27 21:09:25 +00002257 // Note: The width operand is encoded as width-1.
2258 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002259 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002260
Jim Grosbach825cb292010-04-22 23:24:18 +00002261 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002262
2263 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2264 // It's cheaper to use a right shift to extract the top bits.
2265 if (Subtarget->isThumb()) {
2266 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2267 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2268 CurDAG->getTargetConstant(LSB, MVT::i32),
2269 getAL(CurDAG), Reg0, Reg0 };
2270 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2271 }
2272
2273 // ARM models shift instructions as MOVsi with shifter operand.
2274 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2275 SDValue ShOpc =
2276 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2277 MVT::i32);
2278 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2279 getAL(CurDAG), Reg0, Reg0 };
2280 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops, 5);
2281 }
2282
Jim Grosbach825cb292010-04-22 23:24:18 +00002283 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2284 CurDAG->getTargetConstant(LSB, MVT::i32),
2285 CurDAG->getTargetConstant(Width, MVT::i32),
2286 getAL(CurDAG), Reg0 };
2287 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2288 }
2289 }
2290 return NULL;
2291 }
2292
2293 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002294 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002295 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002296 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2297 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002298 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002299 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002300 // Note: The width operand is encoded as width-1.
2301 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002302 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002303 if (LSB < 0)
Sandeep Patel423e42b2009-10-13 18:59:48 +00002304 return NULL;
2305 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002306 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002307 CurDAG->getTargetConstant(LSB, MVT::i32),
2308 CurDAG->getTargetConstant(Width, MVT::i32),
2309 getAL(CurDAG), Reg0 };
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002310 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002311 }
2312 }
2313 return NULL;
2314}
2315
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002316/// Target-specific DAG combining for ISD::XOR.
2317/// Target-independent combining lowers SELECT_CC nodes of the form
2318/// select_cc setg[ge] X, 0, X, -X
2319/// select_cc setgt X, -1, X, -X
2320/// select_cc setl[te] X, 0, -X, X
2321/// select_cc setlt X, 1, -X, X
2322/// which represent Integer ABS into:
2323/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2324/// ARM instruction selection detects the latter and matches it to
2325/// ARM::ABS or ARM::t2ABS machine node.
2326SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2327 SDValue XORSrc0 = N->getOperand(0);
2328 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002329 EVT VT = N->getValueType(0);
2330
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002331 if (Subtarget->isThumb1Only())
2332 return NULL;
2333
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002334 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002335 return NULL;
2336
2337 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2338 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2339 SDValue SRASrc0 = XORSrc1.getOperand(0);
2340 SDValue SRASrc1 = XORSrc1.getOperand(1);
2341 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2342 EVT XType = SRASrc0.getValueType();
2343 unsigned Size = XType.getSizeInBits() - 1;
2344
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002345 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2346 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002347 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002348 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002349 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2350 }
2351
2352 return NULL;
2353}
2354
Evan Chengd85631e2010-05-05 18:28:36 +00002355SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2356 // The only time a CONCAT_VECTORS operation can have legal types is when
2357 // two 64-bit vectors are concatenated to a 128-bit vector.
2358 EVT VT = N->getValueType(0);
2359 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2360 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002361 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002362}
2363
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002364SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002365 SmallVector<SDValue, 6> Ops;
2366 Ops.push_back(Node->getOperand(1)); // Ptr
2367 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2368 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Anderson939cd212011-08-31 20:00:11 +00002369 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002370 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2371 Ops.push_back(Node->getOperand(5)); // High part of Val2
2372 }
2373 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002374 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2375 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Andrew Trickef9de2a2013-05-25 02:42:55 +00002376 SDNode *ResNode = CurDAG->getMachineNode(Opc, SDLoc(Node),
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002377 MVT::i32, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002378 Ops);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002379 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2380 return ResNode;
2381}
2382
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002383SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002384 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002385
Dan Gohman17059682008-07-17 19:10:17 +00002386 if (N->isMachineOpcode())
Evan Cheng10043e22007-01-19 07:51:42 +00002387 return NULL; // Already selected.
Rafael Espindola4e760152006-06-12 12:28:08 +00002388
2389 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002390 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002391 case ISD::INLINEASM: {
2392 SDNode *ResNode = SelectInlineAsm(N);
2393 if (ResNode)
2394 return ResNode;
2395 break;
2396 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002397 case ISD::XOR: {
2398 // Select special operations if XOR node forms integer ABS pattern
2399 SDNode *ResNode = SelectABSOp(N);
2400 if (ResNode)
2401 return ResNode;
2402 // Other cases are autogenerated.
2403 break;
2404 }
Evan Cheng10043e22007-01-19 07:51:42 +00002405 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002406 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002407 bool UseCP = true;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002408 if (Subtarget->hasThumb2())
2409 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2410 // be done with MOV + MOVT, at worst.
2411 UseCP = 0;
2412 else {
2413 if (Subtarget->isThumb()) {
Bob Wilson360eef02009-06-22 17:29:13 +00002414 UseCP = (Val > 255 && // MOV
2415 ~Val > 255 && // MOV + MVN
2416 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002417 } else
2418 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2419 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2420 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2421 }
2422
Evan Cheng10043e22007-01-19 07:51:42 +00002423 if (UseCP) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002424 SDValue CPIdx =
Owen Anderson55f1c092009-08-13 21:58:54 +00002425 CurDAG->getTargetConstantPool(ConstantInt::get(
2426 Type::getInt32Ty(*CurDAG->getContext()), Val),
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002427 getTargetLowering()->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002428
2429 SDNode *ResNode;
Evan Chengcd4cdd12009-07-11 06:43:01 +00002430 if (Subtarget->isThumb1Only()) {
Evan Cheng3da64f762010-04-16 05:46:06 +00002431 SDValue Pred = getAL(CurDAG);
Owen Anderson9f944592009-08-11 20:47:22 +00002432 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002433 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002434 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002435 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002436 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002437 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002438 CPIdx,
Owen Anderson9f944592009-08-11 20:47:22 +00002439 CurDAG->getTargetConstant(0, MVT::i32),
Evan Cheng7e90b112007-07-05 07:15:27 +00002440 getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00002441 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002442 CurDAG->getEntryNode()
2443 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002444 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002445 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002446 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002447 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Cheng10043e22007-01-19 07:51:42 +00002448 return NULL;
2449 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002450
Evan Cheng10043e22007-01-19 07:51:42 +00002451 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002452 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002453 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002454 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002455 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002456 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002457 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
2458 getTargetLowering()->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002459 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002460 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2461 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2462 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbachfde21102009-04-07 20:34:09 +00002463 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002464 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2465 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002466 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2467 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2468 CurDAG->getRegister(0, MVT::i32) };
2469 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng7e90b112007-07-05 07:15:27 +00002470 }
Evan Cheng10043e22007-01-19 07:51:42 +00002471 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002472 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002473 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002474 return I;
2475 break;
2476 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002477 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002478 return I;
2479 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002480 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002481 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002482 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002483 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002484 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002485 if (!RHSV) break;
2486 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002487 unsigned ShImm = Log2_32(RHSV-1);
2488 if (ShImm >= 32)
2489 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002490 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002491 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002492 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2493 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002494 if (Subtarget->isThumb()) {
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002495 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson9f944592009-08-11 20:47:22 +00002496 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002497 } else {
2498 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002499 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002500 }
Evan Cheng10043e22007-01-19 07:51:42 +00002501 }
2502 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002503 unsigned ShImm = Log2_32(RHSV+1);
2504 if (ShImm >= 32)
2505 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002506 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002507 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002508 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2509 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002510 if (Subtarget->isThumb()) {
Bob Wilsonb6112e82010-05-28 00:27:15 +00002511 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2512 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002513 } else {
2514 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002515 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002516 }
Evan Cheng10043e22007-01-19 07:51:42 +00002517 }
2518 }
2519 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002520 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002521 // Check for unsigned bitfield extract
2522 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2523 return I;
2524
Evan Cheng786b15f2009-10-21 08:15:52 +00002525 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2526 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2527 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2528 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2529 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002530 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002531 if (VT != MVT::i32)
2532 break;
2533 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2534 ? ARM::t2MOVTi16
2535 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2536 if (!Opc)
2537 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002538 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002539 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2540 if (!N1C)
2541 break;
2542 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2543 SDValue N2 = N0.getOperand(1);
2544 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2545 if (!N2C)
2546 break;
2547 unsigned N1CVal = N1C->getZExtValue();
2548 unsigned N2CVal = N2C->getZExtValue();
2549 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2550 (N1CVal & 0xffffU) == 0xffffU &&
2551 (N2CVal & 0xffffU) == 0x0U) {
2552 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2553 MVT::i32);
2554 SDValue Ops[] = { N0.getOperand(0), Imm16,
2555 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002556 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002557 }
2558 }
2559 break;
2560 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002561 case ARMISD::VMOVRRD:
2562 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002563 N->getOperand(0), getAL(CurDAG),
Dan Gohman32f71d72009-09-25 18:54:59 +00002564 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002565 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002566 if (Subtarget->isThumb1Only())
2567 break;
2568 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002569 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Michael Liaob53d8962013-04-19 22:22:57 +00002570 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2571 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002572 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002573 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002574 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2575 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002576 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2577 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002578 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002579 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002580 }
Dan Gohmana1603612007-10-08 18:33:35 +00002581 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002582 if (Subtarget->isThumb1Only())
2583 break;
2584 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002585 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002586 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002587 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002588 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002589 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002590 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2591 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002592 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2593 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002594 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002595 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002596 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002597 case ARMISD::UMLAL:{
2598 if (Subtarget->isThumb()) {
2599 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2600 N->getOperand(3), getAL(CurDAG),
2601 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002602 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002603 }else{
2604 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2605 N->getOperand(3), getAL(CurDAG),
2606 CurDAG->getRegister(0, MVT::i32),
2607 CurDAG->getRegister(0, MVT::i32) };
2608 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2609 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002610 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002611 }
2612 }
2613 case ARMISD::SMLAL:{
2614 if (Subtarget->isThumb()) {
2615 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2616 N->getOperand(3), getAL(CurDAG),
2617 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002618 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002619 }else{
2620 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2621 N->getOperand(3), getAL(CurDAG),
2622 CurDAG->getRegister(0, MVT::i32),
2623 CurDAG->getRegister(0, MVT::i32) };
2624 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2625 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002626 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002627 }
2628 }
Evan Cheng10043e22007-01-19 07:51:42 +00002629 case ISD::LOAD: {
Evan Cheng84c6cda2009-07-02 07:28:31 +00002630 SDNode *ResNode = 0;
Evan Chengb24e51e2009-07-07 01:17:28 +00002631 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002632 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002633 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002634 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002635 if (ResNode)
2636 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002637 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002638 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002639 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002640 case ARMISD::BRCOND: {
2641 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2642 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2643 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002644
Evan Cheng7e90b112007-07-05 07:15:27 +00002645 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2646 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2647 // Pattern complexity = 6 cost = 1 size = 0
2648
David Goodwin27303cd2009-06-30 18:04:13 +00002649 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2650 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2651 // Pattern complexity = 6 cost = 1 size = 0
2652
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002653 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002654 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002655 SDValue Chain = N->getOperand(0);
2656 SDValue N1 = N->getOperand(1);
2657 SDValue N2 = N->getOperand(2);
2658 SDValue N3 = N->getOperand(3);
2659 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002660 assert(N1.getOpcode() == ISD::BasicBlock);
2661 assert(N2.getOpcode() == ISD::Constant);
2662 assert(N3.getOpcode() == ISD::Register);
2663
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002664 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmaneffb8942008-09-12 16:56:44 +00002665 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson9f944592009-08-11 20:47:22 +00002666 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002667 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002668 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002669 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002670 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002671 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002672 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002673 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002674 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002675 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002676 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Cheng7e90b112007-07-05 07:15:27 +00002677 return NULL;
2678 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002679 case ARMISD::VZIP: {
2680 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002681 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002682 switch (VT.getSimpleVT().SimpleTy) {
2683 default: return NULL;
2684 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2685 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2686 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002687 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2688 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002689 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2690 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2691 case MVT::v4f32:
2692 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2693 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002694 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002695 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2696 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002697 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002698 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002699 case ARMISD::VUZP: {
2700 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002701 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002702 switch (VT.getSimpleVT().SimpleTy) {
2703 default: return NULL;
2704 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2705 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2706 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002707 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2708 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002709 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2710 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2711 case MVT::v4f32:
2712 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2713 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002714 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002715 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2716 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002717 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002718 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002719 case ARMISD::VTRN: {
2720 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002721 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002722 switch (VT.getSimpleVT().SimpleTy) {
2723 default: return NULL;
2724 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2725 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2726 case MVT::v2f32:
2727 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2728 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2729 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2730 case MVT::v4f32:
2731 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2732 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002733 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002734 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2735 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002736 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002737 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002738 case ARMISD::BUILD_VECTOR: {
2739 EVT VecVT = N->getValueType(0);
2740 EVT EltVT = VecVT.getVectorElementType();
2741 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002742 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002743 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002744 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002745 }
Duncan Sands14627772010-11-03 12:17:33 +00002746 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002747 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002748 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002749 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002750 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002751 N->getOperand(2), N->getOperand(3));
2752 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002753
Bob Wilson2d790df2010-11-28 06:51:26 +00002754 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002755 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2756 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002757 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002758 }
2759
Bob Wilson77ab1652010-11-29 19:35:29 +00002760 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002761 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2762 ARM::VLD3DUPd16Pseudo,
2763 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002764 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002765 }
2766
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002767 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002768 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2769 ARM::VLD4DUPd16Pseudo,
2770 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002771 return SelectVLDDup(N, false, 4, Opcodes);
2772 }
2773
2774 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002775 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2776 ARM::VLD2DUPd16wb_fixed,
2777 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002778 return SelectVLDDup(N, true, 2, Opcodes);
2779 }
2780
2781 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002782 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2783 ARM::VLD3DUPd16Pseudo_UPD,
2784 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002785 return SelectVLDDup(N, true, 3, Opcodes);
2786 }
2787
2788 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002789 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2790 ARM::VLD4DUPd16Pseudo_UPD,
2791 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002792 return SelectVLDDup(N, true, 4, Opcodes);
2793 }
2794
2795 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002796 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2797 ARM::VLD1d16wb_fixed,
2798 ARM::VLD1d32wb_fixed,
2799 ARM::VLD1d64wb_fixed };
2800 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2801 ARM::VLD1q16wb_fixed,
2802 ARM::VLD1q32wb_fixed,
2803 ARM::VLD1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002804 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2805 }
2806
2807 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002808 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2809 ARM::VLD2d16wb_fixed,
2810 ARM::VLD2d32wb_fixed,
2811 ARM::VLD1q64wb_fixed};
2812 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2813 ARM::VLD2q16PseudoWB_fixed,
2814 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002815 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2816 }
2817
2818 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002819 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2820 ARM::VLD3d16Pseudo_UPD,
2821 ARM::VLD3d32Pseudo_UPD,
2822 ARM::VLD1q64wb_fixed};
2823 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2824 ARM::VLD3q16Pseudo_UPD,
2825 ARM::VLD3q32Pseudo_UPD };
2826 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2827 ARM::VLD3q16oddPseudo_UPD,
2828 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002829 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2830 }
2831
2832 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002833 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2834 ARM::VLD4d16Pseudo_UPD,
2835 ARM::VLD4d32Pseudo_UPD,
2836 ARM::VLD1q64wb_fixed};
2837 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2838 ARM::VLD4q16Pseudo_UPD,
2839 ARM::VLD4q32Pseudo_UPD };
2840 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2841 ARM::VLD4q16oddPseudo_UPD,
2842 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002843 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2844 }
2845
2846 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002847 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2848 ARM::VLD2LNd16Pseudo_UPD,
2849 ARM::VLD2LNd32Pseudo_UPD };
2850 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2851 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002852 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2853 }
2854
2855 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002856 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2857 ARM::VLD3LNd16Pseudo_UPD,
2858 ARM::VLD3LNd32Pseudo_UPD };
2859 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2860 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002861 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2862 }
2863
2864 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002865 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2866 ARM::VLD4LNd16Pseudo_UPD,
2867 ARM::VLD4LNd32Pseudo_UPD };
2868 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2869 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002870 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2871 }
2872
2873 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002874 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2875 ARM::VST1d16wb_fixed,
2876 ARM::VST1d32wb_fixed,
2877 ARM::VST1d64wb_fixed };
2878 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2879 ARM::VST1q16wb_fixed,
2880 ARM::VST1q32wb_fixed,
2881 ARM::VST1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002882 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2883 }
2884
2885 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002886 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2887 ARM::VST2d16wb_fixed,
2888 ARM::VST2d32wb_fixed,
2889 ARM::VST1q64wb_fixed};
2890 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2891 ARM::VST2q16PseudoWB_fixed,
2892 ARM::VST2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002893 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2894 }
2895
2896 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002897 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2898 ARM::VST3d16Pseudo_UPD,
2899 ARM::VST3d32Pseudo_UPD,
2900 ARM::VST1d64TPseudoWB_fixed};
2901 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2902 ARM::VST3q16Pseudo_UPD,
2903 ARM::VST3q32Pseudo_UPD };
2904 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2905 ARM::VST3q16oddPseudo_UPD,
2906 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002907 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2908 }
2909
2910 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002911 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2912 ARM::VST4d16Pseudo_UPD,
2913 ARM::VST4d32Pseudo_UPD,
2914 ARM::VST1d64QPseudoWB_fixed};
2915 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2916 ARM::VST4q16Pseudo_UPD,
2917 ARM::VST4q32Pseudo_UPD };
2918 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2919 ARM::VST4q16oddPseudo_UPD,
2920 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002921 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2922 }
2923
2924 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002925 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2926 ARM::VST2LNd16Pseudo_UPD,
2927 ARM::VST2LNd32Pseudo_UPD };
2928 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2929 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002930 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2931 }
2932
2933 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002934 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2935 ARM::VST3LNd16Pseudo_UPD,
2936 ARM::VST3LNd32Pseudo_UPD };
2937 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2938 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002939 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2940 }
2941
2942 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002943 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2944 ARM::VST4LNd16Pseudo_UPD,
2945 ARM::VST4LNd32Pseudo_UPD };
2946 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2947 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002948 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002949 }
2950
Bob Wilsone0636a72009-08-26 17:39:53 +00002951 case ISD::INTRINSIC_VOID:
2952 case ISD::INTRINSIC_W_CHAIN: {
2953 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00002954 switch (IntNo) {
2955 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00002956 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00002957
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002958 case Intrinsic::arm_ldrexd: {
2959 SDValue MemAddr = N->getOperand(2);
Andrew Trickef9de2a2013-05-25 02:42:55 +00002960 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002961 SDValue Chain = N->getOperand(0);
2962
Weiming Zhao8f56f882012-11-16 21:55:34 +00002963 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
2964 unsigned NewOpc = isThumb ? ARM::t2LDREXD :ARM::LDREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002965
2966 // arm_ldrexd returns a i64 value in {i32, i32}
2967 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00002968 if (isThumb) {
2969 ResTys.push_back(MVT::i32);
2970 ResTys.push_back(MVT::i32);
2971 } else
2972 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002973 ResTys.push_back(MVT::Other);
2974
Weiming Zhao8f56f882012-11-16 21:55:34 +00002975 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002976 SmallVector<SDValue, 7> Ops;
2977 Ops.push_back(MemAddr);
2978 Ops.push_back(getAL(CurDAG));
2979 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2980 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00002981 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002982 // Transfer memoperands.
2983 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2984 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2985 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2986
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002987 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00002988 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002989 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00002990 SDValue Result;
2991 if (isThumb)
2992 Result = SDValue(Ld, 0);
2993 else {
2994 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
2995 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00002996 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00002997 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00002998 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002999 ReplaceUses(SDValue(N, 0), Result);
3000 }
3001 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003002 SDValue Result;
3003 if (isThumb)
3004 Result = SDValue(Ld, 1);
3005 else {
3006 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3007 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003008 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003009 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003010 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003011 ReplaceUses(SDValue(N, 1), Result);
3012 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003013 ReplaceUses(SDValue(N, 2), OutChain);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003014 return NULL;
3015 }
3016
3017 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003018 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003019 SDValue Chain = N->getOperand(0);
3020 SDValue Val0 = N->getOperand(2);
3021 SDValue Val1 = N->getOperand(3);
3022 SDValue MemAddr = N->getOperand(4);
3023
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003024 // Store exclusive double return a i32 value which is the return status
3025 // of the issued store.
Benjamin Kramerfdf362b2013-03-07 20:33:29 +00003026 EVT ResTys[] = { MVT::i32, MVT::Other };
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003027
Weiming Zhao8f56f882012-11-16 21:55:34 +00003028 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3029 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003030 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003031 if (isThumb) {
3032 Ops.push_back(Val0);
3033 Ops.push_back(Val1);
3034 } else
3035 // arm_strexd uses GPRPair.
3036 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003037 Ops.push_back(MemAddr);
3038 Ops.push_back(getAL(CurDAG));
3039 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3040 Ops.push_back(Chain);
3041
Weiming Zhao8f56f882012-11-16 21:55:34 +00003042 unsigned NewOpc = isThumb ? ARM::t2STREXD : ARM::STREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003043
Michael Liaob53d8962013-04-19 22:22:57 +00003044 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003045 // Transfer memoperands.
3046 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3047 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3048 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3049
3050 return St;
3051 }
3052
Bob Wilson340861d2010-03-23 05:25:43 +00003053 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003054 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3055 ARM::VLD1d32, ARM::VLD1d64 };
3056 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3057 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson06fce872011-02-07 17:43:21 +00003058 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson340861d2010-03-23 05:25:43 +00003059 }
3060
Bob Wilsone0636a72009-08-26 17:39:53 +00003061 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003062 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3063 ARM::VLD2d32, ARM::VLD1q64 };
3064 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3065 ARM::VLD2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003066 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003067 }
3068
3069 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003070 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3071 ARM::VLD3d16Pseudo,
3072 ARM::VLD3d32Pseudo,
3073 ARM::VLD1d64TPseudo };
3074 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3075 ARM::VLD3q16Pseudo_UPD,
3076 ARM::VLD3q32Pseudo_UPD };
3077 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3078 ARM::VLD3q16oddPseudo,
3079 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003080 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003081 }
3082
3083 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003084 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3085 ARM::VLD4d16Pseudo,
3086 ARM::VLD4d32Pseudo,
3087 ARM::VLD1d64QPseudo };
3088 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3089 ARM::VLD4q16Pseudo_UPD,
3090 ARM::VLD4q32Pseudo_UPD };
3091 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3092 ARM::VLD4q16oddPseudo,
3093 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003094 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003095 }
3096
Bob Wilsonda9817c2009-09-01 04:26:28 +00003097 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003098 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3099 ARM::VLD2LNd16Pseudo,
3100 ARM::VLD2LNd32Pseudo };
3101 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3102 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003103 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003104 }
3105
3106 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003107 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3108 ARM::VLD3LNd16Pseudo,
3109 ARM::VLD3LNd32Pseudo };
3110 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3111 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003112 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003113 }
3114
3115 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003116 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3117 ARM::VLD4LNd16Pseudo,
3118 ARM::VLD4LNd32Pseudo };
3119 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3120 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003121 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003122 }
3123
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003124 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003125 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3126 ARM::VST1d32, ARM::VST1d64 };
3127 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3128 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson06fce872011-02-07 17:43:21 +00003129 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003130 }
3131
Bob Wilsone0636a72009-08-26 17:39:53 +00003132 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003133 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3134 ARM::VST2d32, ARM::VST1q64 };
3135 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3136 ARM::VST2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003137 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003138 }
3139
3140 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003141 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3142 ARM::VST3d16Pseudo,
3143 ARM::VST3d32Pseudo,
3144 ARM::VST1d64TPseudo };
3145 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3146 ARM::VST3q16Pseudo_UPD,
3147 ARM::VST3q32Pseudo_UPD };
3148 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3149 ARM::VST3q16oddPseudo,
3150 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003151 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003152 }
3153
3154 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003155 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3156 ARM::VST4d16Pseudo,
3157 ARM::VST4d32Pseudo,
3158 ARM::VST1d64QPseudo };
3159 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3160 ARM::VST4q16Pseudo_UPD,
3161 ARM::VST4q32Pseudo_UPD };
3162 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3163 ARM::VST4q16oddPseudo,
3164 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003165 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003166 }
Bob Wilsond7797752009-09-01 18:51:56 +00003167
3168 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003169 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3170 ARM::VST2LNd16Pseudo,
3171 ARM::VST2LNd32Pseudo };
3172 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3173 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003174 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003175 }
3176
3177 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003178 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3179 ARM::VST3LNd16Pseudo,
3180 ARM::VST3LNd32Pseudo };
3181 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3182 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003183 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003184 }
3185
3186 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003187 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3188 ARM::VST4LNd16Pseudo,
3189 ARM::VST4LNd32Pseudo };
3190 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3191 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003192 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003193 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003194 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003195 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003196 }
Evan Chengd85631e2010-05-05 18:28:36 +00003197
Bob Wilson3ed511b2010-07-06 23:36:25 +00003198 case ISD::INTRINSIC_WO_CHAIN: {
3199 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3200 switch (IntNo) {
3201 default:
3202 break;
3203
3204 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003205 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003206 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003207 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003208 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003209 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003210
3211 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003212 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003213 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003214 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003215 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003216 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003217 }
3218 break;
3219 }
3220
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003221 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003222 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003223 EVT VT = N->getValueType(0);
3224 SmallVector<SDValue, 6> Ops;
3225
3226 Ops.push_back(N->getOperand(0));
3227 Ops.push_back(N->getOperand(1));
3228 Ops.push_back(getAL(CurDAG)); // Predicate
3229 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003230 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003231 }
3232 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003233 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003234 EVT VT = N->getValueType(0);
3235
3236 // Form a REG_SEQUENCE to force register allocation.
3237 SDValue V0 = N->getOperand(0);
3238 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003239 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003240
3241 SmallVector<SDValue, 6> Ops;
3242 Ops.push_back(RegSeq);
3243 Ops.push_back(N->getOperand(2));
3244 Ops.push_back(getAL(CurDAG)); // Predicate
3245 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003246 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003247 }
3248
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003249 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003250 return SelectConcatVector(N);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00003251
3252 case ARMISD::ATOMOR64_DAG:
3253 return SelectAtomic64(N, ARM::ATOMOR6432);
3254 case ARMISD::ATOMXOR64_DAG:
3255 return SelectAtomic64(N, ARM::ATOMXOR6432);
3256 case ARMISD::ATOMADD64_DAG:
3257 return SelectAtomic64(N, ARM::ATOMADD6432);
3258 case ARMISD::ATOMSUB64_DAG:
3259 return SelectAtomic64(N, ARM::ATOMSUB6432);
3260 case ARMISD::ATOMNAND64_DAG:
3261 return SelectAtomic64(N, ARM::ATOMNAND6432);
3262 case ARMISD::ATOMAND64_DAG:
3263 return SelectAtomic64(N, ARM::ATOMAND6432);
3264 case ARMISD::ATOMSWAP64_DAG:
3265 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman1ccecbb2011-08-31 17:52:22 +00003266 case ARMISD::ATOMCMPXCHG64_DAG:
3267 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Silviu Baranga93aefa52012-11-29 14:41:25 +00003268
3269 case ARMISD::ATOMMIN64_DAG:
3270 return SelectAtomic64(N, ARM::ATOMMIN6432);
3271 case ARMISD::ATOMUMIN64_DAG:
3272 return SelectAtomic64(N, ARM::ATOMUMIN6432);
3273 case ARMISD::ATOMMAX64_DAG:
3274 return SelectAtomic64(N, ARM::ATOMMAX6432);
3275 case ARMISD::ATOMUMAX64_DAG:
3276 return SelectAtomic64(N, ARM::ATOMUMAX6432);
Evan Chengd85631e2010-05-05 18:28:36 +00003277 }
Evan Chengd5021732008-12-10 21:54:21 +00003278
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003279 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003280}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003281
Weiming Zhaoc5987002013-02-14 18:10:21 +00003282SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3283 std::vector<SDValue> AsmNodeOperands;
3284 unsigned Flag, Kind;
3285 bool Changed = false;
3286 unsigned NumOps = N->getNumOperands();
3287
Weiming Zhaoc5987002013-02-14 18:10:21 +00003288 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3289 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3290 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3291 // respectively. Since there is no constraint to explicitly specify a
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003292 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3293 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3294 // them into a GPRPair.
Weiming Zhaoc5987002013-02-14 18:10:21 +00003295
Andrew Trickef9de2a2013-05-25 02:42:55 +00003296 SDLoc dl(N);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003297 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1) : SDValue(0,0);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003298
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003299 SmallVector<bool, 8> OpChanged;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003300 // Glue node will be appended late.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003301 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
Weiming Zhaoc5987002013-02-14 18:10:21 +00003302 SDValue op = N->getOperand(i);
3303 AsmNodeOperands.push_back(op);
3304
3305 if (i < InlineAsm::Op_FirstOperand)
3306 continue;
3307
3308 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3309 Flag = C->getZExtValue();
3310 Kind = InlineAsm::getKind(Flag);
3311 }
3312 else
3313 continue;
3314
Joey Gouly392cdad2013-07-08 19:52:51 +00003315 // Immediate operands to inline asm in the SelectionDAG are modeled with
3316 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3317 // the second is a constant with the value of the immediate. If we get here
3318 // and we have a Kind_Imm, skip the next operand, and continue.
Joey Gouly606f3fb2013-07-05 10:19:40 +00003319 if (Kind == InlineAsm::Kind_Imm) {
3320 SDValue op = N->getOperand(++i);
3321 AsmNodeOperands.push_back(op);
3322 continue;
3323 }
3324
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003325 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3326 if (NumRegs)
3327 OpChanged.push_back(false);
3328
3329 unsigned DefIdx = 0;
3330 bool IsTiedToChangedOp = false;
3331 // If it's a use that is tied with a previous def, it has no
3332 // reg class constraint.
3333 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3334 IsTiedToChangedOp = OpChanged[DefIdx];
3335
Weiming Zhaoc5987002013-02-14 18:10:21 +00003336 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3337 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3338 continue;
3339
Weiming Zhaoc5987002013-02-14 18:10:21 +00003340 unsigned RC;
3341 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003342 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3343 || NumRegs != 2)
Weiming Zhaoc5987002013-02-14 18:10:21 +00003344 continue;
3345
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003346 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
Weiming Zhaoc5987002013-02-14 18:10:21 +00003347 SDValue V0 = N->getOperand(i+1);
3348 SDValue V1 = N->getOperand(i+2);
3349 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3350 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3351 SDValue PairedReg;
3352 MachineRegisterInfo &MRI = MF->getRegInfo();
3353
3354 if (Kind == InlineAsm::Kind_RegDef ||
3355 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3356 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3357 // the original GPRs.
3358
3359 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3360 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3361 SDValue Chain = SDValue(N,0);
3362
3363 SDNode *GU = N->getGluedUser();
3364 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3365 Chain.getValue(1));
3366
3367 // Extract values from a GPRPair reg and copy to the original GPR reg.
3368 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3369 RegCopy);
3370 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3371 RegCopy);
3372 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3373 RegCopy.getValue(1));
3374 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3375
3376 // Update the original glue user.
3377 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3378 Ops.push_back(T1.getValue(1));
3379 CurDAG->UpdateNodeOperands(GU, &Ops[0], Ops.size());
3380 GU = T1.getNode();
3381 }
3382 else {
3383 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3384 // GPRPair and then pass the GPRPair to the inline asm.
3385 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3386
3387 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3388 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3389 Chain.getValue(1));
3390 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3391 T0.getValue(1));
3392 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3393
3394 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3395 // i32 VRs of inline asm with it.
3396 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3397 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3398 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3399
3400 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3401 Glue = Chain.getValue(1);
3402 }
3403
3404 Changed = true;
3405
3406 if(PairedReg.getNode()) {
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003407 OpChanged[OpChanged.size() -1 ] = true;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003408 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
Tim Northover55349a22013-08-18 18:06:03 +00003409 if (IsTiedToChangedOp)
3410 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3411 else
3412 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003413 // Replace the current flag.
3414 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3415 Flag, MVT::i32);
3416 // Add the new register node and skip the original two GPRs.
3417 AsmNodeOperands.push_back(PairedReg);
3418 // Skip the next two GPRs.
3419 i += 2;
3420 }
3421 }
3422
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003423 if (Glue.getNode())
3424 AsmNodeOperands.push_back(Glue);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003425 if (!Changed)
3426 return NULL;
3427
Andrew Trickef9de2a2013-05-25 02:42:55 +00003428 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Weiming Zhaoc5987002013-02-14 18:10:21 +00003429 CurDAG->getVTList(MVT::Other, MVT::Glue), &AsmNodeOperands[0],
3430 AsmNodeOperands.size());
3431 New->setNodeId(-1);
3432 return New.getNode();
3433}
3434
3435
Bob Wilsona2c462b2009-05-19 05:53:42 +00003436bool ARMDAGToDAGISel::
3437SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3438 std::vector<SDValue> &OutOps) {
3439 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003440 // Require the address to be in a register. That is safe for all ARM
3441 // variants and it is hard to do anything much smarter without knowing
3442 // how the operand is used.
3443 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003444 return false;
3445}
3446
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003447/// createARMISelDag - This pass converts a legalized DAG into a
3448/// ARM-specific DAG, ready for instruction scheduling.
3449///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003450FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3451 CodeGenOpt::Level OptLevel) {
3452 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003453}