blob: 70e11c50e6d62c0d4aec0439bd6fbc10da1ac0cd [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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Target/TargetLowering.h"
36#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000037
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Cheng59069ec2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng62c7b5b2010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000049
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikov99152f32009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Chengbc0d0ec2008-09-18 07:24:33 +000063
Evan Cheng10043e22007-01-19 07:51:42 +000064 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
65 /// make the right decision when generating code for different targets.
66 const ARMSubtarget *Subtarget;
67
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000068public:
Bob Wilson2dd957f2009-09-28 14:30:20 +000069 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
70 CodeGenOpt::Level OptLevel)
71 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng62c7b5b2010-12-05 22:04:16 +000072 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000073 }
74
Craig Topper6bc27bf2014-03-10 02:09:33 +000075 const char *getPassName() const override {
Evan Cheng10043e22007-01-19 07:51:42 +000076 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000077 }
78
Craig Topper6bc27bf2014-03-10 02:09:33 +000079 void PreprocessISelDAG() override;
Evan Chengeae6d2c2012-12-19 20:16:09 +000080
Bob Wilson4facd962009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000085 }
86
Craig Topper6bc27bf2014-03-10 02:09:33 +000087 SDNode *Select(SDNode *N) override;
Evan Cheng5e73ff22010-02-15 19:41:07 +000088
Evan Cheng62c7b5b2010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000093 bool SelectRegShifterOperand(SDValue N, SDValue &A,
94 SDValue &B, SDValue &C,
95 bool CheckProfitability = true);
96 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +000097 SDValue &B, bool CheckProfitability = true);
98 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +000099 SDValue &B, SDValue &C) {
100 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000101 return SelectRegShifterOperand(N, A, B, C, false);
102 }
103 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
104 SDValue &B) {
105 // Don't apply the profitability check
106 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000107 }
108
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000109 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
110 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
111
Jim Grosbach08605202010-09-29 19:03:54 +0000112 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
113 SDValue &Offset, SDValue &Opc);
114 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
115 SDValue &Opc) {
116 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
117 }
118
119 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
122 }
123
124 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000127// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000128 // This always matches one way or another.
129 return true;
130 }
131
Tim Northover42180442013-08-22 09:57:11 +0000132 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
133 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
134 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
135 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
136 return true;
137 }
138
Owen Anderson2aedba62011-07-26 20:54:26 +0000139 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
140 SDValue &Offset, SDValue &Opc);
141 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000142 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000143 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
144 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000145 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000146 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000147 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000148 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000149 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000150 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000151 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000152 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000153 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000154
Evan Chengdfce83c2011-01-17 08:03:18 +0000155 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000156
Bill Wendling092a7bd2010-12-14 03:36:38 +0000157 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000158 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000159 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
160 unsigned Scale);
161 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
162 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
163 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
164 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
165 SDValue &OffImm);
166 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
167 SDValue &OffImm);
168 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
169 SDValue &OffImm);
170 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
171 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000172 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000173
Bill Wendling092a7bd2010-12-14 03:36:38 +0000174 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000175 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000176 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000177 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
178 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000179 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000180 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000181 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000182 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000183 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000184 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000185
Evan Cheng0fc80842010-11-12 22:42:47 +0000186 inline bool is_so_imm(unsigned Imm) const {
187 return ARM_AM::getSOImmVal(Imm) != -1;
188 }
189
190 inline bool is_so_imm_not(unsigned Imm) const {
191 return ARM_AM::getSOImmVal(~Imm) != -1;
192 }
193
194 inline bool is_t2_so_imm(unsigned Imm) const {
195 return ARM_AM::getT2SOImmVal(Imm) != -1;
196 }
197
198 inline bool is_t2_so_imm_not(unsigned Imm) const {
199 return ARM_AM::getT2SOImmVal(~Imm) != -1;
200 }
201
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000202 // Include the pieces autogenerated from the target description.
203#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000204
205private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000206 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
207 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000208 SDNode *SelectARMIndexedLoad(SDNode *N);
209 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000210
Bob Wilson340861d2010-03-23 05:25:43 +0000211 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
212 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000213 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000214 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000215 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000216 const uint16_t *DOpcodes,
217 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000218
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000219 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000220 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000221 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000222 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000223 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000224 const uint16_t *DOpcodes,
225 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000226
Bob Wilson93117bc2009-10-14 16:46:45 +0000227 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000228 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000229 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000230 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
231 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000232 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000233
Bob Wilson2d790df2010-11-28 06:51:26 +0000234 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
235 /// should be 2, 3 or 4. The opcode array specifies the instructions used
236 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000237 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000238 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000239
Bob Wilson5bc8a792010-07-07 00:08:54 +0000240 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
241 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
242 /// generated to force the table registers to be consecutive.
243 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000244
Sandeep Patel7460e082009-10-13 20:25:58 +0000245 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000246 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000247
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000248 // Select special operations if node forms integer ABS pattern
249 SDNode *SelectABSOp(SDNode *N);
250
Weiming Zhaoc5987002013-02-14 18:10:21 +0000251 SDNode *SelectInlineAsm(SDNode *N);
252
Evan Chengd85631e2010-05-05 18:28:36 +0000253 SDNode *SelectConcatVector(SDNode *N);
254
Evan Chengd9c55362009-07-02 01:23:32 +0000255 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
256 /// inline asm expressions.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000257 bool SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
258 std::vector<SDValue> &OutOps) override;
Bob Wilsone6b778d2009-10-06 22:01:59 +0000259
Weiming Zhao95782222012-11-17 00:23:35 +0000260 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000261 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000262 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
263 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
264 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000265
Bob Wilsond8a9a042010-06-04 00:04:02 +0000266 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000267 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
268 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
269 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000270
271 // Get the alignment operand for a NEON VLD or VST instruction.
272 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000273};
Evan Cheng10043e22007-01-19 07:51:42 +0000274}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000275
Sandeep Patel423e42b2009-10-13 18:59:48 +0000276/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
277/// operand. If so Imm will receive the 32-bit value.
278static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
279 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
280 Imm = cast<ConstantSDNode>(N)->getZExtValue();
281 return true;
282 }
283 return false;
284}
285
286// isInt32Immediate - This method tests to see if a constant operand.
287// If so Imm will receive the 32 bit value.
288static bool isInt32Immediate(SDValue N, unsigned &Imm) {
289 return isInt32Immediate(N.getNode(), Imm);
290}
291
292// isOpcWithIntImmediate - This method tests to see if the node is a specific
293// opcode and that it has a immediate integer right operand.
294// If so Imm will receive the 32 bit value.
295static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
296 return N->getOpcode() == Opc &&
297 isInt32Immediate(N->getOperand(1).getNode(), Imm);
298}
299
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000300/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000301/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000302///
303/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000304static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000305 int RangeMin, int RangeMax,
306 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000307 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000308
309 // Check that this is a constant.
310 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
311 if (!C)
312 return false;
313
314 ScaledConstant = (int) C->getZExtValue();
315 if ((ScaledConstant % Scale) != 0)
316 return false;
317
318 ScaledConstant /= Scale;
319 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
320}
321
Evan Chengeae6d2c2012-12-19 20:16:09 +0000322void ARMDAGToDAGISel::PreprocessISelDAG() {
323 if (!Subtarget->hasV6T2Ops())
324 return;
325
326 bool isThumb2 = Subtarget->isThumb();
327 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
328 E = CurDAG->allnodes_end(); I != E; ) {
329 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
330
331 if (N->getOpcode() != ISD::ADD)
332 continue;
333
334 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
335 // leading zeros, followed by consecutive set bits, followed by 1 or 2
336 // trailing zeros, e.g. 1020.
337 // Transform the expression to
338 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
339 // of trailing zeros of c2. The left shift would be folded as an shifter
340 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
341 // node (UBFX).
342
343 SDValue N0 = N->getOperand(0);
344 SDValue N1 = N->getOperand(1);
345 unsigned And_imm = 0;
346 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
347 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
348 std::swap(N0, N1);
349 }
350 if (!And_imm)
351 continue;
352
353 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000354 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000355 if (TZ != 1 && TZ != 2)
356 // Be conservative here. Shifter operands aren't always free. e.g. On
357 // Swift, left shifter operand of 1 / 2 for free but others are not.
358 // e.g.
359 // ubfx r3, r1, #16, #8
360 // ldr.w r3, [r0, r3, lsl #2]
361 // vs.
362 // mov.w r9, #1020
363 // and.w r2, r9, r1, lsr #14
364 // ldr r2, [r0, r2]
365 continue;
366 And_imm >>= TZ;
367 if (And_imm & (And_imm + 1))
368 continue;
369
370 // Look for (and (srl X, c1), c2).
371 SDValue Srl = N1.getOperand(0);
372 unsigned Srl_imm = 0;
373 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
374 (Srl_imm <= 2))
375 continue;
376
377 // Make sure first operand is not a shifter operand which would prevent
378 // folding of the left shift.
379 SDValue CPTmp0;
380 SDValue CPTmp1;
381 SDValue CPTmp2;
382 if (isThumb2) {
383 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
384 continue;
385 } else {
386 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
387 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
388 continue;
389 }
390
391 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000392 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000393 Srl.getOperand(0),
394 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000395 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000396 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000397 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000398 N1, CurDAG->getConstant(TZ, MVT::i32));
399 CurDAG->UpdateNodeOperands(N, N0, N1);
400 }
401}
402
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000403/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
404/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
405/// least on current ARM implementations) which should be avoidded.
406bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
407 if (OptLevel == CodeGenOpt::None)
408 return true;
409
410 if (!CheckVMLxHazard)
411 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000412
Tim Northover0feb91e2014-04-01 14:10:07 +0000413 if (!Subtarget->isCortexA7() && !Subtarget->isCortexA8() &&
414 !Subtarget->isCortexA9() && !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000415 return true;
416
417 if (!N->hasOneUse())
418 return false;
419
420 SDNode *Use = *N->use_begin();
421 if (Use->getOpcode() == ISD::CopyToReg)
422 return true;
423 if (Use->isMachineOpcode()) {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000424 const ARMBaseInstrInfo *TII =
425 static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
426
Evan Cheng6cc775f2011-06-28 19:10:37 +0000427 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
428 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000429 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000430 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000431 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
432 return true;
433 // vmlx feeding into another vmlx. We actually want to unfold
434 // the use later in the MLxExpansion pass. e.g.
435 // vmla
436 // vmla (stall 8 cycles)
437 //
438 // vmul (5 cycles)
439 // vadd (5 cycles)
440 // vmla
441 // This adds up to about 18 - 19 cycles.
442 //
443 // vmla
444 // vmul (stall 4 cycles)
445 // vadd adds up to about 14 cycles.
446 return TII->isFpMLxInstruction(Opcode);
447 }
448
449 return false;
450}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000451
Evan Cheng59bbc542010-10-27 23:41:30 +0000452bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
453 ARM_AM::ShiftOpc ShOpcVal,
454 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000455 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000456 return true;
457 if (Shift.hasOneUse())
458 return true;
459 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000460 return ShOpcVal == ARM_AM::lsl &&
461 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000462}
463
Owen Andersonb595ed02011-07-21 18:54:16 +0000464bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000465 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000466 SDValue &Opc,
467 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000468 if (DisableShifterOp)
469 return false;
470
Evan Chenga20cde32011-07-20 23:34:39 +0000471 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000472
473 // Don't match base register only case. That is matched to a separate
474 // lower complexity pattern with explicit register operand.
475 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000476
Evan Chengb23b50d2009-06-29 07:51:04 +0000477 BaseReg = N.getOperand(0);
478 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000479 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
480 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000481 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000482 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
483 MVT::i32);
484 return true;
485}
486
Owen Andersonb595ed02011-07-21 18:54:16 +0000487bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
488 SDValue &BaseReg,
489 SDValue &ShReg,
490 SDValue &Opc,
491 bool CheckProfitability) {
492 if (DisableShifterOp)
493 return false;
494
495 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
496
497 // Don't match base register only case. That is matched to a separate
498 // lower complexity pattern with explicit register operand.
499 if (ShOpcVal == ARM_AM::no_shift) return false;
500
501 BaseReg = N.getOperand(0);
502 unsigned ShImmVal = 0;
503 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
504 if (RHS) return false;
505
506 ShReg = N.getOperand(1);
507 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
508 return false;
509 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
510 MVT::i32);
511 return true;
512}
513
514
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000515bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
516 SDValue &Base,
517 SDValue &OffImm) {
518 // Match simple R + imm12 operands.
519
520 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000521 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
522 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000523 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000524 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000525 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000526 Base = CurDAG->getTargetFrameIndex(FI,
527 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000528 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
529 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000530 }
Owen Anderson6d557452011-03-18 19:46:58 +0000531
Chris Lattner46c01a32011-02-13 22:25:43 +0000532 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000533 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000534 Base = N.getOperand(0);
535 } else
536 Base = N;
537 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
538 return true;
539 }
540
541 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
542 int RHSC = (int)RHS->getZExtValue();
543 if (N.getOpcode() == ISD::SUB)
544 RHSC = -RHSC;
545
546 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
547 Base = N.getOperand(0);
548 if (Base.getOpcode() == ISD::FrameIndex) {
549 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000550 Base = CurDAG->getTargetFrameIndex(FI,
551 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000552 }
553 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
554 return true;
555 }
556 }
557
558 // Base only.
559 Base = N;
560 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
561 return true;
562}
563
564
565
566bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
567 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000568 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000569 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000570 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
571 // X * [3,5,9] -> X + X * [2,4,8] etc.
572 int RHSC = (int)RHS->getZExtValue();
573 if (RHSC & 1) {
574 RHSC = RHSC & ~1;
575 ARM_AM::AddrOpc AddSub = ARM_AM::add;
576 if (RHSC < 0) {
577 AddSub = ARM_AM::sub;
578 RHSC = - RHSC;
579 }
580 if (isPowerOf2_32(RHSC)) {
581 unsigned ShAmt = Log2_32(RHSC);
582 Base = Offset = N.getOperand(0);
583 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
584 ARM_AM::lsl),
585 MVT::i32);
586 return true;
587 }
588 }
589 }
590 }
591
Chris Lattner46c01a32011-02-13 22:25:43 +0000592 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
593 // ISD::OR that is equivalent to an ISD::ADD.
594 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000595 return false;
596
597 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000598 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000599 int RHSC;
600 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
601 -0x1000+1, 0x1000, RHSC)) // 12 bits.
602 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000603 }
604
605 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000606 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000607 ARM_AM::ShiftOpc ShOpcVal =
608 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000609 unsigned ShAmt = 0;
610
611 Base = N.getOperand(0);
612 Offset = N.getOperand(1);
613
614 if (ShOpcVal != ARM_AM::no_shift) {
615 // Check to see if the RHS of the shift is a constant, if not, we can't fold
616 // it.
617 if (ConstantSDNode *Sh =
618 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
619 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000620 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
621 Offset = N.getOperand(1).getOperand(0);
622 else {
623 ShAmt = 0;
624 ShOpcVal = ARM_AM::no_shift;
625 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000626 } else {
627 ShOpcVal = ARM_AM::no_shift;
628 }
629 }
630
631 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000632 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000633 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
634 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000635 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000636 if (ShOpcVal != ARM_AM::no_shift) {
637 // Check to see if the RHS of the shift is a constant, if not, we can't
638 // fold it.
639 if (ConstantSDNode *Sh =
640 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
641 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000642 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000643 Offset = N.getOperand(0).getOperand(0);
644 Base = N.getOperand(1);
645 } else {
646 ShAmt = 0;
647 ShOpcVal = ARM_AM::no_shift;
648 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000649 } else {
650 ShOpcVal = ARM_AM::no_shift;
651 }
652 }
653 }
654
655 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
656 MVT::i32);
657 return true;
658}
659
660
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000661//-----
662
Jim Grosbach08605202010-09-29 19:03:54 +0000663AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
664 SDValue &Base,
665 SDValue &Offset,
666 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000667 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000668 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000669 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
670 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000671 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000672 if (RHSC & 1) {
673 RHSC = RHSC & ~1;
674 ARM_AM::AddrOpc AddSub = ARM_AM::add;
675 if (RHSC < 0) {
676 AddSub = ARM_AM::sub;
677 RHSC = - RHSC;
678 }
679 if (isPowerOf2_32(RHSC)) {
680 unsigned ShAmt = Log2_32(RHSC);
681 Base = Offset = N.getOperand(0);
682 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
683 ARM_AM::lsl),
Owen Anderson9f944592009-08-11 20:47:22 +0000684 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000685 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000686 }
687 }
688 }
689 }
690
Chris Lattner46c01a32011-02-13 22:25:43 +0000691 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
692 // ISD::OR that is equivalent to an ADD.
693 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000694 Base = N;
695 if (N.getOpcode() == ISD::FrameIndex) {
696 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000697 Base = CurDAG->getTargetFrameIndex(FI,
698 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000699 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000700 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000701 Base = N.getOperand(0);
702 }
Owen Anderson9f944592009-08-11 20:47:22 +0000703 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000704 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
705 ARM_AM::no_shift),
Owen Anderson9f944592009-08-11 20:47:22 +0000706 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000707 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000708 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000709
Evan Cheng10043e22007-01-19 07:51:42 +0000710 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000711 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000712 int RHSC;
713 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
714 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
715 Base = N.getOperand(0);
716 if (Base.getOpcode() == ISD::FrameIndex) {
717 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000718 Base = CurDAG->getTargetFrameIndex(FI,
719 getTargetLowering()->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000720 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000721 Offset = CurDAG->getRegister(0, MVT::i32);
722
723 ARM_AM::AddrOpc AddSub = ARM_AM::add;
724 if (RHSC < 0) {
725 AddSub = ARM_AM::sub;
726 RHSC = - RHSC;
727 }
728 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
729 ARM_AM::no_shift),
730 MVT::i32);
731 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000732 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000733 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000734
Bob Wilsone8a549c2012-09-29 21:43:49 +0000735 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000736 // Compute R +/- (R << N) and reuse it.
737 Base = N;
738 Offset = CurDAG->getRegister(0, MVT::i32);
739 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
740 ARM_AM::no_shift),
741 MVT::i32);
742 return AM2_BASE;
743 }
744
Johnny Chenb678a562009-10-27 17:25:15 +0000745 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000746 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000747 ARM_AM::ShiftOpc ShOpcVal =
748 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000749 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000750
Evan Cheng10043e22007-01-19 07:51:42 +0000751 Base = N.getOperand(0);
752 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000753
Evan Cheng10043e22007-01-19 07:51:42 +0000754 if (ShOpcVal != ARM_AM::no_shift) {
755 // Check to see if the RHS of the shift is a constant, if not, we can't fold
756 // it.
757 if (ConstantSDNode *Sh =
758 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000759 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000760 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
761 Offset = N.getOperand(1).getOperand(0);
762 else {
763 ShAmt = 0;
764 ShOpcVal = ARM_AM::no_shift;
765 }
Evan Cheng10043e22007-01-19 07:51:42 +0000766 } else {
767 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000768 }
769 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000770
Evan Cheng10043e22007-01-19 07:51:42 +0000771 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000772 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000773 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
774 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000775 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000776 if (ShOpcVal != ARM_AM::no_shift) {
777 // Check to see if the RHS of the shift is a constant, if not, we can't
778 // fold it.
779 if (ConstantSDNode *Sh =
780 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000781 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000782 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000783 Offset = N.getOperand(0).getOperand(0);
784 Base = N.getOperand(1);
785 } else {
786 ShAmt = 0;
787 ShOpcVal = ARM_AM::no_shift;
788 }
Evan Cheng10043e22007-01-19 07:51:42 +0000789 } else {
790 ShOpcVal = ARM_AM::no_shift;
791 }
792 }
793 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000794
Evan Cheng10043e22007-01-19 07:51:42 +0000795 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000796 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000797 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000798}
799
Owen Anderson2aedba62011-07-26 20:54:26 +0000800bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000801 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000802 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000803 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
804 ? cast<LoadSDNode>(Op)->getAddressingMode()
805 : cast<StoreSDNode>(Op)->getAddressingMode();
806 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
807 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000808 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000809 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
810 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000811
812 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000813 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000814 unsigned ShAmt = 0;
815 if (ShOpcVal != ARM_AM::no_shift) {
816 // Check to see if the RHS of the shift is a constant, if not, we can't fold
817 // it.
818 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000819 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000820 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
821 Offset = N.getOperand(0);
822 else {
823 ShAmt = 0;
824 ShOpcVal = ARM_AM::no_shift;
825 }
Evan Cheng10043e22007-01-19 07:51:42 +0000826 } else {
827 ShOpcVal = ARM_AM::no_shift;
828 }
829 }
830
831 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000832 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000833 return true;
834}
835
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000836bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
837 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000838 unsigned Opcode = Op->getOpcode();
839 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
840 ? cast<LoadSDNode>(Op)->getAddressingMode()
841 : cast<StoreSDNode>(Op)->getAddressingMode();
842 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
843 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000844 int Val;
845 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000846 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000847 Offset = CurDAG->getRegister(0, MVT::i32);
848 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
849 return true;
850 }
851
852 return false;
853}
854
855
Owen Anderson2aedba62011-07-26 20:54:26 +0000856bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
857 SDValue &Offset, SDValue &Opc) {
858 unsigned Opcode = Op->getOpcode();
859 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
860 ? cast<LoadSDNode>(Op)->getAddressingMode()
861 : cast<StoreSDNode>(Op)->getAddressingMode();
862 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
863 ? ARM_AM::add : ARM_AM::sub;
864 int Val;
865 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
866 Offset = CurDAG->getRegister(0, MVT::i32);
867 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
868 ARM_AM::no_shift),
869 MVT::i32);
870 return true;
871 }
872
873 return false;
874}
875
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000876bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
877 Base = N;
878 return true;
879}
Evan Cheng10043e22007-01-19 07:51:42 +0000880
Chris Lattner0e023ea2010-09-21 20:31:19 +0000881bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000882 SDValue &Base, SDValue &Offset,
883 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000884 if (N.getOpcode() == ISD::SUB) {
885 // X - C is canonicalize to X + -C, no need to handle it here.
886 Base = N.getOperand(0);
887 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000888 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000889 return true;
890 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000891
Chris Lattner46c01a32011-02-13 22:25:43 +0000892 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000893 Base = N;
894 if (N.getOpcode() == ISD::FrameIndex) {
895 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000896 Base = CurDAG->getTargetFrameIndex(FI,
897 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000898 }
Owen Anderson9f944592009-08-11 20:47:22 +0000899 Offset = CurDAG->getRegister(0, MVT::i32);
900 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000901 return true;
902 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000903
Evan Cheng10043e22007-01-19 07:51:42 +0000904 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000905 int RHSC;
906 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
907 -256 + 1, 256, RHSC)) { // 8 bits.
908 Base = N.getOperand(0);
909 if (Base.getOpcode() == ISD::FrameIndex) {
910 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000911 Base = CurDAG->getTargetFrameIndex(FI,
912 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000913 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000914 Offset = CurDAG->getRegister(0, MVT::i32);
915
916 ARM_AM::AddrOpc AddSub = ARM_AM::add;
917 if (RHSC < 0) {
918 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000919 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000920 }
921 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
922 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000923 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000924
Evan Cheng10043e22007-01-19 07:51:42 +0000925 Base = N.getOperand(0);
926 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000927 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000928 return true;
929}
930
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000931bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000932 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000933 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000934 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
935 ? cast<LoadSDNode>(Op)->getAddressingMode()
936 : cast<StoreSDNode>(Op)->getAddressingMode();
937 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
938 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000939 int Val;
940 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
941 Offset = CurDAG->getRegister(0, MVT::i32);
942 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
943 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000944 }
945
946 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000947 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000948 return true;
949}
950
Jim Grosbachd37f0712010-10-21 19:38:40 +0000951bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000952 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000953 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000954 Base = N;
955 if (N.getOpcode() == ISD::FrameIndex) {
956 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000957 Base = CurDAG->getTargetFrameIndex(FI,
958 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000959 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000960 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000961 Base = N.getOperand(0);
962 }
963 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000964 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000965 return true;
966 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000967
Evan Cheng10043e22007-01-19 07:51:42 +0000968 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000969 int RHSC;
970 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
971 -256 + 1, 256, RHSC)) {
972 Base = N.getOperand(0);
973 if (Base.getOpcode() == ISD::FrameIndex) {
974 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000975 Base = CurDAG->getTargetFrameIndex(FI,
976 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000977 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000978
979 ARM_AM::AddrOpc AddSub = ARM_AM::add;
980 if (RHSC < 0) {
981 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000982 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000983 }
984 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
985 MVT::i32);
986 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000987 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000988
Evan Cheng10043e22007-01-19 07:51:42 +0000989 Base = N;
990 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000991 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000992 return true;
993}
994
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000995bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
996 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +0000997 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000998
999 unsigned Alignment = 0;
1000 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1001 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1002 // The maximum alignment is equal to the memory size being referenced.
1003 unsigned LSNAlign = LSN->getAlignment();
1004 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001005 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001006 Alignment = MemSize;
1007 } else {
1008 // All other uses of addrmode6 are for intrinsics. For now just record
1009 // the raw alignment value; it will be refined later based on the legal
1010 // alignment operands for the intrinsic.
1011 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1012 }
1013
1014 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001015 return true;
1016}
1017
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001018bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1019 SDValue &Offset) {
1020 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1021 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1022 if (AM != ISD::POST_INC)
1023 return false;
1024 Offset = N;
1025 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1026 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1027 Offset = CurDAG->getRegister(0, MVT::i32);
1028 }
1029 return true;
1030}
1031
Chris Lattner0e023ea2010-09-21 20:31:19 +00001032bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001033 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001034 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1035 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001036 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001037 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1038 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001039 return true;
1040 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001041
Evan Cheng10043e22007-01-19 07:51:42 +00001042 return false;
1043}
1044
Bill Wendling092a7bd2010-12-14 03:36:38 +00001045
1046//===----------------------------------------------------------------------===//
1047// Thumb Addressing Modes
1048//===----------------------------------------------------------------------===//
1049
Chris Lattner0e023ea2010-09-21 20:31:19 +00001050bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001051 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001052 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001053 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001054 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001055 return false;
1056
1057 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001058 return true;
1059 }
1060
Evan Cheng10043e22007-01-19 07:51:42 +00001061 Base = N.getOperand(0);
1062 Offset = N.getOperand(1);
1063 return true;
1064}
1065
Evan Cheng139edae2007-01-24 02:21:22 +00001066bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001067ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1068 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001069 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001070 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001071 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001072 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001073
Evan Cheng1526ba52007-01-24 08:53:17 +00001074 if (N.getOpcode() == ARMISD::Wrapper &&
1075 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1076 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001077 }
1078
Chris Lattner46c01a32011-02-13 22:25:43 +00001079 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001080 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001081
Evan Cheng650d0672007-02-06 00:22:06 +00001082 // Thumb does not have [sp, r] address mode.
1083 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1084 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1085 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001086 (RHSR && RHSR->getReg() == ARM::SP))
1087 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001088
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001089 // FIXME: Why do we explicitly check for a match here and then return false?
1090 // Presumably to allow something else to match, but shouldn't this be
1091 // documented?
1092 int RHSC;
1093 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1094 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001095
1096 Base = N.getOperand(0);
1097 Offset = N.getOperand(1);
1098 return true;
1099}
1100
1101bool
1102ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1103 SDValue &Base,
1104 SDValue &Offset) {
1105 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1106}
1107
1108bool
1109ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1110 SDValue &Base,
1111 SDValue &Offset) {
1112 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1113}
1114
1115bool
1116ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1117 SDValue &Base,
1118 SDValue &Offset) {
1119 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1120}
1121
1122bool
1123ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1124 SDValue &Base, SDValue &OffImm) {
1125 if (Scale == 4) {
1126 SDValue TmpBase, TmpOffImm;
1127 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1128 return false; // We want to select tLDRspi / tSTRspi instead.
1129
1130 if (N.getOpcode() == ARMISD::Wrapper &&
1131 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1132 return false; // We want to select tLDRpci instead.
1133 }
1134
Chris Lattner46c01a32011-02-13 22:25:43 +00001135 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001136 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001137 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001138 Base = N.getOperand(0);
1139 } else {
1140 Base = N;
1141 }
1142
Owen Anderson9f944592009-08-11 20:47:22 +00001143 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001144 return true;
1145 }
1146
Bill Wendling832a5da2010-12-15 01:03:19 +00001147 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1148 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1149 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1150 (RHSR && RHSR->getReg() == ARM::SP)) {
1151 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1152 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1153 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1154 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1155
1156 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1157 if (LHSC != 0 || RHSC != 0) return false;
1158
1159 Base = N;
1160 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1161 return true;
1162 }
1163
Evan Cheng10043e22007-01-19 07:51:42 +00001164 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001165 int RHSC;
1166 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1167 Base = N.getOperand(0);
1168 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1169 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001170 }
1171
Evan Chengc0b73662007-01-23 22:59:13 +00001172 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001173 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001174 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001175}
1176
Bill Wendling092a7bd2010-12-14 03:36:38 +00001177bool
1178ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1179 SDValue &OffImm) {
1180 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001181}
1182
Bill Wendling092a7bd2010-12-14 03:36:38 +00001183bool
1184ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1185 SDValue &OffImm) {
1186 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001187}
1188
Bill Wendling092a7bd2010-12-14 03:36:38 +00001189bool
1190ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1191 SDValue &OffImm) {
1192 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001193}
1194
Chris Lattner0e023ea2010-09-21 20:31:19 +00001195bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1196 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001197 if (N.getOpcode() == ISD::FrameIndex) {
1198 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001199 Base = CurDAG->getTargetFrameIndex(FI,
1200 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001201 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001202 return true;
1203 }
Evan Cheng139edae2007-01-24 02:21:22 +00001204
Chris Lattner46c01a32011-02-13 22:25:43 +00001205 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001206 return false;
1207
1208 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001209 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1210 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001211 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001212 int RHSC;
1213 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1214 Base = N.getOperand(0);
1215 if (Base.getOpcode() == ISD::FrameIndex) {
1216 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001217 Base = CurDAG->getTargetFrameIndex(FI,
1218 getTargetLowering()->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001219 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001220 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1221 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001222 }
1223 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001224
Evan Cheng10043e22007-01-19 07:51:42 +00001225 return false;
1226}
1227
Bill Wendling092a7bd2010-12-14 03:36:38 +00001228
1229//===----------------------------------------------------------------------===//
1230// Thumb 2 Addressing Modes
1231//===----------------------------------------------------------------------===//
1232
1233
Chris Lattner0e023ea2010-09-21 20:31:19 +00001234bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001235 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001236 if (DisableShifterOp)
1237 return false;
1238
Evan Chenga20cde32011-07-20 23:34:39 +00001239 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001240
1241 // Don't match base register only case. That is matched to a separate
1242 // lower complexity pattern with explicit register operand.
1243 if (ShOpcVal == ARM_AM::no_shift) return false;
1244
1245 BaseReg = N.getOperand(0);
1246 unsigned ShImmVal = 0;
1247 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1248 ShImmVal = RHS->getZExtValue() & 31;
1249 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1250 return true;
1251 }
1252
1253 return false;
1254}
1255
Chris Lattner0e023ea2010-09-21 20:31:19 +00001256bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001257 SDValue &Base, SDValue &OffImm) {
1258 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001259
Evan Cheng36064672009-08-11 08:52:18 +00001260 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001261 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1262 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001263 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001264 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001265 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001266 Base = CurDAG->getTargetFrameIndex(FI,
1267 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001268 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001269 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001270 }
Owen Anderson6d557452011-03-18 19:46:58 +00001271
Chris Lattner46c01a32011-02-13 22:25:43 +00001272 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001273 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng36064672009-08-11 08:52:18 +00001274 Base = N.getOperand(0);
1275 if (Base.getOpcode() == ISD::TargetConstantPool)
1276 return false; // We want to select t2LDRpci instead.
1277 } else
1278 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001279 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001280 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001281 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001282
1283 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001284 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001285 // Let t2LDRi8 handle (R - imm8).
1286 return false;
1287
Evan Chengb23b50d2009-06-29 07:51:04 +00001288 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001289 if (N.getOpcode() == ISD::SUB)
1290 RHSC = -RHSC;
1291
1292 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001293 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001294 if (Base.getOpcode() == ISD::FrameIndex) {
1295 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001296 Base = CurDAG->getTargetFrameIndex(FI,
1297 getTargetLowering()->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001298 }
Owen Anderson9f944592009-08-11 20:47:22 +00001299 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001300 return true;
1301 }
1302 }
1303
Evan Cheng36064672009-08-11 08:52:18 +00001304 // Base only.
1305 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001306 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001307 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001308}
1309
Chris Lattner0e023ea2010-09-21 20:31:19 +00001310bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001311 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001312 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001313 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1314 !CurDAG->isBaseWithConstantOffset(N))
1315 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001316
Chris Lattner46c01a32011-02-13 22:25:43 +00001317 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1318 int RHSC = (int)RHS->getSExtValue();
1319 if (N.getOpcode() == ISD::SUB)
1320 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001321
Chris Lattner46c01a32011-02-13 22:25:43 +00001322 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1323 Base = N.getOperand(0);
1324 if (Base.getOpcode() == ISD::FrameIndex) {
1325 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001326 Base = CurDAG->getTargetFrameIndex(FI,
1327 getTargetLowering()->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001328 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001329 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1330 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001331 }
1332 }
1333
1334 return false;
1335}
1336
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001337bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001338 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001339 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001340 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1341 ? cast<LoadSDNode>(Op)->getAddressingMode()
1342 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001343 int RHSC;
1344 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1345 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1346 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1347 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1348 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001349 }
1350
1351 return false;
1352}
1353
Chris Lattner0e023ea2010-09-21 20:31:19 +00001354bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001355 SDValue &Base,
1356 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001357 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001358 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001359 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001360
Evan Cheng36064672009-08-11 08:52:18 +00001361 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1362 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1363 int RHSC = (int)RHS->getZExtValue();
1364 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1365 return false;
1366 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001367 return false;
1368 }
1369
Evan Chengb23b50d2009-06-29 07:51:04 +00001370 // Look for (R + R) or (R + (R << [1,2,3])).
1371 unsigned ShAmt = 0;
1372 Base = N.getOperand(0);
1373 OffReg = N.getOperand(1);
1374
1375 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001376 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001377 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001378 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001379 if (ShOpcVal == ARM_AM::lsl)
1380 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001381 }
1382
Evan Chengb23b50d2009-06-29 07:51:04 +00001383 if (ShOpcVal == ARM_AM::lsl) {
1384 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1385 // it.
1386 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1387 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001388 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1389 OffReg = OffReg.getOperand(0);
1390 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001391 ShAmt = 0;
1392 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001393 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001394 } else {
1395 ShOpcVal = ARM_AM::no_shift;
1396 }
David Goodwinf3912052009-07-15 15:50:19 +00001397 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001398
Owen Anderson9f944592009-08-11 20:47:22 +00001399 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001400
1401 return true;
1402}
1403
Tim Northovera7ecd242013-07-16 09:46:55 +00001404bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1405 SDValue &OffImm) {
Alp Tokercb402912014-01-24 17:20:08 +00001406 // This *must* succeed since it's used for the irreplaceable ldrex and strex
Tim Northovera7ecd242013-07-16 09:46:55 +00001407 // instructions.
1408 Base = N;
1409 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1410
1411 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1412 return true;
1413
1414 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1415 if (!RHS)
1416 return true;
1417
1418 uint32_t RHSC = (int)RHS->getZExtValue();
1419 if (RHSC > 1020 || RHSC % 4 != 0)
1420 return true;
1421
1422 Base = N.getOperand(0);
1423 if (Base.getOpcode() == ISD::FrameIndex) {
1424 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1425 Base = CurDAG->getTargetFrameIndex(FI, getTargetLowering()->getPointerTy());
1426 }
1427
1428 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1429 return true;
1430}
1431
Evan Chengb23b50d2009-06-29 07:51:04 +00001432//===--------------------------------------------------------------------===//
1433
Evan Cheng7e90b112007-07-05 07:15:27 +00001434/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001435static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001436 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001437}
1438
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001439SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1440 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001441 ISD::MemIndexedMode AM = LD->getAddressingMode();
1442 if (AM == ISD::UNINDEXED)
1443 return NULL;
1444
Owen Anderson53aa7a92009-08-10 22:56:29 +00001445 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001446 SDValue Offset, AMOpc;
1447 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1448 unsigned Opcode = 0;
1449 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001450 if (LoadedVT == MVT::i32 && isPre &&
1451 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1452 Opcode = ARM::LDR_PRE_IMM;
1453 Match = true;
1454 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001455 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001456 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001457 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001458 } else if (LoadedVT == MVT::i32 &&
1459 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001460 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001461 Match = true;
1462
Owen Anderson9f944592009-08-11 20:47:22 +00001463 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001464 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001465 Match = true;
1466 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1467 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1468 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001469 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001470 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001471 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001472 Match = true;
1473 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1474 }
1475 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001476 if (isPre &&
1477 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001478 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001479 Opcode = ARM::LDRB_PRE_IMM;
1480 } else if (!isPre &&
1481 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1482 Match = true;
1483 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001484 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1485 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001486 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001487 }
1488 }
1489 }
1490
1491 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001492 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1493 SDValue Chain = LD->getChain();
1494 SDValue Base = LD->getBasePtr();
1495 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1496 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001497 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001498 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001499 } else {
1500 SDValue Chain = LD->getChain();
1501 SDValue Base = LD->getBasePtr();
1502 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1503 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001504 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001505 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001506 }
Evan Chengd9c55362009-07-02 01:23:32 +00001507 }
1508
1509 return NULL;
1510}
1511
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001512SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1513 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001514 ISD::MemIndexedMode AM = LD->getAddressingMode();
1515 if (AM == ISD::UNINDEXED)
1516 return NULL;
1517
Owen Anderson53aa7a92009-08-10 22:56:29 +00001518 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001519 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001520 SDValue Offset;
1521 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1522 unsigned Opcode = 0;
1523 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001524 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001525 switch (LoadedVT.getSimpleVT().SimpleTy) {
1526 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001527 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1528 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001529 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001530 if (isSExtLd)
1531 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1532 else
1533 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001534 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001535 case MVT::i8:
1536 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001537 if (isSExtLd)
1538 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1539 else
1540 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001541 break;
1542 default:
1543 return NULL;
1544 }
1545 Match = true;
1546 }
1547
1548 if (Match) {
1549 SDValue Chain = LD->getChain();
1550 SDValue Base = LD->getBasePtr();
1551 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001552 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001553 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001554 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001555 }
1556
1557 return NULL;
1558}
1559
Weiming Zhao8f56f882012-11-16 21:55:34 +00001560/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1561SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001562 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001563 SDValue RegClass =
1564 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1565 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1566 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1567 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001568 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001569}
1570
Weiming Zhao95782222012-11-17 00:23:35 +00001571/// \brief Form a D register from a pair of S registers.
1572SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001573 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001574 SDValue RegClass =
1575 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001576 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1577 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001578 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001579 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001580}
1581
Weiming Zhao95782222012-11-17 00:23:35 +00001582/// \brief Form a quad register from a pair of D registers.
1583SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001584 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001585 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001586 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1587 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001588 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001589 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001590}
1591
Weiming Zhao95782222012-11-17 00:23:35 +00001592/// \brief Form 4 consecutive D registers from a pair of Q registers.
1593SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001594 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001595 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001596 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1597 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001598 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001599 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001600}
1601
Weiming Zhao95782222012-11-17 00:23:35 +00001602/// \brief Form 4 consecutive S registers.
1603SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001604 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001605 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001606 SDValue RegClass =
1607 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001608 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1609 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1610 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1611 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001612 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1613 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001614 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001615}
1616
Weiming Zhao95782222012-11-17 00:23:35 +00001617/// \brief Form 4 consecutive D registers.
1618SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001619 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001620 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001621 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001622 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1623 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1624 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1625 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001626 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1627 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001628 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001629}
1630
Weiming Zhao95782222012-11-17 00:23:35 +00001631/// \brief Form 4 consecutive Q registers.
1632SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001633 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001634 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001635 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001636 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1637 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1638 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1639 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001640 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1641 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001642 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001643}
1644
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001645/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1646/// of a NEON VLD or VST instruction. The supported values depend on the
1647/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001648SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1649 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001650 unsigned NumRegs = NumVecs;
1651 if (!is64BitVector && NumVecs < 3)
1652 NumRegs *= 2;
1653
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001654 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001655 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001656 Alignment = 32;
1657 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1658 Alignment = 16;
1659 else if (Alignment >= 8)
1660 Alignment = 8;
1661 else
1662 Alignment = 0;
1663
1664 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001665}
1666
Jiangning Liu4df23632014-01-16 09:16:13 +00001667static bool isVLDfixed(unsigned Opc)
1668{
1669 switch (Opc) {
1670 default: return false;
1671 case ARM::VLD1d8wb_fixed : return true;
1672 case ARM::VLD1d16wb_fixed : return true;
1673 case ARM::VLD1d64Qwb_fixed : return true;
1674 case ARM::VLD1d32wb_fixed : return true;
1675 case ARM::VLD1d64wb_fixed : return true;
1676 case ARM::VLD1d64TPseudoWB_fixed : return true;
1677 case ARM::VLD1d64QPseudoWB_fixed : return true;
1678 case ARM::VLD1q8wb_fixed : return true;
1679 case ARM::VLD1q16wb_fixed : return true;
1680 case ARM::VLD1q32wb_fixed : return true;
1681 case ARM::VLD1q64wb_fixed : return true;
1682 case ARM::VLD2d8wb_fixed : return true;
1683 case ARM::VLD2d16wb_fixed : return true;
1684 case ARM::VLD2d32wb_fixed : return true;
1685 case ARM::VLD2q8PseudoWB_fixed : return true;
1686 case ARM::VLD2q16PseudoWB_fixed : return true;
1687 case ARM::VLD2q32PseudoWB_fixed : return true;
1688 case ARM::VLD2DUPd8wb_fixed : return true;
1689 case ARM::VLD2DUPd16wb_fixed : return true;
1690 case ARM::VLD2DUPd32wb_fixed : return true;
1691 }
1692}
1693
1694static bool isVSTfixed(unsigned Opc)
1695{
1696 switch (Opc) {
1697 default: return false;
1698 case ARM::VST1d8wb_fixed : return true;
1699 case ARM::VST1d16wb_fixed : return true;
1700 case ARM::VST1d32wb_fixed : return true;
1701 case ARM::VST1d64wb_fixed : return true;
1702 case ARM::VST1q8wb_fixed : return true;
1703 case ARM::VST1q16wb_fixed : return true;
1704 case ARM::VST1q32wb_fixed : return true;
1705 case ARM::VST1q64wb_fixed : return true;
1706 case ARM::VST1d64TPseudoWB_fixed : return true;
1707 case ARM::VST1d64QPseudoWB_fixed : return true;
1708 case ARM::VST2d8wb_fixed : return true;
1709 case ARM::VST2d16wb_fixed : return true;
1710 case ARM::VST2d32wb_fixed : return true;
1711 case ARM::VST2q8PseudoWB_fixed : return true;
1712 case ARM::VST2q16PseudoWB_fixed : return true;
1713 case ARM::VST2q32PseudoWB_fixed : return true;
1714 }
1715}
1716
Jim Grosbach2098cb12011-10-24 21:45:13 +00001717// Get the register stride update opcode of a VLD/VST instruction that
1718// is otherwise equivalent to the given fixed stride updating instruction.
1719static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
Jiangning Liu4df23632014-01-16 09:16:13 +00001720 assert((isVLDfixed(Opc) || isVSTfixed(Opc))
1721 && "Incorrect fixed stride updating instruction.");
Jim Grosbach2098cb12011-10-24 21:45:13 +00001722 switch (Opc) {
1723 default: break;
1724 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1725 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1726 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1727 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1728 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1729 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1730 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1731 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jiangning Liu4df23632014-01-16 09:16:13 +00001732 case ARM::VLD1d64Twb_fixed: return ARM::VLD1d64Twb_register;
1733 case ARM::VLD1d64Qwb_fixed: return ARM::VLD1d64Qwb_register;
1734 case ARM::VLD1d64TPseudoWB_fixed: return ARM::VLD1d64TPseudoWB_register;
1735 case ARM::VLD1d64QPseudoWB_fixed: return ARM::VLD1d64QPseudoWB_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001736
1737 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1738 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1739 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1740 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1741 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1742 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1743 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1744 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001745 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001746 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001747
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001748 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1749 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1750 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001751 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1752 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1753 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1754
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001755 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1756 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1757 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001758 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1759 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1760 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001761
Jim Grosbach13a292c2012-03-06 22:01:44 +00001762 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1763 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1764 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001765 }
1766 return Opc; // If not one we handle, return it unchanged.
1767}
1768
Bob Wilson06fce872011-02-07 17:43:21 +00001769SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001770 const uint16_t *DOpcodes,
1771 const uint16_t *QOpcodes0,
1772 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001773 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001774 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001775
Bob Wilsonae08a732010-03-20 22:13:40 +00001776 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001777 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1778 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson12b47992009-10-14 17:28:52 +00001779 return NULL;
1780
1781 SDValue Chain = N->getOperand(0);
1782 EVT VT = N->getValueType(0);
1783 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001784 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001785
Bob Wilson12b47992009-10-14 17:28:52 +00001786 unsigned OpcodeIndex;
1787 switch (VT.getSimpleVT().SimpleTy) {
1788 default: llvm_unreachable("unhandled vld type");
1789 // Double-register operations:
1790 case MVT::v8i8: OpcodeIndex = 0; break;
1791 case MVT::v4i16: OpcodeIndex = 1; break;
1792 case MVT::v2f32:
1793 case MVT::v2i32: OpcodeIndex = 2; break;
1794 case MVT::v1i64: OpcodeIndex = 3; break;
1795 // Quad-register operations:
1796 case MVT::v16i8: OpcodeIndex = 0; break;
1797 case MVT::v8i16: OpcodeIndex = 1; break;
1798 case MVT::v4f32:
1799 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001800 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001801 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001802 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001803 }
1804
Bob Wilson35fafca2010-09-03 18:16:02 +00001805 EVT ResTy;
1806 if (NumVecs == 1)
1807 ResTy = VT;
1808 else {
1809 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1810 if (!is64BitVector)
1811 ResTyElts *= 2;
1812 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1813 }
Bob Wilson06fce872011-02-07 17:43:21 +00001814 std::vector<EVT> ResTys;
1815 ResTys.push_back(ResTy);
1816 if (isUpdating)
1817 ResTys.push_back(MVT::i32);
1818 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001819
Evan Cheng3da64f762010-04-16 05:46:06 +00001820 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001821 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001822 SDNode *VLd;
1823 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001824
Bob Wilson06fce872011-02-07 17:43:21 +00001825 // Double registers and VLD1/VLD2 quad registers are directly supported.
1826 if (is64BitVector || NumVecs <= 2) {
1827 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1828 QOpcodes0[OpcodeIndex]);
1829 Ops.push_back(MemAddr);
1830 Ops.push_back(Align);
1831 if (isUpdating) {
1832 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001833 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001834 // case entirely when the rest are updated to that form, too.
Jiangning Liu4df23632014-01-16 09:16:13 +00001835 if ((NumVecs <= 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001836 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001837 // FIXME: We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001838 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001839 if ((NumVecs > 2 && !isVLDfixed(Opc)) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001840 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001841 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001842 }
Bob Wilson06fce872011-02-07 17:43:21 +00001843 Ops.push_back(Pred);
1844 Ops.push_back(Reg0);
1845 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001846 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001847
Bob Wilson12b47992009-10-14 17:28:52 +00001848 } else {
1849 // Otherwise, quad registers are loaded with two separate instructions,
1850 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001851 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001852
Bob Wilson06fce872011-02-07 17:43:21 +00001853 // Load the even subregs. This is always an updating load, so that it
1854 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001855 SDValue ImplDef =
1856 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1857 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001858 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001859 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001860 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001861
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001862 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001863 Ops.push_back(SDValue(VLdA, 1));
1864 Ops.push_back(Align);
1865 if (isUpdating) {
1866 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1867 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1868 "only constant post-increment update allowed for VLD3/4");
1869 (void)Inc;
1870 Ops.push_back(Reg0);
1871 }
1872 Ops.push_back(SDValue(VLdA, 0));
1873 Ops.push_back(Pred);
1874 Ops.push_back(Reg0);
1875 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001876 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001877 }
Bob Wilson12b47992009-10-14 17:28:52 +00001878
Evan Cheng40791332011-04-19 00:04:03 +00001879 // Transfer memoperands.
1880 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1881 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1882 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1883
Bob Wilson06fce872011-02-07 17:43:21 +00001884 if (NumVecs == 1)
1885 return VLd;
1886
1887 // Extract out the subregisters.
1888 SDValue SuperReg = SDValue(VLd, 0);
1889 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1890 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1891 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1892 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1893 ReplaceUses(SDValue(N, Vec),
1894 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1895 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1896 if (isUpdating)
1897 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson12b47992009-10-14 17:28:52 +00001898 return NULL;
1899}
1900
Bob Wilson06fce872011-02-07 17:43:21 +00001901SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001902 const uint16_t *DOpcodes,
1903 const uint16_t *QOpcodes0,
1904 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001905 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001906 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001907
Bob Wilsonae08a732010-03-20 22:13:40 +00001908 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001909 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1910 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1911 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001912 return NULL;
1913
Evan Cheng40791332011-04-19 00:04:03 +00001914 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1915 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1916
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001917 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001918 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001919 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001920 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001921
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001922 unsigned OpcodeIndex;
1923 switch (VT.getSimpleVT().SimpleTy) {
1924 default: llvm_unreachable("unhandled vst type");
1925 // Double-register operations:
1926 case MVT::v8i8: OpcodeIndex = 0; break;
1927 case MVT::v4i16: OpcodeIndex = 1; break;
1928 case MVT::v2f32:
1929 case MVT::v2i32: OpcodeIndex = 2; break;
1930 case MVT::v1i64: OpcodeIndex = 3; break;
1931 // Quad-register operations:
1932 case MVT::v16i8: OpcodeIndex = 0; break;
1933 case MVT::v8i16: OpcodeIndex = 1; break;
1934 case MVT::v4f32:
1935 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001936 case MVT::v2i64: OpcodeIndex = 3;
1937 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1938 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001939 }
1940
Bob Wilson06fce872011-02-07 17:43:21 +00001941 std::vector<EVT> ResTys;
1942 if (isUpdating)
1943 ResTys.push_back(MVT::i32);
1944 ResTys.push_back(MVT::Other);
1945
Evan Cheng3da64f762010-04-16 05:46:06 +00001946 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001947 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001948 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001949
Bob Wilson06fce872011-02-07 17:43:21 +00001950 // Double registers and VST1/VST2 quad registers are directly supported.
1951 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001952 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001953 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001954 SrcReg = N->getOperand(Vec0Idx);
1955 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001956 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001957 SDValue V0 = N->getOperand(Vec0Idx + 0);
1958 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001959 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001960 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001961 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001962 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001963 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001964 // an undef.
1965 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 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001969 }
Bob Wilson950882b2010-08-28 05:12:57 +00001970 } else {
1971 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001972 SDValue Q0 = N->getOperand(Vec0Idx);
1973 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001974 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001975 }
Bob Wilson06fce872011-02-07 17:43:21 +00001976
1977 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1978 QOpcodes0[OpcodeIndex]);
1979 Ops.push_back(MemAddr);
1980 Ops.push_back(Align);
1981 if (isUpdating) {
1982 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001983 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001984 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001985 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001986 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001987 // FIXME: We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001988 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001989 if (!isa<ConstantSDNode>(Inc.getNode()))
1990 Ops.push_back(Inc);
1991 else if (NumVecs > 2 && !isVSTfixed(Opc))
1992 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00001993 }
1994 Ops.push_back(SrcReg);
1995 Ops.push_back(Pred);
1996 Ops.push_back(Reg0);
1997 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001998 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001999
2000 // Transfer memoperands.
2001 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
2002
2003 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002004 }
2005
2006 // Otherwise, quad registers are stored with two separate instructions,
2007 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00002008
Bob Wilson01ac8f92010-06-16 21:34:01 +00002009 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00002010 SDValue V0 = N->getOperand(Vec0Idx + 0);
2011 SDValue V1 = N->getOperand(Vec0Idx + 1);
2012 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00002013 SDValue V3 = (NumVecs == 3)
2014 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00002015 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002016 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002017
Bob Wilson06fce872011-02-07 17:43:21 +00002018 // Store the even D registers. This is always an updating store, so that it
2019 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00002020 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
2021 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
2022 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00002023 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00002024 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002025 Chain = SDValue(VStA, 1);
2026
2027 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00002028 Ops.push_back(SDValue(VStA, 0));
2029 Ops.push_back(Align);
2030 if (isUpdating) {
2031 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2032 assert(isa<ConstantSDNode>(Inc.getNode()) &&
2033 "only constant post-increment update allowed for VST3/4");
2034 (void)Inc;
2035 Ops.push_back(Reg0);
2036 }
2037 Ops.push_back(RegSeq);
2038 Ops.push_back(Pred);
2039 Ops.push_back(Reg0);
2040 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00002041 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00002042 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002043 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
2044 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002045}
2046
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002047SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00002048 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00002049 const uint16_t *DOpcodes,
2050 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002051 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002052 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002053
Bob Wilsonae08a732010-03-20 22:13:40 +00002054 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002055 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2056 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2057 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson4145e3a2009-10-14 16:19:03 +00002058 return NULL;
2059
Evan Cheng40791332011-04-19 00:04:03 +00002060 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2061 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2062
Bob Wilson4145e3a2009-10-14 16:19:03 +00002063 SDValue Chain = N->getOperand(0);
2064 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002065 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2066 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002067 bool is64BitVector = VT.is64BitVector();
2068
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002069 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002070 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002071 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002072 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2073 if (Alignment > NumBytes)
2074 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002075 if (Alignment < 8 && Alignment < NumBytes)
2076 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002077 // Alignment must be a power of two; make sure of that.
2078 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002079 if (Alignment == 1)
2080 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002081 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002082 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002083
Bob Wilson4145e3a2009-10-14 16:19:03 +00002084 unsigned OpcodeIndex;
2085 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002086 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002087 // Double-register operations:
2088 case MVT::v8i8: OpcodeIndex = 0; break;
2089 case MVT::v4i16: OpcodeIndex = 1; break;
2090 case MVT::v2f32:
2091 case MVT::v2i32: OpcodeIndex = 2; break;
2092 // Quad-register operations:
2093 case MVT::v8i16: OpcodeIndex = 0; break;
2094 case MVT::v4f32:
2095 case MVT::v4i32: OpcodeIndex = 1; break;
2096 }
2097
Bob Wilson06fce872011-02-07 17:43:21 +00002098 std::vector<EVT> ResTys;
2099 if (IsLoad) {
2100 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2101 if (!is64BitVector)
2102 ResTyElts *= 2;
2103 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2104 MVT::i64, ResTyElts));
2105 }
2106 if (isUpdating)
2107 ResTys.push_back(MVT::i32);
2108 ResTys.push_back(MVT::Other);
2109
Evan Cheng3da64f762010-04-16 05:46:06 +00002110 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002111 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002112
Bob Wilson06fce872011-02-07 17:43:21 +00002113 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002114 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002115 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002116 if (isUpdating) {
2117 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2118 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2119 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002120
Bob Wilsond5c57a52010-09-13 23:01:35 +00002121 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002122 SDValue V0 = N->getOperand(Vec0Idx + 0);
2123 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002124 if (NumVecs == 2) {
2125 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002126 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002127 else
Weiming Zhao95782222012-11-17 00:23:35 +00002128 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002129 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002130 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002131 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002132 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2133 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002134 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002135 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002136 else
Weiming Zhao95782222012-11-17 00:23:35 +00002137 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002138 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002139 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002140 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002141 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002142 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002143 Ops.push_back(Chain);
2144
Bob Wilson06fce872011-02-07 17:43:21 +00002145 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2146 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002147 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002148 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002149 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002150 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002151
Bob Wilsond5c57a52010-09-13 23:01:35 +00002152 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002153 SuperReg = SDValue(VLdLn, 0);
2154 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2155 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2156 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002157 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2158 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002159 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2160 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2161 if (isUpdating)
2162 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilson4145e3a2009-10-14 16:19:03 +00002163 return NULL;
2164}
2165
Bob Wilson06fce872011-02-07 17:43:21 +00002166SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002167 unsigned NumVecs,
2168 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002169 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002170 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002171
2172 SDValue MemAddr, Align;
2173 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2174 return NULL;
2175
Evan Cheng40791332011-04-19 00:04:03 +00002176 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2177 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2178
Bob Wilson2d790df2010-11-28 06:51:26 +00002179 SDValue Chain = N->getOperand(0);
2180 EVT VT = N->getValueType(0);
2181
2182 unsigned Alignment = 0;
2183 if (NumVecs != 3) {
2184 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2185 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2186 if (Alignment > NumBytes)
2187 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002188 if (Alignment < 8 && Alignment < NumBytes)
2189 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002190 // Alignment must be a power of two; make sure of that.
2191 Alignment = (Alignment & -Alignment);
2192 if (Alignment == 1)
2193 Alignment = 0;
2194 }
2195 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2196
2197 unsigned OpcodeIndex;
2198 switch (VT.getSimpleVT().SimpleTy) {
2199 default: llvm_unreachable("unhandled vld-dup type");
2200 case MVT::v8i8: OpcodeIndex = 0; break;
2201 case MVT::v4i16: OpcodeIndex = 1; break;
2202 case MVT::v2f32:
2203 case MVT::v2i32: OpcodeIndex = 2; break;
2204 }
2205
2206 SDValue Pred = getAL(CurDAG);
2207 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2208 SDValue SuperReg;
2209 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002210 SmallVector<SDValue, 6> Ops;
2211 Ops.push_back(MemAddr);
2212 Ops.push_back(Align);
2213 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002214 // fixed-stride update instructions don't have an explicit writeback
2215 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002216 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002217 if (!isa<ConstantSDNode>(Inc.getNode()))
2218 Ops.push_back(Inc);
2219 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2220 else if (NumVecs > 2)
2221 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002222 }
2223 Ops.push_back(Pred);
2224 Ops.push_back(Reg0);
2225 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002226
2227 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002228 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002229 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002230 if (isUpdating)
2231 ResTys.push_back(MVT::i32);
2232 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002233 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002234 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002235 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002236
2237 // Extract the subregisters.
2238 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2239 unsigned SubIdx = ARM::dsub_0;
2240 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2241 ReplaceUses(SDValue(N, Vec),
2242 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002243 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2244 if (isUpdating)
2245 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilson2d790df2010-11-28 06:51:26 +00002246 return NULL;
2247}
2248
Bob Wilson5bc8a792010-07-07 00:08:54 +00002249SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2250 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002251 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002252 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002253 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002254 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002255
2256 // Form a REG_SEQUENCE to force register allocation.
2257 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002258 SDValue V0 = N->getOperand(FirstTblReg + 0);
2259 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002260 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002261 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002262 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002263 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002264 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002265 // an undef.
2266 SDValue V3 = (NumVecs == 3)
2267 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002268 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002269 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002270 }
2271
Bob Wilson5bc8a792010-07-07 00:08:54 +00002272 SmallVector<SDValue, 6> Ops;
2273 if (IsExt)
2274 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002275 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002276 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002277 Ops.push_back(getAL(CurDAG)); // predicate
2278 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002279 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002280}
2281
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002282SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002283 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002284 if (!Subtarget->hasV6T2Ops())
2285 return NULL;
Bob Wilson93117bc2009-10-14 16:46:45 +00002286
Evan Chengeae6d2c2012-12-19 20:16:09 +00002287 unsigned Opc = isSigned
2288 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002289 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2290
Jim Grosbach825cb292010-04-22 23:24:18 +00002291 // For unsigned extracts, check for a shift right and mask
2292 unsigned And_imm = 0;
2293 if (N->getOpcode() == ISD::AND) {
2294 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2295
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002296 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002297 if (And_imm & (And_imm + 1))
2298 return NULL;
2299
2300 unsigned Srl_imm = 0;
2301 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2302 Srl_imm)) {
2303 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2304
Jim Grosbach03f56d92011-07-27 21:09:25 +00002305 // Note: The width operand is encoded as width-1.
2306 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002307 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002308
Jim Grosbach825cb292010-04-22 23:24:18 +00002309 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002310
2311 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2312 // It's cheaper to use a right shift to extract the top bits.
2313 if (Subtarget->isThumb()) {
2314 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2315 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2316 CurDAG->getTargetConstant(LSB, MVT::i32),
2317 getAL(CurDAG), Reg0, Reg0 };
2318 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2319 }
2320
2321 // ARM models shift instructions as MOVsi with shifter operand.
2322 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2323 SDValue ShOpc =
2324 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2325 MVT::i32);
2326 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2327 getAL(CurDAG), Reg0, Reg0 };
2328 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops, 5);
2329 }
2330
Jim Grosbach825cb292010-04-22 23:24:18 +00002331 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2332 CurDAG->getTargetConstant(LSB, MVT::i32),
2333 CurDAG->getTargetConstant(Width, MVT::i32),
2334 getAL(CurDAG), Reg0 };
2335 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2336 }
2337 }
2338 return NULL;
2339 }
2340
2341 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002342 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002343 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002344 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2345 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002346 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002347 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002348 // Note: The width operand is encoded as width-1.
2349 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002350 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002351 if (LSB < 0)
Sandeep Patel423e42b2009-10-13 18:59:48 +00002352 return NULL;
2353 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002354 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002355 CurDAG->getTargetConstant(LSB, MVT::i32),
2356 CurDAG->getTargetConstant(Width, MVT::i32),
2357 getAL(CurDAG), Reg0 };
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002358 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002359 }
2360 }
2361 return NULL;
2362}
2363
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002364/// Target-specific DAG combining for ISD::XOR.
2365/// Target-independent combining lowers SELECT_CC nodes of the form
2366/// select_cc setg[ge] X, 0, X, -X
2367/// select_cc setgt X, -1, X, -X
2368/// select_cc setl[te] X, 0, -X, X
2369/// select_cc setlt X, 1, -X, X
2370/// which represent Integer ABS into:
2371/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2372/// ARM instruction selection detects the latter and matches it to
2373/// ARM::ABS or ARM::t2ABS machine node.
2374SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2375 SDValue XORSrc0 = N->getOperand(0);
2376 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002377 EVT VT = N->getValueType(0);
2378
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002379 if (Subtarget->isThumb1Only())
2380 return NULL;
2381
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002382 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002383 return NULL;
2384
2385 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2386 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2387 SDValue SRASrc0 = XORSrc1.getOperand(0);
2388 SDValue SRASrc1 = XORSrc1.getOperand(1);
2389 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2390 EVT XType = SRASrc0.getValueType();
2391 unsigned Size = XType.getSizeInBits() - 1;
2392
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002393 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2394 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002395 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002396 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002397 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2398 }
2399
2400 return NULL;
2401}
2402
Evan Chengd85631e2010-05-05 18:28:36 +00002403SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2404 // The only time a CONCAT_VECTORS operation can have legal types is when
2405 // two 64-bit vectors are concatenated to a 128-bit vector.
2406 EVT VT = N->getValueType(0);
2407 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2408 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002409 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002410}
2411
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002412SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002413 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002414
Tim Northover31d093c2013-09-22 08:21:56 +00002415 if (N->isMachineOpcode()) {
2416 N->setNodeId(-1);
Evan Cheng10043e22007-01-19 07:51:42 +00002417 return NULL; // Already selected.
Tim Northover31d093c2013-09-22 08:21:56 +00002418 }
Rafael Espindola4e760152006-06-12 12:28:08 +00002419
2420 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002421 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002422 case ISD::INLINEASM: {
2423 SDNode *ResNode = SelectInlineAsm(N);
2424 if (ResNode)
2425 return ResNode;
2426 break;
2427 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002428 case ISD::XOR: {
2429 // Select special operations if XOR node forms integer ABS pattern
2430 SDNode *ResNode = SelectABSOp(N);
2431 if (ResNode)
2432 return ResNode;
2433 // Other cases are autogenerated.
2434 break;
2435 }
Evan Cheng10043e22007-01-19 07:51:42 +00002436 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002437 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002438 bool UseCP = true;
Tim Northover55c625f2014-01-23 13:43:47 +00002439 if (Subtarget->useMovt())
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002440 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2441 // be done with MOV + MOVT, at worst.
Tim Northover55c625f2014-01-23 13:43:47 +00002442 UseCP = false;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002443 else {
2444 if (Subtarget->isThumb()) {
Tim Northover55c625f2014-01-23 13:43:47 +00002445 UseCP = (Val > 255 && // MOV
2446 ~Val > 255 && // MOV + MVN
2447 !ARM_AM::isThumbImmShiftedVal(Val) && // MOV + LSL
2448 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002449 } else
Tim Northover55c625f2014-01-23 13:43:47 +00002450 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2451 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2452 !ARM_AM::isSOImmTwoPartVal(Val) && // two instrs.
2453 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002454 }
2455
Evan Cheng10043e22007-01-19 07:51:42 +00002456 if (UseCP) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002457 SDValue CPIdx =
Owen Anderson55f1c092009-08-13 21:58:54 +00002458 CurDAG->getTargetConstantPool(ConstantInt::get(
2459 Type::getInt32Ty(*CurDAG->getContext()), Val),
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002460 getTargetLowering()->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002461
2462 SDNode *ResNode;
Tim Northover55c625f2014-01-23 13:43:47 +00002463 if (Subtarget->isThumb()) {
Evan Cheng3da64f762010-04-16 05:46:06 +00002464 SDValue Pred = getAL(CurDAG);
Owen Anderson9f944592009-08-11 20:47:22 +00002465 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002466 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002467 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002468 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002469 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002470 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002471 CPIdx,
Owen Anderson9f944592009-08-11 20:47:22 +00002472 CurDAG->getTargetConstant(0, MVT::i32),
Evan Cheng7e90b112007-07-05 07:15:27 +00002473 getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00002474 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002475 CurDAG->getEntryNode()
2476 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002477 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002478 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002479 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002480 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Cheng10043e22007-01-19 07:51:42 +00002481 return NULL;
2482 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002483
Evan Cheng10043e22007-01-19 07:51:42 +00002484 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002485 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002486 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002487 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002488 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002489 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002490 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
2491 getTargetLowering()->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002492 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002493 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2494 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2495 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbachfde21102009-04-07 20:34:09 +00002496 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002497 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2498 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002499 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2500 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2501 CurDAG->getRegister(0, MVT::i32) };
2502 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng7e90b112007-07-05 07:15:27 +00002503 }
Evan Cheng10043e22007-01-19 07:51:42 +00002504 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002505 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002506 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002507 return I;
2508 break;
2509 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002510 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002511 return I;
2512 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002513 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002514 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002515 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002516 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002517 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002518 if (!RHSV) break;
2519 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002520 unsigned ShImm = Log2_32(RHSV-1);
2521 if (ShImm >= 32)
2522 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002523 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002524 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002525 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2526 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002527 if (Subtarget->isThumb()) {
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002528 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson9f944592009-08-11 20:47:22 +00002529 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002530 } else {
2531 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002532 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002533 }
Evan Cheng10043e22007-01-19 07:51:42 +00002534 }
2535 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002536 unsigned ShImm = Log2_32(RHSV+1);
2537 if (ShImm >= 32)
2538 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002539 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002540 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002541 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2542 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002543 if (Subtarget->isThumb()) {
Bob Wilsonb6112e82010-05-28 00:27:15 +00002544 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2545 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002546 } else {
2547 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002548 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002549 }
Evan Cheng10043e22007-01-19 07:51:42 +00002550 }
2551 }
2552 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002553 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002554 // Check for unsigned bitfield extract
2555 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2556 return I;
2557
Evan Cheng786b15f2009-10-21 08:15:52 +00002558 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2559 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2560 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2561 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2562 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002563 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002564 if (VT != MVT::i32)
2565 break;
2566 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2567 ? ARM::t2MOVTi16
2568 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2569 if (!Opc)
2570 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002571 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002572 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2573 if (!N1C)
2574 break;
2575 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2576 SDValue N2 = N0.getOperand(1);
2577 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2578 if (!N2C)
2579 break;
2580 unsigned N1CVal = N1C->getZExtValue();
2581 unsigned N2CVal = N2C->getZExtValue();
2582 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2583 (N1CVal & 0xffffU) == 0xffffU &&
2584 (N2CVal & 0xffffU) == 0x0U) {
2585 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2586 MVT::i32);
2587 SDValue Ops[] = { N0.getOperand(0), Imm16,
2588 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002589 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002590 }
2591 }
2592 break;
2593 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002594 case ARMISD::VMOVRRD:
2595 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002596 N->getOperand(0), getAL(CurDAG),
Dan Gohman32f71d72009-09-25 18:54:59 +00002597 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002598 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002599 if (Subtarget->isThumb1Only())
2600 break;
2601 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002602 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Michael Liaob53d8962013-04-19 22:22:57 +00002603 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2604 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002605 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002606 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002607 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2608 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002609 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2610 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002611 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002612 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002613 }
Dan Gohmana1603612007-10-08 18:33:35 +00002614 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002615 if (Subtarget->isThumb1Only())
2616 break;
2617 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002618 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002619 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002620 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002621 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002622 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002623 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2624 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002625 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2626 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002627 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002628 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002629 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002630 case ARMISD::UMLAL:{
2631 if (Subtarget->isThumb()) {
2632 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2633 N->getOperand(3), getAL(CurDAG),
2634 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002635 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002636 }else{
2637 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2638 N->getOperand(3), getAL(CurDAG),
2639 CurDAG->getRegister(0, MVT::i32),
2640 CurDAG->getRegister(0, MVT::i32) };
2641 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2642 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002643 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002644 }
2645 }
2646 case ARMISD::SMLAL:{
2647 if (Subtarget->isThumb()) {
2648 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2649 N->getOperand(3), getAL(CurDAG),
2650 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002651 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002652 }else{
2653 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2654 N->getOperand(3), getAL(CurDAG),
2655 CurDAG->getRegister(0, MVT::i32),
2656 CurDAG->getRegister(0, MVT::i32) };
2657 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2658 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002659 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002660 }
2661 }
Evan Cheng10043e22007-01-19 07:51:42 +00002662 case ISD::LOAD: {
Evan Cheng84c6cda2009-07-02 07:28:31 +00002663 SDNode *ResNode = 0;
Evan Chengb24e51e2009-07-07 01:17:28 +00002664 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002665 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002666 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002667 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002668 if (ResNode)
2669 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002670 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002671 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002672 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002673 case ARMISD::BRCOND: {
2674 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2675 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2676 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002677
Evan Cheng7e90b112007-07-05 07:15:27 +00002678 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2679 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2680 // Pattern complexity = 6 cost = 1 size = 0
2681
David Goodwin27303cd2009-06-30 18:04:13 +00002682 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2683 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2684 // Pattern complexity = 6 cost = 1 size = 0
2685
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002686 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002687 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002688 SDValue Chain = N->getOperand(0);
2689 SDValue N1 = N->getOperand(1);
2690 SDValue N2 = N->getOperand(2);
2691 SDValue N3 = N->getOperand(3);
2692 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002693 assert(N1.getOpcode() == ISD::BasicBlock);
2694 assert(N2.getOpcode() == ISD::Constant);
2695 assert(N3.getOpcode() == ISD::Register);
2696
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002697 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmaneffb8942008-09-12 16:56:44 +00002698 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson9f944592009-08-11 20:47:22 +00002699 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002700 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002701 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002702 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002703 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002704 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002705 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002706 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002707 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002708 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002709 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Cheng7e90b112007-07-05 07:15:27 +00002710 return NULL;
2711 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002712 case ARMISD::VZIP: {
2713 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002714 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002715 switch (VT.getSimpleVT().SimpleTy) {
2716 default: return NULL;
2717 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2718 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2719 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002720 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2721 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002722 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2723 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2724 case MVT::v4f32:
2725 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2726 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002727 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002728 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2729 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002730 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002731 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002732 case ARMISD::VUZP: {
2733 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002734 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002735 switch (VT.getSimpleVT().SimpleTy) {
2736 default: return NULL;
2737 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2738 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2739 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002740 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2741 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002742 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2743 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2744 case MVT::v4f32:
2745 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2746 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002747 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002748 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2749 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002750 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002751 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002752 case ARMISD::VTRN: {
2753 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002754 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002755 switch (VT.getSimpleVT().SimpleTy) {
2756 default: return NULL;
2757 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2758 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2759 case MVT::v2f32:
2760 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2761 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2762 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2763 case MVT::v4f32:
2764 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2765 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002766 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002767 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2768 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002769 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002770 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002771 case ARMISD::BUILD_VECTOR: {
2772 EVT VecVT = N->getValueType(0);
2773 EVT EltVT = VecVT.getVectorElementType();
2774 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002775 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002776 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002777 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002778 }
Duncan Sands14627772010-11-03 12:17:33 +00002779 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002780 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002781 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002782 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002783 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002784 N->getOperand(2), N->getOperand(3));
2785 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002786
Bob Wilson2d790df2010-11-28 06:51:26 +00002787 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002788 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2789 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002790 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002791 }
2792
Bob Wilson77ab1652010-11-29 19:35:29 +00002793 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002794 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2795 ARM::VLD3DUPd16Pseudo,
2796 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002797 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002798 }
2799
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002800 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002801 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2802 ARM::VLD4DUPd16Pseudo,
2803 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002804 return SelectVLDDup(N, false, 4, Opcodes);
2805 }
2806
2807 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002808 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2809 ARM::VLD2DUPd16wb_fixed,
2810 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002811 return SelectVLDDup(N, true, 2, Opcodes);
2812 }
2813
2814 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002815 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2816 ARM::VLD3DUPd16Pseudo_UPD,
2817 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002818 return SelectVLDDup(N, true, 3, Opcodes);
2819 }
2820
2821 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002822 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2823 ARM::VLD4DUPd16Pseudo_UPD,
2824 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002825 return SelectVLDDup(N, true, 4, Opcodes);
2826 }
2827
2828 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002829 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2830 ARM::VLD1d16wb_fixed,
2831 ARM::VLD1d32wb_fixed,
2832 ARM::VLD1d64wb_fixed };
2833 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2834 ARM::VLD1q16wb_fixed,
2835 ARM::VLD1q32wb_fixed,
2836 ARM::VLD1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002837 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2838 }
2839
2840 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002841 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2842 ARM::VLD2d16wb_fixed,
2843 ARM::VLD2d32wb_fixed,
2844 ARM::VLD1q64wb_fixed};
2845 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2846 ARM::VLD2q16PseudoWB_fixed,
2847 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002848 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2849 }
2850
2851 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002852 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2853 ARM::VLD3d16Pseudo_UPD,
2854 ARM::VLD3d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002855 ARM::VLD1d64TPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002856 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2857 ARM::VLD3q16Pseudo_UPD,
2858 ARM::VLD3q32Pseudo_UPD };
2859 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2860 ARM::VLD3q16oddPseudo_UPD,
2861 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002862 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2863 }
2864
2865 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002866 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2867 ARM::VLD4d16Pseudo_UPD,
2868 ARM::VLD4d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002869 ARM::VLD1d64QPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002870 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2871 ARM::VLD4q16Pseudo_UPD,
2872 ARM::VLD4q32Pseudo_UPD };
2873 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2874 ARM::VLD4q16oddPseudo_UPD,
2875 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002876 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2877 }
2878
2879 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002880 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2881 ARM::VLD2LNd16Pseudo_UPD,
2882 ARM::VLD2LNd32Pseudo_UPD };
2883 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2884 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002885 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2886 }
2887
2888 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002889 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2890 ARM::VLD3LNd16Pseudo_UPD,
2891 ARM::VLD3LNd32Pseudo_UPD };
2892 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2893 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002894 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2895 }
2896
2897 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002898 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2899 ARM::VLD4LNd16Pseudo_UPD,
2900 ARM::VLD4LNd32Pseudo_UPD };
2901 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2902 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002903 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2904 }
2905
2906 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002907 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2908 ARM::VST1d16wb_fixed,
2909 ARM::VST1d32wb_fixed,
2910 ARM::VST1d64wb_fixed };
2911 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2912 ARM::VST1q16wb_fixed,
2913 ARM::VST1q32wb_fixed,
2914 ARM::VST1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002915 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2916 }
2917
2918 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002919 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2920 ARM::VST2d16wb_fixed,
2921 ARM::VST2d32wb_fixed,
2922 ARM::VST1q64wb_fixed};
2923 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2924 ARM::VST2q16PseudoWB_fixed,
2925 ARM::VST2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002926 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2927 }
2928
2929 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002930 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2931 ARM::VST3d16Pseudo_UPD,
2932 ARM::VST3d32Pseudo_UPD,
2933 ARM::VST1d64TPseudoWB_fixed};
2934 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2935 ARM::VST3q16Pseudo_UPD,
2936 ARM::VST3q32Pseudo_UPD };
2937 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2938 ARM::VST3q16oddPseudo_UPD,
2939 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002940 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2941 }
2942
2943 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002944 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2945 ARM::VST4d16Pseudo_UPD,
2946 ARM::VST4d32Pseudo_UPD,
2947 ARM::VST1d64QPseudoWB_fixed};
2948 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2949 ARM::VST4q16Pseudo_UPD,
2950 ARM::VST4q32Pseudo_UPD };
2951 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2952 ARM::VST4q16oddPseudo_UPD,
2953 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002954 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2955 }
2956
2957 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002958 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2959 ARM::VST2LNd16Pseudo_UPD,
2960 ARM::VST2LNd32Pseudo_UPD };
2961 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2962 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002963 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2964 }
2965
2966 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002967 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2968 ARM::VST3LNd16Pseudo_UPD,
2969 ARM::VST3LNd32Pseudo_UPD };
2970 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2971 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002972 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2973 }
2974
2975 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002976 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2977 ARM::VST4LNd16Pseudo_UPD,
2978 ARM::VST4LNd32Pseudo_UPD };
2979 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2980 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002981 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002982 }
2983
Bob Wilsone0636a72009-08-26 17:39:53 +00002984 case ISD::INTRINSIC_VOID:
2985 case ISD::INTRINSIC_W_CHAIN: {
2986 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00002987 switch (IntNo) {
2988 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00002989 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00002990
Tim Northover1ff5f292014-03-26 14:39:31 +00002991 case Intrinsic::arm_ldaexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002992 case Intrinsic::arm_ldrexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002993 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002994 SDValue Chain = N->getOperand(0);
Tim Northover1ff5f292014-03-26 14:39:31 +00002995 SDValue MemAddr = N->getOperand(2);
Weiming Zhao8f56f882012-11-16 21:55:34 +00002996 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
Tim Northover1ff5f292014-03-26 14:39:31 +00002997
2998 bool IsAcquire = IntNo == Intrinsic::arm_ldaexd;
2999 unsigned NewOpc = isThumb ? (IsAcquire ? ARM::t2LDAEXD : ARM::t2LDREXD)
3000 : (IsAcquire ? ARM::LDAEXD : ARM::LDREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003001
3002 // arm_ldrexd returns a i64 value in {i32, i32}
3003 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003004 if (isThumb) {
3005 ResTys.push_back(MVT::i32);
3006 ResTys.push_back(MVT::i32);
3007 } else
3008 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003009 ResTys.push_back(MVT::Other);
3010
Weiming Zhao8f56f882012-11-16 21:55:34 +00003011 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003012 SmallVector<SDValue, 7> Ops;
3013 Ops.push_back(MemAddr);
3014 Ops.push_back(getAL(CurDAG));
3015 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3016 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00003017 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003018 // Transfer memoperands.
3019 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3020 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3021 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3022
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003023 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00003024 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003025 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003026 SDValue Result;
3027 if (isThumb)
3028 Result = SDValue(Ld, 0);
3029 else {
3030 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
3031 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003032 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003033 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003034 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003035 ReplaceUses(SDValue(N, 0), Result);
3036 }
3037 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003038 SDValue Result;
3039 if (isThumb)
3040 Result = SDValue(Ld, 1);
3041 else {
3042 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3043 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003044 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003045 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003046 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003047 ReplaceUses(SDValue(N, 1), Result);
3048 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003049 ReplaceUses(SDValue(N, 2), OutChain);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003050 return NULL;
3051 }
Tim Northover1ff5f292014-03-26 14:39:31 +00003052 case Intrinsic::arm_stlexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003053 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003054 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003055 SDValue Chain = N->getOperand(0);
3056 SDValue Val0 = N->getOperand(2);
3057 SDValue Val1 = N->getOperand(3);
3058 SDValue MemAddr = N->getOperand(4);
3059
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003060 // Store exclusive double return a i32 value which is the return status
3061 // of the issued store.
Benjamin Kramerfdf362b2013-03-07 20:33:29 +00003062 EVT ResTys[] = { MVT::i32, MVT::Other };
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003063
Weiming Zhao8f56f882012-11-16 21:55:34 +00003064 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3065 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003066 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003067 if (isThumb) {
3068 Ops.push_back(Val0);
3069 Ops.push_back(Val1);
3070 } else
3071 // arm_strexd uses GPRPair.
3072 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003073 Ops.push_back(MemAddr);
3074 Ops.push_back(getAL(CurDAG));
3075 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3076 Ops.push_back(Chain);
3077
Tim Northover1ff5f292014-03-26 14:39:31 +00003078 bool IsRelease = IntNo == Intrinsic::arm_stlexd;
3079 unsigned NewOpc = isThumb ? (IsRelease ? ARM::t2STLEXD : ARM::t2STREXD)
3080 : (IsRelease ? ARM::STLEXD : ARM::STREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003081
Michael Liaob53d8962013-04-19 22:22:57 +00003082 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003083 // Transfer memoperands.
3084 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3085 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3086 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3087
3088 return St;
3089 }
3090
Bob Wilson340861d2010-03-23 05:25:43 +00003091 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003092 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3093 ARM::VLD1d32, ARM::VLD1d64 };
3094 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3095 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson06fce872011-02-07 17:43:21 +00003096 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson340861d2010-03-23 05:25:43 +00003097 }
3098
Bob Wilsone0636a72009-08-26 17:39:53 +00003099 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003100 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3101 ARM::VLD2d32, ARM::VLD1q64 };
3102 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3103 ARM::VLD2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003104 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003105 }
3106
3107 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003108 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3109 ARM::VLD3d16Pseudo,
3110 ARM::VLD3d32Pseudo,
3111 ARM::VLD1d64TPseudo };
3112 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3113 ARM::VLD3q16Pseudo_UPD,
3114 ARM::VLD3q32Pseudo_UPD };
3115 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3116 ARM::VLD3q16oddPseudo,
3117 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003118 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003119 }
3120
3121 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003122 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3123 ARM::VLD4d16Pseudo,
3124 ARM::VLD4d32Pseudo,
3125 ARM::VLD1d64QPseudo };
3126 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3127 ARM::VLD4q16Pseudo_UPD,
3128 ARM::VLD4q32Pseudo_UPD };
3129 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3130 ARM::VLD4q16oddPseudo,
3131 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003132 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003133 }
3134
Bob Wilsonda9817c2009-09-01 04:26:28 +00003135 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003136 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3137 ARM::VLD2LNd16Pseudo,
3138 ARM::VLD2LNd32Pseudo };
3139 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3140 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003141 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003142 }
3143
3144 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003145 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3146 ARM::VLD3LNd16Pseudo,
3147 ARM::VLD3LNd32Pseudo };
3148 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3149 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003150 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003151 }
3152
3153 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003154 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3155 ARM::VLD4LNd16Pseudo,
3156 ARM::VLD4LNd32Pseudo };
3157 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3158 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003159 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003160 }
3161
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003162 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003163 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3164 ARM::VST1d32, ARM::VST1d64 };
3165 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3166 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson06fce872011-02-07 17:43:21 +00003167 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003168 }
3169
Bob Wilsone0636a72009-08-26 17:39:53 +00003170 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003171 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3172 ARM::VST2d32, ARM::VST1q64 };
3173 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3174 ARM::VST2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003175 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003176 }
3177
3178 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003179 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3180 ARM::VST3d16Pseudo,
3181 ARM::VST3d32Pseudo,
3182 ARM::VST1d64TPseudo };
3183 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3184 ARM::VST3q16Pseudo_UPD,
3185 ARM::VST3q32Pseudo_UPD };
3186 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3187 ARM::VST3q16oddPseudo,
3188 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003189 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003190 }
3191
3192 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003193 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3194 ARM::VST4d16Pseudo,
3195 ARM::VST4d32Pseudo,
3196 ARM::VST1d64QPseudo };
3197 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3198 ARM::VST4q16Pseudo_UPD,
3199 ARM::VST4q32Pseudo_UPD };
3200 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3201 ARM::VST4q16oddPseudo,
3202 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003203 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003204 }
Bob Wilsond7797752009-09-01 18:51:56 +00003205
3206 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003207 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3208 ARM::VST2LNd16Pseudo,
3209 ARM::VST2LNd32Pseudo };
3210 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3211 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003212 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003213 }
3214
3215 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003216 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3217 ARM::VST3LNd16Pseudo,
3218 ARM::VST3LNd32Pseudo };
3219 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3220 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003221 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003222 }
3223
3224 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003225 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3226 ARM::VST4LNd16Pseudo,
3227 ARM::VST4LNd32Pseudo };
3228 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3229 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003230 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003231 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003232 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003233 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003234 }
Evan Chengd85631e2010-05-05 18:28:36 +00003235
Bob Wilson3ed511b2010-07-06 23:36:25 +00003236 case ISD::INTRINSIC_WO_CHAIN: {
3237 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3238 switch (IntNo) {
3239 default:
3240 break;
3241
3242 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003243 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003244 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003245 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003246 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003247 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003248
3249 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003250 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003251 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003252 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003253 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003254 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003255 }
3256 break;
3257 }
3258
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003259 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003260 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003261 EVT VT = N->getValueType(0);
3262 SmallVector<SDValue, 6> Ops;
3263
3264 Ops.push_back(N->getOperand(0));
3265 Ops.push_back(N->getOperand(1));
3266 Ops.push_back(getAL(CurDAG)); // Predicate
3267 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003268 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003269 }
3270 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003271 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003272 EVT VT = N->getValueType(0);
3273
3274 // Form a REG_SEQUENCE to force register allocation.
3275 SDValue V0 = N->getOperand(0);
3276 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003277 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003278
3279 SmallVector<SDValue, 6> Ops;
3280 Ops.push_back(RegSeq);
3281 Ops.push_back(N->getOperand(2));
3282 Ops.push_back(getAL(CurDAG)); // Predicate
3283 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003284 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003285 }
3286
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003287 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003288 return SelectConcatVector(N);
3289 }
Evan Chengd5021732008-12-10 21:54:21 +00003290
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003291 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003292}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003293
Weiming Zhaoc5987002013-02-14 18:10:21 +00003294SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3295 std::vector<SDValue> AsmNodeOperands;
3296 unsigned Flag, Kind;
3297 bool Changed = false;
3298 unsigned NumOps = N->getNumOperands();
3299
Weiming Zhaoc5987002013-02-14 18:10:21 +00003300 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3301 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3302 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3303 // respectively. Since there is no constraint to explicitly specify a
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003304 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3305 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3306 // them into a GPRPair.
Weiming Zhaoc5987002013-02-14 18:10:21 +00003307
Andrew Trickef9de2a2013-05-25 02:42:55 +00003308 SDLoc dl(N);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003309 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1) : SDValue(0,0);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003310
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003311 SmallVector<bool, 8> OpChanged;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003312 // Glue node will be appended late.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003313 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
Weiming Zhaoc5987002013-02-14 18:10:21 +00003314 SDValue op = N->getOperand(i);
3315 AsmNodeOperands.push_back(op);
3316
3317 if (i < InlineAsm::Op_FirstOperand)
3318 continue;
3319
3320 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3321 Flag = C->getZExtValue();
3322 Kind = InlineAsm::getKind(Flag);
3323 }
3324 else
3325 continue;
3326
Joey Gouly392cdad2013-07-08 19:52:51 +00003327 // Immediate operands to inline asm in the SelectionDAG are modeled with
3328 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3329 // the second is a constant with the value of the immediate. If we get here
3330 // and we have a Kind_Imm, skip the next operand, and continue.
Joey Gouly606f3fb2013-07-05 10:19:40 +00003331 if (Kind == InlineAsm::Kind_Imm) {
3332 SDValue op = N->getOperand(++i);
3333 AsmNodeOperands.push_back(op);
3334 continue;
3335 }
3336
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003337 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3338 if (NumRegs)
3339 OpChanged.push_back(false);
3340
3341 unsigned DefIdx = 0;
3342 bool IsTiedToChangedOp = false;
3343 // If it's a use that is tied with a previous def, it has no
3344 // reg class constraint.
3345 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3346 IsTiedToChangedOp = OpChanged[DefIdx];
3347
Weiming Zhaoc5987002013-02-14 18:10:21 +00003348 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3349 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3350 continue;
3351
Weiming Zhaoc5987002013-02-14 18:10:21 +00003352 unsigned RC;
3353 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003354 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3355 || NumRegs != 2)
Weiming Zhaoc5987002013-02-14 18:10:21 +00003356 continue;
3357
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003358 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
Weiming Zhaoc5987002013-02-14 18:10:21 +00003359 SDValue V0 = N->getOperand(i+1);
3360 SDValue V1 = N->getOperand(i+2);
3361 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3362 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3363 SDValue PairedReg;
3364 MachineRegisterInfo &MRI = MF->getRegInfo();
3365
3366 if (Kind == InlineAsm::Kind_RegDef ||
3367 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3368 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3369 // the original GPRs.
3370
3371 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3372 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3373 SDValue Chain = SDValue(N,0);
3374
3375 SDNode *GU = N->getGluedUser();
3376 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3377 Chain.getValue(1));
3378
3379 // Extract values from a GPRPair reg and copy to the original GPR reg.
3380 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3381 RegCopy);
3382 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3383 RegCopy);
3384 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3385 RegCopy.getValue(1));
3386 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3387
3388 // Update the original glue user.
3389 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3390 Ops.push_back(T1.getValue(1));
3391 CurDAG->UpdateNodeOperands(GU, &Ops[0], Ops.size());
3392 GU = T1.getNode();
3393 }
3394 else {
3395 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3396 // GPRPair and then pass the GPRPair to the inline asm.
3397 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3398
3399 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3400 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3401 Chain.getValue(1));
3402 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3403 T0.getValue(1));
3404 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3405
3406 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3407 // i32 VRs of inline asm with it.
3408 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3409 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3410 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3411
3412 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3413 Glue = Chain.getValue(1);
3414 }
3415
3416 Changed = true;
3417
3418 if(PairedReg.getNode()) {
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003419 OpChanged[OpChanged.size() -1 ] = true;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003420 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
Tim Northover55349a22013-08-18 18:06:03 +00003421 if (IsTiedToChangedOp)
3422 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3423 else
3424 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003425 // Replace the current flag.
3426 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3427 Flag, MVT::i32);
3428 // Add the new register node and skip the original two GPRs.
3429 AsmNodeOperands.push_back(PairedReg);
3430 // Skip the next two GPRs.
3431 i += 2;
3432 }
3433 }
3434
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003435 if (Glue.getNode())
3436 AsmNodeOperands.push_back(Glue);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003437 if (!Changed)
3438 return NULL;
3439
Andrew Trickef9de2a2013-05-25 02:42:55 +00003440 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Weiming Zhaoc5987002013-02-14 18:10:21 +00003441 CurDAG->getVTList(MVT::Other, MVT::Glue), &AsmNodeOperands[0],
3442 AsmNodeOperands.size());
3443 New->setNodeId(-1);
3444 return New.getNode();
3445}
3446
3447
Bob Wilsona2c462b2009-05-19 05:53:42 +00003448bool ARMDAGToDAGISel::
3449SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3450 std::vector<SDValue> &OutOps) {
3451 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003452 // Require the address to be in a register. That is safe for all ARM
3453 // variants and it is hard to do anything much smarter without knowing
3454 // how the operand is used.
3455 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003456 return false;
3457}
3458
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003459/// createARMISelDag - This pass converts a legalized DAG into a
3460/// ARM-specific DAG, ready for instruction scheduling.
3461///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003462FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3463 CodeGenOpt::Level OptLevel) {
3464 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003465}