blob: 19bc2cab668e3c9aa6e004003f2eeb0650ebe8d2 [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
14#include "ARM.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000015#include "ARMBaseInstrInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Evan Chenga20cde32011-07-20 23:34:39 +000017#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000018#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
Weiming Zhaoc5987002013-02-14 18:10:21 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000022#include "llvm/CodeGen/SelectionDAG.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/CallingConv.h"
25#include "llvm/IR/Constants.h"
26#include "llvm/IR/DerivedTypes.h"
27#include "llvm/IR/Function.h"
28#include "llvm/IR/Intrinsics.h"
29#include "llvm/IR/LLVMContext.h"
Evan Cheng8e6b40a2010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner1770fb82008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Target/TargetLowering.h"
35#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000036
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000037using namespace llvm;
38
Chandler Carruth84e68b22014-04-22 02:41:26 +000039#define DEBUG_TYPE "arm-isel"
40
Evan Cheng59069ec2010-07-30 23:33:54 +000041static cl::opt<bool>
42DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
44 cl::init(false));
45
Evan Cheng62c7b5b2010-12-05 22:04:16 +000046static cl::opt<bool>
47CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000049 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000050
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000051//===--------------------------------------------------------------------===//
52/// ARMDAGToDAGISel - ARM specific code to select ARM machine
53/// instructions for SelectionDAG operations.
54///
55namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000056
57enum AddrMode2Type {
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
60};
61
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000062class ARMDAGToDAGISel : public SelectionDAGISel {
Evan Cheng10043e22007-01-19 07:51:42 +000063 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
64 /// make the right decision when generating code for different targets.
65 const ARMSubtarget *Subtarget;
66
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000067public:
Eric Christopher2f991c92014-07-03 22:24:49 +000068 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm, CodeGenOpt::Level OptLevel)
69 : SelectionDAGISel(tm, OptLevel) {}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000070
Eric Christopher0e6e7cf2014-05-22 02:00:27 +000071 bool runOnMachineFunction(MachineFunction &MF) override {
72 // Reset the subtarget each time through.
Eric Christopher2f991c92014-07-03 22:24:49 +000073 Subtarget = &MF.getTarget().getSubtarget<ARMSubtarget>();
Eric Christopher0e6e7cf2014-05-22 02:00:27 +000074 SelectionDAGISel::runOnMachineFunction(MF);
75 return true;
76 }
77
Craig Topper6bc27bf2014-03-10 02:09:33 +000078 const char *getPassName() const override {
Evan Cheng10043e22007-01-19 07:51:42 +000079 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000080 }
81
Craig Topper6bc27bf2014-03-10 02:09:33 +000082 void PreprocessISelDAG() override;
Evan Chengeae6d2c2012-12-19 20:16:09 +000083
Bob Wilson4facd962009-10-08 18:51:31 +000084 /// getI32Imm - Return a target constant of type i32 with the specified
85 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000086 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000087 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000088 }
89
Craig Topper6bc27bf2014-03-10 02:09:33 +000090 SDNode *Select(SDNode *N) override;
Evan Cheng5e73ff22010-02-15 19:41:07 +000091
Evan Cheng62c7b5b2010-12-05 22:04:16 +000092
93 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000094 bool isShifterOpProfitable(const SDValue &Shift,
95 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000096 bool SelectRegShifterOperand(SDValue N, SDValue &A,
97 SDValue &B, SDValue &C,
98 bool CheckProfitability = true);
99 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +0000100 SDValue &B, bool CheckProfitability = true);
101 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000102 SDValue &B, SDValue &C) {
103 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000104 return SelectRegShifterOperand(N, A, B, C, false);
105 }
106 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
107 SDValue &B) {
108 // Don't apply the profitability check
109 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000110 }
111
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000112 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
113 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
114
Jim Grosbach08605202010-09-29 19:03:54 +0000115 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
116 SDValue &Offset, SDValue &Opc);
117 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
118 SDValue &Opc) {
119 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
120 }
121
122 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
123 SDValue &Opc) {
124 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
125 }
126
127 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
128 SDValue &Opc) {
129 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000130// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000131 // This always matches one way or another.
132 return true;
133 }
134
Tim Northover42180442013-08-22 09:57:11 +0000135 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
136 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
137 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
138 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
139 return true;
140 }
141
Owen Anderson2aedba62011-07-26 20:54:26 +0000142 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
143 SDValue &Offset, SDValue &Opc);
144 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000145 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000146 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
147 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000148 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000149 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000150 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000151 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000152 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000153 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000154 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000155 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000156 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000157
Evan Chengdfce83c2011-01-17 08:03:18 +0000158 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000159
Bill Wendling092a7bd2010-12-14 03:36:38 +0000160 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000161 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000162 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
163 unsigned Scale);
164 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
165 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
166 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
167 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
168 SDValue &OffImm);
169 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
170 SDValue &OffImm);
171 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
172 SDValue &OffImm);
173 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
174 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000175 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000176
Bill Wendling092a7bd2010-12-14 03:36:38 +0000177 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000178 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000179 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000180 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
181 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000182 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000183 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000184 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000185 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000186 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000187 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000188
Evan Cheng0fc80842010-11-12 22:42:47 +0000189 inline bool is_so_imm(unsigned Imm) const {
190 return ARM_AM::getSOImmVal(Imm) != -1;
191 }
192
193 inline bool is_so_imm_not(unsigned Imm) const {
194 return ARM_AM::getSOImmVal(~Imm) != -1;
195 }
196
197 inline bool is_t2_so_imm(unsigned Imm) const {
198 return ARM_AM::getT2SOImmVal(Imm) != -1;
199 }
200
201 inline bool is_t2_so_imm_not(unsigned Imm) const {
202 return ARM_AM::getT2SOImmVal(~Imm) != -1;
203 }
204
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000205 // Include the pieces autogenerated from the target description.
206#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000207
208private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000209 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
210 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000211 SDNode *SelectARMIndexedLoad(SDNode *N);
212 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000213
Bob Wilson340861d2010-03-23 05:25:43 +0000214 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
215 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000216 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000217 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000218 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000219 const uint16_t *DOpcodes,
220 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000221
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000222 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000223 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000224 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000225 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000226 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000227 const uint16_t *DOpcodes,
228 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000229
Bob Wilson93117bc2009-10-14 16:46:45 +0000230 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000231 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000232 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000233 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
234 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000235 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000236
Bob Wilson2d790df2010-11-28 06:51:26 +0000237 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
238 /// should be 2, 3 or 4. The opcode array specifies the instructions used
239 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000240 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000241 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000242
Bob Wilson5bc8a792010-07-07 00:08:54 +0000243 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
244 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
245 /// generated to force the table registers to be consecutive.
246 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000247
Sandeep Patel7460e082009-10-13 20:25:58 +0000248 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000249 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000250
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000251 // Select special operations if node forms integer ABS pattern
252 SDNode *SelectABSOp(SDNode *N);
253
Weiming Zhaoc5987002013-02-14 18:10:21 +0000254 SDNode *SelectInlineAsm(SDNode *N);
255
Evan Chengd85631e2010-05-05 18:28:36 +0000256 SDNode *SelectConcatVector(SDNode *N);
257
Evan Chengd9c55362009-07-02 01:23:32 +0000258 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
259 /// inline asm expressions.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000260 bool SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
261 std::vector<SDValue> &OutOps) override;
Bob Wilsone6b778d2009-10-06 22:01:59 +0000262
Weiming Zhao95782222012-11-17 00:23:35 +0000263 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000264 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000265 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
266 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
267 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000268
Bob Wilsond8a9a042010-06-04 00:04:02 +0000269 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000270 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
271 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
272 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000273
274 // Get the alignment operand for a NEON VLD or VST instruction.
275 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000276};
Evan Cheng10043e22007-01-19 07:51:42 +0000277}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000278
Sandeep Patel423e42b2009-10-13 18:59:48 +0000279/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
280/// operand. If so Imm will receive the 32-bit value.
281static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
282 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
283 Imm = cast<ConstantSDNode>(N)->getZExtValue();
284 return true;
285 }
286 return false;
287}
288
289// isInt32Immediate - This method tests to see if a constant operand.
290// If so Imm will receive the 32 bit value.
291static bool isInt32Immediate(SDValue N, unsigned &Imm) {
292 return isInt32Immediate(N.getNode(), Imm);
293}
294
295// isOpcWithIntImmediate - This method tests to see if the node is a specific
296// opcode and that it has a immediate integer right operand.
297// If so Imm will receive the 32 bit value.
298static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
299 return N->getOpcode() == Opc &&
300 isInt32Immediate(N->getOperand(1).getNode(), Imm);
301}
302
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000303/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000304/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000305///
306/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000307static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000308 int RangeMin, int RangeMax,
309 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000310 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000311
312 // Check that this is a constant.
313 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
314 if (!C)
315 return false;
316
317 ScaledConstant = (int) C->getZExtValue();
318 if ((ScaledConstant % Scale) != 0)
319 return false;
320
321 ScaledConstant /= Scale;
322 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
323}
324
Evan Chengeae6d2c2012-12-19 20:16:09 +0000325void ARMDAGToDAGISel::PreprocessISelDAG() {
326 if (!Subtarget->hasV6T2Ops())
327 return;
328
329 bool isThumb2 = Subtarget->isThumb();
330 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
331 E = CurDAG->allnodes_end(); I != E; ) {
332 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
333
334 if (N->getOpcode() != ISD::ADD)
335 continue;
336
337 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
338 // leading zeros, followed by consecutive set bits, followed by 1 or 2
339 // trailing zeros, e.g. 1020.
340 // Transform the expression to
341 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
342 // of trailing zeros of c2. The left shift would be folded as an shifter
343 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
344 // node (UBFX).
345
346 SDValue N0 = N->getOperand(0);
347 SDValue N1 = N->getOperand(1);
348 unsigned And_imm = 0;
349 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
350 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
351 std::swap(N0, N1);
352 }
353 if (!And_imm)
354 continue;
355
356 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000357 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000358 if (TZ != 1 && TZ != 2)
359 // Be conservative here. Shifter operands aren't always free. e.g. On
360 // Swift, left shifter operand of 1 / 2 for free but others are not.
361 // e.g.
362 // ubfx r3, r1, #16, #8
363 // ldr.w r3, [r0, r3, lsl #2]
364 // vs.
365 // mov.w r9, #1020
366 // and.w r2, r9, r1, lsr #14
367 // ldr r2, [r0, r2]
368 continue;
369 And_imm >>= TZ;
370 if (And_imm & (And_imm + 1))
371 continue;
372
373 // Look for (and (srl X, c1), c2).
374 SDValue Srl = N1.getOperand(0);
375 unsigned Srl_imm = 0;
376 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
377 (Srl_imm <= 2))
378 continue;
379
380 // Make sure first operand is not a shifter operand which would prevent
381 // folding of the left shift.
382 SDValue CPTmp0;
383 SDValue CPTmp1;
384 SDValue CPTmp2;
385 if (isThumb2) {
386 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
387 continue;
388 } else {
389 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
390 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
391 continue;
392 }
393
394 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000395 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000396 Srl.getOperand(0),
397 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000398 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000399 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000400 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000401 N1, CurDAG->getConstant(TZ, MVT::i32));
402 CurDAG->UpdateNodeOperands(N, N0, N1);
Jim Grosbach1a597112014-04-03 23:43:18 +0000403 }
Evan Chengeae6d2c2012-12-19 20:16:09 +0000404}
405
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000406/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
407/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
408/// least on current ARM implementations) which should be avoidded.
409bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
410 if (OptLevel == CodeGenOpt::None)
411 return true;
412
413 if (!CheckVMLxHazard)
414 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000415
Tim Northover0feb91e2014-04-01 14:10:07 +0000416 if (!Subtarget->isCortexA7() && !Subtarget->isCortexA8() &&
417 !Subtarget->isCortexA9() && !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000418 return true;
419
420 if (!N->hasOneUse())
421 return false;
422
423 SDNode *Use = *N->use_begin();
424 if (Use->getOpcode() == ISD::CopyToReg)
425 return true;
426 if (Use->isMachineOpcode()) {
Eric Christopher2f991c92014-07-03 22:24:49 +0000427 const ARMBaseInstrInfo *TII = static_cast<const ARMBaseInstrInfo *>(
Eric Christopherfc6de422014-08-05 02:39:49 +0000428 CurDAG->getSubtarget().getInstrInfo());
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000429
Evan Cheng6cc775f2011-06-28 19:10:37 +0000430 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
431 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000432 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000433 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000434 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
435 return true;
436 // vmlx feeding into another vmlx. We actually want to unfold
437 // the use later in the MLxExpansion pass. e.g.
438 // vmla
439 // vmla (stall 8 cycles)
440 //
441 // vmul (5 cycles)
442 // vadd (5 cycles)
443 // vmla
444 // This adds up to about 18 - 19 cycles.
445 //
446 // vmla
447 // vmul (stall 4 cycles)
448 // vadd adds up to about 14 cycles.
449 return TII->isFpMLxInstruction(Opcode);
450 }
451
452 return false;
453}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000454
Evan Cheng59bbc542010-10-27 23:41:30 +0000455bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
456 ARM_AM::ShiftOpc ShOpcVal,
457 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000458 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000459 return true;
460 if (Shift.hasOneUse())
461 return true;
462 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000463 return ShOpcVal == ARM_AM::lsl &&
464 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000465}
466
Owen Andersonb595ed02011-07-21 18:54:16 +0000467bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000468 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000469 SDValue &Opc,
470 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000471 if (DisableShifterOp)
472 return false;
473
Evan Chenga20cde32011-07-20 23:34:39 +0000474 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000475
476 // Don't match base register only case. That is matched to a separate
477 // lower complexity pattern with explicit register operand.
478 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000479
Evan Chengb23b50d2009-06-29 07:51:04 +0000480 BaseReg = N.getOperand(0);
481 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000482 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
483 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000484 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000485 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
486 MVT::i32);
487 return true;
488}
489
Owen Andersonb595ed02011-07-21 18:54:16 +0000490bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
491 SDValue &BaseReg,
492 SDValue &ShReg,
493 SDValue &Opc,
494 bool CheckProfitability) {
495 if (DisableShifterOp)
496 return false;
497
498 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
499
500 // Don't match base register only case. That is matched to a separate
501 // lower complexity pattern with explicit register operand.
502 if (ShOpcVal == ARM_AM::no_shift) return false;
503
504 BaseReg = N.getOperand(0);
505 unsigned ShImmVal = 0;
506 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
507 if (RHS) return false;
508
509 ShReg = N.getOperand(1);
510 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
511 return false;
512 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
513 MVT::i32);
514 return true;
515}
516
517
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000518bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
519 SDValue &Base,
520 SDValue &OffImm) {
521 // Match simple R + imm12 operands.
522
523 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000524 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
525 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000526 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000527 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000528 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000529 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000530 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
531 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000532 }
Owen Anderson6d557452011-03-18 19:46:58 +0000533
Chris Lattner46c01a32011-02-13 22:25:43 +0000534 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000535 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000536 Base = N.getOperand(0);
537 } else
538 Base = N;
539 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
540 return true;
541 }
542
543 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Renato Golin63e27982014-09-09 09:57:59 +0000544 int RHSC = (int)RHS->getSExtValue();
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000545 if (N.getOpcode() == ISD::SUB)
546 RHSC = -RHSC;
547
Renato Golin63e27982014-09-09 09:57:59 +0000548 if (RHSC > -0x1000 && RHSC < 0x1000) { // 12 bits
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000549 Base = N.getOperand(0);
550 if (Base.getOpcode() == ISD::FrameIndex) {
551 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000552 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000553 }
554 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
555 return true;
556 }
557 }
558
559 // Base only.
560 Base = N;
561 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
562 return true;
563}
564
565
566
567bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
568 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000569 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000570 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000571 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
572 // X * [3,5,9] -> X + X * [2,4,8] etc.
573 int RHSC = (int)RHS->getZExtValue();
574 if (RHSC & 1) {
575 RHSC = RHSC & ~1;
576 ARM_AM::AddrOpc AddSub = ARM_AM::add;
577 if (RHSC < 0) {
578 AddSub = ARM_AM::sub;
579 RHSC = - RHSC;
580 }
581 if (isPowerOf2_32(RHSC)) {
582 unsigned ShAmt = Log2_32(RHSC);
583 Base = Offset = N.getOperand(0);
584 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
585 ARM_AM::lsl),
586 MVT::i32);
587 return true;
588 }
589 }
590 }
591 }
592
Chris Lattner46c01a32011-02-13 22:25:43 +0000593 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
594 // ISD::OR that is equivalent to an ISD::ADD.
595 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000596 return false;
597
598 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000599 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000600 int RHSC;
601 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
602 -0x1000+1, 0x1000, RHSC)) // 12 bits.
603 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000604 }
605
606 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000607 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000608 ARM_AM::ShiftOpc ShOpcVal =
609 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000610 unsigned ShAmt = 0;
611
612 Base = N.getOperand(0);
613 Offset = N.getOperand(1);
614
615 if (ShOpcVal != ARM_AM::no_shift) {
616 // Check to see if the RHS of the shift is a constant, if not, we can't fold
617 // it.
618 if (ConstantSDNode *Sh =
619 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
620 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000621 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
622 Offset = N.getOperand(1).getOperand(0);
623 else {
624 ShAmt = 0;
625 ShOpcVal = ARM_AM::no_shift;
626 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000627 } else {
628 ShOpcVal = ARM_AM::no_shift;
629 }
630 }
631
632 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000633 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000634 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
635 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000636 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000637 if (ShOpcVal != ARM_AM::no_shift) {
638 // Check to see if the RHS of the shift is a constant, if not, we can't
639 // fold it.
640 if (ConstantSDNode *Sh =
641 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
642 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000643 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000644 Offset = N.getOperand(0).getOperand(0);
645 Base = N.getOperand(1);
646 } else {
647 ShAmt = 0;
648 ShOpcVal = ARM_AM::no_shift;
649 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000650 } else {
651 ShOpcVal = ARM_AM::no_shift;
652 }
653 }
654 }
655
656 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
657 MVT::i32);
658 return true;
659}
660
661
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000662//-----
663
Jim Grosbach08605202010-09-29 19:03:54 +0000664AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
665 SDValue &Base,
666 SDValue &Offset,
667 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000668 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000669 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000670 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
671 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000672 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000673 if (RHSC & 1) {
674 RHSC = RHSC & ~1;
675 ARM_AM::AddrOpc AddSub = ARM_AM::add;
676 if (RHSC < 0) {
677 AddSub = ARM_AM::sub;
678 RHSC = - RHSC;
679 }
680 if (isPowerOf2_32(RHSC)) {
681 unsigned ShAmt = Log2_32(RHSC);
682 Base = Offset = N.getOperand(0);
683 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
684 ARM_AM::lsl),
Owen Anderson9f944592009-08-11 20:47:22 +0000685 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000686 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000687 }
688 }
689 }
690 }
691
Chris Lattner46c01a32011-02-13 22:25:43 +0000692 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
693 // ISD::OR that is equivalent to an ADD.
694 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000695 Base = N;
696 if (N.getOpcode() == ISD::FrameIndex) {
697 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000698 Base = CurDAG->getTargetFrameIndex(FI, TLI->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();
Eric Christopherb17140d2014-10-08 07:32:17 +0000718 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000719 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000720 Offset = CurDAG->getRegister(0, MVT::i32);
721
722 ARM_AM::AddrOpc AddSub = ARM_AM::add;
723 if (RHSC < 0) {
724 AddSub = ARM_AM::sub;
725 RHSC = - RHSC;
726 }
727 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
728 ARM_AM::no_shift),
729 MVT::i32);
730 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000731 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000732 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000733
Bob Wilsone8a549c2012-09-29 21:43:49 +0000734 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000735 // Compute R +/- (R << N) and reuse it.
736 Base = N;
737 Offset = CurDAG->getRegister(0, MVT::i32);
738 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
739 ARM_AM::no_shift),
740 MVT::i32);
741 return AM2_BASE;
742 }
743
Johnny Chenb678a562009-10-27 17:25:15 +0000744 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000745 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000746 ARM_AM::ShiftOpc ShOpcVal =
747 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000748 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000749
Evan Cheng10043e22007-01-19 07:51:42 +0000750 Base = N.getOperand(0);
751 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000752
Evan Cheng10043e22007-01-19 07:51:42 +0000753 if (ShOpcVal != ARM_AM::no_shift) {
754 // Check to see if the RHS of the shift is a constant, if not, we can't fold
755 // it.
756 if (ConstantSDNode *Sh =
757 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000758 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000759 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
760 Offset = N.getOperand(1).getOperand(0);
761 else {
762 ShAmt = 0;
763 ShOpcVal = ARM_AM::no_shift;
764 }
Evan Cheng10043e22007-01-19 07:51:42 +0000765 } else {
766 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000767 }
768 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000769
Evan Cheng10043e22007-01-19 07:51:42 +0000770 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000771 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000772 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
773 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000774 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000775 if (ShOpcVal != ARM_AM::no_shift) {
776 // Check to see if the RHS of the shift is a constant, if not, we can't
777 // fold it.
778 if (ConstantSDNode *Sh =
779 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000780 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000781 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000782 Offset = N.getOperand(0).getOperand(0);
783 Base = N.getOperand(1);
784 } else {
785 ShAmt = 0;
786 ShOpcVal = ARM_AM::no_shift;
787 }
Evan Cheng10043e22007-01-19 07:51:42 +0000788 } else {
789 ShOpcVal = ARM_AM::no_shift;
790 }
791 }
792 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000793
Evan Cheng10043e22007-01-19 07:51:42 +0000794 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000795 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000796 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000797}
798
Owen Anderson2aedba62011-07-26 20:54:26 +0000799bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000800 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000801 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000802 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
803 ? cast<LoadSDNode>(Op)->getAddressingMode()
804 : cast<StoreSDNode>(Op)->getAddressingMode();
805 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
806 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000807 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000808 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
809 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000810
811 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000812 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000813 unsigned ShAmt = 0;
814 if (ShOpcVal != ARM_AM::no_shift) {
815 // Check to see if the RHS of the shift is a constant, if not, we can't fold
816 // it.
817 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000818 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000819 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
820 Offset = N.getOperand(0);
821 else {
822 ShAmt = 0;
823 ShOpcVal = ARM_AM::no_shift;
824 }
Evan Cheng10043e22007-01-19 07:51:42 +0000825 } else {
826 ShOpcVal = ARM_AM::no_shift;
827 }
828 }
829
830 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000831 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000832 return true;
833}
834
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000835bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
836 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000837 unsigned Opcode = Op->getOpcode();
838 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
839 ? cast<LoadSDNode>(Op)->getAddressingMode()
840 : cast<StoreSDNode>(Op)->getAddressingMode();
841 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
842 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000843 int Val;
844 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000845 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000846 Offset = CurDAG->getRegister(0, MVT::i32);
847 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
848 return true;
849 }
850
851 return false;
852}
853
854
Owen Anderson2aedba62011-07-26 20:54:26 +0000855bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
856 SDValue &Offset, SDValue &Opc) {
857 unsigned Opcode = Op->getOpcode();
858 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
859 ? cast<LoadSDNode>(Op)->getAddressingMode()
860 : cast<StoreSDNode>(Op)->getAddressingMode();
861 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
862 ? ARM_AM::add : ARM_AM::sub;
863 int Val;
864 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
865 Offset = CurDAG->getRegister(0, MVT::i32);
866 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
867 ARM_AM::no_shift),
868 MVT::i32);
869 return true;
870 }
871
872 return false;
873}
874
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000875bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
876 Base = N;
877 return true;
878}
Evan Cheng10043e22007-01-19 07:51:42 +0000879
Chris Lattner0e023ea2010-09-21 20:31:19 +0000880bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000881 SDValue &Base, SDValue &Offset,
882 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000883 if (N.getOpcode() == ISD::SUB) {
884 // X - C is canonicalize to X + -C, no need to handle it here.
885 Base = N.getOperand(0);
886 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000887 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000888 return true;
889 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000890
Chris Lattner46c01a32011-02-13 22:25:43 +0000891 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000892 Base = N;
893 if (N.getOpcode() == ISD::FrameIndex) {
894 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000895 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000896 }
Owen Anderson9f944592009-08-11 20:47:22 +0000897 Offset = CurDAG->getRegister(0, MVT::i32);
898 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000899 return true;
900 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000901
Evan Cheng10043e22007-01-19 07:51:42 +0000902 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000903 int RHSC;
904 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
905 -256 + 1, 256, RHSC)) { // 8 bits.
906 Base = N.getOperand(0);
907 if (Base.getOpcode() == ISD::FrameIndex) {
908 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000909 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000910 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000911 Offset = CurDAG->getRegister(0, MVT::i32);
912
913 ARM_AM::AddrOpc AddSub = ARM_AM::add;
914 if (RHSC < 0) {
915 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000916 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000917 }
918 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
919 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000920 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000921
Evan Cheng10043e22007-01-19 07:51:42 +0000922 Base = N.getOperand(0);
923 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000924 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000925 return true;
926}
927
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000928bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000929 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000930 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000931 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
932 ? cast<LoadSDNode>(Op)->getAddressingMode()
933 : cast<StoreSDNode>(Op)->getAddressingMode();
934 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
935 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000936 int Val;
937 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
938 Offset = CurDAG->getRegister(0, MVT::i32);
939 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
940 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000941 }
942
943 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000944 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000945 return true;
946}
947
Jim Grosbachd37f0712010-10-21 19:38:40 +0000948bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000949 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000950 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000951 Base = N;
952 if (N.getOpcode() == ISD::FrameIndex) {
953 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000954 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000955 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000956 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000957 Base = N.getOperand(0);
958 }
959 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000960 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000961 return true;
962 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000963
Evan Cheng10043e22007-01-19 07:51:42 +0000964 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000965 int RHSC;
966 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
967 -256 + 1, 256, RHSC)) {
968 Base = N.getOperand(0);
969 if (Base.getOpcode() == ISD::FrameIndex) {
970 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000971 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000972 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000973
974 ARM_AM::AddrOpc AddSub = ARM_AM::add;
975 if (RHSC < 0) {
976 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000977 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000978 }
979 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
980 MVT::i32);
981 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000982 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000983
Evan Cheng10043e22007-01-19 07:51:42 +0000984 Base = N;
985 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000986 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000987 return true;
988}
989
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000990bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
991 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +0000992 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000993
994 unsigned Alignment = 0;
995 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
996 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
997 // The maximum alignment is equal to the memory size being referenced.
998 unsigned LSNAlign = LSN->getAlignment();
999 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001000 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001001 Alignment = MemSize;
1002 } else {
1003 // All other uses of addrmode6 are for intrinsics. For now just record
1004 // the raw alignment value; it will be refined later based on the legal
1005 // alignment operands for the intrinsic.
1006 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1007 }
1008
1009 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001010 return true;
1011}
1012
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001013bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1014 SDValue &Offset) {
1015 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1016 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1017 if (AM != ISD::POST_INC)
1018 return false;
1019 Offset = N;
1020 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1021 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1022 Offset = CurDAG->getRegister(0, MVT::i32);
1023 }
1024 return true;
1025}
1026
Chris Lattner0e023ea2010-09-21 20:31:19 +00001027bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001028 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001029 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1030 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001031 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001032 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1033 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001034 return true;
1035 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001036
Evan Cheng10043e22007-01-19 07:51:42 +00001037 return false;
1038}
1039
Bill Wendling092a7bd2010-12-14 03:36:38 +00001040
1041//===----------------------------------------------------------------------===//
1042// Thumb Addressing Modes
1043//===----------------------------------------------------------------------===//
1044
Chris Lattner0e023ea2010-09-21 20:31:19 +00001045bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001046 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001047 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001048 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001049 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001050 return false;
1051
1052 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001053 return true;
1054 }
1055
Evan Cheng10043e22007-01-19 07:51:42 +00001056 Base = N.getOperand(0);
1057 Offset = N.getOperand(1);
1058 return true;
1059}
1060
Evan Cheng139edae2007-01-24 02:21:22 +00001061bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001062ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1063 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001064 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001065 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001066 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001067 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001068
Evan Cheng1526ba52007-01-24 08:53:17 +00001069 if (N.getOpcode() == ARMISD::Wrapper &&
1070 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1071 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001072 }
1073
Chris Lattner46c01a32011-02-13 22:25:43 +00001074 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001075 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001076
Evan Cheng650d0672007-02-06 00:22:06 +00001077 // Thumb does not have [sp, r] address mode.
1078 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1079 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1080 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001081 (RHSR && RHSR->getReg() == ARM::SP))
1082 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001083
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001084 // FIXME: Why do we explicitly check for a match here and then return false?
1085 // Presumably to allow something else to match, but shouldn't this be
1086 // documented?
1087 int RHSC;
1088 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1089 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001090
1091 Base = N.getOperand(0);
1092 Offset = N.getOperand(1);
1093 return true;
1094}
1095
1096bool
1097ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1098 SDValue &Base,
1099 SDValue &Offset) {
1100 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1101}
1102
1103bool
1104ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1105 SDValue &Base,
1106 SDValue &Offset) {
1107 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1108}
1109
1110bool
1111ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1112 SDValue &Base,
1113 SDValue &Offset) {
1114 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1115}
1116
1117bool
1118ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1119 SDValue &Base, SDValue &OffImm) {
1120 if (Scale == 4) {
1121 SDValue TmpBase, TmpOffImm;
1122 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1123 return false; // We want to select tLDRspi / tSTRspi instead.
1124
1125 if (N.getOpcode() == ARMISD::Wrapper &&
1126 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1127 return false; // We want to select tLDRpci instead.
1128 }
1129
Chris Lattner46c01a32011-02-13 22:25:43 +00001130 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001131 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001132 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001133 Base = N.getOperand(0);
1134 } else {
1135 Base = N;
1136 }
1137
Owen Anderson9f944592009-08-11 20:47:22 +00001138 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001139 return true;
1140 }
1141
Bill Wendling832a5da2010-12-15 01:03:19 +00001142 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1143 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1144 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1145 (RHSR && RHSR->getReg() == ARM::SP)) {
1146 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1147 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1148 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1149 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1150
1151 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1152 if (LHSC != 0 || RHSC != 0) return false;
1153
1154 Base = N;
1155 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1156 return true;
1157 }
1158
Evan Cheng10043e22007-01-19 07:51:42 +00001159 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001160 int RHSC;
1161 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1162 Base = N.getOperand(0);
1163 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1164 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001165 }
1166
Evan Chengc0b73662007-01-23 22:59:13 +00001167 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001168 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001169 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001170}
1171
Bill Wendling092a7bd2010-12-14 03:36:38 +00001172bool
1173ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1174 SDValue &OffImm) {
1175 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001176}
1177
Bill Wendling092a7bd2010-12-14 03:36:38 +00001178bool
1179ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1180 SDValue &OffImm) {
1181 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001182}
1183
Bill Wendling092a7bd2010-12-14 03:36:38 +00001184bool
1185ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1186 SDValue &OffImm) {
1187 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001188}
1189
Chris Lattner0e023ea2010-09-21 20:31:19 +00001190bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1191 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001192 if (N.getOpcode() == ISD::FrameIndex) {
1193 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001194 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001195 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001196 return true;
1197 }
Evan Cheng139edae2007-01-24 02:21:22 +00001198
Chris Lattner46c01a32011-02-13 22:25:43 +00001199 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001200 return false;
1201
1202 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001203 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1204 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001205 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001206 int RHSC;
1207 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1208 Base = N.getOperand(0);
1209 if (Base.getOpcode() == ISD::FrameIndex) {
1210 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001211 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001212 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001213 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1214 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001215 }
1216 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001217
Evan Cheng10043e22007-01-19 07:51:42 +00001218 return false;
1219}
1220
Bill Wendling092a7bd2010-12-14 03:36:38 +00001221
1222//===----------------------------------------------------------------------===//
1223// Thumb 2 Addressing Modes
1224//===----------------------------------------------------------------------===//
1225
1226
Chris Lattner0e023ea2010-09-21 20:31:19 +00001227bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001228 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001229 if (DisableShifterOp)
1230 return false;
1231
Evan Chenga20cde32011-07-20 23:34:39 +00001232 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001233
1234 // Don't match base register only case. That is matched to a separate
1235 // lower complexity pattern with explicit register operand.
1236 if (ShOpcVal == ARM_AM::no_shift) return false;
1237
1238 BaseReg = N.getOperand(0);
1239 unsigned ShImmVal = 0;
1240 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1241 ShImmVal = RHS->getZExtValue() & 31;
1242 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1243 return true;
1244 }
1245
1246 return false;
1247}
1248
Chris Lattner0e023ea2010-09-21 20:31:19 +00001249bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001250 SDValue &Base, SDValue &OffImm) {
1251 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001252
Evan Cheng36064672009-08-11 08:52:18 +00001253 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001254 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1255 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001256 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001257 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001258 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001259 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001260 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001261 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001262 }
Owen Anderson6d557452011-03-18 19:46:58 +00001263
Chris Lattner46c01a32011-02-13 22:25:43 +00001264 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001265 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng36064672009-08-11 08:52:18 +00001266 Base = N.getOperand(0);
1267 if (Base.getOpcode() == ISD::TargetConstantPool)
1268 return false; // We want to select t2LDRpci instead.
1269 } else
1270 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001271 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001272 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001273 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001274
1275 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001276 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001277 // Let t2LDRi8 handle (R - imm8).
1278 return false;
1279
Evan Chengb23b50d2009-06-29 07:51:04 +00001280 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001281 if (N.getOpcode() == ISD::SUB)
1282 RHSC = -RHSC;
1283
1284 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001285 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001286 if (Base.getOpcode() == ISD::FrameIndex) {
1287 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001288 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001289 }
Owen Anderson9f944592009-08-11 20:47:22 +00001290 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001291 return true;
1292 }
1293 }
1294
Evan Cheng36064672009-08-11 08:52:18 +00001295 // Base only.
1296 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001297 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001298 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001299}
1300
Chris Lattner0e023ea2010-09-21 20:31:19 +00001301bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001302 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001303 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001304 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1305 !CurDAG->isBaseWithConstantOffset(N))
1306 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001307
Chris Lattner46c01a32011-02-13 22:25:43 +00001308 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1309 int RHSC = (int)RHS->getSExtValue();
1310 if (N.getOpcode() == ISD::SUB)
1311 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001312
Chris Lattner46c01a32011-02-13 22:25:43 +00001313 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1314 Base = N.getOperand(0);
1315 if (Base.getOpcode() == ISD::FrameIndex) {
1316 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001317 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001318 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001319 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1320 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001321 }
1322 }
1323
1324 return false;
1325}
1326
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001327bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001328 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001329 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001330 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1331 ? cast<LoadSDNode>(Op)->getAddressingMode()
1332 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001333 int RHSC;
1334 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1335 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1336 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1337 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1338 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001339 }
1340
1341 return false;
1342}
1343
Chris Lattner0e023ea2010-09-21 20:31:19 +00001344bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001345 SDValue &Base,
1346 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001347 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001348 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001349 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001350
Evan Cheng36064672009-08-11 08:52:18 +00001351 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1352 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1353 int RHSC = (int)RHS->getZExtValue();
1354 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1355 return false;
1356 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001357 return false;
1358 }
1359
Evan Chengb23b50d2009-06-29 07:51:04 +00001360 // Look for (R + R) or (R + (R << [1,2,3])).
1361 unsigned ShAmt = 0;
1362 Base = N.getOperand(0);
1363 OffReg = N.getOperand(1);
1364
1365 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001366 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001367 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001368 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001369 if (ShOpcVal == ARM_AM::lsl)
1370 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001371 }
1372
Evan Chengb23b50d2009-06-29 07:51:04 +00001373 if (ShOpcVal == ARM_AM::lsl) {
1374 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1375 // it.
1376 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1377 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001378 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1379 OffReg = OffReg.getOperand(0);
1380 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001381 ShAmt = 0;
1382 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001383 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001384 } else {
1385 ShOpcVal = ARM_AM::no_shift;
1386 }
David Goodwinf3912052009-07-15 15:50:19 +00001387 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001388
Owen Anderson9f944592009-08-11 20:47:22 +00001389 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001390
1391 return true;
1392}
1393
Tim Northovera7ecd242013-07-16 09:46:55 +00001394bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1395 SDValue &OffImm) {
Alp Tokercb402912014-01-24 17:20:08 +00001396 // This *must* succeed since it's used for the irreplaceable ldrex and strex
Tim Northovera7ecd242013-07-16 09:46:55 +00001397 // instructions.
1398 Base = N;
1399 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1400
1401 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1402 return true;
1403
1404 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1405 if (!RHS)
1406 return true;
1407
1408 uint32_t RHSC = (int)RHS->getZExtValue();
1409 if (RHSC > 1020 || RHSC % 4 != 0)
1410 return true;
1411
1412 Base = N.getOperand(0);
1413 if (Base.getOpcode() == ISD::FrameIndex) {
1414 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001415 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Tim Northovera7ecd242013-07-16 09:46:55 +00001416 }
1417
1418 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1419 return true;
1420}
1421
Evan Chengb23b50d2009-06-29 07:51:04 +00001422//===--------------------------------------------------------------------===//
1423
Evan Cheng7e90b112007-07-05 07:15:27 +00001424/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001425static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001426 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001427}
1428
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001429SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1430 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001431 ISD::MemIndexedMode AM = LD->getAddressingMode();
1432 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001433 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001434
Owen Anderson53aa7a92009-08-10 22:56:29 +00001435 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001436 SDValue Offset, AMOpc;
1437 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1438 unsigned Opcode = 0;
1439 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001440 if (LoadedVT == MVT::i32 && isPre &&
1441 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1442 Opcode = ARM::LDR_PRE_IMM;
1443 Match = true;
1444 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001445 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001446 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001447 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001448 } else if (LoadedVT == MVT::i32 &&
1449 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001450 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001451 Match = true;
1452
Owen Anderson9f944592009-08-11 20:47:22 +00001453 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001454 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001455 Match = true;
1456 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1457 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1458 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001459 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001460 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001461 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001462 Match = true;
1463 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1464 }
1465 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001466 if (isPre &&
1467 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001468 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001469 Opcode = ARM::LDRB_PRE_IMM;
1470 } else if (!isPre &&
1471 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1472 Match = true;
1473 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001474 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1475 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001476 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001477 }
1478 }
1479 }
1480
1481 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001482 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1483 SDValue Chain = LD->getChain();
1484 SDValue Base = LD->getBasePtr();
1485 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1486 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001487 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001488 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001489 } else {
1490 SDValue Chain = LD->getChain();
1491 SDValue Base = LD->getBasePtr();
1492 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1493 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001494 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001495 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001496 }
Evan Chengd9c55362009-07-02 01:23:32 +00001497 }
1498
Craig Topper062a2ba2014-04-25 05:30:21 +00001499 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001500}
1501
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001502SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1503 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001504 ISD::MemIndexedMode AM = LD->getAddressingMode();
1505 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001506 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001507
Owen Anderson53aa7a92009-08-10 22:56:29 +00001508 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001509 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001510 SDValue Offset;
1511 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1512 unsigned Opcode = 0;
1513 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001514 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001515 switch (LoadedVT.getSimpleVT().SimpleTy) {
1516 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001517 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1518 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001519 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001520 if (isSExtLd)
1521 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1522 else
1523 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001524 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001525 case MVT::i8:
1526 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001527 if (isSExtLd)
1528 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1529 else
1530 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001531 break;
1532 default:
Craig Topper062a2ba2014-04-25 05:30:21 +00001533 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001534 }
1535 Match = true;
1536 }
1537
1538 if (Match) {
1539 SDValue Chain = LD->getChain();
1540 SDValue Base = LD->getBasePtr();
1541 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001542 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001543 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001544 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001545 }
1546
Craig Topper062a2ba2014-04-25 05:30:21 +00001547 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001548}
1549
Weiming Zhao8f56f882012-11-16 21:55:34 +00001550/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1551SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001552 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001553 SDValue RegClass =
1554 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1555 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1556 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1557 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001558 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001559}
1560
Weiming Zhao95782222012-11-17 00:23:35 +00001561/// \brief Form a D register from a pair of S registers.
1562SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001563 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001564 SDValue RegClass =
1565 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001566 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1567 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001568 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001569 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001570}
1571
Weiming Zhao95782222012-11-17 00:23:35 +00001572/// \brief Form a quad register from a pair of D registers.
1573SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001574 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001575 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001576 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1577 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_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 Wilsone6b778d2009-10-06 22:01:59 +00001580}
1581
Weiming Zhao95782222012-11-17 00:23:35 +00001582/// \brief Form 4 consecutive D registers from a pair of Q registers.
1583SDNode *ARMDAGToDAGISel::createQRegPairNode(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::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001586 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1587 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_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);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001590}
1591
Weiming Zhao95782222012-11-17 00:23:35 +00001592/// \brief Form 4 consecutive S registers.
1593SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001594 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001595 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001596 SDValue RegClass =
1597 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001598 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1599 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1600 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1601 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001602 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1603 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001604 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001605}
1606
Weiming Zhao95782222012-11-17 00:23:35 +00001607/// \brief Form 4 consecutive D registers.
1608SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001609 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001610 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001611 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001612 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1613 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1614 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1615 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001616 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1617 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001618 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001619}
1620
Weiming Zhao95782222012-11-17 00:23:35 +00001621/// \brief Form 4 consecutive Q registers.
1622SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001623 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001624 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001625 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001626 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1627 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1628 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1629 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001630 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1631 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001632 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001633}
1634
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001635/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1636/// of a NEON VLD or VST instruction. The supported values depend on the
1637/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001638SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1639 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001640 unsigned NumRegs = NumVecs;
1641 if (!is64BitVector && NumVecs < 3)
1642 NumRegs *= 2;
1643
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001644 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001645 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001646 Alignment = 32;
1647 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1648 Alignment = 16;
1649 else if (Alignment >= 8)
1650 Alignment = 8;
1651 else
1652 Alignment = 0;
1653
1654 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001655}
1656
Jiangning Liu4df23632014-01-16 09:16:13 +00001657static bool isVLDfixed(unsigned Opc)
1658{
1659 switch (Opc) {
1660 default: return false;
1661 case ARM::VLD1d8wb_fixed : return true;
1662 case ARM::VLD1d16wb_fixed : return true;
1663 case ARM::VLD1d64Qwb_fixed : return true;
1664 case ARM::VLD1d32wb_fixed : return true;
1665 case ARM::VLD1d64wb_fixed : return true;
1666 case ARM::VLD1d64TPseudoWB_fixed : return true;
1667 case ARM::VLD1d64QPseudoWB_fixed : return true;
1668 case ARM::VLD1q8wb_fixed : return true;
1669 case ARM::VLD1q16wb_fixed : return true;
1670 case ARM::VLD1q32wb_fixed : return true;
1671 case ARM::VLD1q64wb_fixed : return true;
1672 case ARM::VLD2d8wb_fixed : return true;
1673 case ARM::VLD2d16wb_fixed : return true;
1674 case ARM::VLD2d32wb_fixed : return true;
1675 case ARM::VLD2q8PseudoWB_fixed : return true;
1676 case ARM::VLD2q16PseudoWB_fixed : return true;
1677 case ARM::VLD2q32PseudoWB_fixed : return true;
1678 case ARM::VLD2DUPd8wb_fixed : return true;
1679 case ARM::VLD2DUPd16wb_fixed : return true;
1680 case ARM::VLD2DUPd32wb_fixed : return true;
1681 }
1682}
1683
1684static bool isVSTfixed(unsigned Opc)
1685{
1686 switch (Opc) {
1687 default: return false;
1688 case ARM::VST1d8wb_fixed : return true;
1689 case ARM::VST1d16wb_fixed : return true;
1690 case ARM::VST1d32wb_fixed : return true;
1691 case ARM::VST1d64wb_fixed : return true;
Jim Grosbach1a597112014-04-03 23:43:18 +00001692 case ARM::VST1q8wb_fixed : return true;
1693 case ARM::VST1q16wb_fixed : return true;
1694 case ARM::VST1q32wb_fixed : return true;
1695 case ARM::VST1q64wb_fixed : return true;
Jiangning Liu4df23632014-01-16 09:16:13 +00001696 case ARM::VST1d64TPseudoWB_fixed : return true;
1697 case ARM::VST1d64QPseudoWB_fixed : return true;
1698 case ARM::VST2d8wb_fixed : return true;
1699 case ARM::VST2d16wb_fixed : return true;
1700 case ARM::VST2d32wb_fixed : return true;
1701 case ARM::VST2q8PseudoWB_fixed : return true;
1702 case ARM::VST2q16PseudoWB_fixed : return true;
1703 case ARM::VST2q32PseudoWB_fixed : return true;
1704 }
1705}
1706
Jim Grosbach2098cb12011-10-24 21:45:13 +00001707// Get the register stride update opcode of a VLD/VST instruction that
1708// is otherwise equivalent to the given fixed stride updating instruction.
1709static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
Jiangning Liu4df23632014-01-16 09:16:13 +00001710 assert((isVLDfixed(Opc) || isVSTfixed(Opc))
1711 && "Incorrect fixed stride updating instruction.");
Jim Grosbach2098cb12011-10-24 21:45:13 +00001712 switch (Opc) {
1713 default: break;
1714 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1715 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1716 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1717 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1718 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1719 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1720 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1721 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jiangning Liu4df23632014-01-16 09:16:13 +00001722 case ARM::VLD1d64Twb_fixed: return ARM::VLD1d64Twb_register;
1723 case ARM::VLD1d64Qwb_fixed: return ARM::VLD1d64Qwb_register;
1724 case ARM::VLD1d64TPseudoWB_fixed: return ARM::VLD1d64TPseudoWB_register;
1725 case ARM::VLD1d64QPseudoWB_fixed: return ARM::VLD1d64QPseudoWB_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001726
1727 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1728 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1729 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1730 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1731 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1732 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1733 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1734 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001735 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001736 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001737
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001738 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1739 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1740 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001741 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1742 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1743 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1744
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001745 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1746 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1747 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001748 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1749 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1750 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001751
Jim Grosbach13a292c2012-03-06 22:01:44 +00001752 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1753 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1754 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001755 }
1756 return Opc; // If not one we handle, return it unchanged.
1757}
1758
Bob Wilson06fce872011-02-07 17:43:21 +00001759SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001760 const uint16_t *DOpcodes,
1761 const uint16_t *QOpcodes0,
1762 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001763 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001764 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001765
Bob Wilsonae08a732010-03-20 22:13:40 +00001766 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001767 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1768 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001769 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001770
1771 SDValue Chain = N->getOperand(0);
1772 EVT VT = N->getValueType(0);
1773 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001774 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001775
Bob Wilson12b47992009-10-14 17:28:52 +00001776 unsigned OpcodeIndex;
1777 switch (VT.getSimpleVT().SimpleTy) {
1778 default: llvm_unreachable("unhandled vld type");
1779 // Double-register operations:
1780 case MVT::v8i8: OpcodeIndex = 0; break;
1781 case MVT::v4i16: OpcodeIndex = 1; break;
1782 case MVT::v2f32:
1783 case MVT::v2i32: OpcodeIndex = 2; break;
1784 case MVT::v1i64: OpcodeIndex = 3; break;
1785 // Quad-register operations:
1786 case MVT::v16i8: OpcodeIndex = 0; break;
1787 case MVT::v8i16: OpcodeIndex = 1; break;
1788 case MVT::v4f32:
1789 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001790 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001791 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001792 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001793 }
1794
Bob Wilson35fafca2010-09-03 18:16:02 +00001795 EVT ResTy;
1796 if (NumVecs == 1)
1797 ResTy = VT;
1798 else {
1799 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1800 if (!is64BitVector)
1801 ResTyElts *= 2;
1802 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1803 }
Bob Wilson06fce872011-02-07 17:43:21 +00001804 std::vector<EVT> ResTys;
1805 ResTys.push_back(ResTy);
1806 if (isUpdating)
1807 ResTys.push_back(MVT::i32);
1808 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001809
Evan Cheng3da64f762010-04-16 05:46:06 +00001810 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001811 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001812 SDNode *VLd;
1813 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001814
Bob Wilson06fce872011-02-07 17:43:21 +00001815 // Double registers and VLD1/VLD2 quad registers are directly supported.
1816 if (is64BitVector || NumVecs <= 2) {
1817 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1818 QOpcodes0[OpcodeIndex]);
1819 Ops.push_back(MemAddr);
1820 Ops.push_back(Align);
1821 if (isUpdating) {
1822 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001823 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001824 // case entirely when the rest are updated to that form, too.
Jiangning Liu4df23632014-01-16 09:16:13 +00001825 if ((NumVecs <= 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001826 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001827 // FIXME: We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001828 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001829 if ((NumVecs > 2 && !isVLDfixed(Opc)) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001830 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001831 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001832 }
Bob Wilson06fce872011-02-07 17:43:21 +00001833 Ops.push_back(Pred);
1834 Ops.push_back(Reg0);
1835 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001836 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001837
Bob Wilson12b47992009-10-14 17:28:52 +00001838 } else {
1839 // Otherwise, quad registers are loaded with two separate instructions,
1840 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001841 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001842
Bob Wilson06fce872011-02-07 17:43:21 +00001843 // Load the even subregs. This is always an updating load, so that it
1844 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001845 SDValue ImplDef =
1846 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1847 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001848 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001849 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001850 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001851
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001852 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001853 Ops.push_back(SDValue(VLdA, 1));
1854 Ops.push_back(Align);
1855 if (isUpdating) {
1856 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1857 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1858 "only constant post-increment update allowed for VLD3/4");
1859 (void)Inc;
1860 Ops.push_back(Reg0);
1861 }
1862 Ops.push_back(SDValue(VLdA, 0));
1863 Ops.push_back(Pred);
1864 Ops.push_back(Reg0);
1865 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001866 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001867 }
Bob Wilson12b47992009-10-14 17:28:52 +00001868
Evan Cheng40791332011-04-19 00:04:03 +00001869 // Transfer memoperands.
1870 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1871 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1872 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1873
Bob Wilson06fce872011-02-07 17:43:21 +00001874 if (NumVecs == 1)
1875 return VLd;
1876
1877 // Extract out the subregisters.
1878 SDValue SuperReg = SDValue(VLd, 0);
1879 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1880 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1881 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1882 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1883 ReplaceUses(SDValue(N, Vec),
1884 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1885 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1886 if (isUpdating)
1887 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00001888 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001889}
1890
Bob Wilson06fce872011-02-07 17:43:21 +00001891SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001892 const uint16_t *DOpcodes,
1893 const uint16_t *QOpcodes0,
1894 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001895 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001896 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001897
Bob Wilsonae08a732010-03-20 22:13:40 +00001898 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001899 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1900 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1901 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001902 return nullptr;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001903
Evan Cheng40791332011-04-19 00:04:03 +00001904 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1905 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1906
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001907 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001908 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001909 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001910 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001911
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001912 unsigned OpcodeIndex;
1913 switch (VT.getSimpleVT().SimpleTy) {
1914 default: llvm_unreachable("unhandled vst type");
1915 // Double-register operations:
1916 case MVT::v8i8: OpcodeIndex = 0; break;
1917 case MVT::v4i16: OpcodeIndex = 1; break;
1918 case MVT::v2f32:
1919 case MVT::v2i32: OpcodeIndex = 2; break;
1920 case MVT::v1i64: OpcodeIndex = 3; break;
1921 // Quad-register operations:
1922 case MVT::v16i8: OpcodeIndex = 0; break;
1923 case MVT::v8i16: OpcodeIndex = 1; break;
1924 case MVT::v4f32:
1925 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001926 case MVT::v2i64: OpcodeIndex = 3;
1927 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1928 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001929 }
1930
Bob Wilson06fce872011-02-07 17:43:21 +00001931 std::vector<EVT> ResTys;
1932 if (isUpdating)
1933 ResTys.push_back(MVT::i32);
1934 ResTys.push_back(MVT::Other);
1935
Evan Cheng3da64f762010-04-16 05:46:06 +00001936 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001937 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001938 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001939
Bob Wilson06fce872011-02-07 17:43:21 +00001940 // Double registers and VST1/VST2 quad registers are directly supported.
1941 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001942 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001943 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001944 SrcReg = N->getOperand(Vec0Idx);
1945 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001946 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001947 SDValue V0 = N->getOperand(Vec0Idx + 0);
1948 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001949 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001950 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001951 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001952 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001953 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001954 // an undef.
1955 SDValue V3 = (NumVecs == 3)
1956 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001957 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001958 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001959 }
Bob Wilson950882b2010-08-28 05:12:57 +00001960 } else {
1961 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001962 SDValue Q0 = N->getOperand(Vec0Idx);
1963 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001964 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001965 }
Bob Wilson06fce872011-02-07 17:43:21 +00001966
1967 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1968 QOpcodes0[OpcodeIndex]);
1969 Ops.push_back(MemAddr);
1970 Ops.push_back(Align);
1971 if (isUpdating) {
1972 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001973 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001974 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001975 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001976 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001977 // FIXME: We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001978 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001979 if (!isa<ConstantSDNode>(Inc.getNode()))
1980 Ops.push_back(Inc);
1981 else if (NumVecs > 2 && !isVSTfixed(Opc))
1982 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00001983 }
1984 Ops.push_back(SrcReg);
1985 Ops.push_back(Pred);
1986 Ops.push_back(Reg0);
1987 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001988 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001989
1990 // Transfer memoperands.
1991 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1992
1993 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001994 }
1995
1996 // Otherwise, quad registers are stored with two separate instructions,
1997 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00001998
Bob Wilson01ac8f92010-06-16 21:34:01 +00001999 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00002000 SDValue V0 = N->getOperand(Vec0Idx + 0);
2001 SDValue V1 = N->getOperand(Vec0Idx + 1);
2002 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00002003 SDValue V3 = (NumVecs == 3)
2004 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00002005 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002006 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002007
Bob Wilson06fce872011-02-07 17:43:21 +00002008 // Store the even D registers. This is always an updating store, so that it
2009 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00002010 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
2011 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
2012 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00002013 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00002014 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002015 Chain = SDValue(VStA, 1);
2016
2017 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00002018 Ops.push_back(SDValue(VStA, 0));
2019 Ops.push_back(Align);
2020 if (isUpdating) {
2021 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2022 assert(isa<ConstantSDNode>(Inc.getNode()) &&
2023 "only constant post-increment update allowed for VST3/4");
2024 (void)Inc;
2025 Ops.push_back(Reg0);
2026 }
2027 Ops.push_back(RegSeq);
2028 Ops.push_back(Pred);
2029 Ops.push_back(Reg0);
2030 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00002031 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00002032 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002033 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
2034 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002035}
2036
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002037SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00002038 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00002039 const uint16_t *DOpcodes,
2040 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002041 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002042 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002043
Bob Wilsonae08a732010-03-20 22:13:40 +00002044 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002045 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2046 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2047 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002048 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002049
Evan Cheng40791332011-04-19 00:04:03 +00002050 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2051 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2052
Bob Wilson4145e3a2009-10-14 16:19:03 +00002053 SDValue Chain = N->getOperand(0);
2054 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002055 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2056 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002057 bool is64BitVector = VT.is64BitVector();
2058
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002059 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002060 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002061 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002062 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2063 if (Alignment > NumBytes)
2064 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002065 if (Alignment < 8 && Alignment < NumBytes)
2066 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002067 // Alignment must be a power of two; make sure of that.
2068 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002069 if (Alignment == 1)
2070 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002071 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002072 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002073
Bob Wilson4145e3a2009-10-14 16:19:03 +00002074 unsigned OpcodeIndex;
2075 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002076 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002077 // Double-register operations:
2078 case MVT::v8i8: OpcodeIndex = 0; break;
2079 case MVT::v4i16: OpcodeIndex = 1; break;
2080 case MVT::v2f32:
2081 case MVT::v2i32: OpcodeIndex = 2; break;
2082 // Quad-register operations:
2083 case MVT::v8i16: OpcodeIndex = 0; break;
2084 case MVT::v4f32:
2085 case MVT::v4i32: OpcodeIndex = 1; break;
2086 }
2087
Bob Wilson06fce872011-02-07 17:43:21 +00002088 std::vector<EVT> ResTys;
2089 if (IsLoad) {
2090 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2091 if (!is64BitVector)
2092 ResTyElts *= 2;
2093 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2094 MVT::i64, ResTyElts));
2095 }
2096 if (isUpdating)
2097 ResTys.push_back(MVT::i32);
2098 ResTys.push_back(MVT::Other);
2099
Evan Cheng3da64f762010-04-16 05:46:06 +00002100 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002101 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002102
Bob Wilson06fce872011-02-07 17:43:21 +00002103 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002104 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002105 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002106 if (isUpdating) {
2107 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2108 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2109 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002110
Bob Wilsond5c57a52010-09-13 23:01:35 +00002111 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002112 SDValue V0 = N->getOperand(Vec0Idx + 0);
2113 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002114 if (NumVecs == 2) {
2115 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002116 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002117 else
Weiming Zhao95782222012-11-17 00:23:35 +00002118 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002119 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002120 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002121 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002122 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2123 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002124 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002125 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002126 else
Weiming Zhao95782222012-11-17 00:23:35 +00002127 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002128 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002129 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002130 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002131 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002132 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002133 Ops.push_back(Chain);
2134
Bob Wilson06fce872011-02-07 17:43:21 +00002135 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2136 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002137 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002138 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002139 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002140 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002141
Bob Wilsond5c57a52010-09-13 23:01:35 +00002142 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002143 SuperReg = SDValue(VLdLn, 0);
2144 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2145 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2146 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002147 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2148 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002149 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2150 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2151 if (isUpdating)
2152 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002153 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002154}
2155
Bob Wilson06fce872011-02-07 17:43:21 +00002156SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002157 unsigned NumVecs,
2158 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002159 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002160 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002161
2162 SDValue MemAddr, Align;
2163 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002164 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002165
Evan Cheng40791332011-04-19 00:04:03 +00002166 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2167 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2168
Bob Wilson2d790df2010-11-28 06:51:26 +00002169 SDValue Chain = N->getOperand(0);
2170 EVT VT = N->getValueType(0);
2171
2172 unsigned Alignment = 0;
2173 if (NumVecs != 3) {
2174 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2175 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2176 if (Alignment > NumBytes)
2177 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002178 if (Alignment < 8 && Alignment < NumBytes)
2179 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002180 // Alignment must be a power of two; make sure of that.
2181 Alignment = (Alignment & -Alignment);
2182 if (Alignment == 1)
2183 Alignment = 0;
2184 }
2185 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2186
2187 unsigned OpcodeIndex;
2188 switch (VT.getSimpleVT().SimpleTy) {
2189 default: llvm_unreachable("unhandled vld-dup type");
2190 case MVT::v8i8: OpcodeIndex = 0; break;
2191 case MVT::v4i16: OpcodeIndex = 1; break;
2192 case MVT::v2f32:
2193 case MVT::v2i32: OpcodeIndex = 2; break;
2194 }
2195
2196 SDValue Pred = getAL(CurDAG);
2197 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2198 SDValue SuperReg;
2199 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002200 SmallVector<SDValue, 6> Ops;
2201 Ops.push_back(MemAddr);
2202 Ops.push_back(Align);
2203 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002204 // fixed-stride update instructions don't have an explicit writeback
2205 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002206 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002207 if (!isa<ConstantSDNode>(Inc.getNode()))
2208 Ops.push_back(Inc);
2209 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2210 else if (NumVecs > 2)
2211 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002212 }
2213 Ops.push_back(Pred);
2214 Ops.push_back(Reg0);
2215 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002216
2217 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002218 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002219 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002220 if (isUpdating)
2221 ResTys.push_back(MVT::i32);
2222 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002223 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002224 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002225 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002226
2227 // Extract the subregisters.
2228 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2229 unsigned SubIdx = ARM::dsub_0;
2230 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2231 ReplaceUses(SDValue(N, Vec),
2232 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002233 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2234 if (isUpdating)
2235 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002236 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002237}
2238
Bob Wilson5bc8a792010-07-07 00:08:54 +00002239SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2240 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002241 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002242 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002243 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002244 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002245
2246 // Form a REG_SEQUENCE to force register allocation.
2247 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002248 SDValue V0 = N->getOperand(FirstTblReg + 0);
2249 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002250 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002251 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002252 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002253 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002254 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002255 // an undef.
2256 SDValue V3 = (NumVecs == 3)
2257 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002258 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002259 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002260 }
2261
Bob Wilson5bc8a792010-07-07 00:08:54 +00002262 SmallVector<SDValue, 6> Ops;
2263 if (IsExt)
2264 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002265 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002266 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002267 Ops.push_back(getAL(CurDAG)); // predicate
2268 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002269 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002270}
2271
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002272SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002273 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002274 if (!Subtarget->hasV6T2Ops())
Craig Topper062a2ba2014-04-25 05:30:21 +00002275 return nullptr;
Bob Wilson93117bc2009-10-14 16:46:45 +00002276
Evan Chengeae6d2c2012-12-19 20:16:09 +00002277 unsigned Opc = isSigned
2278 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002279 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2280
Jim Grosbach825cb292010-04-22 23:24:18 +00002281 // For unsigned extracts, check for a shift right and mask
2282 unsigned And_imm = 0;
2283 if (N->getOpcode() == ISD::AND) {
2284 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2285
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002286 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002287 if (And_imm & (And_imm + 1))
Craig Topper062a2ba2014-04-25 05:30:21 +00002288 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002289
2290 unsigned Srl_imm = 0;
2291 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2292 Srl_imm)) {
2293 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2294
Jim Grosbach03f56d92011-07-27 21:09:25 +00002295 // Note: The width operand is encoded as width-1.
2296 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002297 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002298
Jim Grosbach825cb292010-04-22 23:24:18 +00002299 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002300
2301 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2302 // It's cheaper to use a right shift to extract the top bits.
2303 if (Subtarget->isThumb()) {
2304 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2305 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2306 CurDAG->getTargetConstant(LSB, MVT::i32),
2307 getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002308 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002309 }
2310
2311 // ARM models shift instructions as MOVsi with shifter operand.
2312 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2313 SDValue ShOpc =
2314 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2315 MVT::i32);
2316 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2317 getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002318 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002319 }
2320
Jim Grosbach825cb292010-04-22 23:24:18 +00002321 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2322 CurDAG->getTargetConstant(LSB, MVT::i32),
2323 CurDAG->getTargetConstant(Width, MVT::i32),
Craig Topper481fb282014-04-27 19:21:11 +00002324 getAL(CurDAG), Reg0 };
2325 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Jim Grosbach825cb292010-04-22 23:24:18 +00002326 }
2327 }
Craig Topper062a2ba2014-04-25 05:30:21 +00002328 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002329 }
2330
2331 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002332 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002333 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002334 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2335 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002336 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002337 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002338 // Note: The width operand is encoded as width-1.
2339 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002340 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002341 if (LSB < 0)
Craig Topper062a2ba2014-04-25 05:30:21 +00002342 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002343 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002344 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002345 CurDAG->getTargetConstant(LSB, MVT::i32),
2346 CurDAG->getTargetConstant(Width, MVT::i32),
2347 getAL(CurDAG), Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002348 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002349 }
2350 }
Tim Northover14ff2df2014-07-23 13:59:12 +00002351
2352 if (N->getOpcode() == ISD::SIGN_EXTEND_INREG) {
2353 unsigned Width = cast<VTSDNode>(N->getOperand(1))->getVT().getSizeInBits();
2354 unsigned LSB = 0;
2355 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL, LSB) &&
2356 !isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRA, LSB))
2357 return nullptr;
2358
2359 if (LSB + Width > 32)
2360 return nullptr;
2361
2362 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2363 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2364 CurDAG->getTargetConstant(LSB, MVT::i32),
2365 CurDAG->getTargetConstant(Width - 1, MVT::i32),
2366 getAL(CurDAG), Reg0 };
2367 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
2368 }
2369
Craig Topper062a2ba2014-04-25 05:30:21 +00002370 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002371}
2372
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002373/// Target-specific DAG combining for ISD::XOR.
2374/// Target-independent combining lowers SELECT_CC nodes of the form
2375/// select_cc setg[ge] X, 0, X, -X
2376/// select_cc setgt X, -1, X, -X
2377/// select_cc setl[te] X, 0, -X, X
2378/// select_cc setlt X, 1, -X, X
2379/// which represent Integer ABS into:
2380/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2381/// ARM instruction selection detects the latter and matches it to
2382/// ARM::ABS or ARM::t2ABS machine node.
2383SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2384 SDValue XORSrc0 = N->getOperand(0);
2385 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002386 EVT VT = N->getValueType(0);
2387
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002388 if (Subtarget->isThumb1Only())
Craig Topper062a2ba2014-04-25 05:30:21 +00002389 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002390
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002391 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Craig Topper062a2ba2014-04-25 05:30:21 +00002392 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002393
2394 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2395 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2396 SDValue SRASrc0 = XORSrc1.getOperand(0);
2397 SDValue SRASrc1 = XORSrc1.getOperand(1);
2398 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2399 EVT XType = SRASrc0.getValueType();
2400 unsigned Size = XType.getSizeInBits() - 1;
2401
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002402 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
Craig Topper062a2ba2014-04-25 05:30:21 +00002403 XType.isInteger() && SRAConstant != nullptr &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002404 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002405 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002406 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2407 }
2408
Craig Topper062a2ba2014-04-25 05:30:21 +00002409 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002410}
2411
Evan Chengd85631e2010-05-05 18:28:36 +00002412SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2413 // The only time a CONCAT_VECTORS operation can have legal types is when
2414 // two 64-bit vectors are concatenated to a 128-bit vector.
2415 EVT VT = N->getValueType(0);
2416 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2417 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002418 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002419}
2420
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002421SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002422 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002423
Tim Northover31d093c2013-09-22 08:21:56 +00002424 if (N->isMachineOpcode()) {
2425 N->setNodeId(-1);
Craig Topper062a2ba2014-04-25 05:30:21 +00002426 return nullptr; // Already selected.
Tim Northover31d093c2013-09-22 08:21:56 +00002427 }
Rafael Espindola4e760152006-06-12 12:28:08 +00002428
2429 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002430 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002431 case ISD::INLINEASM: {
2432 SDNode *ResNode = SelectInlineAsm(N);
2433 if (ResNode)
2434 return ResNode;
2435 break;
2436 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002437 case ISD::XOR: {
2438 // Select special operations if XOR node forms integer ABS pattern
2439 SDNode *ResNode = SelectABSOp(N);
2440 if (ResNode)
2441 return ResNode;
2442 // Other cases are autogenerated.
2443 break;
2444 }
Evan Cheng10043e22007-01-19 07:51:42 +00002445 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002446 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002447 bool UseCP = true;
Eric Christopherc1058df2014-07-04 01:55:26 +00002448 if (Subtarget->useMovt(*MF))
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002449 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2450 // be done with MOV + MOVT, at worst.
Tim Northover55c625f2014-01-23 13:43:47 +00002451 UseCP = false;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002452 else {
2453 if (Subtarget->isThumb()) {
Tim Northover55c625f2014-01-23 13:43:47 +00002454 UseCP = (Val > 255 && // MOV
2455 ~Val > 255 && // MOV + MVN
2456 !ARM_AM::isThumbImmShiftedVal(Val) && // MOV + LSL
2457 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002458 } else
Tim Northover55c625f2014-01-23 13:43:47 +00002459 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2460 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2461 !ARM_AM::isSOImmTwoPartVal(Val) && // two instrs.
2462 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002463 }
2464
Evan Cheng10043e22007-01-19 07:51:42 +00002465 if (UseCP) {
Eric Christopherb17140d2014-10-08 07:32:17 +00002466 SDValue CPIdx = CurDAG->getTargetConstantPool(
2467 ConstantInt::get(Type::getInt32Ty(*CurDAG->getContext()), Val),
2468 TLI->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002469
2470 SDNode *ResNode;
Tim Northover55c625f2014-01-23 13:43:47 +00002471 if (Subtarget->isThumb()) {
Evan Cheng3da64f762010-04-16 05:46:06 +00002472 SDValue Pred = getAL(CurDAG);
Owen Anderson9f944592009-08-11 20:47:22 +00002473 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002474 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002475 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002476 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002477 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002478 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002479 CPIdx,
Owen Anderson9f944592009-08-11 20:47:22 +00002480 CurDAG->getTargetConstant(0, MVT::i32),
Evan Cheng7e90b112007-07-05 07:15:27 +00002481 getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00002482 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002483 CurDAG->getEntryNode()
2484 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002485 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002486 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002487 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002488 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Craig Topper062a2ba2014-04-25 05:30:21 +00002489 return nullptr;
Evan Cheng10043e22007-01-19 07:51:42 +00002490 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002491
Evan Cheng10043e22007-01-19 07:51:42 +00002492 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002493 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002494 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002495 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002496 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002497 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00002498 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002499 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002500 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2501 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Craig Topper481fb282014-04-27 19:21:11 +00002502 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops);
Jim Grosbachfde21102009-04-07 20:34:09 +00002503 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002504 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2505 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002506 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2507 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2508 CurDAG->getRegister(0, MVT::i32) };
Craig Topper481fb282014-04-27 19:21:11 +00002509 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Cheng7e90b112007-07-05 07:15:27 +00002510 }
Evan Cheng10043e22007-01-19 07:51:42 +00002511 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002512 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002513 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002514 return I;
2515 break;
Tim Northover14ff2df2014-07-23 13:59:12 +00002516 case ISD::SIGN_EXTEND_INREG:
Sandeep Patel423e42b2009-10-13 18:59:48 +00002517 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002518 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002519 return I;
2520 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002521 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002522 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002523 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002524 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002525 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002526 if (!RHSV) break;
2527 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002528 unsigned ShImm = Log2_32(RHSV-1);
2529 if (ShImm >= 32)
2530 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002531 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002532 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002533 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2534 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002535 if (Subtarget->isThumb()) {
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002536 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002537 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002538 } else {
2539 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002540 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002541 }
Evan Cheng10043e22007-01-19 07:51:42 +00002542 }
2543 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002544 unsigned ShImm = Log2_32(RHSV+1);
2545 if (ShImm >= 32)
2546 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002547 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002548 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002549 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2550 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002551 if (Subtarget->isThumb()) {
Bob Wilsonb6112e82010-05-28 00:27:15 +00002552 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002553 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002554 } else {
2555 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002556 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002557 }
Evan Cheng10043e22007-01-19 07:51:42 +00002558 }
2559 }
2560 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002561 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002562 // Check for unsigned bitfield extract
2563 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2564 return I;
2565
Evan Cheng786b15f2009-10-21 08:15:52 +00002566 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2567 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2568 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2569 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2570 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002571 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002572 if (VT != MVT::i32)
2573 break;
2574 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2575 ? ARM::t2MOVTi16
2576 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2577 if (!Opc)
2578 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002579 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002580 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2581 if (!N1C)
2582 break;
2583 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2584 SDValue N2 = N0.getOperand(1);
2585 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2586 if (!N2C)
2587 break;
2588 unsigned N1CVal = N1C->getZExtValue();
2589 unsigned N2CVal = N2C->getZExtValue();
2590 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2591 (N1CVal & 0xffffU) == 0xffffU &&
2592 (N2CVal & 0xffffU) == 0x0U) {
2593 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2594 MVT::i32);
2595 SDValue Ops[] = { N0.getOperand(0), Imm16,
2596 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002597 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002598 }
2599 }
2600 break;
2601 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002602 case ARMISD::VMOVRRD:
2603 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002604 N->getOperand(0), getAL(CurDAG),
Dan Gohman32f71d72009-09-25 18:54:59 +00002605 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002606 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002607 if (Subtarget->isThumb1Only())
2608 break;
2609 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002610 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Michael Liaob53d8962013-04-19 22:22:57 +00002611 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2612 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002613 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002614 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002615 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2616 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002617 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2618 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002619 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002620 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002621 }
Dan Gohmana1603612007-10-08 18:33:35 +00002622 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002623 if (Subtarget->isThumb1Only())
2624 break;
2625 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002626 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002627 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002628 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002629 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002630 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002631 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2632 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002633 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2634 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002635 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002636 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002637 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002638 case ARMISD::UMLAL:{
2639 if (Subtarget->isThumb()) {
2640 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2641 N->getOperand(3), getAL(CurDAG),
2642 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002643 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002644 }else{
2645 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2646 N->getOperand(3), getAL(CurDAG),
2647 CurDAG->getRegister(0, MVT::i32),
2648 CurDAG->getRegister(0, MVT::i32) };
2649 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2650 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002651 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002652 }
2653 }
2654 case ARMISD::SMLAL:{
2655 if (Subtarget->isThumb()) {
2656 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2657 N->getOperand(3), getAL(CurDAG),
2658 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002659 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002660 }else{
2661 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2662 N->getOperand(3), getAL(CurDAG),
2663 CurDAG->getRegister(0, MVT::i32),
2664 CurDAG->getRegister(0, MVT::i32) };
2665 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2666 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002667 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002668 }
2669 }
Evan Cheng10043e22007-01-19 07:51:42 +00002670 case ISD::LOAD: {
Craig Topper062a2ba2014-04-25 05:30:21 +00002671 SDNode *ResNode = nullptr;
Evan Chengb24e51e2009-07-07 01:17:28 +00002672 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002673 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002674 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002675 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002676 if (ResNode)
2677 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002678 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002679 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002680 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002681 case ARMISD::BRCOND: {
2682 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2683 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2684 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002685
Evan Cheng7e90b112007-07-05 07:15:27 +00002686 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2687 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2688 // Pattern complexity = 6 cost = 1 size = 0
2689
David Goodwin27303cd2009-06-30 18:04:13 +00002690 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2691 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2692 // Pattern complexity = 6 cost = 1 size = 0
2693
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002694 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002695 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002696 SDValue Chain = N->getOperand(0);
2697 SDValue N1 = N->getOperand(1);
2698 SDValue N2 = N->getOperand(2);
2699 SDValue N3 = N->getOperand(3);
2700 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002701 assert(N1.getOpcode() == ISD::BasicBlock);
2702 assert(N2.getOpcode() == ISD::Constant);
2703 assert(N3.getOpcode() == ISD::Register);
2704
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002705 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmaneffb8942008-09-12 16:56:44 +00002706 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson9f944592009-08-11 20:47:22 +00002707 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002708 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002709 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002710 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002711 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002712 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002713 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002714 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002715 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002716 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002717 SDValue(Chain.getNode(), Chain.getResNo()));
Craig Topper062a2ba2014-04-25 05:30:21 +00002718 return nullptr;
Evan Cheng7e90b112007-07-05 07:15:27 +00002719 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002720 case ARMISD::VZIP: {
2721 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002722 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002723 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002724 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002725 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2726 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2727 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002728 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2729 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002730 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2731 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2732 case MVT::v4f32:
2733 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2734 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002735 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002736 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2737 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002738 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002739 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002740 case ARMISD::VUZP: {
2741 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002742 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002743 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002744 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002745 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2746 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2747 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002748 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2749 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002750 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2751 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2752 case MVT::v4f32:
2753 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2754 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002755 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002756 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2757 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002758 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002759 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002760 case ARMISD::VTRN: {
2761 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002762 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002763 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002764 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002765 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2766 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2767 case MVT::v2f32:
2768 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2769 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2770 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2771 case MVT::v4f32:
2772 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2773 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002774 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002775 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2776 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002777 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002778 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002779 case ARMISD::BUILD_VECTOR: {
2780 EVT VecVT = N->getValueType(0);
2781 EVT EltVT = VecVT.getVectorElementType();
2782 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002783 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002784 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002785 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002786 }
Duncan Sands14627772010-11-03 12:17:33 +00002787 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002788 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002789 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002790 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002791 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002792 N->getOperand(2), N->getOperand(3));
2793 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002794
Bob Wilson2d790df2010-11-28 06:51:26 +00002795 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002796 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2797 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002798 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002799 }
2800
Bob Wilson77ab1652010-11-29 19:35:29 +00002801 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002802 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2803 ARM::VLD3DUPd16Pseudo,
2804 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002805 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002806 }
2807
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002808 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002809 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2810 ARM::VLD4DUPd16Pseudo,
2811 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002812 return SelectVLDDup(N, false, 4, Opcodes);
2813 }
2814
2815 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002816 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2817 ARM::VLD2DUPd16wb_fixed,
2818 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002819 return SelectVLDDup(N, true, 2, Opcodes);
2820 }
2821
2822 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002823 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2824 ARM::VLD3DUPd16Pseudo_UPD,
2825 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002826 return SelectVLDDup(N, true, 3, Opcodes);
2827 }
2828
2829 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002830 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2831 ARM::VLD4DUPd16Pseudo_UPD,
2832 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002833 return SelectVLDDup(N, true, 4, Opcodes);
2834 }
2835
2836 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002837 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2838 ARM::VLD1d16wb_fixed,
2839 ARM::VLD1d32wb_fixed,
2840 ARM::VLD1d64wb_fixed };
2841 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2842 ARM::VLD1q16wb_fixed,
2843 ARM::VLD1q32wb_fixed,
2844 ARM::VLD1q64wb_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002845 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002846 }
2847
2848 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002849 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2850 ARM::VLD2d16wb_fixed,
2851 ARM::VLD2d32wb_fixed,
2852 ARM::VLD1q64wb_fixed};
2853 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2854 ARM::VLD2q16PseudoWB_fixed,
2855 ARM::VLD2q32PseudoWB_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002856 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002857 }
2858
2859 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002860 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2861 ARM::VLD3d16Pseudo_UPD,
2862 ARM::VLD3d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002863 ARM::VLD1d64TPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002864 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2865 ARM::VLD3q16Pseudo_UPD,
2866 ARM::VLD3q32Pseudo_UPD };
2867 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2868 ARM::VLD3q16oddPseudo_UPD,
2869 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002870 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2871 }
2872
2873 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002874 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2875 ARM::VLD4d16Pseudo_UPD,
2876 ARM::VLD4d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002877 ARM::VLD1d64QPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002878 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2879 ARM::VLD4q16Pseudo_UPD,
2880 ARM::VLD4q32Pseudo_UPD };
2881 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2882 ARM::VLD4q16oddPseudo_UPD,
2883 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002884 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2885 }
2886
2887 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002888 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2889 ARM::VLD2LNd16Pseudo_UPD,
2890 ARM::VLD2LNd32Pseudo_UPD };
2891 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2892 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002893 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2894 }
2895
2896 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002897 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2898 ARM::VLD3LNd16Pseudo_UPD,
2899 ARM::VLD3LNd32Pseudo_UPD };
2900 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2901 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002902 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2903 }
2904
2905 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002906 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2907 ARM::VLD4LNd16Pseudo_UPD,
2908 ARM::VLD4LNd32Pseudo_UPD };
2909 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2910 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002911 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2912 }
2913
2914 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002915 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2916 ARM::VST1d16wb_fixed,
2917 ARM::VST1d32wb_fixed,
2918 ARM::VST1d64wb_fixed };
2919 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2920 ARM::VST1q16wb_fixed,
2921 ARM::VST1q32wb_fixed,
2922 ARM::VST1q64wb_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002923 return SelectVST(N, true, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002924 }
2925
2926 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002927 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2928 ARM::VST2d16wb_fixed,
2929 ARM::VST2d32wb_fixed,
2930 ARM::VST1q64wb_fixed};
2931 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2932 ARM::VST2q16PseudoWB_fixed,
2933 ARM::VST2q32PseudoWB_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002934 return SelectVST(N, true, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002935 }
2936
2937 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002938 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2939 ARM::VST3d16Pseudo_UPD,
2940 ARM::VST3d32Pseudo_UPD,
2941 ARM::VST1d64TPseudoWB_fixed};
2942 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2943 ARM::VST3q16Pseudo_UPD,
2944 ARM::VST3q32Pseudo_UPD };
2945 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2946 ARM::VST3q16oddPseudo_UPD,
2947 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002948 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2949 }
2950
2951 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002952 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2953 ARM::VST4d16Pseudo_UPD,
2954 ARM::VST4d32Pseudo_UPD,
2955 ARM::VST1d64QPseudoWB_fixed};
2956 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2957 ARM::VST4q16Pseudo_UPD,
2958 ARM::VST4q32Pseudo_UPD };
2959 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2960 ARM::VST4q16oddPseudo_UPD,
2961 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002962 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2963 }
2964
2965 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002966 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2967 ARM::VST2LNd16Pseudo_UPD,
2968 ARM::VST2LNd32Pseudo_UPD };
2969 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2970 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002971 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2972 }
2973
2974 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002975 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2976 ARM::VST3LNd16Pseudo_UPD,
2977 ARM::VST3LNd32Pseudo_UPD };
2978 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2979 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002980 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2981 }
2982
2983 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002984 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2985 ARM::VST4LNd16Pseudo_UPD,
2986 ARM::VST4LNd32Pseudo_UPD };
2987 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2988 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002989 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002990 }
2991
Bob Wilsone0636a72009-08-26 17:39:53 +00002992 case ISD::INTRINSIC_VOID:
2993 case ISD::INTRINSIC_W_CHAIN: {
2994 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00002995 switch (IntNo) {
2996 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00002997 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00002998
Tim Northover1ff5f292014-03-26 14:39:31 +00002999 case Intrinsic::arm_ldaexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003000 case Intrinsic::arm_ldrexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003001 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003002 SDValue Chain = N->getOperand(0);
Tim Northover1ff5f292014-03-26 14:39:31 +00003003 SDValue MemAddr = N->getOperand(2);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003004 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
Tim Northover1ff5f292014-03-26 14:39:31 +00003005
3006 bool IsAcquire = IntNo == Intrinsic::arm_ldaexd;
3007 unsigned NewOpc = isThumb ? (IsAcquire ? ARM::t2LDAEXD : ARM::t2LDREXD)
3008 : (IsAcquire ? ARM::LDAEXD : ARM::LDREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003009
3010 // arm_ldrexd returns a i64 value in {i32, i32}
3011 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003012 if (isThumb) {
3013 ResTys.push_back(MVT::i32);
3014 ResTys.push_back(MVT::i32);
3015 } else
3016 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003017 ResTys.push_back(MVT::Other);
3018
Weiming Zhao8f56f882012-11-16 21:55:34 +00003019 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003020 SmallVector<SDValue, 7> Ops;
3021 Ops.push_back(MemAddr);
3022 Ops.push_back(getAL(CurDAG));
3023 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3024 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00003025 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003026 // Transfer memoperands.
3027 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3028 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3029 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3030
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003031 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00003032 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003033 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003034 SDValue Result;
3035 if (isThumb)
3036 Result = SDValue(Ld, 0);
3037 else {
3038 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
3039 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003040 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003041 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003042 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003043 ReplaceUses(SDValue(N, 0), Result);
3044 }
3045 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003046 SDValue Result;
3047 if (isThumb)
3048 Result = SDValue(Ld, 1);
3049 else {
3050 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3051 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003052 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003053 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003054 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003055 ReplaceUses(SDValue(N, 1), Result);
3056 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003057 ReplaceUses(SDValue(N, 2), OutChain);
Craig Topper062a2ba2014-04-25 05:30:21 +00003058 return nullptr;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003059 }
Tim Northover1ff5f292014-03-26 14:39:31 +00003060 case Intrinsic::arm_stlexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003061 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003062 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003063 SDValue Chain = N->getOperand(0);
3064 SDValue Val0 = N->getOperand(2);
3065 SDValue Val1 = N->getOperand(3);
3066 SDValue MemAddr = N->getOperand(4);
3067
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003068 // Store exclusive double return a i32 value which is the return status
3069 // of the issued store.
Benjamin Kramerfdf362b2013-03-07 20:33:29 +00003070 EVT ResTys[] = { MVT::i32, MVT::Other };
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003071
Weiming Zhao8f56f882012-11-16 21:55:34 +00003072 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3073 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003074 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003075 if (isThumb) {
3076 Ops.push_back(Val0);
3077 Ops.push_back(Val1);
3078 } else
3079 // arm_strexd uses GPRPair.
3080 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003081 Ops.push_back(MemAddr);
3082 Ops.push_back(getAL(CurDAG));
3083 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3084 Ops.push_back(Chain);
3085
Tim Northover1ff5f292014-03-26 14:39:31 +00003086 bool IsRelease = IntNo == Intrinsic::arm_stlexd;
3087 unsigned NewOpc = isThumb ? (IsRelease ? ARM::t2STLEXD : ARM::t2STREXD)
3088 : (IsRelease ? ARM::STLEXD : ARM::STREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003089
Michael Liaob53d8962013-04-19 22:22:57 +00003090 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003091 // Transfer memoperands.
3092 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3093 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3094 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3095
3096 return St;
3097 }
3098
Bob Wilson340861d2010-03-23 05:25:43 +00003099 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003100 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3101 ARM::VLD1d32, ARM::VLD1d64 };
3102 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3103 ARM::VLD1q32, ARM::VLD1q64};
Craig Topper062a2ba2014-04-25 05:30:21 +00003104 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson340861d2010-03-23 05:25:43 +00003105 }
3106
Bob Wilsone0636a72009-08-26 17:39:53 +00003107 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003108 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3109 ARM::VLD2d32, ARM::VLD1q64 };
3110 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3111 ARM::VLD2q32Pseudo };
Craig Topper062a2ba2014-04-25 05:30:21 +00003112 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilsone0636a72009-08-26 17:39:53 +00003113 }
3114
3115 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003116 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3117 ARM::VLD3d16Pseudo,
3118 ARM::VLD3d32Pseudo,
3119 ARM::VLD1d64TPseudo };
3120 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3121 ARM::VLD3q16Pseudo_UPD,
3122 ARM::VLD3q32Pseudo_UPD };
3123 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3124 ARM::VLD3q16oddPseudo,
3125 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003126 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003127 }
3128
3129 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003130 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3131 ARM::VLD4d16Pseudo,
3132 ARM::VLD4d32Pseudo,
3133 ARM::VLD1d64QPseudo };
3134 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3135 ARM::VLD4q16Pseudo_UPD,
3136 ARM::VLD4q32Pseudo_UPD };
3137 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3138 ARM::VLD4q16oddPseudo,
3139 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003140 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003141 }
3142
Bob Wilsonda9817c2009-09-01 04:26:28 +00003143 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003144 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3145 ARM::VLD2LNd16Pseudo,
3146 ARM::VLD2LNd32Pseudo };
3147 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3148 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003149 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003150 }
3151
3152 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003153 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3154 ARM::VLD3LNd16Pseudo,
3155 ARM::VLD3LNd32Pseudo };
3156 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3157 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003158 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003159 }
3160
3161 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003162 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3163 ARM::VLD4LNd16Pseudo,
3164 ARM::VLD4LNd32Pseudo };
3165 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3166 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003167 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003168 }
3169
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003170 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003171 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3172 ARM::VST1d32, ARM::VST1d64 };
3173 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3174 ARM::VST1q32, ARM::VST1q64 };
Craig Topper062a2ba2014-04-25 05:30:21 +00003175 return SelectVST(N, false, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003176 }
3177
Bob Wilsone0636a72009-08-26 17:39:53 +00003178 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003179 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3180 ARM::VST2d32, ARM::VST1q64 };
3181 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3182 ARM::VST2q32Pseudo };
Craig Topper062a2ba2014-04-25 05:30:21 +00003183 return SelectVST(N, false, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilsone0636a72009-08-26 17:39:53 +00003184 }
3185
3186 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003187 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3188 ARM::VST3d16Pseudo,
3189 ARM::VST3d32Pseudo,
3190 ARM::VST1d64TPseudo };
3191 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3192 ARM::VST3q16Pseudo_UPD,
3193 ARM::VST3q32Pseudo_UPD };
3194 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3195 ARM::VST3q16oddPseudo,
3196 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003197 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003198 }
3199
3200 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003201 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3202 ARM::VST4d16Pseudo,
3203 ARM::VST4d32Pseudo,
3204 ARM::VST1d64QPseudo };
3205 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3206 ARM::VST4q16Pseudo_UPD,
3207 ARM::VST4q32Pseudo_UPD };
3208 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3209 ARM::VST4q16oddPseudo,
3210 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003211 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003212 }
Bob Wilsond7797752009-09-01 18:51:56 +00003213
3214 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003215 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3216 ARM::VST2LNd16Pseudo,
3217 ARM::VST2LNd32Pseudo };
3218 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3219 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003220 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003221 }
3222
3223 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003224 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3225 ARM::VST3LNd16Pseudo,
3226 ARM::VST3LNd32Pseudo };
3227 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3228 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003229 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003230 }
3231
3232 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003233 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3234 ARM::VST4LNd16Pseudo,
3235 ARM::VST4LNd32Pseudo };
3236 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3237 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003238 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003239 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003240 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003241 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003242 }
Evan Chengd85631e2010-05-05 18:28:36 +00003243
Bob Wilson3ed511b2010-07-06 23:36:25 +00003244 case ISD::INTRINSIC_WO_CHAIN: {
3245 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3246 switch (IntNo) {
3247 default:
3248 break;
3249
3250 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003251 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003252 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003253 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003254 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003255 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003256
3257 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003258 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003259 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003260 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003261 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003262 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003263 }
3264 break;
3265 }
3266
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003267 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003268 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003269 EVT VT = N->getValueType(0);
3270 SmallVector<SDValue, 6> Ops;
3271
3272 Ops.push_back(N->getOperand(0));
3273 Ops.push_back(N->getOperand(1));
3274 Ops.push_back(getAL(CurDAG)); // Predicate
3275 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003276 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003277 }
3278 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003279 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003280 EVT VT = N->getValueType(0);
3281
3282 // Form a REG_SEQUENCE to force register allocation.
3283 SDValue V0 = N->getOperand(0);
3284 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003285 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003286
3287 SmallVector<SDValue, 6> Ops;
3288 Ops.push_back(RegSeq);
3289 Ops.push_back(N->getOperand(2));
3290 Ops.push_back(getAL(CurDAG)); // Predicate
3291 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003292 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003293 }
3294
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003295 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003296 return SelectConcatVector(N);
3297 }
Evan Chengd5021732008-12-10 21:54:21 +00003298
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003299 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003300}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003301
Weiming Zhaoc5987002013-02-14 18:10:21 +00003302SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3303 std::vector<SDValue> AsmNodeOperands;
3304 unsigned Flag, Kind;
3305 bool Changed = false;
3306 unsigned NumOps = N->getNumOperands();
3307
Weiming Zhaoc5987002013-02-14 18:10:21 +00003308 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3309 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3310 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3311 // respectively. Since there is no constraint to explicitly specify a
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003312 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3313 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3314 // them into a GPRPair.
Weiming Zhaoc5987002013-02-14 18:10:21 +00003315
Andrew Trickef9de2a2013-05-25 02:42:55 +00003316 SDLoc dl(N);
Craig Topper062a2ba2014-04-25 05:30:21 +00003317 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1)
3318 : SDValue(nullptr,0);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003319
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003320 SmallVector<bool, 8> OpChanged;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003321 // Glue node will be appended late.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003322 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
Weiming Zhaoc5987002013-02-14 18:10:21 +00003323 SDValue op = N->getOperand(i);
3324 AsmNodeOperands.push_back(op);
3325
3326 if (i < InlineAsm::Op_FirstOperand)
3327 continue;
3328
3329 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3330 Flag = C->getZExtValue();
3331 Kind = InlineAsm::getKind(Flag);
3332 }
3333 else
3334 continue;
3335
Joey Gouly392cdad2013-07-08 19:52:51 +00003336 // Immediate operands to inline asm in the SelectionDAG are modeled with
3337 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3338 // the second is a constant with the value of the immediate. If we get here
3339 // and we have a Kind_Imm, skip the next operand, and continue.
Joey Gouly606f3fb2013-07-05 10:19:40 +00003340 if (Kind == InlineAsm::Kind_Imm) {
3341 SDValue op = N->getOperand(++i);
3342 AsmNodeOperands.push_back(op);
3343 continue;
3344 }
3345
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003346 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3347 if (NumRegs)
3348 OpChanged.push_back(false);
3349
3350 unsigned DefIdx = 0;
3351 bool IsTiedToChangedOp = false;
3352 // If it's a use that is tied with a previous def, it has no
3353 // reg class constraint.
3354 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3355 IsTiedToChangedOp = OpChanged[DefIdx];
3356
Weiming Zhaoc5987002013-02-14 18:10:21 +00003357 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3358 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3359 continue;
3360
Weiming Zhaoc5987002013-02-14 18:10:21 +00003361 unsigned RC;
3362 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003363 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3364 || NumRegs != 2)
Weiming Zhaoc5987002013-02-14 18:10:21 +00003365 continue;
3366
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003367 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
Weiming Zhaoc5987002013-02-14 18:10:21 +00003368 SDValue V0 = N->getOperand(i+1);
3369 SDValue V1 = N->getOperand(i+2);
3370 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3371 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3372 SDValue PairedReg;
3373 MachineRegisterInfo &MRI = MF->getRegInfo();
3374
3375 if (Kind == InlineAsm::Kind_RegDef ||
3376 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3377 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3378 // the original GPRs.
3379
3380 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3381 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3382 SDValue Chain = SDValue(N,0);
3383
3384 SDNode *GU = N->getGluedUser();
3385 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3386 Chain.getValue(1));
3387
3388 // Extract values from a GPRPair reg and copy to the original GPR reg.
3389 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3390 RegCopy);
3391 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3392 RegCopy);
3393 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3394 RegCopy.getValue(1));
3395 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3396
3397 // Update the original glue user.
3398 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3399 Ops.push_back(T1.getValue(1));
Craig Topper8c0b4d02014-04-28 05:57:50 +00003400 CurDAG->UpdateNodeOperands(GU, Ops);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003401 GU = T1.getNode();
3402 }
3403 else {
3404 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3405 // GPRPair and then pass the GPRPair to the inline asm.
3406 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3407
3408 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3409 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3410 Chain.getValue(1));
3411 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3412 T0.getValue(1));
3413 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3414
3415 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3416 // i32 VRs of inline asm with it.
3417 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3418 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3419 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3420
3421 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3422 Glue = Chain.getValue(1);
3423 }
3424
3425 Changed = true;
3426
3427 if(PairedReg.getNode()) {
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003428 OpChanged[OpChanged.size() -1 ] = true;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003429 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
Tim Northover55349a22013-08-18 18:06:03 +00003430 if (IsTiedToChangedOp)
3431 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3432 else
3433 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003434 // Replace the current flag.
3435 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3436 Flag, MVT::i32);
3437 // Add the new register node and skip the original two GPRs.
3438 AsmNodeOperands.push_back(PairedReg);
3439 // Skip the next two GPRs.
3440 i += 2;
3441 }
3442 }
3443
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003444 if (Glue.getNode())
3445 AsmNodeOperands.push_back(Glue);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003446 if (!Changed)
Craig Topper062a2ba2014-04-25 05:30:21 +00003447 return nullptr;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003448
Andrew Trickef9de2a2013-05-25 02:42:55 +00003449 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Craig Topper48d114b2014-04-26 18:35:24 +00003450 CurDAG->getVTList(MVT::Other, MVT::Glue), AsmNodeOperands);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003451 New->setNodeId(-1);
3452 return New.getNode();
3453}
3454
3455
Bob Wilsona2c462b2009-05-19 05:53:42 +00003456bool ARMDAGToDAGISel::
3457SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3458 std::vector<SDValue> &OutOps) {
3459 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003460 // Require the address to be in a register. That is safe for all ARM
3461 // variants and it is hard to do anything much smarter without knowing
3462 // how the operand is used.
3463 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003464 return false;
3465}
3466
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003467/// createARMISelDag - This pass converts a legalized DAG into a
3468/// ARM-specific DAG, ready for instruction scheduling.
3469///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003470FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3471 CodeGenOpt::Level OptLevel) {
3472 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003473}