blob: 4405625e47cd5b62a17cb4a3698a3e33326a392e [file] [log] [blame]
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARM.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000015#include "ARMBaseInstrInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000016#include "ARMTargetMachine.h"
Evan Chenga20cde32011-07-20 23:34:39 +000017#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000018#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineInstrBuilder.h"
Weiming Zhaoc5987002013-02-14 18:10:21 +000021#include "llvm/CodeGen/MachineRegisterInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000022#include "llvm/CodeGen/SelectionDAG.h"
23#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/CallingConv.h"
25#include "llvm/IR/Constants.h"
26#include "llvm/IR/DerivedTypes.h"
27#include "llvm/IR/Function.h"
28#include "llvm/IR/Intrinsics.h"
29#include "llvm/IR/LLVMContext.h"
Evan Cheng8e6b40a2010-05-04 20:39:49 +000030#include "llvm/Support/CommandLine.h"
Chris Lattner1770fb82008-02-03 05:43:57 +000031#include "llvm/Support/Compiler.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000032#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000033#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/Target/TargetLowering.h"
35#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000036
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000037using namespace llvm;
38
Chandler Carruth84e68b22014-04-22 02:41:26 +000039#define DEBUG_TYPE "arm-isel"
40
Evan Cheng59069ec2010-07-30 23:33:54 +000041static cl::opt<bool>
42DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
44 cl::init(false));
45
Evan Cheng62c7b5b2010-12-05 22:04:16 +000046static cl::opt<bool>
47CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000049 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000050
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000051//===--------------------------------------------------------------------===//
52/// ARMDAGToDAGISel - ARM specific code to select ARM machine
53/// instructions for SelectionDAG operations.
54///
55namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000056
57enum AddrMode2Type {
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
60};
61
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000062class ARMDAGToDAGISel : public SelectionDAGISel {
Evan Cheng10043e22007-01-19 07:51:42 +000063 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
64 /// make the right decision when generating code for different targets.
65 const ARMSubtarget *Subtarget;
66
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000067public:
Eric Christopher2f991c92014-07-03 22:24:49 +000068 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm, CodeGenOpt::Level OptLevel)
69 : SelectionDAGISel(tm, OptLevel) {}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000070
Eric Christopher0e6e7cf2014-05-22 02:00:27 +000071 bool runOnMachineFunction(MachineFunction &MF) override {
72 // Reset the subtarget each time through.
Eric Christopher22b2ad22015-02-20 08:24:37 +000073 Subtarget = &MF.getSubtarget<ARMSubtarget>();
Eric Christopher0e6e7cf2014-05-22 02:00:27 +000074 SelectionDAGISel::runOnMachineFunction(MF);
75 return true;
76 }
77
Craig Topper6bc27bf2014-03-10 02:09:33 +000078 const char *getPassName() const override {
Evan Cheng10043e22007-01-19 07:51:42 +000079 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000080 }
81
Craig Topper6bc27bf2014-03-10 02:09:33 +000082 void PreprocessISelDAG() override;
Evan Chengeae6d2c2012-12-19 20:16:09 +000083
Bob Wilson4facd962009-10-08 18:51:31 +000084 /// getI32Imm - Return a target constant of type i32 with the specified
85 /// value.
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000086 inline SDValue getI32Imm(unsigned Imm, SDLoc dl) {
87 return CurDAG->getTargetConstant(Imm, dl, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000088 }
89
Craig Topper6bc27bf2014-03-10 02:09:33 +000090 SDNode *Select(SDNode *N) override;
Evan Cheng5e73ff22010-02-15 19:41:07 +000091
Evan Cheng62c7b5b2010-12-05 22:04:16 +000092
93 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000094 bool isShifterOpProfitable(const SDValue &Shift,
95 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000096 bool SelectRegShifterOperand(SDValue N, SDValue &A,
97 SDValue &B, SDValue &C,
98 bool CheckProfitability = true);
99 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +0000100 SDValue &B, bool CheckProfitability = true);
101 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000102 SDValue &B, SDValue &C) {
103 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000104 return SelectRegShifterOperand(N, A, B, C, false);
105 }
106 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
107 SDValue &B) {
108 // Don't apply the profitability check
109 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000110 }
111
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000112 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
113 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
114
Jim Grosbach08605202010-09-29 19:03:54 +0000115 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
116 SDValue &Offset, SDValue &Opc);
117 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
118 SDValue &Opc) {
119 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
120 }
121
122 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
123 SDValue &Opc) {
124 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
125 }
126
127 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
128 SDValue &Opc) {
129 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000130// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000131 // This always matches one way or another.
132 return true;
133 }
134
Tim Northover42180442013-08-22 09:57:11 +0000135 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
136 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000137 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(N), MVT::i32);
Tim Northover42180442013-08-22 09:57:11 +0000138 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
139 return true;
140 }
141
Owen Anderson2aedba62011-07-26 20:54:26 +0000142 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
143 SDValue &Offset, SDValue &Opc);
144 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000145 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000146 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
147 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000148 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000149 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000150 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000151 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000152 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000153 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000154 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000155 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000156 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000157
Evan Chengdfce83c2011-01-17 08:03:18 +0000158 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000159
Bill Wendling092a7bd2010-12-14 03:36:38 +0000160 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000161 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000162 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
163 unsigned Scale);
164 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
165 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
166 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
167 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
168 SDValue &OffImm);
169 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
170 SDValue &OffImm);
171 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
172 SDValue &OffImm);
173 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
174 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000175 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000176
Bill Wendling092a7bd2010-12-14 03:36:38 +0000177 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000178 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000179 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000180 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
181 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000182 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000183 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000184 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000185 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000186 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000187 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000188
Evan Cheng0fc80842010-11-12 22:42:47 +0000189 inline bool is_so_imm(unsigned Imm) const {
190 return ARM_AM::getSOImmVal(Imm) != -1;
191 }
192
193 inline bool is_so_imm_not(unsigned Imm) const {
194 return ARM_AM::getSOImmVal(~Imm) != -1;
195 }
196
197 inline bool is_t2_so_imm(unsigned Imm) const {
198 return ARM_AM::getT2SOImmVal(Imm) != -1;
199 }
200
201 inline bool is_t2_so_imm_not(unsigned Imm) const {
202 return ARM_AM::getT2SOImmVal(~Imm) != -1;
203 }
204
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000205 // Include the pieces autogenerated from the target description.
206#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000207
208private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000209 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
210 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000211 SDNode *SelectARMIndexedLoad(SDNode *N);
212 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000213
Bob Wilson340861d2010-03-23 05:25:43 +0000214 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
215 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000216 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000217 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000218 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000219 const uint16_t *DOpcodes,
220 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000221
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000222 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000223 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000224 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000225 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000226 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000227 const uint16_t *DOpcodes,
228 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000229
Bob Wilson93117bc2009-10-14 16:46:45 +0000230 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000231 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000232 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000233 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
234 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000235 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000236
Bob Wilson2d790df2010-11-28 06:51:26 +0000237 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
238 /// should be 2, 3 or 4. The opcode array specifies the instructions used
239 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000240 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000241 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000242
Bob Wilson5bc8a792010-07-07 00:08:54 +0000243 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
244 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
245 /// generated to force the table registers to be consecutive.
246 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000247
Sandeep Patel7460e082009-10-13 20:25:58 +0000248 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000249 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000250
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000251 // Select special operations if node forms integer ABS pattern
252 SDNode *SelectABSOp(SDNode *N);
253
Weiming Zhaoc5987002013-02-14 18:10:21 +0000254 SDNode *SelectInlineAsm(SDNode *N);
255
Evan Chengd85631e2010-05-05 18:28:36 +0000256 SDNode *SelectConcatVector(SDNode *N);
257
Evan Chengd9c55362009-07-02 01:23:32 +0000258 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
259 /// inline asm expressions.
Daniel Sanders60f1db02015-03-13 12:45:09 +0000260 bool SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
Craig Topper6bc27bf2014-03-10 02:09:33 +0000261 std::vector<SDValue> &OutOps) override;
Bob Wilsone6b778d2009-10-06 22:01:59 +0000262
Weiming Zhao95782222012-11-17 00:23:35 +0000263 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000264 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000265 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
266 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
267 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000268
Bob Wilsond8a9a042010-06-04 00:04:02 +0000269 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000270 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
271 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
272 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000273
274 // Get the alignment operand for a NEON VLD or VST instruction.
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000275 SDValue GetVLDSTAlign(SDValue Align, SDLoc dl, unsigned NumVecs,
276 bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000277};
Evan Cheng10043e22007-01-19 07:51:42 +0000278}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000279
Sandeep Patel423e42b2009-10-13 18:59:48 +0000280/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
281/// operand. If so Imm will receive the 32-bit value.
282static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
283 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
284 Imm = cast<ConstantSDNode>(N)->getZExtValue();
285 return true;
286 }
287 return false;
288}
289
290// isInt32Immediate - This method tests to see if a constant operand.
291// If so Imm will receive the 32 bit value.
292static bool isInt32Immediate(SDValue N, unsigned &Imm) {
293 return isInt32Immediate(N.getNode(), Imm);
294}
295
296// isOpcWithIntImmediate - This method tests to see if the node is a specific
297// opcode and that it has a immediate integer right operand.
298// If so Imm will receive the 32 bit value.
299static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
300 return N->getOpcode() == Opc &&
301 isInt32Immediate(N->getOperand(1).getNode(), Imm);
302}
303
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000304/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000305/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000306///
307/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000308static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000311 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000312
313 // Check that this is a constant.
314 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
315 if (!C)
316 return false;
317
318 ScaledConstant = (int) C->getZExtValue();
319 if ((ScaledConstant % Scale) != 0)
320 return false;
321
322 ScaledConstant /= Scale;
323 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
324}
325
Evan Chengeae6d2c2012-12-19 20:16:09 +0000326void ARMDAGToDAGISel::PreprocessISelDAG() {
327 if (!Subtarget->hasV6T2Ops())
328 return;
329
330 bool isThumb2 = Subtarget->isThumb();
331 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
332 E = CurDAG->allnodes_end(); I != E; ) {
333 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
334
335 if (N->getOpcode() != ISD::ADD)
336 continue;
337
338 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
339 // leading zeros, followed by consecutive set bits, followed by 1 or 2
340 // trailing zeros, e.g. 1020.
341 // Transform the expression to
342 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
343 // of trailing zeros of c2. The left shift would be folded as an shifter
344 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
345 // node (UBFX).
346
347 SDValue N0 = N->getOperand(0);
348 SDValue N1 = N->getOperand(1);
349 unsigned And_imm = 0;
350 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
351 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
352 std::swap(N0, N1);
353 }
354 if (!And_imm)
355 continue;
356
357 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000358 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000359 if (TZ != 1 && TZ != 2)
360 // Be conservative here. Shifter operands aren't always free. e.g. On
361 // Swift, left shifter operand of 1 / 2 for free but others are not.
362 // e.g.
363 // ubfx r3, r1, #16, #8
364 // ldr.w r3, [r0, r3, lsl #2]
365 // vs.
366 // mov.w r9, #1020
367 // and.w r2, r9, r1, lsr #14
368 // ldr r2, [r0, r2]
369 continue;
370 And_imm >>= TZ;
371 if (And_imm & (And_imm + 1))
372 continue;
373
374 // Look for (and (srl X, c1), c2).
375 SDValue Srl = N1.getOperand(0);
376 unsigned Srl_imm = 0;
377 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
378 (Srl_imm <= 2))
379 continue;
380
381 // Make sure first operand is not a shifter operand which would prevent
382 // folding of the left shift.
383 SDValue CPTmp0;
384 SDValue CPTmp1;
385 SDValue CPTmp2;
386 if (isThumb2) {
387 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
388 continue;
389 } else {
390 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
391 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
392 continue;
393 }
394
395 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000396 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000397 Srl.getOperand(0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000398 CurDAG->getConstant(Srl_imm + TZ, SDLoc(Srl),
399 MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000400 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000401 Srl,
402 CurDAG->getConstant(And_imm, SDLoc(Srl), MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000403 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000404 N1, CurDAG->getConstant(TZ, SDLoc(Srl), MVT::i32));
Evan Chengeae6d2c2012-12-19 20:16:09 +0000405 CurDAG->UpdateNodeOperands(N, N0, N1);
Jim Grosbach1a597112014-04-03 23:43:18 +0000406 }
Evan Chengeae6d2c2012-12-19 20:16:09 +0000407}
408
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000409/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
410/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
411/// least on current ARM implementations) which should be avoidded.
412bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
413 if (OptLevel == CodeGenOpt::None)
414 return true;
415
416 if (!CheckVMLxHazard)
417 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000418
Tim Northover0feb91e2014-04-01 14:10:07 +0000419 if (!Subtarget->isCortexA7() && !Subtarget->isCortexA8() &&
420 !Subtarget->isCortexA9() && !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000421 return true;
422
423 if (!N->hasOneUse())
424 return false;
425
426 SDNode *Use = *N->use_begin();
427 if (Use->getOpcode() == ISD::CopyToReg)
428 return true;
429 if (Use->isMachineOpcode()) {
Eric Christopher2f991c92014-07-03 22:24:49 +0000430 const ARMBaseInstrInfo *TII = static_cast<const ARMBaseInstrInfo *>(
Eric Christopherfc6de422014-08-05 02:39:49 +0000431 CurDAG->getSubtarget().getInstrInfo());
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000432
Evan Cheng6cc775f2011-06-28 19:10:37 +0000433 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
434 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000435 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000436 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000437 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
438 return true;
439 // vmlx feeding into another vmlx. We actually want to unfold
440 // the use later in the MLxExpansion pass. e.g.
441 // vmla
442 // vmla (stall 8 cycles)
443 //
444 // vmul (5 cycles)
445 // vadd (5 cycles)
446 // vmla
447 // This adds up to about 18 - 19 cycles.
448 //
449 // vmla
450 // vmul (stall 4 cycles)
451 // vadd adds up to about 14 cycles.
452 return TII->isFpMLxInstruction(Opcode);
453 }
454
455 return false;
456}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000457
Evan Cheng59bbc542010-10-27 23:41:30 +0000458bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
459 ARM_AM::ShiftOpc ShOpcVal,
460 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000461 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000462 return true;
463 if (Shift.hasOneUse())
464 return true;
465 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000466 return ShOpcVal == ARM_AM::lsl &&
467 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000468}
469
Owen Andersonb595ed02011-07-21 18:54:16 +0000470bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000471 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000472 SDValue &Opc,
473 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000474 if (DisableShifterOp)
475 return false;
476
Evan Chenga20cde32011-07-20 23:34:39 +0000477 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000478
479 // Don't match base register only case. That is matched to a separate
480 // lower complexity pattern with explicit register operand.
481 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000482
Evan Chengb23b50d2009-06-29 07:51:04 +0000483 BaseReg = N.getOperand(0);
484 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000485 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
486 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000487 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000488 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000489 SDLoc(N), MVT::i32);
Evan Cheng59bbc542010-10-27 23:41:30 +0000490 return true;
491}
492
Owen Andersonb595ed02011-07-21 18:54:16 +0000493bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
494 SDValue &BaseReg,
495 SDValue &ShReg,
496 SDValue &Opc,
497 bool CheckProfitability) {
498 if (DisableShifterOp)
499 return false;
500
501 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
502
503 // Don't match base register only case. That is matched to a separate
504 // lower complexity pattern with explicit register operand.
505 if (ShOpcVal == ARM_AM::no_shift) return false;
506
507 BaseReg = N.getOperand(0);
508 unsigned ShImmVal = 0;
509 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
510 if (RHS) return false;
511
512 ShReg = N.getOperand(1);
513 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
514 return false;
515 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000516 SDLoc(N), MVT::i32);
Owen Andersonb595ed02011-07-21 18:54:16 +0000517 return true;
518}
519
520
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000521bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
522 SDValue &Base,
523 SDValue &OffImm) {
524 // Match simple R + imm12 operands.
525
526 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000527 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
528 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000529 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000530 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000531 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000532 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000533 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000534 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000535 }
Owen Anderson6d557452011-03-18 19:46:58 +0000536
Chris Lattner46c01a32011-02-13 22:25:43 +0000537 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000538 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000539 Base = N.getOperand(0);
540 } else
541 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000542 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000543 return true;
544 }
545
546 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Renato Golin63e27982014-09-09 09:57:59 +0000547 int RHSC = (int)RHS->getSExtValue();
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000548 if (N.getOpcode() == ISD::SUB)
549 RHSC = -RHSC;
550
Renato Golin63e27982014-09-09 09:57:59 +0000551 if (RHSC > -0x1000 && RHSC < 0x1000) { // 12 bits
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000552 Base = N.getOperand(0);
553 if (Base.getOpcode() == ISD::FrameIndex) {
554 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000555 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000556 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000557 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000558 return true;
559 }
560 }
561
562 // Base only.
563 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000564 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000565 return true;
566}
567
568
569
570bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
571 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000572 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000573 ((!Subtarget->isLikeA9() && !Subtarget->isSwift()) || N.hasOneUse())) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000574 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
575 // X * [3,5,9] -> X + X * [2,4,8] etc.
576 int RHSC = (int)RHS->getZExtValue();
577 if (RHSC & 1) {
578 RHSC = RHSC & ~1;
579 ARM_AM::AddrOpc AddSub = ARM_AM::add;
580 if (RHSC < 0) {
581 AddSub = ARM_AM::sub;
582 RHSC = - RHSC;
583 }
584 if (isPowerOf2_32(RHSC)) {
585 unsigned ShAmt = Log2_32(RHSC);
586 Base = Offset = N.getOperand(0);
587 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
588 ARM_AM::lsl),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000589 SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000590 return true;
591 }
592 }
593 }
594 }
595
Chris Lattner46c01a32011-02-13 22:25:43 +0000596 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
597 // ISD::OR that is equivalent to an ISD::ADD.
598 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000599 return false;
600
601 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner46c01a32011-02-13 22:25:43 +0000602 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000603 int RHSC;
604 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
605 -0x1000+1, 0x1000, RHSC)) // 12 bits.
606 return false;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000607 }
608
609 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000610 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chenga20cde32011-07-20 23:34:39 +0000611 ARM_AM::ShiftOpc ShOpcVal =
612 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000613 unsigned ShAmt = 0;
614
615 Base = N.getOperand(0);
616 Offset = N.getOperand(1);
617
618 if (ShOpcVal != ARM_AM::no_shift) {
619 // Check to see if the RHS of the shift is a constant, if not, we can't fold
620 // it.
621 if (ConstantSDNode *Sh =
622 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
623 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000624 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
625 Offset = N.getOperand(1).getOperand(0);
626 else {
627 ShAmt = 0;
628 ShOpcVal = ARM_AM::no_shift;
629 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000630 } else {
631 ShOpcVal = ARM_AM::no_shift;
632 }
633 }
634
635 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000636 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000637 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
638 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000639 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000640 if (ShOpcVal != ARM_AM::no_shift) {
641 // Check to see if the RHS of the shift is a constant, if not, we can't
642 // fold it.
643 if (ConstantSDNode *Sh =
644 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
645 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000646 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000647 Offset = N.getOperand(0).getOperand(0);
648 Base = N.getOperand(1);
649 } else {
650 ShAmt = 0;
651 ShOpcVal = ARM_AM::no_shift;
652 }
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000653 } else {
654 ShOpcVal = ARM_AM::no_shift;
655 }
656 }
657 }
658
659 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000660 SDLoc(N), MVT::i32);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000661 return true;
662}
663
664
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000665//-----
666
Jim Grosbach08605202010-09-29 19:03:54 +0000667AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
668 SDValue &Base,
669 SDValue &Offset,
670 SDValue &Opc) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000671 if (N.getOpcode() == ISD::MUL &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000672 (!(Subtarget->isLikeA9() || Subtarget->isSwift()) || N.hasOneUse())) {
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000673 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
674 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmaneffb8942008-09-12 16:56:44 +0000675 int RHSC = (int)RHS->getZExtValue();
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000676 if (RHSC & 1) {
677 RHSC = RHSC & ~1;
678 ARM_AM::AddrOpc AddSub = ARM_AM::add;
679 if (RHSC < 0) {
680 AddSub = ARM_AM::sub;
681 RHSC = - RHSC;
682 }
683 if (isPowerOf2_32(RHSC)) {
684 unsigned ShAmt = Log2_32(RHSC);
685 Base = Offset = N.getOperand(0);
686 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
687 ARM_AM::lsl),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000688 SDLoc(N), MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000689 return AM2_SHOP;
Evan Cheng72a8bcf2007-03-13 21:05:54 +0000690 }
691 }
692 }
693 }
694
Chris Lattner46c01a32011-02-13 22:25:43 +0000695 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
696 // ISD::OR that is equivalent to an ADD.
697 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000698 Base = N;
699 if (N.getOpcode() == ISD::FrameIndex) {
700 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000701 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000702 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000703 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000704 Base = N.getOperand(0);
705 }
Owen Anderson9f944592009-08-11 20:47:22 +0000706 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000707 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
708 ARM_AM::no_shift),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000709 SDLoc(N), MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000710 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000711 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000712
Evan Cheng10043e22007-01-19 07:51:42 +0000713 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000714 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000715 int RHSC;
716 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
717 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
718 Base = N.getOperand(0);
719 if (Base.getOpcode() == ISD::FrameIndex) {
720 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000721 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000722 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000723 Offset = CurDAG->getRegister(0, MVT::i32);
724
725 ARM_AM::AddrOpc AddSub = ARM_AM::add;
726 if (RHSC < 0) {
727 AddSub = ARM_AM::sub;
728 RHSC = - RHSC;
729 }
730 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
731 ARM_AM::no_shift),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000732 SDLoc(N), MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000733 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000734 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000735 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000736
Bob Wilsone8a549c2012-09-29 21:43:49 +0000737 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000738 // Compute R +/- (R << N) and reuse it.
739 Base = N;
740 Offset = CurDAG->getRegister(0, MVT::i32);
741 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
742 ARM_AM::no_shift),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000743 SDLoc(N), MVT::i32);
Evan Cheng59bbc542010-10-27 23:41:30 +0000744 return AM2_BASE;
745 }
746
Johnny Chenb678a562009-10-27 17:25:15 +0000747 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000748 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000749 ARM_AM::ShiftOpc ShOpcVal =
750 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000751 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000752
Evan Cheng10043e22007-01-19 07:51:42 +0000753 Base = N.getOperand(0);
754 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000755
Evan Cheng10043e22007-01-19 07:51:42 +0000756 if (ShOpcVal != ARM_AM::no_shift) {
757 // Check to see if the RHS of the shift is a constant, if not, we can't fold
758 // it.
759 if (ConstantSDNode *Sh =
760 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000761 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000762 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
763 Offset = N.getOperand(1).getOperand(0);
764 else {
765 ShAmt = 0;
766 ShOpcVal = ARM_AM::no_shift;
767 }
Evan Cheng10043e22007-01-19 07:51:42 +0000768 } else {
769 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000770 }
771 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000772
Evan Cheng10043e22007-01-19 07:51:42 +0000773 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000774 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000775 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
776 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000777 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000778 if (ShOpcVal != ARM_AM::no_shift) {
779 // Check to see if the RHS of the shift is a constant, if not, we can't
780 // fold it.
781 if (ConstantSDNode *Sh =
782 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000783 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000784 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000785 Offset = N.getOperand(0).getOperand(0);
786 Base = N.getOperand(1);
787 } else {
788 ShAmt = 0;
789 ShOpcVal = ARM_AM::no_shift;
790 }
Evan Cheng10043e22007-01-19 07:51:42 +0000791 } else {
792 ShOpcVal = ARM_AM::no_shift;
793 }
794 }
795 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000796
Evan Cheng10043e22007-01-19 07:51:42 +0000797 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000798 SDLoc(N), MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000799 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000800}
801
Owen Anderson2aedba62011-07-26 20:54:26 +0000802bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000803 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000804 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000805 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
806 ? cast<LoadSDNode>(Op)->getAddressingMode()
807 : cast<StoreSDNode>(Op)->getAddressingMode();
808 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
809 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000810 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000811 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
812 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000813
814 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000815 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000816 unsigned ShAmt = 0;
817 if (ShOpcVal != ARM_AM::no_shift) {
818 // Check to see if the RHS of the shift is a constant, if not, we can't fold
819 // it.
820 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000821 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000822 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
823 Offset = N.getOperand(0);
824 else {
825 ShAmt = 0;
826 ShOpcVal = ARM_AM::no_shift;
827 }
Evan Cheng10043e22007-01-19 07:51:42 +0000828 } else {
829 ShOpcVal = ARM_AM::no_shift;
830 }
831 }
832
833 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000834 SDLoc(N), MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000835 return true;
836}
837
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000838bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
839 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000840 unsigned Opcode = Op->getOpcode();
841 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
842 ? cast<LoadSDNode>(Op)->getAddressingMode()
843 : cast<StoreSDNode>(Op)->getAddressingMode();
844 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
845 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000846 int Val;
847 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000848 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000849 Offset = CurDAG->getRegister(0, MVT::i32);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000850 Opc = CurDAG->getTargetConstant(Val, SDLoc(Op), MVT::i32);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000851 return true;
852 }
853
854 return false;
855}
856
857
Owen Anderson2aedba62011-07-26 20:54:26 +0000858bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
859 SDValue &Offset, SDValue &Opc) {
860 unsigned Opcode = Op->getOpcode();
861 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
862 ? cast<LoadSDNode>(Op)->getAddressingMode()
863 : cast<StoreSDNode>(Op)->getAddressingMode();
864 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
865 ? ARM_AM::add : ARM_AM::sub;
866 int Val;
867 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
868 Offset = CurDAG->getRegister(0, MVT::i32);
869 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
870 ARM_AM::no_shift),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000871 SDLoc(Op), MVT::i32);
Owen Anderson2aedba62011-07-26 20:54:26 +0000872 return true;
873 }
874
875 return false;
876}
877
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000878bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
879 Base = N;
880 return true;
881}
Evan Cheng10043e22007-01-19 07:51:42 +0000882
Chris Lattner0e023ea2010-09-21 20:31:19 +0000883bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000884 SDValue &Base, SDValue &Offset,
885 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000886 if (N.getOpcode() == ISD::SUB) {
887 // X - C is canonicalize to X + -C, no need to handle it here.
888 Base = N.getOperand(0);
889 Offset = N.getOperand(1);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000890 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0), SDLoc(N),
891 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000892 return true;
893 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000894
Chris Lattner46c01a32011-02-13 22:25:43 +0000895 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000896 Base = N;
897 if (N.getOpcode() == ISD::FrameIndex) {
898 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000899 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000900 }
Owen Anderson9f944592009-08-11 20:47:22 +0000901 Offset = CurDAG->getRegister(0, MVT::i32);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000902 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), SDLoc(N),
903 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000904 return true;
905 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000906
Evan Cheng10043e22007-01-19 07:51:42 +0000907 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000908 int RHSC;
909 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
910 -256 + 1, 256, RHSC)) { // 8 bits.
911 Base = N.getOperand(0);
912 if (Base.getOpcode() == ISD::FrameIndex) {
913 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000914 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000915 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000916 Offset = CurDAG->getRegister(0, MVT::i32);
917
918 ARM_AM::AddrOpc AddSub = ARM_AM::add;
919 if (RHSC < 0) {
920 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000921 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000922 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000923 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC), SDLoc(N),
924 MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000925 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000926 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000927
Evan Cheng10043e22007-01-19 07:51:42 +0000928 Base = N.getOperand(0);
929 Offset = N.getOperand(1);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000930 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), SDLoc(N),
931 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000932 return true;
933}
934
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000935bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000936 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000937 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000938 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
939 ? cast<LoadSDNode>(Op)->getAddressingMode()
940 : cast<StoreSDNode>(Op)->getAddressingMode();
941 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
942 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000943 int Val;
944 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
945 Offset = CurDAG->getRegister(0, MVT::i32);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000946 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), SDLoc(Op),
947 MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000948 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000949 }
950
951 Offset = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000952 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), SDLoc(Op),
953 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000954 return true;
955}
956
Jim Grosbachd37f0712010-10-21 19:38:40 +0000957bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000958 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000959 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000960 Base = N;
961 if (N.getOpcode() == ISD::FrameIndex) {
962 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000963 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000964 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000965 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000966 Base = N.getOperand(0);
967 }
968 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000969 SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000970 return true;
971 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000972
Evan Cheng10043e22007-01-19 07:51:42 +0000973 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000974 int RHSC;
975 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
976 -256 + 1, 256, RHSC)) {
977 Base = N.getOperand(0);
978 if (Base.getOpcode() == ISD::FrameIndex) {
979 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +0000980 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000981 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000982
983 ARM_AM::AddrOpc AddSub = ARM_AM::add;
984 if (RHSC < 0) {
985 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000986 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000987 }
988 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000989 SDLoc(N), MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000990 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000991 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000992
Evan Cheng10043e22007-01-19 07:51:42 +0000993 Base = N;
994 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +0000995 SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000996 return true;
997}
998
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000999bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
1000 SDValue &Align) {
Bob Wilsondeb35af2009-07-01 23:16:05 +00001001 Addr = N;
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001002
1003 unsigned Alignment = 0;
Ahmed Bougachadb141ac2015-02-19 23:52:41 +00001004
1005 MemSDNode *MemN = cast<MemSDNode>(Parent);
1006
1007 if (isa<LSBaseSDNode>(MemN) ||
1008 ((MemN->getOpcode() == ARMISD::VST1_UPD ||
1009 MemN->getOpcode() == ARMISD::VLD1_UPD) &&
1010 MemN->getConstantOperandVal(MemN->getNumOperands() - 1) == 1)) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001011 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1012 // The maximum alignment is equal to the memory size being referenced.
Ahmed Bougachadb141ac2015-02-19 23:52:41 +00001013 unsigned MMOAlign = MemN->getAlignment();
1014 unsigned MemSize = MemN->getMemoryVT().getSizeInBits() / 8;
1015 if (MMOAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001016 Alignment = MemSize;
1017 } else {
1018 // All other uses of addrmode6 are for intrinsics. For now just record
1019 // the raw alignment value; it will be refined later based on the legal
1020 // alignment operands for the intrinsic.
Ahmed Bougachadb141ac2015-02-19 23:52:41 +00001021 Alignment = MemN->getAlignment();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001022 }
1023
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001024 Align = CurDAG->getTargetConstant(Alignment, SDLoc(N), MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001025 return true;
1026}
1027
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001028bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1029 SDValue &Offset) {
1030 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1031 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1032 if (AM != ISD::POST_INC)
1033 return false;
1034 Offset = N;
1035 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1036 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1037 Offset = CurDAG->getRegister(0, MVT::i32);
1038 }
1039 return true;
1040}
1041
Chris Lattner0e023ea2010-09-21 20:31:19 +00001042bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001043 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001044 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1045 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001046 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001047 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001048 SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001049 return true;
1050 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001051
Evan Cheng10043e22007-01-19 07:51:42 +00001052 return false;
1053}
1054
Bill Wendling092a7bd2010-12-14 03:36:38 +00001055
1056//===----------------------------------------------------------------------===//
1057// Thumb Addressing Modes
1058//===----------------------------------------------------------------------===//
1059
Chris Lattner0e023ea2010-09-21 20:31:19 +00001060bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001061 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001062 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001063 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001064 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001065 return false;
1066
1067 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001068 return true;
1069 }
1070
Evan Cheng10043e22007-01-19 07:51:42 +00001071 Base = N.getOperand(0);
1072 Offset = N.getOperand(1);
1073 return true;
1074}
1075
Evan Cheng139edae2007-01-24 02:21:22 +00001076bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001077ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1078 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001079 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001080 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001081 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001082 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001083
Evan Cheng1526ba52007-01-24 08:53:17 +00001084 if (N.getOpcode() == ARMISD::Wrapper &&
1085 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1086 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001087 }
1088
Chris Lattner46c01a32011-02-13 22:25:43 +00001089 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001090 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001091
Evan Cheng650d0672007-02-06 00:22:06 +00001092 // Thumb does not have [sp, r] address mode.
1093 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1094 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1095 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001096 (RHSR && RHSR->getReg() == ARM::SP))
1097 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001098
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001099 // FIXME: Why do we explicitly check for a match here and then return false?
1100 // Presumably to allow something else to match, but shouldn't this be
1101 // documented?
1102 int RHSC;
1103 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1104 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001105
1106 Base = N.getOperand(0);
1107 Offset = N.getOperand(1);
1108 return true;
1109}
1110
1111bool
1112ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1113 SDValue &Base,
1114 SDValue &Offset) {
1115 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1116}
1117
1118bool
1119ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1120 SDValue &Base,
1121 SDValue &Offset) {
1122 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1123}
1124
1125bool
1126ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1127 SDValue &Base,
1128 SDValue &Offset) {
1129 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1130}
1131
1132bool
1133ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1134 SDValue &Base, SDValue &OffImm) {
1135 if (Scale == 4) {
1136 SDValue TmpBase, TmpOffImm;
1137 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1138 return false; // We want to select tLDRspi / tSTRspi instead.
1139
1140 if (N.getOpcode() == ARMISD::Wrapper &&
1141 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1142 return false; // We want to select tLDRpci instead.
1143 }
1144
Chris Lattner46c01a32011-02-13 22:25:43 +00001145 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001146 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001147 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001148 Base = N.getOperand(0);
1149 } else {
1150 Base = N;
1151 }
1152
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001153 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001154 return true;
1155 }
1156
Bill Wendling832a5da2010-12-15 01:03:19 +00001157 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1158 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1159 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1160 (RHSR && RHSR->getReg() == ARM::SP)) {
1161 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1162 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1163 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1164 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1165
1166 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1167 if (LHSC != 0 || RHSC != 0) return false;
1168
1169 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001170 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Bill Wendling832a5da2010-12-15 01:03:19 +00001171 return true;
1172 }
1173
Evan Cheng10043e22007-01-19 07:51:42 +00001174 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001175 int RHSC;
1176 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1177 Base = N.getOperand(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001178 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001179 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001180 }
1181
Evan Chengc0b73662007-01-23 22:59:13 +00001182 Base = N.getOperand(0);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001183 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001184 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001185}
1186
Bill Wendling092a7bd2010-12-14 03:36:38 +00001187bool
1188ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1189 SDValue &OffImm) {
1190 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001191}
1192
Bill Wendling092a7bd2010-12-14 03:36:38 +00001193bool
1194ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1195 SDValue &OffImm) {
1196 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001197}
1198
Bill Wendling092a7bd2010-12-14 03:36:38 +00001199bool
1200ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1201 SDValue &OffImm) {
1202 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001203}
1204
Chris Lattner0e023ea2010-09-21 20:31:19 +00001205bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1206 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001207 if (N.getOpcode() == ISD::FrameIndex) {
1208 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Renato Golinb9887ef2015-02-25 14:41:06 +00001209 // Only multiples of 4 are allowed for the offset, so the frame object
1210 // alignment must be at least 4.
1211 MachineFrameInfo *MFI = MF->getFrameInfo();
1212 if (MFI->getObjectAlignment(FI) < 4)
1213 MFI->setObjectAlignment(FI, 4);
Eric Christopherb17140d2014-10-08 07:32:17 +00001214 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001215 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001216 return true;
1217 }
Evan Cheng139edae2007-01-24 02:21:22 +00001218
Chris Lattner46c01a32011-02-13 22:25:43 +00001219 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001220 return false;
1221
1222 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001223 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1224 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001225 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001226 int RHSC;
1227 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1228 Base = N.getOperand(0);
1229 if (Base.getOpcode() == ISD::FrameIndex) {
1230 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Renato Golinb9887ef2015-02-25 14:41:06 +00001231 // For LHS+RHS to result in an offset that's a multiple of 4 the object
1232 // indexed by the LHS must be 4-byte aligned.
1233 MachineFrameInfo *MFI = MF->getFrameInfo();
1234 if (MFI->getObjectAlignment(FI) < 4)
1235 MFI->setObjectAlignment(FI, 4);
Eric Christopherb17140d2014-10-08 07:32:17 +00001236 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001237 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001238 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001239 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001240 }
1241 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001242
Evan Cheng10043e22007-01-19 07:51:42 +00001243 return false;
1244}
1245
Bill Wendling092a7bd2010-12-14 03:36:38 +00001246
1247//===----------------------------------------------------------------------===//
1248// Thumb 2 Addressing Modes
1249//===----------------------------------------------------------------------===//
1250
1251
Chris Lattner0e023ea2010-09-21 20:31:19 +00001252bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001253 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001254 if (DisableShifterOp)
1255 return false;
1256
Evan Chenga20cde32011-07-20 23:34:39 +00001257 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001258
1259 // Don't match base register only case. That is matched to a separate
1260 // lower complexity pattern with explicit register operand.
1261 if (ShOpcVal == ARM_AM::no_shift) return false;
1262
1263 BaseReg = N.getOperand(0);
1264 unsigned ShImmVal = 0;
1265 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1266 ShImmVal = RHS->getZExtValue() & 31;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001267 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal), SDLoc(N));
Evan Chengeab9ca72009-06-27 02:26:13 +00001268 return true;
1269 }
1270
1271 return false;
1272}
1273
Chris Lattner0e023ea2010-09-21 20:31:19 +00001274bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001275 SDValue &Base, SDValue &OffImm) {
1276 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001277
Evan Cheng36064672009-08-11 08:52:18 +00001278 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001279 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1280 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001281 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001282 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001283 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001284 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001285 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001286 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001287 }
Owen Anderson6d557452011-03-18 19:46:58 +00001288
Chris Lattner46c01a32011-02-13 22:25:43 +00001289 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001290 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng36064672009-08-11 08:52:18 +00001291 Base = N.getOperand(0);
1292 if (Base.getOpcode() == ISD::TargetConstantPool)
1293 return false; // We want to select t2LDRpci instead.
1294 } else
1295 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001296 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001297 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001298 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001299
1300 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001301 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001302 // Let t2LDRi8 handle (R - imm8).
1303 return false;
1304
Evan Chengb23b50d2009-06-29 07:51:04 +00001305 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001306 if (N.getOpcode() == ISD::SUB)
1307 RHSC = -RHSC;
1308
1309 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001310 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001311 if (Base.getOpcode() == ISD::FrameIndex) {
1312 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001313 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001314 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001315 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001316 return true;
1317 }
1318 }
1319
Evan Cheng36064672009-08-11 08:52:18 +00001320 // Base only.
1321 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001322 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001323 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001324}
1325
Chris Lattner0e023ea2010-09-21 20:31:19 +00001326bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001327 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001328 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001329 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1330 !CurDAG->isBaseWithConstantOffset(N))
1331 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001332
Chris Lattner46c01a32011-02-13 22:25:43 +00001333 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1334 int RHSC = (int)RHS->getSExtValue();
1335 if (N.getOpcode() == ISD::SUB)
1336 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001337
Chris Lattner46c01a32011-02-13 22:25:43 +00001338 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1339 Base = N.getOperand(0);
1340 if (Base.getOpcode() == ISD::FrameIndex) {
1341 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001342 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001343 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001344 OffImm = CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32);
Chris Lattner46c01a32011-02-13 22:25:43 +00001345 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001346 }
1347 }
1348
1349 return false;
1350}
1351
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001352bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001353 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001354 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001355 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1356 ? cast<LoadSDNode>(Op)->getAddressingMode()
1357 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001358 int RHSC;
1359 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1360 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001361 ? CurDAG->getTargetConstant(RHSC, SDLoc(N), MVT::i32)
1362 : CurDAG->getTargetConstant(-RHSC, SDLoc(N), MVT::i32);
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001363 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001364 }
1365
1366 return false;
1367}
1368
Chris Lattner0e023ea2010-09-21 20:31:19 +00001369bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001370 SDValue &Base,
1371 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001372 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001373 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001374 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001375
Evan Cheng36064672009-08-11 08:52:18 +00001376 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1377 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1378 int RHSC = (int)RHS->getZExtValue();
1379 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1380 return false;
1381 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001382 return false;
1383 }
1384
Evan Chengb23b50d2009-06-29 07:51:04 +00001385 // Look for (R + R) or (R + (R << [1,2,3])).
1386 unsigned ShAmt = 0;
1387 Base = N.getOperand(0);
1388 OffReg = N.getOperand(1);
1389
1390 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001391 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001392 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001393 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001394 if (ShOpcVal == ARM_AM::lsl)
1395 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001396 }
1397
Evan Chengb23b50d2009-06-29 07:51:04 +00001398 if (ShOpcVal == ARM_AM::lsl) {
1399 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1400 // it.
1401 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1402 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001403 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1404 OffReg = OffReg.getOperand(0);
1405 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001406 ShAmt = 0;
Evan Cheng59bbc542010-10-27 23:41:30 +00001407 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001408 }
David Goodwinf3912052009-07-15 15:50:19 +00001409 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001410
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001411 ShImm = CurDAG->getTargetConstant(ShAmt, SDLoc(N), MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001412
1413 return true;
1414}
1415
Tim Northovera7ecd242013-07-16 09:46:55 +00001416bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1417 SDValue &OffImm) {
Alp Tokercb402912014-01-24 17:20:08 +00001418 // This *must* succeed since it's used for the irreplaceable ldrex and strex
Tim Northovera7ecd242013-07-16 09:46:55 +00001419 // instructions.
1420 Base = N;
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001421 OffImm = CurDAG->getTargetConstant(0, SDLoc(N), MVT::i32);
Tim Northovera7ecd242013-07-16 09:46:55 +00001422
1423 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1424 return true;
1425
1426 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1427 if (!RHS)
1428 return true;
1429
1430 uint32_t RHSC = (int)RHS->getZExtValue();
1431 if (RHSC > 1020 || RHSC % 4 != 0)
1432 return true;
1433
1434 Base = N.getOperand(0);
1435 if (Base.getOpcode() == ISD::FrameIndex) {
1436 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00001437 Base = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
Tim Northovera7ecd242013-07-16 09:46:55 +00001438 }
1439
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001440 OffImm = CurDAG->getTargetConstant(RHSC/4, SDLoc(N), MVT::i32);
Tim Northovera7ecd242013-07-16 09:46:55 +00001441 return true;
1442}
1443
Evan Chengb23b50d2009-06-29 07:51:04 +00001444//===--------------------------------------------------------------------===//
1445
Evan Cheng7e90b112007-07-05 07:15:27 +00001446/// getAL - Returns a ARMCC::AL immediate node.
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001447static inline SDValue getAL(SelectionDAG *CurDAG, SDLoc dl) {
1448 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, dl, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001449}
1450
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001451SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1452 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001453 ISD::MemIndexedMode AM = LD->getAddressingMode();
1454 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001455 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001456
Owen Anderson53aa7a92009-08-10 22:56:29 +00001457 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001458 SDValue Offset, AMOpc;
1459 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1460 unsigned Opcode = 0;
1461 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001462 if (LoadedVT == MVT::i32 && isPre &&
1463 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1464 Opcode = ARM::LDR_PRE_IMM;
1465 Match = true;
1466 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001467 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001468 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001469 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001470 } else if (LoadedVT == MVT::i32 &&
1471 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001472 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001473 Match = true;
1474
Owen Anderson9f944592009-08-11 20:47:22 +00001475 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001476 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001477 Match = true;
1478 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1479 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1480 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001481 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001482 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001483 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001484 Match = true;
1485 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1486 }
1487 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001488 if (isPre &&
1489 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001490 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001491 Opcode = ARM::LDRB_PRE_IMM;
1492 } else if (!isPre &&
1493 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1494 Match = true;
1495 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001496 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1497 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001498 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001499 }
1500 }
1501 }
1502
1503 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001504 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1505 SDValue Chain = LD->getChain();
1506 SDValue Base = LD->getBasePtr();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001507 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG, SDLoc(N)),
Owen Andersonfd60f602011-08-26 21:12:37 +00001508 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001509 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001510 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001511 } else {
1512 SDValue Chain = LD->getChain();
1513 SDValue Base = LD->getBasePtr();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001514 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG, SDLoc(N)),
Owen Andersonfd60f602011-08-26 21:12:37 +00001515 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001516 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001517 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001518 }
Evan Chengd9c55362009-07-02 01:23:32 +00001519 }
1520
Craig Topper062a2ba2014-04-25 05:30:21 +00001521 return nullptr;
Evan Chengd9c55362009-07-02 01:23:32 +00001522}
1523
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001524SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1525 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001526 ISD::MemIndexedMode AM = LD->getAddressingMode();
1527 if (AM == ISD::UNINDEXED)
Craig Topper062a2ba2014-04-25 05:30:21 +00001528 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001529
Owen Anderson53aa7a92009-08-10 22:56:29 +00001530 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001531 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001532 SDValue Offset;
1533 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1534 unsigned Opcode = 0;
1535 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001536 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001537 switch (LoadedVT.getSimpleVT().SimpleTy) {
1538 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001539 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1540 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001541 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001542 if (isSExtLd)
1543 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1544 else
1545 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001546 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001547 case MVT::i8:
1548 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001549 if (isSExtLd)
1550 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1551 else
1552 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001553 break;
1554 default:
Craig Topper062a2ba2014-04-25 05:30:21 +00001555 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001556 }
1557 Match = true;
1558 }
1559
1560 if (Match) {
1561 SDValue Chain = LD->getChain();
1562 SDValue Base = LD->getBasePtr();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001563 SDValue Ops[]= { Base, Offset, getAL(CurDAG, SDLoc(N)),
Owen Anderson9f944592009-08-11 20:47:22 +00001564 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001565 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001566 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001567 }
1568
Craig Topper062a2ba2014-04-25 05:30:21 +00001569 return nullptr;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001570}
1571
Weiming Zhao8f56f882012-11-16 21:55:34 +00001572/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1573SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001574 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001575 SDValue RegClass =
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001576 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, dl, MVT::i32);
1577 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, dl, MVT::i32);
1578 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, dl, MVT::i32);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001579 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001580 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001581}
1582
Weiming Zhao95782222012-11-17 00:23:35 +00001583/// \brief Form a D register from a pair of S registers.
1584SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001585 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001586 SDValue RegClass =
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001587 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, dl, MVT::i32);
1588 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, dl, MVT::i32);
1589 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001590 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001591 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001592}
1593
Weiming Zhao95782222012-11-17 00:23:35 +00001594/// \brief Form a quad register from a pair of D registers.
1595SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001596 SDLoc dl(V0.getNode());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001597 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, dl,
1598 MVT::i32);
1599 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, dl, MVT::i32);
1600 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001601 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001602 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001603}
1604
Weiming Zhao95782222012-11-17 00:23:35 +00001605/// \brief Form 4 consecutive D registers from a pair of Q registers.
1606SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001607 SDLoc dl(V0.getNode());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001608 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, dl,
1609 MVT::i32);
1610 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, dl, MVT::i32);
1611 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001612 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001613 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001614}
1615
Weiming Zhao95782222012-11-17 00:23:35 +00001616/// \brief Form 4 consecutive S registers.
1617SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001618 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001619 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001620 SDValue RegClass =
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001621 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, dl, MVT::i32);
1622 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, dl, MVT::i32);
1623 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, dl, MVT::i32);
1624 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, dl, MVT::i32);
1625 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001626 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1627 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001628 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001629}
1630
Weiming Zhao95782222012-11-17 00:23:35 +00001631/// \brief Form 4 consecutive D registers.
1632SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001633 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001634 SDLoc dl(V0.getNode());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001635 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, dl,
1636 MVT::i32);
1637 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, dl, MVT::i32);
1638 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, dl, MVT::i32);
1639 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, dl, MVT::i32);
1640 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001641 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1642 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001643 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001644}
1645
Weiming Zhao95782222012-11-17 00:23:35 +00001646/// \brief Form 4 consecutive Q registers.
1647SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001648 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001649 SDLoc dl(V0.getNode());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001650 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, dl,
1651 MVT::i32);
1652 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, dl, MVT::i32);
1653 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, dl, MVT::i32);
1654 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, dl, MVT::i32);
1655 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, dl, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001656 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1657 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001658 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001659}
1660
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001661/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1662/// of a NEON VLD or VST instruction. The supported values depend on the
1663/// number of registers being loaded.
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001664SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, SDLoc dl,
1665 unsigned NumVecs, bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001666 unsigned NumRegs = NumVecs;
1667 if (!is64BitVector && NumVecs < 3)
1668 NumRegs *= 2;
1669
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001670 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001671 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001672 Alignment = 32;
1673 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1674 Alignment = 16;
1675 else if (Alignment >= 8)
1676 Alignment = 8;
1677 else
1678 Alignment = 0;
1679
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001680 return CurDAG->getTargetConstant(Alignment, dl, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001681}
1682
Jiangning Liu4df23632014-01-16 09:16:13 +00001683static bool isVLDfixed(unsigned Opc)
1684{
1685 switch (Opc) {
1686 default: return false;
1687 case ARM::VLD1d8wb_fixed : return true;
1688 case ARM::VLD1d16wb_fixed : return true;
1689 case ARM::VLD1d64Qwb_fixed : return true;
1690 case ARM::VLD1d32wb_fixed : return true;
1691 case ARM::VLD1d64wb_fixed : return true;
1692 case ARM::VLD1d64TPseudoWB_fixed : return true;
1693 case ARM::VLD1d64QPseudoWB_fixed : return true;
1694 case ARM::VLD1q8wb_fixed : return true;
1695 case ARM::VLD1q16wb_fixed : return true;
1696 case ARM::VLD1q32wb_fixed : return true;
1697 case ARM::VLD1q64wb_fixed : return true;
1698 case ARM::VLD2d8wb_fixed : return true;
1699 case ARM::VLD2d16wb_fixed : return true;
1700 case ARM::VLD2d32wb_fixed : return true;
1701 case ARM::VLD2q8PseudoWB_fixed : return true;
1702 case ARM::VLD2q16PseudoWB_fixed : return true;
1703 case ARM::VLD2q32PseudoWB_fixed : return true;
1704 case ARM::VLD2DUPd8wb_fixed : return true;
1705 case ARM::VLD2DUPd16wb_fixed : return true;
1706 case ARM::VLD2DUPd32wb_fixed : return true;
1707 }
1708}
1709
1710static bool isVSTfixed(unsigned Opc)
1711{
1712 switch (Opc) {
1713 default: return false;
1714 case ARM::VST1d8wb_fixed : return true;
1715 case ARM::VST1d16wb_fixed : return true;
1716 case ARM::VST1d32wb_fixed : return true;
1717 case ARM::VST1d64wb_fixed : return true;
Jim Grosbach1a597112014-04-03 23:43:18 +00001718 case ARM::VST1q8wb_fixed : return true;
1719 case ARM::VST1q16wb_fixed : return true;
1720 case ARM::VST1q32wb_fixed : return true;
1721 case ARM::VST1q64wb_fixed : return true;
Jiangning Liu4df23632014-01-16 09:16:13 +00001722 case ARM::VST1d64TPseudoWB_fixed : return true;
1723 case ARM::VST1d64QPseudoWB_fixed : return true;
1724 case ARM::VST2d8wb_fixed : return true;
1725 case ARM::VST2d16wb_fixed : return true;
1726 case ARM::VST2d32wb_fixed : return true;
1727 case ARM::VST2q8PseudoWB_fixed : return true;
1728 case ARM::VST2q16PseudoWB_fixed : return true;
1729 case ARM::VST2q32PseudoWB_fixed : return true;
1730 }
1731}
1732
Jim Grosbach2098cb12011-10-24 21:45:13 +00001733// Get the register stride update opcode of a VLD/VST instruction that
1734// is otherwise equivalent to the given fixed stride updating instruction.
1735static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
Jiangning Liu4df23632014-01-16 09:16:13 +00001736 assert((isVLDfixed(Opc) || isVSTfixed(Opc))
1737 && "Incorrect fixed stride updating instruction.");
Jim Grosbach2098cb12011-10-24 21:45:13 +00001738 switch (Opc) {
1739 default: break;
1740 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1741 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1742 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1743 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1744 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1745 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1746 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1747 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jiangning Liu4df23632014-01-16 09:16:13 +00001748 case ARM::VLD1d64Twb_fixed: return ARM::VLD1d64Twb_register;
1749 case ARM::VLD1d64Qwb_fixed: return ARM::VLD1d64Qwb_register;
1750 case ARM::VLD1d64TPseudoWB_fixed: return ARM::VLD1d64TPseudoWB_register;
1751 case ARM::VLD1d64QPseudoWB_fixed: return ARM::VLD1d64QPseudoWB_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001752
1753 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1754 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1755 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1756 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1757 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1758 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1759 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1760 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001761 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001762 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001763
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001764 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1765 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1766 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001767 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1768 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1769 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1770
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001771 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1772 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1773 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001774 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1775 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1776 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001777
Jim Grosbach13a292c2012-03-06 22:01:44 +00001778 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1779 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1780 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001781 }
1782 return Opc; // If not one we handle, return it unchanged.
1783}
1784
Bob Wilson06fce872011-02-07 17:43:21 +00001785SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001786 const uint16_t *DOpcodes,
1787 const uint16_t *QOpcodes0,
1788 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001789 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001790 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001791
Bob Wilsonae08a732010-03-20 22:13:40 +00001792 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001793 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1794 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001795 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001796
1797 SDValue Chain = N->getOperand(0);
1798 EVT VT = N->getValueType(0);
1799 bool is64BitVector = VT.is64BitVector();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001800 Align = GetVLDSTAlign(Align, dl, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001801
Bob Wilson12b47992009-10-14 17:28:52 +00001802 unsigned OpcodeIndex;
1803 switch (VT.getSimpleVT().SimpleTy) {
1804 default: llvm_unreachable("unhandled vld type");
1805 // Double-register operations:
1806 case MVT::v8i8: OpcodeIndex = 0; break;
1807 case MVT::v4i16: OpcodeIndex = 1; break;
1808 case MVT::v2f32:
1809 case MVT::v2i32: OpcodeIndex = 2; break;
1810 case MVT::v1i64: OpcodeIndex = 3; break;
1811 // Quad-register operations:
1812 case MVT::v16i8: OpcodeIndex = 0; break;
1813 case MVT::v8i16: OpcodeIndex = 1; break;
1814 case MVT::v4f32:
1815 case MVT::v4i32: OpcodeIndex = 2; break;
Ahmed Bougachabe0b2272014-12-09 21:25:00 +00001816 case MVT::v2f64:
Bob Wilson340861d2010-03-23 05:25:43 +00001817 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001818 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001819 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001820 }
1821
Bob Wilson35fafca2010-09-03 18:16:02 +00001822 EVT ResTy;
1823 if (NumVecs == 1)
1824 ResTy = VT;
1825 else {
1826 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1827 if (!is64BitVector)
1828 ResTyElts *= 2;
1829 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1830 }
Bob Wilson06fce872011-02-07 17:43:21 +00001831 std::vector<EVT> ResTys;
1832 ResTys.push_back(ResTy);
1833 if (isUpdating)
1834 ResTys.push_back(MVT::i32);
1835 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001836
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001837 SDValue Pred = getAL(CurDAG, dl);
Bob Wilsonae08a732010-03-20 22:13:40 +00001838 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001839 SDNode *VLd;
1840 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001841
Bob Wilson06fce872011-02-07 17:43:21 +00001842 // Double registers and VLD1/VLD2 quad registers are directly supported.
1843 if (is64BitVector || NumVecs <= 2) {
1844 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1845 QOpcodes0[OpcodeIndex]);
1846 Ops.push_back(MemAddr);
1847 Ops.push_back(Align);
1848 if (isUpdating) {
1849 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001850 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001851 // case entirely when the rest are updated to that form, too.
Jiangning Liu4df23632014-01-16 09:16:13 +00001852 if ((NumVecs <= 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001853 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00001854 // FIXME: We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001855 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00001856 if ((NumVecs > 2 && !isVLDfixed(Opc)) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001857 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001858 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001859 }
Bob Wilson06fce872011-02-07 17:43:21 +00001860 Ops.push_back(Pred);
1861 Ops.push_back(Reg0);
1862 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001863 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001864
Bob Wilson12b47992009-10-14 17:28:52 +00001865 } else {
1866 // Otherwise, quad registers are loaded with two separate instructions,
1867 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001868 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001869
Bob Wilson06fce872011-02-07 17:43:21 +00001870 // Load the even subregs. This is always an updating load, so that it
1871 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001872 SDValue ImplDef =
1873 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1874 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001875 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001876 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001877 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001878
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001879 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001880 Ops.push_back(SDValue(VLdA, 1));
1881 Ops.push_back(Align);
1882 if (isUpdating) {
1883 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1884 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1885 "only constant post-increment update allowed for VLD3/4");
1886 (void)Inc;
1887 Ops.push_back(Reg0);
1888 }
1889 Ops.push_back(SDValue(VLdA, 0));
1890 Ops.push_back(Pred);
1891 Ops.push_back(Reg0);
1892 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001893 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001894 }
Bob Wilson12b47992009-10-14 17:28:52 +00001895
Evan Cheng40791332011-04-19 00:04:03 +00001896 // Transfer memoperands.
1897 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1898 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1899 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1900
Bob Wilson06fce872011-02-07 17:43:21 +00001901 if (NumVecs == 1)
1902 return VLd;
1903
1904 // Extract out the subregisters.
1905 SDValue SuperReg = SDValue(VLd, 0);
1906 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1907 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1908 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1909 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1910 ReplaceUses(SDValue(N, Vec),
1911 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1912 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1913 if (isUpdating)
1914 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00001915 return nullptr;
Bob Wilson12b47992009-10-14 17:28:52 +00001916}
1917
Bob Wilson06fce872011-02-07 17:43:21 +00001918SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001919 const uint16_t *DOpcodes,
1920 const uint16_t *QOpcodes0,
1921 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001922 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001923 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001924
Bob Wilsonae08a732010-03-20 22:13:40 +00001925 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001926 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1927 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1928 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00001929 return nullptr;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001930
Evan Cheng40791332011-04-19 00:04:03 +00001931 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1932 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1933
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001934 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001935 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001936 bool is64BitVector = VT.is64BitVector();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001937 Align = GetVLDSTAlign(Align, dl, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001938
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001939 unsigned OpcodeIndex;
1940 switch (VT.getSimpleVT().SimpleTy) {
1941 default: llvm_unreachable("unhandled vst type");
1942 // Double-register operations:
1943 case MVT::v8i8: OpcodeIndex = 0; break;
1944 case MVT::v4i16: OpcodeIndex = 1; break;
1945 case MVT::v2f32:
1946 case MVT::v2i32: OpcodeIndex = 2; break;
1947 case MVT::v1i64: OpcodeIndex = 3; break;
1948 // Quad-register operations:
1949 case MVT::v16i8: OpcodeIndex = 0; break;
1950 case MVT::v8i16: OpcodeIndex = 1; break;
1951 case MVT::v4f32:
1952 case MVT::v4i32: OpcodeIndex = 2; break;
Ahmed Bougachabe0b2272014-12-09 21:25:00 +00001953 case MVT::v2f64:
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001954 case MVT::v2i64: OpcodeIndex = 3;
1955 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1956 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001957 }
1958
Bob Wilson06fce872011-02-07 17:43:21 +00001959 std::vector<EVT> ResTys;
1960 if (isUpdating)
1961 ResTys.push_back(MVT::i32);
1962 ResTys.push_back(MVT::Other);
1963
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00001964 SDValue Pred = getAL(CurDAG, dl);
Bob Wilsonae08a732010-03-20 22:13:40 +00001965 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001966 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001967
Bob Wilson06fce872011-02-07 17:43:21 +00001968 // Double registers and VST1/VST2 quad registers are directly supported.
1969 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001970 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001971 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001972 SrcReg = N->getOperand(Vec0Idx);
1973 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001974 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001975 SDValue V0 = N->getOperand(Vec0Idx + 0);
1976 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001977 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001978 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001979 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001980 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001981 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001982 // an undef.
1983 SDValue V3 = (NumVecs == 3)
1984 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001985 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001986 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001987 }
Bob Wilson950882b2010-08-28 05:12:57 +00001988 } else {
1989 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001990 SDValue Q0 = N->getOperand(Vec0Idx);
1991 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001992 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001993 }
Bob Wilson06fce872011-02-07 17:43:21 +00001994
1995 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1996 QOpcodes0[OpcodeIndex]);
1997 Ops.push_back(MemAddr);
1998 Ops.push_back(Align);
1999 if (isUpdating) {
2000 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00002001 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00002002 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00002003 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00002004 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jiangning Liu4df23632014-01-16 09:16:13 +00002005 // FIXME: We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00002006 // check for that explicitly too. Horribly hacky, but temporary.
Jiangning Liu4df23632014-01-16 09:16:13 +00002007 if (!isa<ConstantSDNode>(Inc.getNode()))
2008 Ops.push_back(Inc);
2009 else if (NumVecs > 2 && !isVSTfixed(Opc))
2010 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002011 }
2012 Ops.push_back(SrcReg);
2013 Ops.push_back(Pred);
2014 Ops.push_back(Reg0);
2015 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00002016 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002017
2018 // Transfer memoperands.
2019 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
2020
2021 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002022 }
2023
2024 // Otherwise, quad registers are stored with two separate instructions,
2025 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00002026
Bob Wilson01ac8f92010-06-16 21:34:01 +00002027 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00002028 SDValue V0 = N->getOperand(Vec0Idx + 0);
2029 SDValue V1 = N->getOperand(Vec0Idx + 1);
2030 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00002031 SDValue V3 = (NumVecs == 3)
2032 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00002033 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002034 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002035
Bob Wilson06fce872011-02-07 17:43:21 +00002036 // Store the even D registers. This is always an updating store, so that it
2037 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00002038 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
2039 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
2040 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00002041 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00002042 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00002043 Chain = SDValue(VStA, 1);
2044
2045 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00002046 Ops.push_back(SDValue(VStA, 0));
2047 Ops.push_back(Align);
2048 if (isUpdating) {
2049 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2050 assert(isa<ConstantSDNode>(Inc.getNode()) &&
2051 "only constant post-increment update allowed for VST3/4");
2052 (void)Inc;
2053 Ops.push_back(Reg0);
2054 }
2055 Ops.push_back(RegSeq);
2056 Ops.push_back(Pred);
2057 Ops.push_back(Reg0);
2058 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00002059 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00002060 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002061 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
2062 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00002063}
2064
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002065SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00002066 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00002067 const uint16_t *DOpcodes,
2068 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002069 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002070 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002071
Bob Wilsonae08a732010-03-20 22:13:40 +00002072 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002073 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2074 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2075 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002076 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002077
Evan Cheng40791332011-04-19 00:04:03 +00002078 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2079 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2080
Bob Wilson4145e3a2009-10-14 16:19:03 +00002081 SDValue Chain = N->getOperand(0);
2082 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002083 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2084 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002085 bool is64BitVector = VT.is64BitVector();
2086
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002087 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002088 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002089 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002090 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2091 if (Alignment > NumBytes)
2092 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002093 if (Alignment < 8 && Alignment < NumBytes)
2094 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002095 // Alignment must be a power of two; make sure of that.
2096 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002097 if (Alignment == 1)
2098 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002099 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002100 Align = CurDAG->getTargetConstant(Alignment, dl, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002101
Bob Wilson4145e3a2009-10-14 16:19:03 +00002102 unsigned OpcodeIndex;
2103 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002104 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002105 // Double-register operations:
2106 case MVT::v8i8: OpcodeIndex = 0; break;
2107 case MVT::v4i16: OpcodeIndex = 1; break;
2108 case MVT::v2f32:
2109 case MVT::v2i32: OpcodeIndex = 2; break;
2110 // Quad-register operations:
2111 case MVT::v8i16: OpcodeIndex = 0; break;
2112 case MVT::v4f32:
2113 case MVT::v4i32: OpcodeIndex = 1; break;
2114 }
2115
Bob Wilson06fce872011-02-07 17:43:21 +00002116 std::vector<EVT> ResTys;
2117 if (IsLoad) {
2118 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2119 if (!is64BitVector)
2120 ResTyElts *= 2;
2121 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2122 MVT::i64, ResTyElts));
2123 }
2124 if (isUpdating)
2125 ResTys.push_back(MVT::i32);
2126 ResTys.push_back(MVT::Other);
2127
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002128 SDValue Pred = getAL(CurDAG, dl);
Bob Wilsonae08a732010-03-20 22:13:40 +00002129 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002130
Bob Wilson06fce872011-02-07 17:43:21 +00002131 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002132 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002133 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002134 if (isUpdating) {
2135 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2136 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2137 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002138
Bob Wilsond5c57a52010-09-13 23:01:35 +00002139 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002140 SDValue V0 = N->getOperand(Vec0Idx + 0);
2141 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002142 if (NumVecs == 2) {
2143 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002144 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002145 else
Weiming Zhao95782222012-11-17 00:23:35 +00002146 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002147 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002148 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002149 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002150 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2151 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002152 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002153 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002154 else
Weiming Zhao95782222012-11-17 00:23:35 +00002155 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002156 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002157 Ops.push_back(SuperReg);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002158 Ops.push_back(getI32Imm(Lane, dl));
Evan Chenga33fc862009-11-21 06:21:52 +00002159 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002160 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002161 Ops.push_back(Chain);
2162
Bob Wilson06fce872011-02-07 17:43:21 +00002163 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2164 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002165 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002166 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002167 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002168 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002169
Bob Wilsond5c57a52010-09-13 23:01:35 +00002170 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002171 SuperReg = SDValue(VLdLn, 0);
2172 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2173 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2174 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002175 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2176 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002177 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2178 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2179 if (isUpdating)
2180 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002181 return nullptr;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002182}
2183
Bob Wilson06fce872011-02-07 17:43:21 +00002184SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002185 unsigned NumVecs,
2186 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002187 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002188 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002189
2190 SDValue MemAddr, Align;
2191 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
Craig Topper062a2ba2014-04-25 05:30:21 +00002192 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002193
Evan Cheng40791332011-04-19 00:04:03 +00002194 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2195 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2196
Bob Wilson2d790df2010-11-28 06:51:26 +00002197 SDValue Chain = N->getOperand(0);
2198 EVT VT = N->getValueType(0);
2199
2200 unsigned Alignment = 0;
2201 if (NumVecs != 3) {
2202 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2203 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2204 if (Alignment > NumBytes)
2205 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002206 if (Alignment < 8 && Alignment < NumBytes)
2207 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002208 // Alignment must be a power of two; make sure of that.
2209 Alignment = (Alignment & -Alignment);
2210 if (Alignment == 1)
2211 Alignment = 0;
2212 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002213 Align = CurDAG->getTargetConstant(Alignment, dl, MVT::i32);
Bob Wilson2d790df2010-11-28 06:51:26 +00002214
2215 unsigned OpcodeIndex;
2216 switch (VT.getSimpleVT().SimpleTy) {
2217 default: llvm_unreachable("unhandled vld-dup type");
2218 case MVT::v8i8: OpcodeIndex = 0; break;
2219 case MVT::v4i16: OpcodeIndex = 1; break;
2220 case MVT::v2f32:
2221 case MVT::v2i32: OpcodeIndex = 2; break;
2222 }
2223
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002224 SDValue Pred = getAL(CurDAG, dl);
Bob Wilson2d790df2010-11-28 06:51:26 +00002225 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2226 SDValue SuperReg;
2227 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002228 SmallVector<SDValue, 6> Ops;
2229 Ops.push_back(MemAddr);
2230 Ops.push_back(Align);
2231 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002232 // fixed-stride update instructions don't have an explicit writeback
2233 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002234 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002235 if (!isa<ConstantSDNode>(Inc.getNode()))
2236 Ops.push_back(Inc);
2237 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2238 else if (NumVecs > 2)
2239 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002240 }
2241 Ops.push_back(Pred);
2242 Ops.push_back(Reg0);
2243 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002244
2245 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002246 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002247 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002248 if (isUpdating)
2249 ResTys.push_back(MVT::i32);
2250 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002251 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002252 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002253 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002254
2255 // Extract the subregisters.
2256 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2257 unsigned SubIdx = ARM::dsub_0;
2258 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2259 ReplaceUses(SDValue(N, Vec),
2260 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002261 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2262 if (isUpdating)
2263 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Craig Topper062a2ba2014-04-25 05:30:21 +00002264 return nullptr;
Bob Wilson2d790df2010-11-28 06:51:26 +00002265}
2266
Bob Wilson5bc8a792010-07-07 00:08:54 +00002267SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2268 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002269 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002270 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002271 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002272 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002273
2274 // Form a REG_SEQUENCE to force register allocation.
2275 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002276 SDValue V0 = N->getOperand(FirstTblReg + 0);
2277 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002278 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002279 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002280 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002281 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002282 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002283 // an undef.
2284 SDValue V3 = (NumVecs == 3)
2285 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002286 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002287 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002288 }
2289
Bob Wilson5bc8a792010-07-07 00:08:54 +00002290 SmallVector<SDValue, 6> Ops;
2291 if (IsExt)
2292 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002293 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002294 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002295 Ops.push_back(getAL(CurDAG, dl)); // predicate
Bob Wilson3ed511b2010-07-06 23:36:25 +00002296 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002297 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002298}
2299
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002300SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002301 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002302 if (!Subtarget->hasV6T2Ops())
Craig Topper062a2ba2014-04-25 05:30:21 +00002303 return nullptr;
Bob Wilson93117bc2009-10-14 16:46:45 +00002304
Evan Chengeae6d2c2012-12-19 20:16:09 +00002305 unsigned Opc = isSigned
2306 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002307 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002308 SDLoc dl(N);
Jim Grosbach825cb292010-04-22 23:24:18 +00002309
Jim Grosbach825cb292010-04-22 23:24:18 +00002310 // For unsigned extracts, check for a shift right and mask
2311 unsigned And_imm = 0;
2312 if (N->getOpcode() == ISD::AND) {
2313 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2314
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002315 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002316 if (And_imm & (And_imm + 1))
Craig Topper062a2ba2014-04-25 05:30:21 +00002317 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002318
2319 unsigned Srl_imm = 0;
2320 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2321 Srl_imm)) {
2322 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2323
Jim Grosbach03f56d92011-07-27 21:09:25 +00002324 // Note: The width operand is encoded as width-1.
Benjamin Kramer5f6a9072015-02-12 15:35:40 +00002325 unsigned Width = countTrailingOnes(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002326 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002327
Jim Grosbach825cb292010-04-22 23:24:18 +00002328 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002329
2330 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2331 // It's cheaper to use a right shift to extract the top bits.
2332 if (Subtarget->isThumb()) {
2333 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2334 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002335 CurDAG->getTargetConstant(LSB, dl, MVT::i32),
2336 getAL(CurDAG, dl), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002337 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002338 }
2339
2340 // ARM models shift instructions as MOVsi with shifter operand.
2341 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2342 SDValue ShOpc =
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002343 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB), dl,
Evan Chengeae6d2c2012-12-19 20:16:09 +00002344 MVT::i32);
2345 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002346 getAL(CurDAG, dl), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002347 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002348 }
2349
Jim Grosbach825cb292010-04-22 23:24:18 +00002350 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002351 CurDAG->getTargetConstant(LSB, dl, MVT::i32),
2352 CurDAG->getTargetConstant(Width, dl, MVT::i32),
2353 getAL(CurDAG, dl), Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002354 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Jim Grosbach825cb292010-04-22 23:24:18 +00002355 }
2356 }
Craig Topper062a2ba2014-04-25 05:30:21 +00002357 return nullptr;
Jim Grosbach825cb292010-04-22 23:24:18 +00002358 }
2359
2360 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002361 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002362 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002363 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2364 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002365 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002366 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002367 // Note: The width operand is encoded as width-1.
2368 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002369 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002370 if (LSB < 0)
Craig Topper062a2ba2014-04-25 05:30:21 +00002371 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002372 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002373 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002374 CurDAG->getTargetConstant(LSB, dl, MVT::i32),
2375 CurDAG->getTargetConstant(Width, dl, MVT::i32),
2376 getAL(CurDAG, dl), Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002377 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002378 }
2379 }
Tim Northover14ff2df2014-07-23 13:59:12 +00002380
2381 if (N->getOpcode() == ISD::SIGN_EXTEND_INREG) {
2382 unsigned Width = cast<VTSDNode>(N->getOperand(1))->getVT().getSizeInBits();
2383 unsigned LSB = 0;
2384 if (!isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL, LSB) &&
2385 !isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRA, LSB))
2386 return nullptr;
2387
2388 if (LSB + Width > 32)
2389 return nullptr;
2390
2391 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2392 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002393 CurDAG->getTargetConstant(LSB, dl, MVT::i32),
2394 CurDAG->getTargetConstant(Width - 1, dl, MVT::i32),
2395 getAL(CurDAG, dl), Reg0 };
Tim Northover14ff2df2014-07-23 13:59:12 +00002396 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
2397 }
2398
Craig Topper062a2ba2014-04-25 05:30:21 +00002399 return nullptr;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002400}
2401
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002402/// Target-specific DAG combining for ISD::XOR.
2403/// Target-independent combining lowers SELECT_CC nodes of the form
2404/// select_cc setg[ge] X, 0, X, -X
2405/// select_cc setgt X, -1, X, -X
2406/// select_cc setl[te] X, 0, -X, X
2407/// select_cc setlt X, 1, -X, X
2408/// which represent Integer ABS into:
2409/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2410/// ARM instruction selection detects the latter and matches it to
2411/// ARM::ABS or ARM::t2ABS machine node.
2412SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2413 SDValue XORSrc0 = N->getOperand(0);
2414 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002415 EVT VT = N->getValueType(0);
2416
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002417 if (Subtarget->isThumb1Only())
Craig Topper062a2ba2014-04-25 05:30:21 +00002418 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002419
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002420 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Craig Topper062a2ba2014-04-25 05:30:21 +00002421 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002422
2423 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2424 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2425 SDValue SRASrc0 = XORSrc1.getOperand(0);
2426 SDValue SRASrc1 = XORSrc1.getOperand(1);
2427 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2428 EVT XType = SRASrc0.getValueType();
2429 unsigned Size = XType.getSizeInBits() - 1;
2430
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002431 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
Craig Topper062a2ba2014-04-25 05:30:21 +00002432 XType.isInteger() && SRAConstant != nullptr &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002433 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002434 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002435 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2436 }
2437
Craig Topper062a2ba2014-04-25 05:30:21 +00002438 return nullptr;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002439}
2440
Evan Chengd85631e2010-05-05 18:28:36 +00002441SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2442 // The only time a CONCAT_VECTORS operation can have legal types is when
2443 // two 64-bit vectors are concatenated to a 128-bit vector.
2444 EVT VT = N->getValueType(0);
2445 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2446 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002447 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002448}
2449
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002450SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002451 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002452
Tim Northover31d093c2013-09-22 08:21:56 +00002453 if (N->isMachineOpcode()) {
2454 N->setNodeId(-1);
Craig Topper062a2ba2014-04-25 05:30:21 +00002455 return nullptr; // Already selected.
Tim Northover31d093c2013-09-22 08:21:56 +00002456 }
Rafael Espindola4e760152006-06-12 12:28:08 +00002457
2458 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002459 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002460 case ISD::INLINEASM: {
2461 SDNode *ResNode = SelectInlineAsm(N);
2462 if (ResNode)
2463 return ResNode;
2464 break;
2465 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002466 case ISD::XOR: {
2467 // Select special operations if XOR node forms integer ABS pattern
2468 SDNode *ResNode = SelectABSOp(N);
2469 if (ResNode)
2470 return ResNode;
2471 // Other cases are autogenerated.
2472 break;
2473 }
Evan Cheng10043e22007-01-19 07:51:42 +00002474 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002475 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002476 bool UseCP = true;
Eric Christopherc1058df2014-07-04 01:55:26 +00002477 if (Subtarget->useMovt(*MF))
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002478 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2479 // be done with MOV + MOVT, at worst.
Tim Northover55c625f2014-01-23 13:43:47 +00002480 UseCP = false;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002481 else {
2482 if (Subtarget->isThumb()) {
Tim Northover55c625f2014-01-23 13:43:47 +00002483 UseCP = (Val > 255 && // MOV
2484 ~Val > 255 && // MOV + MVN
2485 !ARM_AM::isThumbImmShiftedVal(Val) && // MOV + LSL
2486 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002487 } else
Tim Northover55c625f2014-01-23 13:43:47 +00002488 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2489 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2490 !ARM_AM::isSOImmTwoPartVal(Val) && // two instrs.
2491 !(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002492 }
2493
Evan Cheng10043e22007-01-19 07:51:42 +00002494 if (UseCP) {
Eric Christopherb17140d2014-10-08 07:32:17 +00002495 SDValue CPIdx = CurDAG->getTargetConstantPool(
2496 ConstantInt::get(Type::getInt32Ty(*CurDAG->getContext()), Val),
2497 TLI->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002498
2499 SDNode *ResNode;
Tim Northover55c625f2014-01-23 13:43:47 +00002500 if (Subtarget->isThumb()) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002501 SDValue Pred = getAL(CurDAG, dl);
Owen Anderson9f944592009-08-11 20:47:22 +00002502 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002503 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002504 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002505 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002506 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002507 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002508 CPIdx,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002509 CurDAG->getTargetConstant(0, dl, MVT::i32),
2510 getAL(CurDAG, dl),
Owen Anderson9f944592009-08-11 20:47:22 +00002511 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002512 CurDAG->getEntryNode()
2513 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002514 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002515 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002516 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002517 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Craig Topper062a2ba2014-04-25 05:30:21 +00002518 return nullptr;
Evan Cheng10043e22007-01-19 07:51:42 +00002519 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002520
Evan Cheng10043e22007-01-19 07:51:42 +00002521 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002522 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002523 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002524 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002525 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002526 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Eric Christopherb17140d2014-10-08 07:32:17 +00002527 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002528 if (Subtarget->isThumb1Only()) {
Renato Golinb9887ef2015-02-25 14:41:06 +00002529 // Set the alignment of the frame object to 4, to avoid having to generate
2530 // more than one ADD
2531 MachineFrameInfo *MFI = MF->getFrameInfo();
2532 if (MFI->getObjectAlignment(FI) < 4)
2533 MFI->setObjectAlignment(FI, 4);
Tim Northover23075cc2014-10-20 21:28:41 +00002534 return CurDAG->SelectNodeTo(N, ARM::tADDframe, MVT::i32, TFI,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002535 CurDAG->getTargetConstant(0, dl, MVT::i32));
Jim Grosbachfde21102009-04-07 20:34:09 +00002536 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002537 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2538 ARM::t2ADDri : ARM::ADDri);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002539 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, dl, MVT::i32),
2540 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32),
Owen Anderson9f944592009-08-11 20:47:22 +00002541 CurDAG->getRegister(0, MVT::i32) };
Craig Topper481fb282014-04-27 19:21:11 +00002542 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops);
Evan Cheng7e90b112007-07-05 07:15:27 +00002543 }
Evan Cheng10043e22007-01-19 07:51:42 +00002544 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002545 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002546 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002547 return I;
2548 break;
Tim Northover14ff2df2014-07-23 13:59:12 +00002549 case ISD::SIGN_EXTEND_INREG:
Sandeep Patel423e42b2009-10-13 18:59:48 +00002550 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002551 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002552 return I;
2553 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002554 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002555 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002556 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002557 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002558 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002559 if (!RHSV) break;
2560 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002561 unsigned ShImm = Log2_32(RHSV-1);
2562 if (ShImm >= 32)
2563 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002564 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002565 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002566 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, dl, MVT::i32);
Owen Anderson9f944592009-08-11 20:47:22 +00002567 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002568 if (Subtarget->isThumb()) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002569 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG, dl), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002570 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002571 } else {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002572 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG, dl), Reg0,
2573 Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002574 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002575 }
Evan Cheng10043e22007-01-19 07:51:42 +00002576 }
2577 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002578 unsigned ShImm = Log2_32(RHSV+1);
2579 if (ShImm >= 32)
2580 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002581 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002582 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002583 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, dl, MVT::i32);
Owen Anderson9f944592009-08-11 20:47:22 +00002584 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002585 if (Subtarget->isThumb()) {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002586 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG, dl), Reg0, Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002587 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002588 } else {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002589 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG, dl), Reg0,
2590 Reg0 };
Craig Topper481fb282014-04-27 19:21:11 +00002591 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002592 }
Evan Cheng10043e22007-01-19 07:51:42 +00002593 }
2594 }
2595 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002596 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002597 // Check for unsigned bitfield extract
2598 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2599 return I;
2600
Evan Cheng786b15f2009-10-21 08:15:52 +00002601 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2602 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2603 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2604 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2605 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002606 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002607 if (VT != MVT::i32)
2608 break;
2609 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2610 ? ARM::t2MOVTi16
2611 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2612 if (!Opc)
2613 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002614 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002615 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2616 if (!N1C)
2617 break;
2618 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2619 SDValue N2 = N0.getOperand(1);
2620 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2621 if (!N2C)
2622 break;
2623 unsigned N1CVal = N1C->getZExtValue();
2624 unsigned N2CVal = N2C->getZExtValue();
2625 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2626 (N1CVal & 0xffffU) == 0xffffU &&
2627 (N2CVal & 0xffffU) == 0x0U) {
2628 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002629 dl, MVT::i32);
Evan Cheng786b15f2009-10-21 08:15:52 +00002630 SDValue Ops[] = { N0.getOperand(0), Imm16,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002631 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002632 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002633 }
2634 }
2635 break;
2636 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002637 case ARMISD::VMOVRRD:
2638 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002639 N->getOperand(0), getAL(CurDAG, dl),
Dan Gohman32f71d72009-09-25 18:54:59 +00002640 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002641 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002642 if (Subtarget->isThumb1Only())
2643 break;
2644 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002645 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002646 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002647 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002648 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002649 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002650 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32),
Owen Anderson9f944592009-08-11 20:47:22 +00002651 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002652 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2653 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002654 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002655 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002656 }
Dan Gohmana1603612007-10-08 18:33:35 +00002657 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002658 if (Subtarget->isThumb1Only())
2659 break;
2660 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002661 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002662 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002663 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002664 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002665 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002666 getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32),
Owen Anderson9f944592009-08-11 20:47:22 +00002667 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002668 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2669 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002670 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002671 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002672 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002673 case ARMISD::UMLAL:{
2674 if (Subtarget->isThumb()) {
2675 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002676 N->getOperand(3), getAL(CurDAG, dl),
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002677 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002678 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002679 }else{
2680 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002681 N->getOperand(3), getAL(CurDAG, dl),
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002682 CurDAG->getRegister(0, MVT::i32),
2683 CurDAG->getRegister(0, MVT::i32) };
2684 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2685 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002686 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002687 }
2688 }
2689 case ARMISD::SMLAL:{
2690 if (Subtarget->isThumb()) {
2691 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002692 N->getOperand(3), getAL(CurDAG, dl),
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002693 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002694 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002695 }else{
2696 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002697 N->getOperand(3), getAL(CurDAG, dl),
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002698 CurDAG->getRegister(0, MVT::i32),
2699 CurDAG->getRegister(0, MVT::i32) };
2700 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2701 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002702 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002703 }
2704 }
Evan Cheng10043e22007-01-19 07:51:42 +00002705 case ISD::LOAD: {
Craig Topper062a2ba2014-04-25 05:30:21 +00002706 SDNode *ResNode = nullptr;
Evan Chengb24e51e2009-07-07 01:17:28 +00002707 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002708 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002709 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002710 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002711 if (ResNode)
2712 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002713 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002714 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002715 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002716 case ARMISD::BRCOND: {
2717 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2718 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2719 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002720
Evan Cheng7e90b112007-07-05 07:15:27 +00002721 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2722 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2723 // Pattern complexity = 6 cost = 1 size = 0
2724
David Goodwin27303cd2009-06-30 18:04:13 +00002725 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2726 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2727 // Pattern complexity = 6 cost = 1 size = 0
2728
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002729 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002730 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002731 SDValue Chain = N->getOperand(0);
2732 SDValue N1 = N->getOperand(1);
2733 SDValue N2 = N->getOperand(2);
2734 SDValue N3 = N->getOperand(3);
2735 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002736 assert(N1.getOpcode() == ISD::BasicBlock);
2737 assert(N2.getOpcode() == ISD::Constant);
2738 assert(N3.getOpcode() == ISD::Register);
2739
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002740 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002741 cast<ConstantSDNode>(N2)->getZExtValue()), dl,
Owen Anderson9f944592009-08-11 20:47:22 +00002742 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002743 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002744 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002745 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002746 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002747 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002748 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002749 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002750 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002751 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002752 SDValue(Chain.getNode(), Chain.getResNo()));
Craig Topper062a2ba2014-04-25 05:30:21 +00002753 return nullptr;
Evan Cheng7e90b112007-07-05 07:15:27 +00002754 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002755 case ARMISD::VZIP: {
2756 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002757 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002758 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002759 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002760 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2761 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2762 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002763 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2764 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002765 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2766 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2767 case MVT::v4f32:
2768 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2769 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002770 SDValue Pred = getAL(CurDAG, dl);
Evan Chenga33fc862009-11-21 06:21:52 +00002771 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2772 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002773 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002774 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002775 case ARMISD::VUZP: {
2776 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002777 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002778 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002779 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002780 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2781 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2782 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002783 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2784 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002785 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2786 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2787 case MVT::v4f32:
2788 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2789 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002790 SDValue Pred = getAL(CurDAG, dl);
Evan Chenga33fc862009-11-21 06:21:52 +00002791 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2792 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002793 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002794 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002795 case ARMISD::VTRN: {
2796 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002797 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002798 switch (VT.getSimpleVT().SimpleTy) {
Craig Topper062a2ba2014-04-25 05:30:21 +00002799 default: return nullptr;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002800 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2801 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2802 case MVT::v2f32:
2803 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2804 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2805 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2806 case MVT::v4f32:
2807 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2808 }
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00002809 SDValue Pred = getAL(CurDAG, dl);
Evan Chenga33fc862009-11-21 06:21:52 +00002810 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2811 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002812 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002813 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002814 case ARMISD::BUILD_VECTOR: {
2815 EVT VecVT = N->getValueType(0);
2816 EVT EltVT = VecVT.getVectorElementType();
2817 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002818 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002819 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002820 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002821 }
Duncan Sands14627772010-11-03 12:17:33 +00002822 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002823 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002824 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002825 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002826 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002827 N->getOperand(2), N->getOperand(3));
2828 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002829
Bob Wilson2d790df2010-11-28 06:51:26 +00002830 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002831 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2832 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002833 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002834 }
2835
Bob Wilson77ab1652010-11-29 19:35:29 +00002836 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002837 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2838 ARM::VLD3DUPd16Pseudo,
2839 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002840 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002841 }
2842
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002843 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002844 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2845 ARM::VLD4DUPd16Pseudo,
2846 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002847 return SelectVLDDup(N, false, 4, Opcodes);
2848 }
2849
2850 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002851 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2852 ARM::VLD2DUPd16wb_fixed,
2853 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002854 return SelectVLDDup(N, true, 2, Opcodes);
2855 }
2856
2857 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002858 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2859 ARM::VLD3DUPd16Pseudo_UPD,
2860 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002861 return SelectVLDDup(N, true, 3, Opcodes);
2862 }
2863
2864 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002865 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2866 ARM::VLD4DUPd16Pseudo_UPD,
2867 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002868 return SelectVLDDup(N, true, 4, Opcodes);
2869 }
2870
2871 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002872 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2873 ARM::VLD1d16wb_fixed,
2874 ARM::VLD1d32wb_fixed,
2875 ARM::VLD1d64wb_fixed };
2876 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2877 ARM::VLD1q16wb_fixed,
2878 ARM::VLD1q32wb_fixed,
2879 ARM::VLD1q64wb_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002880 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002881 }
2882
2883 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002884 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2885 ARM::VLD2d16wb_fixed,
2886 ARM::VLD2d32wb_fixed,
2887 ARM::VLD1q64wb_fixed};
2888 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2889 ARM::VLD2q16PseudoWB_fixed,
2890 ARM::VLD2q32PseudoWB_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002891 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002892 }
2893
2894 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002895 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2896 ARM::VLD3d16Pseudo_UPD,
2897 ARM::VLD3d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002898 ARM::VLD1d64TPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002899 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2900 ARM::VLD3q16Pseudo_UPD,
2901 ARM::VLD3q32Pseudo_UPD };
2902 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2903 ARM::VLD3q16oddPseudo_UPD,
2904 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002905 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2906 }
2907
2908 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002909 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2910 ARM::VLD4d16Pseudo_UPD,
2911 ARM::VLD4d32Pseudo_UPD,
Jiangning Liu4df23632014-01-16 09:16:13 +00002912 ARM::VLD1d64QPseudoWB_fixed};
Craig Topper01736f82012-05-24 05:17:00 +00002913 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2914 ARM::VLD4q16Pseudo_UPD,
2915 ARM::VLD4q32Pseudo_UPD };
2916 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2917 ARM::VLD4q16oddPseudo_UPD,
2918 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002919 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2920 }
2921
2922 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002923 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2924 ARM::VLD2LNd16Pseudo_UPD,
2925 ARM::VLD2LNd32Pseudo_UPD };
2926 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2927 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002928 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2929 }
2930
2931 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002932 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2933 ARM::VLD3LNd16Pseudo_UPD,
2934 ARM::VLD3LNd32Pseudo_UPD };
2935 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2936 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002937 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2938 }
2939
2940 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002941 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2942 ARM::VLD4LNd16Pseudo_UPD,
2943 ARM::VLD4LNd32Pseudo_UPD };
2944 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2945 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002946 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2947 }
2948
2949 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002950 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2951 ARM::VST1d16wb_fixed,
2952 ARM::VST1d32wb_fixed,
2953 ARM::VST1d64wb_fixed };
2954 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2955 ARM::VST1q16wb_fixed,
2956 ARM::VST1q32wb_fixed,
2957 ARM::VST1q64wb_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002958 return SelectVST(N, true, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002959 }
2960
2961 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002962 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2963 ARM::VST2d16wb_fixed,
2964 ARM::VST2d32wb_fixed,
2965 ARM::VST1q64wb_fixed};
2966 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2967 ARM::VST2q16PseudoWB_fixed,
2968 ARM::VST2q32PseudoWB_fixed };
Craig Topper062a2ba2014-04-25 05:30:21 +00002969 return SelectVST(N, true, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilson06fce872011-02-07 17:43:21 +00002970 }
2971
2972 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002973 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2974 ARM::VST3d16Pseudo_UPD,
2975 ARM::VST3d32Pseudo_UPD,
2976 ARM::VST1d64TPseudoWB_fixed};
2977 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2978 ARM::VST3q16Pseudo_UPD,
2979 ARM::VST3q32Pseudo_UPD };
2980 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2981 ARM::VST3q16oddPseudo_UPD,
2982 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002983 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2984 }
2985
2986 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002987 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2988 ARM::VST4d16Pseudo_UPD,
2989 ARM::VST4d32Pseudo_UPD,
2990 ARM::VST1d64QPseudoWB_fixed};
2991 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2992 ARM::VST4q16Pseudo_UPD,
2993 ARM::VST4q32Pseudo_UPD };
2994 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2995 ARM::VST4q16oddPseudo_UPD,
2996 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002997 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2998 }
2999
3000 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003001 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
3002 ARM::VST2LNd16Pseudo_UPD,
3003 ARM::VST2LNd32Pseudo_UPD };
3004 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
3005 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003006 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
3007 }
3008
3009 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003010 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
3011 ARM::VST3LNd16Pseudo_UPD,
3012 ARM::VST3LNd32Pseudo_UPD };
3013 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
3014 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003015 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
3016 }
3017
3018 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00003019 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
3020 ARM::VST4LNd16Pseudo_UPD,
3021 ARM::VST4LNd32Pseudo_UPD };
3022 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
3023 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00003024 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00003025 }
3026
Bob Wilsone0636a72009-08-26 17:39:53 +00003027 case ISD::INTRINSIC_VOID:
3028 case ISD::INTRINSIC_W_CHAIN: {
3029 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00003030 switch (IntNo) {
3031 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003032 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003033
Tim Northover1ff5f292014-03-26 14:39:31 +00003034 case Intrinsic::arm_ldaexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003035 case Intrinsic::arm_ldrexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003036 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003037 SDValue Chain = N->getOperand(0);
Tim Northover1ff5f292014-03-26 14:39:31 +00003038 SDValue MemAddr = N->getOperand(2);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003039 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
Tim Northover1ff5f292014-03-26 14:39:31 +00003040
3041 bool IsAcquire = IntNo == Intrinsic::arm_ldaexd;
3042 unsigned NewOpc = isThumb ? (IsAcquire ? ARM::t2LDAEXD : ARM::t2LDREXD)
3043 : (IsAcquire ? ARM::LDAEXD : ARM::LDREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003044
3045 // arm_ldrexd returns a i64 value in {i32, i32}
3046 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003047 if (isThumb) {
3048 ResTys.push_back(MVT::i32);
3049 ResTys.push_back(MVT::i32);
3050 } else
3051 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003052 ResTys.push_back(MVT::Other);
3053
Weiming Zhao8f56f882012-11-16 21:55:34 +00003054 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003055 SmallVector<SDValue, 7> Ops;
3056 Ops.push_back(MemAddr);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003057 Ops.push_back(getAL(CurDAG, dl));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003058 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3059 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00003060 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003061 // Transfer memoperands.
3062 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3063 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3064 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3065
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003066 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00003067 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003068 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003069 SDValue Result;
3070 if (isThumb)
3071 Result = SDValue(Ld, 0);
3072 else {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003073 SDValue SubRegIdx =
3074 CurDAG->getTargetConstant(ARM::gsub_0, dl, MVT::i32);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003075 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003076 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003077 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003078 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003079 ReplaceUses(SDValue(N, 0), Result);
3080 }
3081 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003082 SDValue Result;
3083 if (isThumb)
3084 Result = SDValue(Ld, 1);
3085 else {
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003086 SDValue SubRegIdx =
3087 CurDAG->getTargetConstant(ARM::gsub_1, dl, MVT::i32);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003088 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003089 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003090 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003091 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003092 ReplaceUses(SDValue(N, 1), Result);
3093 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003094 ReplaceUses(SDValue(N, 2), OutChain);
Craig Topper062a2ba2014-04-25 05:30:21 +00003095 return nullptr;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003096 }
Tim Northover1ff5f292014-03-26 14:39:31 +00003097 case Intrinsic::arm_stlexd:
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003098 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003099 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003100 SDValue Chain = N->getOperand(0);
3101 SDValue Val0 = N->getOperand(2);
3102 SDValue Val1 = N->getOperand(3);
3103 SDValue MemAddr = N->getOperand(4);
3104
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003105 // Store exclusive double return a i32 value which is the return status
3106 // of the issued store.
Benjamin Kramer867bfc52015-03-07 17:41:00 +00003107 const EVT ResTys[] = {MVT::i32, MVT::Other};
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003108
Weiming Zhao8f56f882012-11-16 21:55:34 +00003109 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3110 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003111 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003112 if (isThumb) {
3113 Ops.push_back(Val0);
3114 Ops.push_back(Val1);
3115 } else
3116 // arm_strexd uses GPRPair.
3117 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003118 Ops.push_back(MemAddr);
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003119 Ops.push_back(getAL(CurDAG, dl));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003120 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3121 Ops.push_back(Chain);
3122
Tim Northover1ff5f292014-03-26 14:39:31 +00003123 bool IsRelease = IntNo == Intrinsic::arm_stlexd;
3124 unsigned NewOpc = isThumb ? (IsRelease ? ARM::t2STLEXD : ARM::t2STREXD)
3125 : (IsRelease ? ARM::STLEXD : ARM::STREXD);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003126
Michael Liaob53d8962013-04-19 22:22:57 +00003127 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003128 // Transfer memoperands.
3129 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3130 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3131 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3132
3133 return St;
3134 }
3135
Bob Wilson340861d2010-03-23 05:25:43 +00003136 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003137 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3138 ARM::VLD1d32, ARM::VLD1d64 };
3139 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3140 ARM::VLD1q32, ARM::VLD1q64};
Craig Topper062a2ba2014-04-25 05:30:21 +00003141 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilson340861d2010-03-23 05:25:43 +00003142 }
3143
Bob Wilsone0636a72009-08-26 17:39:53 +00003144 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003145 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3146 ARM::VLD2d32, ARM::VLD1q64 };
3147 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3148 ARM::VLD2q32Pseudo };
Craig Topper062a2ba2014-04-25 05:30:21 +00003149 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilsone0636a72009-08-26 17:39:53 +00003150 }
3151
3152 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003153 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3154 ARM::VLD3d16Pseudo,
3155 ARM::VLD3d32Pseudo,
3156 ARM::VLD1d64TPseudo };
3157 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3158 ARM::VLD3q16Pseudo_UPD,
3159 ARM::VLD3q32Pseudo_UPD };
3160 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3161 ARM::VLD3q16oddPseudo,
3162 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003163 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003164 }
3165
3166 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003167 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3168 ARM::VLD4d16Pseudo,
3169 ARM::VLD4d32Pseudo,
3170 ARM::VLD1d64QPseudo };
3171 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3172 ARM::VLD4q16Pseudo_UPD,
3173 ARM::VLD4q32Pseudo_UPD };
3174 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3175 ARM::VLD4q16oddPseudo,
3176 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003177 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003178 }
3179
Bob Wilsonda9817c2009-09-01 04:26:28 +00003180 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003181 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3182 ARM::VLD2LNd16Pseudo,
3183 ARM::VLD2LNd32Pseudo };
3184 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3185 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003186 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003187 }
3188
3189 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003190 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3191 ARM::VLD3LNd16Pseudo,
3192 ARM::VLD3LNd32Pseudo };
3193 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3194 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003195 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003196 }
3197
3198 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003199 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3200 ARM::VLD4LNd16Pseudo,
3201 ARM::VLD4LNd32Pseudo };
3202 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3203 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003204 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003205 }
3206
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003207 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003208 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3209 ARM::VST1d32, ARM::VST1d64 };
3210 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3211 ARM::VST1q32, ARM::VST1q64 };
Craig Topper062a2ba2014-04-25 05:30:21 +00003212 return SelectVST(N, false, 1, DOpcodes, QOpcodes, nullptr);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003213 }
3214
Bob Wilsone0636a72009-08-26 17:39:53 +00003215 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003216 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3217 ARM::VST2d32, ARM::VST1q64 };
3218 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3219 ARM::VST2q32Pseudo };
Craig Topper062a2ba2014-04-25 05:30:21 +00003220 return SelectVST(N, false, 2, DOpcodes, QOpcodes, nullptr);
Bob Wilsone0636a72009-08-26 17:39:53 +00003221 }
3222
3223 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003224 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3225 ARM::VST3d16Pseudo,
3226 ARM::VST3d32Pseudo,
3227 ARM::VST1d64TPseudo };
3228 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3229 ARM::VST3q16Pseudo_UPD,
3230 ARM::VST3q32Pseudo_UPD };
3231 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3232 ARM::VST3q16oddPseudo,
3233 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003234 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003235 }
3236
3237 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003238 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3239 ARM::VST4d16Pseudo,
3240 ARM::VST4d32Pseudo,
3241 ARM::VST1d64QPseudo };
3242 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3243 ARM::VST4q16Pseudo_UPD,
3244 ARM::VST4q32Pseudo_UPD };
3245 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3246 ARM::VST4q16oddPseudo,
3247 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003248 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003249 }
Bob Wilsond7797752009-09-01 18:51:56 +00003250
3251 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003252 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3253 ARM::VST2LNd16Pseudo,
3254 ARM::VST2LNd32Pseudo };
3255 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3256 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003257 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003258 }
3259
3260 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003261 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3262 ARM::VST3LNd16Pseudo,
3263 ARM::VST3LNd32Pseudo };
3264 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3265 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003266 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003267 }
3268
3269 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003270 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3271 ARM::VST4LNd16Pseudo,
3272 ARM::VST4LNd32Pseudo };
3273 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3274 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003275 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003276 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003277 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003278 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003279 }
Evan Chengd85631e2010-05-05 18:28:36 +00003280
Bob Wilson3ed511b2010-07-06 23:36:25 +00003281 case ISD::INTRINSIC_WO_CHAIN: {
3282 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3283 switch (IntNo) {
3284 default:
3285 break;
3286
3287 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003288 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003289 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003290 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003291 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003292 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003293
3294 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003295 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003296 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003297 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003298 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003299 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003300 }
3301 break;
3302 }
3303
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003304 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003305 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003306 EVT VT = N->getValueType(0);
3307 SmallVector<SDValue, 6> Ops;
3308
3309 Ops.push_back(N->getOperand(0));
3310 Ops.push_back(N->getOperand(1));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003311 Ops.push_back(getAL(CurDAG, dl)); // Predicate
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003312 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003313 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003314 }
3315 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003316 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003317 EVT VT = N->getValueType(0);
3318
3319 // Form a REG_SEQUENCE to force register allocation.
3320 SDValue V0 = N->getOperand(0);
3321 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003322 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003323
3324 SmallVector<SDValue, 6> Ops;
3325 Ops.push_back(RegSeq);
3326 Ops.push_back(N->getOperand(2));
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003327 Ops.push_back(getAL(CurDAG, dl)); // Predicate
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003328 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003329 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003330 }
3331
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003332 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003333 return SelectConcatVector(N);
3334 }
Evan Chengd5021732008-12-10 21:54:21 +00003335
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003336 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003337}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003338
Weiming Zhaoc5987002013-02-14 18:10:21 +00003339SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3340 std::vector<SDValue> AsmNodeOperands;
3341 unsigned Flag, Kind;
3342 bool Changed = false;
3343 unsigned NumOps = N->getNumOperands();
3344
Weiming Zhaoc5987002013-02-14 18:10:21 +00003345 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3346 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3347 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3348 // respectively. Since there is no constraint to explicitly specify a
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003349 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3350 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3351 // them into a GPRPair.
Weiming Zhaoc5987002013-02-14 18:10:21 +00003352
Andrew Trickef9de2a2013-05-25 02:42:55 +00003353 SDLoc dl(N);
Craig Topper062a2ba2014-04-25 05:30:21 +00003354 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1)
3355 : SDValue(nullptr,0);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003356
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003357 SmallVector<bool, 8> OpChanged;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003358 // Glue node will be appended late.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003359 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
Weiming Zhaoc5987002013-02-14 18:10:21 +00003360 SDValue op = N->getOperand(i);
3361 AsmNodeOperands.push_back(op);
3362
3363 if (i < InlineAsm::Op_FirstOperand)
3364 continue;
3365
3366 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3367 Flag = C->getZExtValue();
3368 Kind = InlineAsm::getKind(Flag);
3369 }
3370 else
3371 continue;
3372
Joey Gouly392cdad2013-07-08 19:52:51 +00003373 // Immediate operands to inline asm in the SelectionDAG are modeled with
3374 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3375 // the second is a constant with the value of the immediate. If we get here
3376 // and we have a Kind_Imm, skip the next operand, and continue.
Joey Gouly606f3fb2013-07-05 10:19:40 +00003377 if (Kind == InlineAsm::Kind_Imm) {
3378 SDValue op = N->getOperand(++i);
3379 AsmNodeOperands.push_back(op);
3380 continue;
3381 }
3382
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003383 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3384 if (NumRegs)
3385 OpChanged.push_back(false);
3386
3387 unsigned DefIdx = 0;
3388 bool IsTiedToChangedOp = false;
3389 // If it's a use that is tied with a previous def, it has no
3390 // reg class constraint.
3391 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3392 IsTiedToChangedOp = OpChanged[DefIdx];
3393
Weiming Zhaoc5987002013-02-14 18:10:21 +00003394 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3395 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3396 continue;
3397
Weiming Zhaoc5987002013-02-14 18:10:21 +00003398 unsigned RC;
3399 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003400 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3401 || NumRegs != 2)
Weiming Zhaoc5987002013-02-14 18:10:21 +00003402 continue;
3403
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003404 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
Weiming Zhaoc5987002013-02-14 18:10:21 +00003405 SDValue V0 = N->getOperand(i+1);
3406 SDValue V1 = N->getOperand(i+2);
3407 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3408 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3409 SDValue PairedReg;
3410 MachineRegisterInfo &MRI = MF->getRegInfo();
3411
3412 if (Kind == InlineAsm::Kind_RegDef ||
3413 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3414 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3415 // the original GPRs.
3416
3417 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3418 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3419 SDValue Chain = SDValue(N,0);
3420
3421 SDNode *GU = N->getGluedUser();
3422 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3423 Chain.getValue(1));
3424
3425 // Extract values from a GPRPair reg and copy to the original GPR reg.
3426 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3427 RegCopy);
3428 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3429 RegCopy);
3430 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3431 RegCopy.getValue(1));
3432 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3433
3434 // Update the original glue user.
3435 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3436 Ops.push_back(T1.getValue(1));
Craig Topper8c0b4d02014-04-28 05:57:50 +00003437 CurDAG->UpdateNodeOperands(GU, Ops);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003438 }
3439 else {
3440 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3441 // GPRPair and then pass the GPRPair to the inline asm.
3442 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3443
3444 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3445 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3446 Chain.getValue(1));
3447 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3448 T0.getValue(1));
3449 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3450
3451 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3452 // i32 VRs of inline asm with it.
3453 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3454 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3455 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3456
3457 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3458 Glue = Chain.getValue(1);
3459 }
3460
3461 Changed = true;
3462
3463 if(PairedReg.getNode()) {
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003464 OpChanged[OpChanged.size() -1 ] = true;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003465 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
Tim Northover55349a22013-08-18 18:06:03 +00003466 if (IsTiedToChangedOp)
3467 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3468 else
3469 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003470 // Replace the current flag.
3471 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +00003472 Flag, dl, MVT::i32);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003473 // Add the new register node and skip the original two GPRs.
3474 AsmNodeOperands.push_back(PairedReg);
3475 // Skip the next two GPRs.
3476 i += 2;
3477 }
3478 }
3479
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003480 if (Glue.getNode())
3481 AsmNodeOperands.push_back(Glue);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003482 if (!Changed)
Craig Topper062a2ba2014-04-25 05:30:21 +00003483 return nullptr;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003484
Andrew Trickef9de2a2013-05-25 02:42:55 +00003485 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Craig Topper48d114b2014-04-26 18:35:24 +00003486 CurDAG->getVTList(MVT::Other, MVT::Glue), AsmNodeOperands);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003487 New->setNodeId(-1);
3488 return New.getNode();
3489}
3490
3491
Bob Wilsona2c462b2009-05-19 05:53:42 +00003492bool ARMDAGToDAGISel::
Daniel Sanders60f1db02015-03-13 12:45:09 +00003493SelectInlineAsmMemoryOperand(const SDValue &Op, unsigned ConstraintID,
Bob Wilsona2c462b2009-05-19 05:53:42 +00003494 std::vector<SDValue> &OutOps) {
Daniel Sanders60f1db02015-03-13 12:45:09 +00003495 assert(ConstraintID == InlineAsm::Constraint_m &&
3496 "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003497 // Require the address to be in a register. That is safe for all ARM
3498 // variants and it is hard to do anything much smarter without knowing
3499 // how the operand is used.
3500 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003501 return false;
3502}
3503
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003504/// createARMISelDag - This pass converts a legalized DAG into a
3505/// ARM-specific DAG, ready for instruction scheduling.
3506///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003507FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3508 CodeGenOpt::Level OptLevel) {
3509 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003510}