blob: 08d598d7c5a66099f764943b660a18d3ef34be85 [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 {
Anton Korobeynikov99152f32009-06-26 21:28:53 +000063 ARMBaseTargetMachine &TM;
Evan Chengbc0d0ec2008-09-18 07:24:33 +000064
Evan Cheng10043e22007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000069public:
Bob Wilson2dd957f2009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng62c7b5b2010-12-05 22:04:16 +000073 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000074 }
75
Eric Christopher0e6e7cf2014-05-22 02:00:27 +000076 bool runOnMachineFunction(MachineFunction &MF) override {
77 // Reset the subtarget each time through.
78 Subtarget = &TM.getSubtarget<ARMSubtarget>();
79 SelectionDAGISel::runOnMachineFunction(MF);
80 return true;
81 }
82
Craig Topper6bc27bf2014-03-10 02:09:33 +000083 const char *getPassName() const override {
Evan Cheng10043e22007-01-19 07:51:42 +000084 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000085 }
86
Craig Topper6bc27bf2014-03-10 02:09:33 +000087 void PreprocessISelDAG() override;
Evan Chengeae6d2c2012-12-19 20:16:09 +000088
Bob Wilson4facd962009-10-08 18:51:31 +000089 /// getI32Imm - Return a target constant of type i32 with the specified
90 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000091 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000092 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000093 }
94
Craig Topper6bc27bf2014-03-10 02:09:33 +000095 SDNode *Select(SDNode *N) override;
Evan Cheng5e73ff22010-02-15 19:41:07 +000096
Evan Cheng62c7b5b2010-12-05 22:04:16 +000097
98 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000099 bool isShifterOpProfitable(const SDValue &Shift,
100 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +0000101 bool SelectRegShifterOperand(SDValue N, SDValue &A,
102 SDValue &B, SDValue &C,
103 bool CheckProfitability = true);
104 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +0000105 SDValue &B, bool CheckProfitability = true);
106 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000107 SDValue &B, SDValue &C) {
108 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000109 return SelectRegShifterOperand(N, A, B, C, false);
110 }
111 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
112 SDValue &B) {
113 // Don't apply the profitability check
114 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000115 }
116
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000117 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
118 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
119
Jim Grosbach08605202010-09-29 19:03:54 +0000120 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
121 SDValue &Offset, SDValue &Opc);
122 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
123 SDValue &Opc) {
124 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
125 }
126
127 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
128 SDValue &Opc) {
129 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
130 }
131
132 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
133 SDValue &Opc) {
134 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000135// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000136 // This always matches one way or another.
137 return true;
138 }
139
Tim Northover42180442013-08-22 09:57:11 +0000140 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
141 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
142 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
143 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
144 return true;
145 }
146
Owen Anderson2aedba62011-07-26 20:54:26 +0000147 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
148 SDValue &Offset, SDValue &Opc);
149 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000150 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000151 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
152 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000153 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000154 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000155 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000156 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000157 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000158 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000159 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000160 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000161 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000162
Evan Chengdfce83c2011-01-17 08:03:18 +0000163 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000164
Bill Wendling092a7bd2010-12-14 03:36:38 +0000165 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000166 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000167 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
168 unsigned Scale);
169 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
170 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
171 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
172 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
173 SDValue &OffImm);
174 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
175 SDValue &OffImm);
176 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
177 SDValue &OffImm);
178 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
179 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000180 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000181
Bill Wendling092a7bd2010-12-14 03:36:38 +0000182 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000183 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000184 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000185 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
186 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000187 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000188 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000189 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000190 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000191 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000192 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000193
Evan Cheng0fc80842010-11-12 22:42:47 +0000194 inline bool is_so_imm(unsigned Imm) const {
195 return ARM_AM::getSOImmVal(Imm) != -1;
196 }
197
198 inline bool is_so_imm_not(unsigned Imm) const {
199 return ARM_AM::getSOImmVal(~Imm) != -1;
200 }
201
202 inline bool is_t2_so_imm(unsigned Imm) const {
203 return ARM_AM::getT2SOImmVal(Imm) != -1;
204 }
205
206 inline bool is_t2_so_imm_not(unsigned Imm) const {
207 return ARM_AM::getT2SOImmVal(~Imm) != -1;
208 }
209
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000210 // Include the pieces autogenerated from the target description.
211#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000212
213private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000214 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
215 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000216 SDNode *SelectARMIndexedLoad(SDNode *N);
217 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000218
Bob Wilson340861d2010-03-23 05:25:43 +0000219 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
220 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000221 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000222 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000223 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000224 const uint16_t *DOpcodes,
225 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000226
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000227 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000228 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000229 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000230 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000231 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000232 const uint16_t *DOpcodes,
233 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000234
Bob Wilson93117bc2009-10-14 16:46:45 +0000235 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000236 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000237 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000238 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
239 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000240 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000241
Bob Wilson2d790df2010-11-28 06:51:26 +0000242 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
243 /// should be 2, 3 or 4. The opcode array specifies the instructions used
244 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000245 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000246 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000247
Bob Wilson5bc8a792010-07-07 00:08:54 +0000248 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
249 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
250 /// generated to force the table registers to be consecutive.
251 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000252
Sandeep Patel7460e082009-10-13 20:25:58 +0000253 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000254 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000255
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000256 // Select special operations if node forms integer ABS pattern
257 SDNode *SelectABSOp(SDNode *N);
258
Weiming Zhaoc5987002013-02-14 18:10:21 +0000259 SDNode *SelectInlineAsm(SDNode *N);
260
Evan Chengd85631e2010-05-05 18:28:36 +0000261 SDNode *SelectConcatVector(SDNode *N);
262
Evan Chengd9c55362009-07-02 01:23:32 +0000263 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
264 /// inline asm expressions.
Craig Topper6bc27bf2014-03-10 02:09:33 +0000265 bool SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
266 std::vector<SDValue> &OutOps) override;
Bob Wilsone6b778d2009-10-06 22:01:59 +0000267
Weiming Zhao95782222012-11-17 00:23:35 +0000268 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000269 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000270 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
271 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
272 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000273
Bob Wilsond8a9a042010-06-04 00:04:02 +0000274 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000275 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
276 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
277 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000278
279 // Get the alignment operand for a NEON VLD or VST instruction.
280 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000281};
Evan Cheng10043e22007-01-19 07:51:42 +0000282}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000283
Sandeep Patel423e42b2009-10-13 18:59:48 +0000284/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
285/// operand. If so Imm will receive the 32-bit value.
286static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
287 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
288 Imm = cast<ConstantSDNode>(N)->getZExtValue();
289 return true;
290 }
291 return false;
292}
293
294// isInt32Immediate - This method tests to see if a constant operand.
295// If so Imm will receive the 32 bit value.
296static bool isInt32Immediate(SDValue N, unsigned &Imm) {
297 return isInt32Immediate(N.getNode(), Imm);
298}
299
300// isOpcWithIntImmediate - This method tests to see if the node is a specific
301// opcode and that it has a immediate integer right operand.
302// If so Imm will receive the 32 bit value.
303static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
304 return N->getOpcode() == Opc &&
305 isInt32Immediate(N->getOperand(1).getNode(), Imm);
306}
307
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000308/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000309/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000310///
311/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000312static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000313 int RangeMin, int RangeMax,
314 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000315 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000316
317 // Check that this is a constant.
318 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
319 if (!C)
320 return false;
321
322 ScaledConstant = (int) C->getZExtValue();
323 if ((ScaledConstant % Scale) != 0)
324 return false;
325
326 ScaledConstant /= Scale;
327 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
328}
329
Evan Chengeae6d2c2012-12-19 20:16:09 +0000330void ARMDAGToDAGISel::PreprocessISelDAG() {
331 if (!Subtarget->hasV6T2Ops())
332 return;
333
334 bool isThumb2 = Subtarget->isThumb();
335 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
336 E = CurDAG->allnodes_end(); I != E; ) {
337 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
338
339 if (N->getOpcode() != ISD::ADD)
340 continue;
341
342 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
343 // leading zeros, followed by consecutive set bits, followed by 1 or 2
344 // trailing zeros, e.g. 1020.
345 // Transform the expression to
346 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
347 // of trailing zeros of c2. The left shift would be folded as an shifter
348 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
349 // node (UBFX).
350
351 SDValue N0 = N->getOperand(0);
352 SDValue N1 = N->getOperand(1);
353 unsigned And_imm = 0;
354 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
355 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
356 std::swap(N0, N1);
357 }
358 if (!And_imm)
359 continue;
360
361 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000362 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000363 if (TZ != 1 && TZ != 2)
364 // Be conservative here. Shifter operands aren't always free. e.g. On
365 // Swift, left shifter operand of 1 / 2 for free but others are not.
366 // e.g.
367 // ubfx r3, r1, #16, #8
368 // ldr.w r3, [r0, r3, lsl #2]
369 // vs.
370 // mov.w r9, #1020
371 // and.w r2, r9, r1, lsr #14
372 // ldr r2, [r0, r2]
373 continue;
374 And_imm >>= TZ;
375 if (And_imm & (And_imm + 1))
376 continue;
377
378 // Look for (and (srl X, c1), c2).
379 SDValue Srl = N1.getOperand(0);
380 unsigned Srl_imm = 0;
381 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
382 (Srl_imm <= 2))
383 continue;
384
385 // Make sure first operand is not a shifter operand which would prevent
386 // folding of the left shift.
387 SDValue CPTmp0;
388 SDValue CPTmp1;
389 SDValue CPTmp2;
390 if (isThumb2) {
391 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
392 continue;
393 } else {
394 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
395 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
396 continue;
397 }
398
399 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000400 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000401 Srl.getOperand(0),
402 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000403 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000404 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000405 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000406 N1, CurDAG->getConstant(TZ, MVT::i32));
407 CurDAG->UpdateNodeOperands(N, N0, N1);
Jim Grosbach1a597112014-04-03 23:43:18 +0000408 }
Evan Chengeae6d2c2012-12-19 20:16:09 +0000409}
410
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000411/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
412/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
413/// least on current ARM implementations) which should be avoidded.
414bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
415 if (OptLevel == CodeGenOpt::None)
416 return true;
417
418 if (!CheckVMLxHazard)
419 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000420
Tim Northover0feb91e2014-04-01 14:10:07 +0000421 if (!Subtarget->isCortexA7() && !Subtarget->isCortexA8() &&
422 !Subtarget->isCortexA9() && !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000423 return true;
424
425 if (!N->hasOneUse())
426 return false;
427
428 SDNode *Use = *N->use_begin();
429 if (Use->getOpcode() == ISD::CopyToReg)
430 return true;
431 if (Use->isMachineOpcode()) {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000432 const ARMBaseInstrInfo *TII =
433 static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
434
Evan Cheng6cc775f2011-06-28 19:10:37 +0000435 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
436 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000437 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000438 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000439 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
440 return true;
441 // vmlx feeding into another vmlx. We actually want to unfold
442 // the use later in the MLxExpansion pass. e.g.
443 // vmla
444 // vmla (stall 8 cycles)
445 //
446 // vmul (5 cycles)
447 // vadd (5 cycles)
448 // vmla
449 // This adds up to about 18 - 19 cycles.
450 //
451 // vmla
452 // vmul (stall 4 cycles)
453 // vadd adds up to about 14 cycles.
454 return TII->isFpMLxInstruction(Opcode);
455 }
456
457 return false;
458}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000459
Evan Cheng59bbc542010-10-27 23:41:30 +0000460bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
461 ARM_AM::ShiftOpc ShOpcVal,
462 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000463 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000464 return true;
465 if (Shift.hasOneUse())
466 return true;
467 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000468 return ShOpcVal == ARM_AM::lsl &&
469 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000470}
471
Owen Andersonb595ed02011-07-21 18:54:16 +0000472bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000473 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000474 SDValue &Opc,
475 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000476 if (DisableShifterOp)
477 return false;
478
Evan Chenga20cde32011-07-20 23:34:39 +0000479 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000480
481 // Don't match base register only case. That is matched to a separate
482 // lower complexity pattern with explicit register operand.
483 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000484
Evan Chengb23b50d2009-06-29 07:51:04 +0000485 BaseReg = N.getOperand(0);
486 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000487 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
488 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000489 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000490 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
491 MVT::i32);
492 return true;
493}
494
Owen Andersonb595ed02011-07-21 18:54:16 +0000495bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
496 SDValue &BaseReg,
497 SDValue &ShReg,
498 SDValue &Opc,
499 bool CheckProfitability) {
500 if (DisableShifterOp)
501 return false;
502
503 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
504
505 // Don't match base register only case. That is matched to a separate
506 // lower complexity pattern with explicit register operand.
507 if (ShOpcVal == ARM_AM::no_shift) return false;
508
509 BaseReg = N.getOperand(0);
510 unsigned ShImmVal = 0;
511 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
512 if (RHS) return false;
513
514 ShReg = N.getOperand(1);
515 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
516 return false;
517 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
518 MVT::i32);
519 return true;
520}
521
522
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000523bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
524 SDValue &Base,
525 SDValue &OffImm) {
526 // Match simple R + imm12 operands.
527
528 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000529 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
530 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000531 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000532 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000533 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000534 Base = CurDAG->getTargetFrameIndex(FI,
535 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000536 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
537 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000538 }
Owen Anderson6d557452011-03-18 19:46:58 +0000539
Chris Lattner46c01a32011-02-13 22:25:43 +0000540 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000541 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000542 Base = N.getOperand(0);
543 } else
544 Base = N;
545 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
546 return true;
547 }
548
549 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
550 int RHSC = (int)RHS->getZExtValue();
551 if (N.getOpcode() == ISD::SUB)
552 RHSC = -RHSC;
553
554 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
555 Base = N.getOperand(0);
556 if (Base.getOpcode() == ISD::FrameIndex) {
557 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000558 Base = CurDAG->getTargetFrameIndex(FI,
559 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000560 }
561 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
562 return true;
563 }
564 }
565
566 // Base only.
567 Base = N;
568 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
569 return true;
570}
571
572
573
574bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
575 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000576 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000577 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000578 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
579 // X * [3,5,9] -> X + X * [2,4,8] etc.
580 int RHSC = (int)RHS->getZExtValue();
581 if (RHSC & 1) {
582 RHSC = RHSC & ~1;
583 ARM_AM::AddrOpc AddSub = ARM_AM::add;
584 if (RHSC < 0) {
585 AddSub = ARM_AM::sub;
586 RHSC = - RHSC;
587 }
588 if (isPowerOf2_32(RHSC)) {
589 unsigned ShAmt = Log2_32(RHSC);
590 Base = Offset = N.getOperand(0);
591 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
592 ARM_AM::lsl),
593 MVT::i32);
594 return true;
595 }
596 }
597 }
598 }
599
Chris Lattner46c01a32011-02-13 22:25:43 +0000600 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
601 // ISD::OR that is equivalent to an ISD::ADD.
602 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000603 return false;
604
605 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000606 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000607 int RHSC;
608 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
609 -0x1000+1, 0x1000, RHSC)) // 12 bits.
610 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000611 }
612
613 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000614 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000615 ARM_AM::ShiftOpc ShOpcVal =
616 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000617 unsigned ShAmt = 0;
618
619 Base = N.getOperand(0);
620 Offset = N.getOperand(1);
621
622 if (ShOpcVal != ARM_AM::no_shift) {
623 // Check to see if the RHS of the shift is a constant, if not, we can't fold
624 // it.
625 if (ConstantSDNode *Sh =
626 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
627 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000628 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
629 Offset = N.getOperand(1).getOperand(0);
630 else {
631 ShAmt = 0;
632 ShOpcVal = ARM_AM::no_shift;
633 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000634 } else {
635 ShOpcVal = ARM_AM::no_shift;
636 }
637 }
638
639 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000640 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000641 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
642 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000643 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000644 if (ShOpcVal != ARM_AM::no_shift) {
645 // Check to see if the RHS of the shift is a constant, if not, we can't
646 // fold it.
647 if (ConstantSDNode *Sh =
648 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
649 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000650 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000651 Offset = N.getOperand(0).getOperand(0);
652 Base = N.getOperand(1);
653 } else {
654 ShAmt = 0;
655 ShOpcVal = ARM_AM::no_shift;
656 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000657 } else {
658 ShOpcVal = ARM_AM::no_shift;
659 }
660 }
661 }
662
663 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
664 MVT::i32);
665 return true;
666}
667
668
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000669//-----
670
Jim Grosbach08605202010-09-29 19:03:54 +0000671AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
672 SDValue &Base,
673 SDValue &Offset,
674 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000675 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000676 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000677 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
678 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000679 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000680 if (RHSC & 1) {
681 RHSC = RHSC & ~1;
682 ARM_AM::AddrOpc AddSub = ARM_AM::add;
683 if (RHSC < 0) {
684 AddSub = ARM_AM::sub;
685 RHSC = - RHSC;
686 }
687 if (isPowerOf2_32(RHSC)) {
688 unsigned ShAmt = Log2_32(RHSC);
689 Base = Offset = N.getOperand(0);
690 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
691 ARM_AM::lsl),
Owen Anderson9f944592009-08-11 20:47:22 +0000692 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000693 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000694 }
695 }
696 }
697 }
698
Chris Lattner46c01a32011-02-13 22:25:43 +0000699 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
700 // ISD::OR that is equivalent to an ADD.
701 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000702 Base = N;
703 if (N.getOpcode() == ISD::FrameIndex) {
704 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000705 Base = CurDAG->getTargetFrameIndex(FI,
706 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000707 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000708 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000709 Base = N.getOperand(0);
710 }
Owen Anderson9f944592009-08-11 20:47:22 +0000711 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000712 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
713 ARM_AM::no_shift),
Owen Anderson9f944592009-08-11 20:47:22 +0000714 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000715 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000716 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000717
Evan Cheng10043e22007-01-19 07:51:42 +0000718 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000719 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000720 int RHSC;
721 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
722 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
723 Base = N.getOperand(0);
724 if (Base.getOpcode() == ISD::FrameIndex) {
725 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000726 Base = CurDAG->getTargetFrameIndex(FI,
727 getTargetLowering()->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000728 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000729 Offset = CurDAG->getRegister(0, MVT::i32);
730
731 ARM_AM::AddrOpc AddSub = ARM_AM::add;
732 if (RHSC < 0) {
733 AddSub = ARM_AM::sub;
734 RHSC = - RHSC;
735 }
736 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
737 ARM_AM::no_shift),
738 MVT::i32);
739 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000740 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000741 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000742
Bob Wilsone8a549c2012-09-29 21:43:49 +0000743 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000744 // Compute R +/- (R << N) and reuse it.
745 Base = N;
746 Offset = CurDAG->getRegister(0, MVT::i32);
747 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
748 ARM_AM::no_shift),
749 MVT::i32);
750 return AM2_BASE;
751 }
752
Johnny Chenb678a562009-10-27 17:25:15 +0000753 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000754 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000755 ARM_AM::ShiftOpc ShOpcVal =
756 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000757 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000758
Evan Cheng10043e22007-01-19 07:51:42 +0000759 Base = N.getOperand(0);
760 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000761
Evan Cheng10043e22007-01-19 07:51:42 +0000762 if (ShOpcVal != ARM_AM::no_shift) {
763 // Check to see if the RHS of the shift is a constant, if not, we can't fold
764 // it.
765 if (ConstantSDNode *Sh =
766 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000767 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000768 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
769 Offset = N.getOperand(1).getOperand(0);
770 else {
771 ShAmt = 0;
772 ShOpcVal = ARM_AM::no_shift;
773 }
Evan Cheng10043e22007-01-19 07:51:42 +0000774 } else {
775 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000776 }
777 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000778
Evan Cheng10043e22007-01-19 07:51:42 +0000779 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000780 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000781 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
782 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000783 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000784 if (ShOpcVal != ARM_AM::no_shift) {
785 // Check to see if the RHS of the shift is a constant, if not, we can't
786 // fold it.
787 if (ConstantSDNode *Sh =
788 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000789 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000790 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000791 Offset = N.getOperand(0).getOperand(0);
792 Base = N.getOperand(1);
793 } else {
794 ShAmt = 0;
795 ShOpcVal = ARM_AM::no_shift;
796 }
Evan Cheng10043e22007-01-19 07:51:42 +0000797 } else {
798 ShOpcVal = ARM_AM::no_shift;
799 }
800 }
801 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000802
Evan Cheng10043e22007-01-19 07:51:42 +0000803 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000804 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000805 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000806}
807
Owen Anderson2aedba62011-07-26 20:54:26 +0000808bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000809 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000810 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000811 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
812 ? cast<LoadSDNode>(Op)->getAddressingMode()
813 : cast<StoreSDNode>(Op)->getAddressingMode();
814 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
815 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000816 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000817 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
818 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000819
820 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000821 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000822 unsigned ShAmt = 0;
823 if (ShOpcVal != ARM_AM::no_shift) {
824 // Check to see if the RHS of the shift is a constant, if not, we can't fold
825 // it.
826 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000827 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000828 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
829 Offset = N.getOperand(0);
830 else {
831 ShAmt = 0;
832 ShOpcVal = ARM_AM::no_shift;
833 }
Evan Cheng10043e22007-01-19 07:51:42 +0000834 } else {
835 ShOpcVal = ARM_AM::no_shift;
836 }
837 }
838
839 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000840 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000841 return true;
842}
843
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000844bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
845 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000846 unsigned Opcode = Op->getOpcode();
847 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
848 ? cast<LoadSDNode>(Op)->getAddressingMode()
849 : cast<StoreSDNode>(Op)->getAddressingMode();
850 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
851 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000852 int Val;
853 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000854 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000855 Offset = CurDAG->getRegister(0, MVT::i32);
856 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
857 return true;
858 }
859
860 return false;
861}
862
863
Owen Anderson2aedba62011-07-26 20:54:26 +0000864bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
865 SDValue &Offset, SDValue &Opc) {
866 unsigned Opcode = Op->getOpcode();
867 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
868 ? cast<LoadSDNode>(Op)->getAddressingMode()
869 : cast<StoreSDNode>(Op)->getAddressingMode();
870 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
871 ? ARM_AM::add : ARM_AM::sub;
872 int Val;
873 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
874 Offset = CurDAG->getRegister(0, MVT::i32);
875 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
876 ARM_AM::no_shift),
877 MVT::i32);
878 return true;
879 }
880
881 return false;
882}
883
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000884bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
885 Base = N;
886 return true;
887}
Evan Cheng10043e22007-01-19 07:51:42 +0000888
Chris Lattner0e023ea2010-09-21 20:31:19 +0000889bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000890 SDValue &Base, SDValue &Offset,
891 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000892 if (N.getOpcode() == ISD::SUB) {
893 // X - C is canonicalize to X + -C, no need to handle it here.
894 Base = N.getOperand(0);
895 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000896 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000897 return true;
898 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000899
Chris Lattner46c01a32011-02-13 22:25:43 +0000900 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000901 Base = N;
902 if (N.getOpcode() == ISD::FrameIndex) {
903 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000904 Base = CurDAG->getTargetFrameIndex(FI,
905 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000906 }
Owen Anderson9f944592009-08-11 20:47:22 +0000907 Offset = CurDAG->getRegister(0, MVT::i32);
908 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000909 return true;
910 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000911
Evan Cheng10043e22007-01-19 07:51:42 +0000912 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000913 int RHSC;
914 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
915 -256 + 1, 256, RHSC)) { // 8 bits.
916 Base = N.getOperand(0);
917 if (Base.getOpcode() == ISD::FrameIndex) {
918 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000919 Base = CurDAG->getTargetFrameIndex(FI,
920 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000921 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000922 Offset = CurDAG->getRegister(0, MVT::i32);
923
924 ARM_AM::AddrOpc AddSub = ARM_AM::add;
925 if (RHSC < 0) {
926 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000927 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000928 }
929 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
930 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000931 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000932
Evan Cheng10043e22007-01-19 07:51:42 +0000933 Base = N.getOperand(0);
934 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000935 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000936 return true;
937}
938
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000939bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000940 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000941 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000942 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
943 ? cast<LoadSDNode>(Op)->getAddressingMode()
944 : cast<StoreSDNode>(Op)->getAddressingMode();
945 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
946 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000947 int Val;
948 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
949 Offset = CurDAG->getRegister(0, MVT::i32);
950 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
951 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000952 }
953
954 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000955 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000956 return true;
957}
958
Jim Grosbachd37f0712010-10-21 19:38:40 +0000959bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000960 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000961 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000962 Base = N;
963 if (N.getOpcode() == ISD::FrameIndex) {
964 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000965 Base = CurDAG->getTargetFrameIndex(FI,
966 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000967 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000968 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000969 Base = N.getOperand(0);
970 }
971 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000972 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000973 return true;
974 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000975
Evan Cheng10043e22007-01-19 07:51:42 +0000976 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000977 int RHSC;
978 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
979 -256 + 1, 256, RHSC)) {
980 Base = N.getOperand(0);
981 if (Base.getOpcode() == ISD::FrameIndex) {
982 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000983 Base = CurDAG->getTargetFrameIndex(FI,
984 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000985 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000986
987 ARM_AM::AddrOpc AddSub = ARM_AM::add;
988 if (RHSC < 0) {
989 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000990 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000991 }
992 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
993 MVT::i32);
994 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000995 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000996
Evan Cheng10043e22007-01-19 07:51:42 +0000997 Base = N;
998 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000999 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001000 return true;
1001}
1002
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001003bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
1004 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +00001005 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001006
1007 unsigned Alignment = 0;
1008 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1009 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1010 // The maximum alignment is equal to the memory size being referenced.
1011 unsigned LSNAlign = LSN->getAlignment();
1012 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001013 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001014 Alignment = MemSize;
1015 } else {
1016 // All other uses of addrmode6 are for intrinsics. For now just record
1017 // the raw alignment value; it will be refined later based on the legal
1018 // alignment operands for the intrinsic.
1019 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1020 }
1021
1022 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001023 return true;
1024}
1025
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001026bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1027 SDValue &Offset) {
1028 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1029 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1030 if (AM != ISD::POST_INC)
1031 return false;
1032 Offset = N;
1033 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1034 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1035 Offset = CurDAG->getRegister(0, MVT::i32);
1036 }
1037 return true;
1038}
1039
Chris Lattner0e023ea2010-09-21 20:31:19 +00001040bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001041 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001042 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1043 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001044 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001045 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1046 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001047 return true;
1048 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001049
Evan Cheng10043e22007-01-19 07:51:42 +00001050 return false;
1051}
1052
Bill Wendling092a7bd2010-12-14 03:36:38 +00001053
1054//===----------------------------------------------------------------------===//
1055// Thumb Addressing Modes
1056//===----------------------------------------------------------------------===//
1057
Chris Lattner0e023ea2010-09-21 20:31:19 +00001058bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001059 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001060 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001061 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001062 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001063 return false;
1064
1065 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001066 return true;
1067 }
1068
Evan Cheng10043e22007-01-19 07:51:42 +00001069 Base = N.getOperand(0);
1070 Offset = N.getOperand(1);
1071 return true;
1072}
1073
Evan Cheng139edae2007-01-24 02:21:22 +00001074bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001075ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1076 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001077 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001078 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001079 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001080 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001081
Evan Cheng1526ba52007-01-24 08:53:17 +00001082 if (N.getOpcode() == ARMISD::Wrapper &&
1083 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1084 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001085 }
1086
Chris Lattner46c01a32011-02-13 22:25:43 +00001087 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001088 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001089
Evan Cheng650d0672007-02-06 00:22:06 +00001090 // Thumb does not have [sp, r] address mode.
1091 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1092 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1093 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001094 (RHSR && RHSR->getReg() == ARM::SP))
1095 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001096
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001097 // FIXME: Why do we explicitly check for a match here and then return false?
1098 // Presumably to allow something else to match, but shouldn't this be
1099 // documented?
1100 int RHSC;
1101 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1102 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001103
1104 Base = N.getOperand(0);
1105 Offset = N.getOperand(1);
1106 return true;
1107}
1108
1109bool
1110ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1111 SDValue &Base,
1112 SDValue &Offset) {
1113 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1114}
1115
1116bool
1117ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1118 SDValue &Base,
1119 SDValue &Offset) {
1120 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1121}
1122
1123bool
1124ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1125 SDValue &Base,
1126 SDValue &Offset) {
1127 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1128}
1129
1130bool
1131ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1132 SDValue &Base, SDValue &OffImm) {
1133 if (Scale == 4) {
1134 SDValue TmpBase, TmpOffImm;
1135 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1136 return false; // We want to select tLDRspi / tSTRspi instead.
1137
1138 if (N.getOpcode() == ARMISD::Wrapper &&
1139 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1140 return false; // We want to select tLDRpci instead.
1141 }
1142
Chris Lattner46c01a32011-02-13 22:25:43 +00001143 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001144 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001145 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001146 Base = N.getOperand(0);
1147 } else {
1148 Base = N;
1149 }
1150
Owen Anderson9f944592009-08-11 20:47:22 +00001151 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001152 return true;
1153 }
1154
Bill Wendling832a5da2010-12-15 01:03:19 +00001155 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1156 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1157 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1158 (RHSR && RHSR->getReg() == ARM::SP)) {
1159 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1160 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1161 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1162 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1163
1164 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1165 if (LHSC != 0 || RHSC != 0) return false;
1166
1167 Base = N;
1168 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1169 return true;
1170 }
1171
Evan Cheng10043e22007-01-19 07:51:42 +00001172 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001173 int RHSC;
1174 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1175 Base = N.getOperand(0);
1176 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1177 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001178 }
1179
Evan Chengc0b73662007-01-23 22:59:13 +00001180 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001181 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001182 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001183}
1184
Bill Wendling092a7bd2010-12-14 03:36:38 +00001185bool
1186ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1187 SDValue &OffImm) {
1188 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001189}
1190
Bill Wendling092a7bd2010-12-14 03:36:38 +00001191bool
1192ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1193 SDValue &OffImm) {
1194 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001195}
1196
Bill Wendling092a7bd2010-12-14 03:36:38 +00001197bool
1198ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1199 SDValue &OffImm) {
1200 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001201}
1202
Chris Lattner0e023ea2010-09-21 20:31:19 +00001203bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1204 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001205 if (N.getOpcode() == ISD::FrameIndex) {
1206 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001207 Base = CurDAG->getTargetFrameIndex(FI,
1208 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001209 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001210 return true;
1211 }
Evan Cheng139edae2007-01-24 02:21:22 +00001212
Chris Lattner46c01a32011-02-13 22:25:43 +00001213 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001214 return false;
1215
1216 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001217 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1218 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001219 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001220 int RHSC;
1221 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1222 Base = N.getOperand(0);
1223 if (Base.getOpcode() == ISD::FrameIndex) {
1224 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001225 Base = CurDAG->getTargetFrameIndex(FI,
1226 getTargetLowering()->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001227 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001228 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1229 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001230 }
1231 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001232
Evan Cheng10043e22007-01-19 07:51:42 +00001233 return false;
1234}
1235
Bill Wendling092a7bd2010-12-14 03:36:38 +00001236
1237//===----------------------------------------------------------------------===//
1238// Thumb 2 Addressing Modes
1239//===----------------------------------------------------------------------===//
1240
1241
Chris Lattner0e023ea2010-09-21 20:31:19 +00001242bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001243 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001244 if (DisableShifterOp)
1245 return false;
1246
Evan Chenga20cde32011-07-20 23:34:39 +00001247 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001248
1249 // Don't match base register only case. That is matched to a separate
1250 // lower complexity pattern with explicit register operand.
1251 if (ShOpcVal == ARM_AM::no_shift) return false;
1252
1253 BaseReg = N.getOperand(0);
1254 unsigned ShImmVal = 0;
1255 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1256 ShImmVal = RHS->getZExtValue() & 31;
1257 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1258 return true;
1259 }
1260
1261 return false;
1262}
1263
Chris Lattner0e023ea2010-09-21 20:31:19 +00001264bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001265 SDValue &Base, SDValue &OffImm) {
1266 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001267
Evan Cheng36064672009-08-11 08:52:18 +00001268 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001269 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1270 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001271 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001272 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001273 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001274 Base = CurDAG->getTargetFrameIndex(FI,
1275 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001276 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001277 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001278 }
Owen Anderson6d557452011-03-18 19:46:58 +00001279
Chris Lattner46c01a32011-02-13 22:25:43 +00001280 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001281 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng36064672009-08-11 08:52:18 +00001282 Base = N.getOperand(0);
1283 if (Base.getOpcode() == ISD::TargetConstantPool)
1284 return false; // We want to select t2LDRpci instead.
1285 } else
1286 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001287 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001288 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001289 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001290
1291 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001292 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001293 // Let t2LDRi8 handle (R - imm8).
1294 return false;
1295
Evan Chengb23b50d2009-06-29 07:51:04 +00001296 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001297 if (N.getOpcode() == ISD::SUB)
1298 RHSC = -RHSC;
1299
1300 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001301 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001302 if (Base.getOpcode() == ISD::FrameIndex) {
1303 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001304 Base = CurDAG->getTargetFrameIndex(FI,
1305 getTargetLowering()->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001306 }
Owen Anderson9f944592009-08-11 20:47:22 +00001307 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001308 return true;
1309 }
1310 }
1311
Evan Cheng36064672009-08-11 08:52:18 +00001312 // Base only.
1313 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001314 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001315 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001316}
1317
Chris Lattner0e023ea2010-09-21 20:31:19 +00001318bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001319 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001320 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001321 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1322 !CurDAG->isBaseWithConstantOffset(N))
1323 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001324
Chris Lattner46c01a32011-02-13 22:25:43 +00001325 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1326 int RHSC = (int)RHS->getSExtValue();
1327 if (N.getOpcode() == ISD::SUB)
1328 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001329
Chris Lattner46c01a32011-02-13 22:25:43 +00001330 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1331 Base = N.getOperand(0);
1332 if (Base.getOpcode() == ISD::FrameIndex) {
1333 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001334 Base = CurDAG->getTargetFrameIndex(FI,
1335 getTargetLowering()->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001336 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001337 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1338 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001339 }
1340 }
1341
1342 return false;
1343}
1344
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001345bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001346 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001347 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001348 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1349 ? cast<LoadSDNode>(Op)->getAddressingMode()
1350 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001351 int RHSC;
1352 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1353 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1354 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1355 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1356 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001357 }
1358
1359 return false;
1360}
1361
Chris Lattner0e023ea2010-09-21 20:31:19 +00001362bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001363 SDValue &Base,
1364 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001365 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001366 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001367 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001368
Evan Cheng36064672009-08-11 08:52:18 +00001369 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1370 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1371 int RHSC = (int)RHS->getZExtValue();
1372 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1373 return false;
1374 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001375 return false;
1376 }
1377
Evan Chengb23b50d2009-06-29 07:51:04 +00001378 // Look for (R + R) or (R + (R << [1,2,3])).
1379 unsigned ShAmt = 0;
1380 Base = N.getOperand(0);
1381 OffReg = N.getOperand(1);
1382
1383 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001384 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001385 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001386 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001387 if (ShOpcVal == ARM_AM::lsl)
1388 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001389 }
1390
Evan Chengb23b50d2009-06-29 07:51:04 +00001391 if (ShOpcVal == ARM_AM::lsl) {
1392 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1393 // it.
1394 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1395 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001396 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1397 OffReg = OffReg.getOperand(0);
1398 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001399 ShAmt = 0;
1400 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001401 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001402 } else {
1403 ShOpcVal = ARM_AM::no_shift;
1404 }
David Goodwinf3912052009-07-15 15:50:19 +00001405 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001406
Owen Anderson9f944592009-08-11 20:47:22 +00001407 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001408
1409 return true;
1410}
1411
Tim Northovera7ecd242013-07-16 09:46:55 +00001412bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1413 SDValue &OffImm) {
Alp Tokercb402912014-01-24 17:20:08 +00001414 // This *must* succeed since it's used for the irreplaceable ldrex and strex
Tim Northovera7ecd242013-07-16 09:46:55 +00001415 // instructions.
1416 Base = N;
1417 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1418
1419 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1420 return true;
1421
1422 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1423 if (!RHS)
1424 return true;
1425
1426 uint32_t RHSC = (int)RHS->getZExtValue();
1427 if (RHSC > 1020 || RHSC % 4 != 0)
1428 return true;
1429
1430 Base = N.getOperand(0);
1431 if (Base.getOpcode() == ISD::FrameIndex) {
1432 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1433 Base = CurDAG->getTargetFrameIndex(FI, getTargetLowering()->getPointerTy());
1434 }
1435
1436 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1437 return true;
1438}
1439
Evan Chengb23b50d2009-06-29 07:51:04 +00001440//===--------------------------------------------------------------------===//
1441
Evan Cheng7e90b112007-07-05 07:15:27 +00001442/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001443static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001444 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001445}
1446
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001447SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1448 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001449 ISD::MemIndexedMode AM = LD->getAddressingMode();
1450 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001451 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001452
Owen Anderson53aa7a92009-08-10 22:56:29 +00001453 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001454 SDValue Offset, AMOpc;
1455 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1456 unsigned Opcode = 0;
1457 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001458 if (LoadedVT == MVT::i32 && isPre &&
1459 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1460 Opcode = ARM::LDR_PRE_IMM;
1461 Match = true;
1462 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001463 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001464 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001465 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001466 } else if (LoadedVT == MVT::i32 &&
1467 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001468 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001469 Match = true;
1470
Owen Anderson9f944592009-08-11 20:47:22 +00001471 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001472 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001473 Match = true;
1474 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1475 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1476 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001477 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001478 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001479 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001480 Match = true;
1481 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1482 }
1483 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001484 if (isPre &&
1485 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001486 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001487 Opcode = ARM::LDRB_PRE_IMM;
1488 } else if (!isPre &&
1489 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1490 Match = true;
1491 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001492 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1493 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001494 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001495 }
1496 }
1497 }
1498
1499 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001500 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1501 SDValue Chain = LD->getChain();
1502 SDValue Base = LD->getBasePtr();
1503 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1504 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001505 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001506 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001507 } else {
1508 SDValue Chain = LD->getChain();
1509 SDValue Base = LD->getBasePtr();
1510 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1511 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001512 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001513 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001514 }
Evan Chengd9c55362009-07-02 01:23:32 +00001515 }
1516
Craig Topper062a2ba2014-04-25 05:30:21 +00001517 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001518}
1519
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001520SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1521 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001522 ISD::MemIndexedMode AM = LD->getAddressingMode();
1523 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001524 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001525
Owen Anderson53aa7a92009-08-10 22:56:29 +00001526 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001527 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001528 SDValue Offset;
1529 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1530 unsigned Opcode = 0;
1531 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001532 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001533 switch (LoadedVT.getSimpleVT().SimpleTy) {
1534 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001535 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1536 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001537 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001538 if (isSExtLd)
1539 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1540 else
1541 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001542 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001543 case MVT::i8:
1544 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001545 if (isSExtLd)
1546 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1547 else
1548 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001549 break;
1550 default:
Craig Topper062a2ba2014-04-25 05:30:21 +00001551 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001552 }
1553 Match = true;
1554 }
1555
1556 if (Match) {
1557 SDValue Chain = LD->getChain();
1558 SDValue Base = LD->getBasePtr();
1559 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001560 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001561 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001562 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001563 }
1564
Craig Topper062a2ba2014-04-25 05:30:21 +00001565 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001566}
1567
Weiming Zhao8f56f882012-11-16 21:55:34 +00001568/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1569SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001570 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001571 SDValue RegClass =
1572 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1573 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1574 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1575 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001576 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001577}
1578
Weiming Zhao95782222012-11-17 00:23:35 +00001579/// \brief Form a D register from a pair of S registers.
1580SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001581 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001582 SDValue RegClass =
1583 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001584 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1585 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001586 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001587 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001588}
1589
Weiming Zhao95782222012-11-17 00:23:35 +00001590/// \brief Form a quad register from a pair of D registers.
1591SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001592 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001593 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001594 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1595 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001596 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001597 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001598}
1599
Weiming Zhao95782222012-11-17 00:23:35 +00001600/// \brief Form 4 consecutive D registers from a pair of Q registers.
1601SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001602 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001603 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001604 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1605 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001606 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001607 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001608}
1609
Weiming Zhao95782222012-11-17 00:23:35 +00001610/// \brief Form 4 consecutive S registers.
1611SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001612 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001613 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001614 SDValue RegClass =
1615 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001616 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1617 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1618 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1619 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001620 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1621 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001622 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001623}
1624
Weiming Zhao95782222012-11-17 00:23:35 +00001625/// \brief Form 4 consecutive D registers.
1626SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001627 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001628 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001629 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001630 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1631 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1632 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1633 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001634 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1635 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001636 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001637}
1638
Weiming Zhao95782222012-11-17 00:23:35 +00001639/// \brief Form 4 consecutive Q registers.
1640SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001641 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001642 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001643 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001644 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1645 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1646 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1647 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001648 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1649 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001650 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001651}
1652
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001653/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1654/// of a NEON VLD or VST instruction. The supported values depend on the
1655/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001656SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1657 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001658 unsigned NumRegs = NumVecs;
1659 if (!is64BitVector && NumVecs < 3)
1660 NumRegs *= 2;
1661
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001662 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001663 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001664 Alignment = 32;
1665 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1666 Alignment = 16;
1667 else if (Alignment >= 8)
1668 Alignment = 8;
1669 else
1670 Alignment = 0;
1671
1672 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001673}
1674
Jiangning Liu4df23632014-01-16 09:16:13 +00001675static bool isVLDfixed(unsigned Opc)
1676{
1677 switch (Opc) {
1678 default: return false;
1679 case ARM::VLD1d8wb_fixed : return true;
1680 case ARM::VLD1d16wb_fixed : return true;
1681 case ARM::VLD1d64Qwb_fixed : return true;
1682 case ARM::VLD1d32wb_fixed : return true;
1683 case ARM::VLD1d64wb_fixed : return true;
1684 case ARM::VLD1d64TPseudoWB_fixed : return true;
1685 case ARM::VLD1d64QPseudoWB_fixed : return true;
1686 case ARM::VLD1q8wb_fixed : return true;
1687 case ARM::VLD1q16wb_fixed : return true;
1688 case ARM::VLD1q32wb_fixed : return true;
1689 case ARM::VLD1q64wb_fixed : return true;
1690 case ARM::VLD2d8wb_fixed : return true;
1691 case ARM::VLD2d16wb_fixed : return true;
1692 case ARM::VLD2d32wb_fixed : return true;
1693 case ARM::VLD2q8PseudoWB_fixed : return true;
1694 case ARM::VLD2q16PseudoWB_fixed : return true;
1695 case ARM::VLD2q32PseudoWB_fixed : return true;
1696 case ARM::VLD2DUPd8wb_fixed : return true;
1697 case ARM::VLD2DUPd16wb_fixed : return true;
1698 case ARM::VLD2DUPd32wb_fixed : return true;
1699 }
1700}
1701
1702static bool isVSTfixed(unsigned Opc)
1703{
1704 switch (Opc) {
1705 default: return false;
1706 case ARM::VST1d8wb_fixed : return true;
1707 case ARM::VST1d16wb_fixed : return true;
1708 case ARM::VST1d32wb_fixed : return true;
1709 case ARM::VST1d64wb_fixed : return true;
Jim Grosbach1a597112014-04-03 23:43:18 +00001710 case ARM::VST1q8wb_fixed : return true;
1711 case ARM::VST1q16wb_fixed : return true;
1712 case ARM::VST1q32wb_fixed : return true;
1713 case ARM::VST1q64wb_fixed : return true;
Jiangning Liu4df23632014-01-16 09:16:13 +00001714 case ARM::VST1d64TPseudoWB_fixed : return true;
1715 case ARM::VST1d64QPseudoWB_fixed : return true;
1716 case ARM::VST2d8wb_fixed : return true;
1717 case ARM::VST2d16wb_fixed : return true;
1718 case ARM::VST2d32wb_fixed : return true;
1719 case ARM::VST2q8PseudoWB_fixed : return true;
1720 case ARM::VST2q16PseudoWB_fixed : return true;
1721 case ARM::VST2q32PseudoWB_fixed : return true;
1722 }
1723}
1724
Jim Grosbach2098cb12011-10-24 21:45:13 +00001725// Get the register stride update opcode of a VLD/VST instruction that
1726// is otherwise equivalent to the given fixed stride updating instruction.
1727static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
Jiangning Liu4df23632014-01-16 09:16:13 +00001728 assert((isVLDfixed(Opc) || isVSTfixed(Opc))
1729 && "Incorrect fixed stride updating instruction.");
Jim Grosbach2098cb12011-10-24 21:45:13 +00001730 switch (Opc) {
1731 default: break;
1732 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1733 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1734 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1735 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1736 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1737 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1738 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1739 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jiangning Liu4df23632014-01-16 09:16:13 +00001740 case ARM::VLD1d64Twb_fixed: return ARM::VLD1d64Twb_register;
1741 case ARM::VLD1d64Qwb_fixed: return ARM::VLD1d64Qwb_register;
1742 case ARM::VLD1d64TPseudoWB_fixed: return ARM::VLD1d64TPseudoWB_register;
1743 case ARM::VLD1d64QPseudoWB_fixed: return ARM::VLD1d64QPseudoWB_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001744
1745 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1746 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1747 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1748 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1749 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1750 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1751 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1752 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001753 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001754 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001755
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001756 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1757 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1758 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001759 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1760 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1761 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1762
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001763 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1764 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1765 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001766 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1767 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1768 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001769
Jim Grosbach13a292c2012-03-06 22:01:44 +00001770 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1771 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1772 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001773 }
1774 return Opc; // If not one we handle, return it unchanged.
1775}
1776
Bob Wilson06fce872011-02-07 17:43:21 +00001777SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001778 const uint16_t *DOpcodes,
1779 const uint16_t *QOpcodes0,
1780 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001781 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001782 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001783
Bob Wilsonae08a732010-03-20 22:13:40 +00001784 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001785 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1786 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001787 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001788
1789 SDValue Chain = N->getOperand(0);
1790 EVT VT = N->getValueType(0);
1791 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001792 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001793
Bob Wilson12b47992009-10-14 17:28:52 +00001794 unsigned OpcodeIndex;
1795 switch (VT.getSimpleVT().SimpleTy) {
1796 default: llvm_unreachable("unhandled vld type");
1797 // Double-register operations:
1798 case MVT::v8i8: OpcodeIndex = 0; break;
1799 case MVT::v4i16: OpcodeIndex = 1; break;
1800 case MVT::v2f32:
1801 case MVT::v2i32: OpcodeIndex = 2; break;
1802 case MVT::v1i64: OpcodeIndex = 3; break;
1803 // Quad-register operations:
1804 case MVT::v16i8: OpcodeIndex = 0; break;
1805 case MVT::v8i16: OpcodeIndex = 1; break;
1806 case MVT::v4f32:
1807 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001808 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001809 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001810 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001811 }
1812
Bob Wilson35fafca2010-09-03 18:16:02 +00001813 EVT ResTy;
1814 if (NumVecs == 1)
1815 ResTy = VT;
1816 else {
1817 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1818 if (!is64BitVector)
1819 ResTyElts *= 2;
1820 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1821 }
Bob Wilson06fce872011-02-07 17:43:21 +00001822 std::vector<EVT> ResTys;
1823 ResTys.push_back(ResTy);
1824 if (isUpdating)
1825 ResTys.push_back(MVT::i32);
1826 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001827
Evan Cheng3da64f762010-04-16 05:46:06 +00001828 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001829 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001830 SDNode *VLd;
1831 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001832
Bob Wilson06fce872011-02-07 17:43:21 +00001833 // Double registers and VLD1/VLD2 quad registers are directly supported.
1834 if (is64BitVector || NumVecs <= 2) {
1835 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1836 QOpcodes0[OpcodeIndex]);
1837 Ops.push_back(MemAddr);
1838 Ops.push_back(Align);
1839 if (isUpdating) {
1840 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001841 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001842 // case entirely when the rest are updated to that form, too.
Jiangning Liu4df23632014-01-16 09:16:13 +00001843 if ((NumVecs <= 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001844 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001845 // FIXME: We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001846 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001847 if ((NumVecs > 2 && !isVLDfixed(Opc)) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001848 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001849 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001850 }
Bob Wilson06fce872011-02-07 17:43:21 +00001851 Ops.push_back(Pred);
1852 Ops.push_back(Reg0);
1853 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001854 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001855
Bob Wilson12b47992009-10-14 17:28:52 +00001856 } else {
1857 // Otherwise, quad registers are loaded with two separate instructions,
1858 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001859 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001860
Bob Wilson06fce872011-02-07 17:43:21 +00001861 // Load the even subregs. This is always an updating load, so that it
1862 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001863 SDValue ImplDef =
1864 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1865 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001866 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001867 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001868 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001869
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001870 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001871 Ops.push_back(SDValue(VLdA, 1));
1872 Ops.push_back(Align);
1873 if (isUpdating) {
1874 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1875 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1876 "only constant post-increment update allowed for VLD3/4");
1877 (void)Inc;
1878 Ops.push_back(Reg0);
1879 }
1880 Ops.push_back(SDValue(VLdA, 0));
1881 Ops.push_back(Pred);
1882 Ops.push_back(Reg0);
1883 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001884 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001885 }
Bob Wilson12b47992009-10-14 17:28:52 +00001886
Evan Cheng40791332011-04-19 00:04:03 +00001887 // Transfer memoperands.
1888 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1889 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1890 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1891
Bob Wilson06fce872011-02-07 17:43:21 +00001892 if (NumVecs == 1)
1893 return VLd;
1894
1895 // Extract out the subregisters.
1896 SDValue SuperReg = SDValue(VLd, 0);
1897 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1898 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1899 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1900 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1901 ReplaceUses(SDValue(N, Vec),
1902 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1903 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1904 if (isUpdating)
1905 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00001906 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001907}
1908
Bob Wilson06fce872011-02-07 17:43:21 +00001909SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001910 const uint16_t *DOpcodes,
1911 const uint16_t *QOpcodes0,
1912 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001913 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001914 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001915
Bob Wilsonae08a732010-03-20 22:13:40 +00001916 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001917 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1918 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1919 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001920 return nullptr;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001921
Evan Cheng40791332011-04-19 00:04:03 +00001922 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1923 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1924
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001925 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001926 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001927 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001928 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001929
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001930 unsigned OpcodeIndex;
1931 switch (VT.getSimpleVT().SimpleTy) {
1932 default: llvm_unreachable("unhandled vst type");
1933 // Double-register operations:
1934 case MVT::v8i8: OpcodeIndex = 0; break;
1935 case MVT::v4i16: OpcodeIndex = 1; break;
1936 case MVT::v2f32:
1937 case MVT::v2i32: OpcodeIndex = 2; break;
1938 case MVT::v1i64: OpcodeIndex = 3; break;
1939 // Quad-register operations:
1940 case MVT::v16i8: OpcodeIndex = 0; break;
1941 case MVT::v8i16: OpcodeIndex = 1; break;
1942 case MVT::v4f32:
1943 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001944 case MVT::v2i64: OpcodeIndex = 3;
1945 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1946 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001947 }
1948
Bob Wilson06fce872011-02-07 17:43:21 +00001949 std::vector<EVT> ResTys;
1950 if (isUpdating)
1951 ResTys.push_back(MVT::i32);
1952 ResTys.push_back(MVT::Other);
1953
Evan Cheng3da64f762010-04-16 05:46:06 +00001954 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001955 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001956 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001957
Bob Wilson06fce872011-02-07 17:43:21 +00001958 // Double registers and VST1/VST2 quad registers are directly supported.
1959 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001960 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001961 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001962 SrcReg = N->getOperand(Vec0Idx);
1963 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001964 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001965 SDValue V0 = N->getOperand(Vec0Idx + 0);
1966 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001967 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001968 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001969 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001970 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001971 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001972 // an undef.
1973 SDValue V3 = (NumVecs == 3)
1974 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001975 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001976 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001977 }
Bob Wilson950882b2010-08-28 05:12:57 +00001978 } else {
1979 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001980 SDValue Q0 = N->getOperand(Vec0Idx);
1981 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001982 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001983 }
Bob Wilson06fce872011-02-07 17:43:21 +00001984
1985 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1986 QOpcodes0[OpcodeIndex]);
1987 Ops.push_back(MemAddr);
1988 Ops.push_back(Align);
1989 if (isUpdating) {
1990 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001991 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001992 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001993 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001994 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001995 // FIXME: We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001996 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001997 if (!isa<ConstantSDNode>(Inc.getNode()))
1998 Ops.push_back(Inc);
1999 else if (NumVecs > 2 && !isVSTfixed(Opc))
2000 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002001 }
2002 Ops.push_back(SrcReg);
2003 Ops.push_back(Pred);
2004 Ops.push_back(Reg0);
2005 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00002006 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002007
2008 // Transfer memoperands.
2009 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
2010
2011 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002012 }
2013
2014 // Otherwise, quad registers are stored with two separate instructions,
2015 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00002016
Bob Wilson01ac8f92010-06-16 21:34:01 +00002017 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00002018 SDValue V0 = N->getOperand(Vec0Idx + 0);
2019 SDValue V1 = N->getOperand(Vec0Idx + 1);
2020 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00002021 SDValue V3 = (NumVecs == 3)
2022 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00002023 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002024 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002025
Bob Wilson06fce872011-02-07 17:43:21 +00002026 // Store the even D registers. This is always an updating store, so that it
2027 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00002028 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
2029 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
2030 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00002031 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00002032 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002033 Chain = SDValue(VStA, 1);
2034
2035 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00002036 Ops.push_back(SDValue(VStA, 0));
2037 Ops.push_back(Align);
2038 if (isUpdating) {
2039 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2040 assert(isa<ConstantSDNode>(Inc.getNode()) &&
2041 "only constant post-increment update allowed for VST3/4");
2042 (void)Inc;
2043 Ops.push_back(Reg0);
2044 }
2045 Ops.push_back(RegSeq);
2046 Ops.push_back(Pred);
2047 Ops.push_back(Reg0);
2048 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00002049 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00002050 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002051 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
2052 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002053}
2054
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002055SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00002056 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00002057 const uint16_t *DOpcodes,
2058 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002059 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002060 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002061
Bob Wilsonae08a732010-03-20 22:13:40 +00002062 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002063 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2064 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2065 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002066 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002067
Evan Cheng40791332011-04-19 00:04:03 +00002068 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2069 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2070
Bob Wilson4145e3a2009-10-14 16:19:03 +00002071 SDValue Chain = N->getOperand(0);
2072 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002073 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2074 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002075 bool is64BitVector = VT.is64BitVector();
2076
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002077 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002078 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002079 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002080 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2081 if (Alignment > NumBytes)
2082 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002083 if (Alignment < 8 && Alignment < NumBytes)
2084 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002085 // Alignment must be a power of two; make sure of that.
2086 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002087 if (Alignment == 1)
2088 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002089 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002090 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002091
Bob Wilson4145e3a2009-10-14 16:19:03 +00002092 unsigned OpcodeIndex;
2093 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002094 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002095 // Double-register operations:
2096 case MVT::v8i8: OpcodeIndex = 0; break;
2097 case MVT::v4i16: OpcodeIndex = 1; break;
2098 case MVT::v2f32:
2099 case MVT::v2i32: OpcodeIndex = 2; break;
2100 // Quad-register operations:
2101 case MVT::v8i16: OpcodeIndex = 0; break;
2102 case MVT::v4f32:
2103 case MVT::v4i32: OpcodeIndex = 1; break;
2104 }
2105
Bob Wilson06fce872011-02-07 17:43:21 +00002106 std::vector<EVT> ResTys;
2107 if (IsLoad) {
2108 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2109 if (!is64BitVector)
2110 ResTyElts *= 2;
2111 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2112 MVT::i64, ResTyElts));
2113 }
2114 if (isUpdating)
2115 ResTys.push_back(MVT::i32);
2116 ResTys.push_back(MVT::Other);
2117
Evan Cheng3da64f762010-04-16 05:46:06 +00002118 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002119 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002120
Bob Wilson06fce872011-02-07 17:43:21 +00002121 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002122 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002123 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002124 if (isUpdating) {
2125 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2126 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2127 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002128
Bob Wilsond5c57a52010-09-13 23:01:35 +00002129 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002130 SDValue V0 = N->getOperand(Vec0Idx + 0);
2131 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002132 if (NumVecs == 2) {
2133 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002134 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002135 else
Weiming Zhao95782222012-11-17 00:23:35 +00002136 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002137 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002138 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002139 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002140 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2141 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002142 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002143 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002144 else
Weiming Zhao95782222012-11-17 00:23:35 +00002145 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002146 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002147 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002148 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002149 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002150 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002151 Ops.push_back(Chain);
2152
Bob Wilson06fce872011-02-07 17:43:21 +00002153 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2154 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002155 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002156 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002157 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002158 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002159
Bob Wilsond5c57a52010-09-13 23:01:35 +00002160 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002161 SuperReg = SDValue(VLdLn, 0);
2162 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2163 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2164 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002165 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2166 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002167 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2168 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2169 if (isUpdating)
2170 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002171 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002172}
2173
Bob Wilson06fce872011-02-07 17:43:21 +00002174SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002175 unsigned NumVecs,
2176 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002177 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002178 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002179
2180 SDValue MemAddr, Align;
2181 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002182 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002183
Evan Cheng40791332011-04-19 00:04:03 +00002184 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2185 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2186
Bob Wilson2d790df2010-11-28 06:51:26 +00002187 SDValue Chain = N->getOperand(0);
2188 EVT VT = N->getValueType(0);
2189
2190 unsigned Alignment = 0;
2191 if (NumVecs != 3) {
2192 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2193 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2194 if (Alignment > NumBytes)
2195 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002196 if (Alignment < 8 && Alignment < NumBytes)
2197 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002198 // Alignment must be a power of two; make sure of that.
2199 Alignment = (Alignment & -Alignment);
2200 if (Alignment == 1)
2201 Alignment = 0;
2202 }
2203 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2204
2205 unsigned OpcodeIndex;
2206 switch (VT.getSimpleVT().SimpleTy) {
2207 default: llvm_unreachable("unhandled vld-dup type");
2208 case MVT::v8i8: OpcodeIndex = 0; break;
2209 case MVT::v4i16: OpcodeIndex = 1; break;
2210 case MVT::v2f32:
2211 case MVT::v2i32: OpcodeIndex = 2; break;
2212 }
2213
2214 SDValue Pred = getAL(CurDAG);
2215 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2216 SDValue SuperReg;
2217 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002218 SmallVector<SDValue, 6> Ops;
2219 Ops.push_back(MemAddr);
2220 Ops.push_back(Align);
2221 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002222 // fixed-stride update instructions don't have an explicit writeback
2223 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002224 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002225 if (!isa<ConstantSDNode>(Inc.getNode()))
2226 Ops.push_back(Inc);
2227 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2228 else if (NumVecs > 2)
2229 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002230 }
2231 Ops.push_back(Pred);
2232 Ops.push_back(Reg0);
2233 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002234
2235 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002236 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002237 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002238 if (isUpdating)
2239 ResTys.push_back(MVT::i32);
2240 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002241 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002242 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002243 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002244
2245 // Extract the subregisters.
2246 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2247 unsigned SubIdx = ARM::dsub_0;
2248 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2249 ReplaceUses(SDValue(N, Vec),
2250 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002251 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2252 if (isUpdating)
2253 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002254 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002255}
2256
Bob Wilson5bc8a792010-07-07 00:08:54 +00002257SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2258 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002259 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002260 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002261 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002262 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002263
2264 // Form a REG_SEQUENCE to force register allocation.
2265 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002266 SDValue V0 = N->getOperand(FirstTblReg + 0);
2267 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002268 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002269 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002270 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002271 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002272 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002273 // an undef.
2274 SDValue V3 = (NumVecs == 3)
2275 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002276 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002277 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002278 }
2279
Bob Wilson5bc8a792010-07-07 00:08:54 +00002280 SmallVector<SDValue, 6> Ops;
2281 if (IsExt)
2282 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002283 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002284 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002285 Ops.push_back(getAL(CurDAG)); // predicate
2286 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002287 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002288}
2289
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002290SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002291 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002292 if (!Subtarget->hasV6T2Ops())
Craig Topper062a2ba2014-04-25 05:30:21 +00002293 return nullptr;
Bob Wilson93117bc2009-10-14 16:46:45 +00002294
Evan Chengeae6d2c2012-12-19 20:16:09 +00002295 unsigned Opc = isSigned
2296 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002297 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2298
Jim Grosbach825cb292010-04-22 23:24:18 +00002299 // For unsigned extracts, check for a shift right and mask
2300 unsigned And_imm = 0;
2301 if (N->getOpcode() == ISD::AND) {
2302 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2303
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002304 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002305 if (And_imm & (And_imm + 1))
Craig Topper062a2ba2014-04-25 05:30:21 +00002306 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002307
2308 unsigned Srl_imm = 0;
2309 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2310 Srl_imm)) {
2311 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2312
Jim Grosbach03f56d92011-07-27 21:09:25 +00002313 // Note: The width operand is encoded as width-1.
2314 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002315 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002316
Jim Grosbach825cb292010-04-22 23:24:18 +00002317 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002318
2319 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2320 // It's cheaper to use a right shift to extract the top bits.
2321 if (Subtarget->isThumb()) {
2322 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2323 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2324 CurDAG->getTargetConstant(LSB, MVT::i32),
2325 getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002326 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002327 }
2328
2329 // ARM models shift instructions as MOVsi with shifter operand.
2330 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2331 SDValue ShOpc =
2332 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2333 MVT::i32);
2334 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2335 getAL(CurDAG), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002336 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002337 }
2338
Jim Grosbach825cb292010-04-22 23:24:18 +00002339 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2340 CurDAG->getTargetConstant(LSB, MVT::i32),
2341 CurDAG->getTargetConstant(Width, MVT::i32),
Craig Topper481fb282014-04-27 19:21:11 +00002342 getAL(CurDAG), Reg0 };
2343 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Jim Grosbach825cb292010-04-22 23:24:18 +00002344 }
2345 }
Craig Topper062a2ba2014-04-25 05:30:21 +00002346 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002347 }
2348
2349 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002350 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002351 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002352 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2353 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002354 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002355 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002356 // Note: The width operand is encoded as width-1.
2357 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002358 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002359 if (LSB < 0)
Craig Topper062a2ba2014-04-25 05:30:21 +00002360 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002361 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002362 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002363 CurDAG->getTargetConstant(LSB, MVT::i32),
2364 CurDAG->getTargetConstant(Width, MVT::i32),
2365 getAL(CurDAG), Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002366 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002367 }
2368 }
Craig Topper062a2ba2014-04-25 05:30:21 +00002369 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002370}
2371
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002372/// Target-specific DAG combining for ISD::XOR.
2373/// Target-independent combining lowers SELECT_CC nodes of the form
2374/// select_cc setg[ge] X, 0, X, -X
2375/// select_cc setgt X, -1, X, -X
2376/// select_cc setl[te] X, 0, -X, X
2377/// select_cc setlt X, 1, -X, X
2378/// which represent Integer ABS into:
2379/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2380/// ARM instruction selection detects the latter and matches it to
2381/// ARM::ABS or ARM::t2ABS machine node.
2382SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2383 SDValue XORSrc0 = N->getOperand(0);
2384 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002385 EVT VT = N->getValueType(0);
2386
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002387 if (Subtarget->isThumb1Only())
Craig Topper062a2ba2014-04-25 05:30:21 +00002388 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002389
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002390 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Craig Topper062a2ba2014-04-25 05:30:21 +00002391 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002392
2393 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2394 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2395 SDValue SRASrc0 = XORSrc1.getOperand(0);
2396 SDValue SRASrc1 = XORSrc1.getOperand(1);
2397 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2398 EVT XType = SRASrc0.getValueType();
2399 unsigned Size = XType.getSizeInBits() - 1;
2400
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002401 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
Craig Topper062a2ba2014-04-25 05:30:21 +00002402 XType.isInteger() && SRAConstant != nullptr &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002403 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002404 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002405 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2406 }
2407
Craig Topper062a2ba2014-04-25 05:30:21 +00002408 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002409}
2410
Evan Chengd85631e2010-05-05 18:28:36 +00002411SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2412 // The only time a CONCAT_VECTORS operation can have legal types is when
2413 // two 64-bit vectors are concatenated to a 128-bit vector.
2414 EVT VT = N->getValueType(0);
2415 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2416 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002417 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002418}
2419
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002420SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002421 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002422
Tim Northover31d093c2013-09-22 08:21:56 +00002423 if (N->isMachineOpcode()) {
2424 N->setNodeId(-1);
Craig Topper062a2ba2014-04-25 05:30:21 +00002425 return nullptr; // Already selected.
Tim Northover31d093c2013-09-22 08:21:56 +00002426 }
Rafael Espindola4e760152006-06-12 12:28:08 +00002427
2428 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002429 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002430 case ISD::INLINEASM: {
2431 SDNode *ResNode = SelectInlineAsm(N);
2432 if (ResNode)
2433 return ResNode;
2434 break;
2435 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002436 case ISD::XOR: {
2437 // Select special operations if XOR node forms integer ABS pattern
2438 SDNode *ResNode = SelectABSOp(N);
2439 if (ResNode)
2440 return ResNode;
2441 // Other cases are autogenerated.
2442 break;
2443 }
Evan Cheng10043e22007-01-19 07:51:42 +00002444 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002445 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002446 bool UseCP = true;
Tim Northover55c625f2014-01-23 13:43:47 +00002447 if (Subtarget->useMovt())
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002448 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2449 // be done with MOV + MOVT, at worst.
Tim Northover55c625f2014-01-23 13:43:47 +00002450 UseCP = false;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002451 else {
2452 if (Subtarget->isThumb()) {
Tim Northover55c625f2014-01-23 13:43:47 +00002453 UseCP = (Val > 255 && // MOV
2454 ~Val > 255 && // MOV + MVN
2455 !ARM_AM::isThumbImmShiftedVal(Val) && // MOV + LSL
2456 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002457 } else
Tim Northover55c625f2014-01-23 13:43:47 +00002458 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2459 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2460 !ARM_AM::isSOImmTwoPartVal(Val) && // two instrs.
2461 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002462 }
2463
Evan Cheng10043e22007-01-19 07:51:42 +00002464 if (UseCP) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002465 SDValue CPIdx =
Owen Anderson55f1c092009-08-13 21:58:54 +00002466 CurDAG->getTargetConstantPool(ConstantInt::get(
2467 Type::getInt32Ty(*CurDAG->getContext()), Val),
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002468 getTargetLowering()->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();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002498 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
2499 getTargetLowering()->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002500 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002501 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2502 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Craig Topper481fb282014-04-27 19:21:11 +00002503 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops);
Jim Grosbachfde21102009-04-07 20:34:09 +00002504 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002505 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2506 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002507 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2508 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2509 CurDAG->getRegister(0, MVT::i32) };
Craig Topper481fb282014-04-27 19:21:11 +00002510 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Cheng7e90b112007-07-05 07:15:27 +00002511 }
Evan Cheng10043e22007-01-19 07:51:42 +00002512 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002513 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002514 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002515 return I;
2516 break;
2517 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}