blob: 44e9dd15b1393e60864bb82ec886f9ba7e6a5cf8 [file] [log] [blame]
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesend679ff72010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng62c7b5b2010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chenga20cde32011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
Weiming Zhaoc5987002013-02-14 18:10:21 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000023#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SelectionDAGISel.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000025#include "llvm/IR/CallingConv.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DerivedTypes.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/Intrinsics.h"
30#include "llvm/IR/LLVMContext.h"
Evan Cheng8e6b40a2010-05-04 20:39:49 +000031#include "llvm/Support/CommandLine.h"
Chris Lattner1770fb82008-02-03 05:43:57 +000032#include "llvm/Support/Compiler.h"
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000033#include "llvm/Support/Debug.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000034#include "llvm/Support/ErrorHandling.h"
35#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/Target/TargetLowering.h"
37#include "llvm/Target/TargetOptions.h"
Torok Edwinfb8d6d52009-07-08 20:53:28 +000038
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000039using namespace llvm;
40
Evan Cheng59069ec2010-07-30 23:33:54 +000041static cl::opt<bool>
42DisableShifterOp("disable-shifter-op", cl::Hidden,
43 cl::desc("Disable isel of shifter-op"),
44 cl::init(false));
45
Evan Cheng62c7b5b2010-12-05 22:04:16 +000046static cl::opt<bool>
47CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
48 cl::desc("Check fp vmla / vmls hazard at isel time"),
Bob Wilson0858c3a2011-04-19 18:11:57 +000049 cl::init(true));
Evan Cheng62c7b5b2010-12-05 22:04:16 +000050
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000051//===--------------------------------------------------------------------===//
52/// ARMDAGToDAGISel - ARM specific code to select ARM machine
53/// instructions for SelectionDAG operations.
54///
55namespace {
Jim Grosbach08605202010-09-29 19:03:54 +000056
57enum AddrMode2Type {
58 AM2_BASE, // Simple AM2 (+-imm12)
59 AM2_SHOP // Shifter-op AM2
60};
61
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000062class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikov99152f32009-06-26 21:28:53 +000063 ARMBaseTargetMachine &TM;
Evan Chengbc0d0ec2008-09-18 07:24:33 +000064
Evan Cheng10043e22007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000069public:
Bob Wilson2dd957f2009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng62c7b5b2010-12-05 22:04:16 +000073 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindolaffdc24b2006-05-14 22:18:28 +000074 }
75
Evan Cheng10043e22007-01-19 07:51:42 +000076 virtual const char *getPassName() const {
77 return "ARM Instruction Selection";
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000078 }
79
Evan Chengeae6d2c2012-12-19 20:16:09 +000080 virtual void PreprocessISelDAG();
81
Bob Wilson4facd962009-10-08 18:51:31 +000082 /// getI32Imm - Return a target constant of type i32 with the specified
83 /// value.
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000084 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson9f944592009-08-11 20:47:22 +000085 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov02bb33c2009-06-17 18:13:58 +000086 }
87
Dan Gohmanea6f91f2010-01-05 01:24:18 +000088 SDNode *Select(SDNode *N);
Evan Cheng5e73ff22010-02-15 19:41:07 +000089
Evan Cheng62c7b5b2010-12-05 22:04:16 +000090
91 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Cheng59bbc542010-10-27 23:41:30 +000092 bool isShifterOpProfitable(const SDValue &Shift,
93 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Andersonb595ed02011-07-21 18:54:16 +000094 bool SelectRegShifterOperand(SDValue N, SDValue &A,
95 SDValue &B, SDValue &C,
96 bool CheckProfitability = true);
97 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson04912702011-07-21 23:38:37 +000098 SDValue &B, bool CheckProfitability = true);
99 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson6d557452011-03-18 19:46:58 +0000100 SDValue &B, SDValue &C) {
101 // Don't apply the profitability check
Owen Anderson04912702011-07-21 23:38:37 +0000102 return SelectRegShifterOperand(N, A, B, C, false);
103 }
104 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
105 SDValue &B) {
106 // Don't apply the profitability check
107 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson6d557452011-03-18 19:46:58 +0000108 }
109
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000110 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
111 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
112
Jim Grosbach08605202010-09-29 19:03:54 +0000113 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
114 SDValue &Offset, SDValue &Opc);
115 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
116 SDValue &Opc) {
117 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
118 }
119
120 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
121 SDValue &Opc) {
122 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
123 }
124
125 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
126 SDValue &Opc) {
127 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000128// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach08605202010-09-29 19:03:54 +0000129 // This always matches one way or another.
130 return true;
131 }
132
Tim Northover42180442013-08-22 09:57:11 +0000133 bool SelectCMOVPred(SDValue N, SDValue &Pred, SDValue &Reg) {
134 const ConstantSDNode *CN = cast<ConstantSDNode>(N);
135 Pred = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
136 Reg = CurDAG->getRegister(ARM::CPSR, MVT::i32);
137 return true;
138 }
139
Owen Anderson2aedba62011-07-26 20:54:26 +0000140 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
141 SDValue &Offset, SDValue &Opc);
142 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000143 SDValue &Offset, SDValue &Opc);
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000144 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
145 SDValue &Offset, SDValue &Opc);
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000146 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000147 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000148 SDValue &Offset, SDValue &Opc);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000149 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000150 SDValue &Offset, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000151 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000152 SDValue &Offset);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000153 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsone3ecd5f2011-02-25 06:42:42 +0000154 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000155
Evan Chengdfce83c2011-01-17 08:03:18 +0000156 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Cheng10043e22007-01-19 07:51:42 +0000157
Bill Wendling092a7bd2010-12-14 03:36:38 +0000158 // Thumb Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000159 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000160 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
161 unsigned Scale);
162 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
163 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
164 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
165 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
166 SDValue &OffImm);
167 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
168 SDValue &OffImm);
169 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
170 SDValue &OffImm);
171 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
172 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000173 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +0000174
Bill Wendling092a7bd2010-12-14 03:36:38 +0000175 // Thumb 2 Addressing Modes:
Chris Lattner0e023ea2010-09-21 20:31:19 +0000176 bool SelectT2ShifterOperandReg(SDValue N,
Evan Chengeab9ca72009-06-27 02:26:13 +0000177 SDValue &BaseReg, SDValue &Opc);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000178 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
179 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000180 SDValue &OffImm);
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000181 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +0000182 SDValue &OffImm);
Chris Lattner0e023ea2010-09-21 20:31:19 +0000183 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Chengb23b50d2009-06-29 07:51:04 +0000184 SDValue &OffReg, SDValue &ShImm);
Tim Northovera7ecd242013-07-16 09:46:55 +0000185 bool SelectT2AddrModeExclusive(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chengb23b50d2009-06-29 07:51:04 +0000186
Evan Cheng0fc80842010-11-12 22:42:47 +0000187 inline bool is_so_imm(unsigned Imm) const {
188 return ARM_AM::getSOImmVal(Imm) != -1;
189 }
190
191 inline bool is_so_imm_not(unsigned Imm) const {
192 return ARM_AM::getSOImmVal(~Imm) != -1;
193 }
194
195 inline bool is_t2_so_imm(unsigned Imm) const {
196 return ARM_AM::getT2SOImmVal(Imm) != -1;
197 }
198
199 inline bool is_t2_so_imm_not(unsigned Imm) const {
200 return ARM_AM::getT2SOImmVal(~Imm) != -1;
201 }
202
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000203 // Include the pieces autogenerated from the target description.
204#include "ARMGenDAGISel.inc"
Bob Wilsona2c462b2009-05-19 05:53:42 +0000205
206private:
Evan Cheng84c6cda2009-07-02 07:28:31 +0000207 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
208 /// ARM.
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000209 SDNode *SelectARMIndexedLoad(SDNode *N);
210 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Cheng84c6cda2009-07-02 07:28:31 +0000211
Bob Wilson340861d2010-03-23 05:25:43 +0000212 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
213 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson12b47992009-10-14 17:28:52 +0000214 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson340861d2010-03-23 05:25:43 +0000215 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000216 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000217 const uint16_t *DOpcodes,
218 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson12b47992009-10-14 17:28:52 +0000219
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000220 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000221 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000222 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilsoncc0a2a72010-03-23 06:20:33 +0000223 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson06fce872011-02-07 17:43:21 +0000224 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000225 const uint16_t *DOpcodes,
226 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilsonc350cdf2009-10-14 18:32:29 +0000227
Bob Wilson93117bc2009-10-14 16:46:45 +0000228 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilson4145e3a2009-10-14 16:19:03 +0000229 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilsond5c57a52010-09-13 23:01:35 +0000230 /// load/store of D registers and Q registers.
Bob Wilson06fce872011-02-07 17:43:21 +0000231 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
232 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000233 const uint16_t *DOpcodes, const uint16_t *QOpcodes);
Bob Wilson4145e3a2009-10-14 16:19:03 +0000234
Bob Wilson2d790df2010-11-28 06:51:26 +0000235 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
236 /// should be 2, 3 or 4. The opcode array specifies the instructions used
237 /// for loading D registers. (Q registers are not supported.)
Bob Wilson06fce872011-02-07 17:43:21 +0000238 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +0000239 const uint16_t *Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +0000240
Bob Wilson5bc8a792010-07-07 00:08:54 +0000241 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
242 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
243 /// generated to force the table registers to be consecutive.
244 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilson3ed511b2010-07-06 23:36:25 +0000245
Sandeep Patel7460e082009-10-13 20:25:58 +0000246 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach825cb292010-04-22 23:24:18 +0000247 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel423e42b2009-10-13 18:59:48 +0000248
Bill Wendlinga7d697e2011-10-10 22:59:55 +0000249 // Select special operations if node forms integer ABS pattern
250 SDNode *SelectABSOp(SDNode *N);
251
Weiming Zhaoc5987002013-02-14 18:10:21 +0000252 SDNode *SelectInlineAsm(SDNode *N);
253
Evan Chengd85631e2010-05-05 18:28:36 +0000254 SDNode *SelectConcatVector(SDNode *N);
255
Amara Emersonb4ad2f32013-09-26 12:22:36 +0000256 SDNode *SelectAtomic(SDNode *N, unsigned Op8, unsigned Op16, unsigned Op32, unsigned Op64);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +0000257
Evan Chengd9c55362009-07-02 01:23:32 +0000258 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
259 /// inline asm expressions.
260 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
261 char ConstraintCode,
262 std::vector<SDValue> &OutOps);
Bob Wilsone6b778d2009-10-06 22:01:59 +0000263
Weiming Zhao95782222012-11-17 00:23:35 +0000264 // Form pairs of consecutive R, S, D, or Q registers.
Weiming Zhao8f56f882012-11-16 21:55:34 +0000265 SDNode *createGPRPairNode(EVT VT, SDValue V0, SDValue V1);
Weiming Zhao95782222012-11-17 00:23:35 +0000266 SDNode *createSRegPairNode(EVT VT, SDValue V0, SDValue V1);
267 SDNode *createDRegPairNode(EVT VT, SDValue V0, SDValue V1);
268 SDNode *createQRegPairNode(EVT VT, SDValue V0, SDValue V1);
Evan Chengc2ae5f52010-05-10 17:34:18 +0000269
Bob Wilsond8a9a042010-06-04 00:04:02 +0000270 // Form sequences of 4 consecutive S, D, or Q registers.
Weiming Zhao95782222012-11-17 00:23:35 +0000271 SDNode *createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
272 SDNode *createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
273 SDNode *createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +0000274
275 // Get the alignment operand for a NEON VLD or VST instruction.
276 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000277};
Evan Cheng10043e22007-01-19 07:51:42 +0000278}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +0000279
Sandeep Patel423e42b2009-10-13 18:59:48 +0000280/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
281/// operand. If so Imm will receive the 32-bit value.
282static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
283 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
284 Imm = cast<ConstantSDNode>(N)->getZExtValue();
285 return true;
286 }
287 return false;
288}
289
290// isInt32Immediate - This method tests to see if a constant operand.
291// If so Imm will receive the 32 bit value.
292static bool isInt32Immediate(SDValue N, unsigned &Imm) {
293 return isInt32Immediate(N.getNode(), Imm);
294}
295
296// isOpcWithIntImmediate - This method tests to see if the node is a specific
297// opcode and that it has a immediate integer right operand.
298// If so Imm will receive the 32 bit value.
299static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
300 return N->getOpcode() == Opc &&
301 isInt32Immediate(N->getOperand(1).getNode(), Imm);
302}
303
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000304/// \brief Check whether a particular node is a constant value representable as
Dmitri Gribenko5485acd2012-09-14 14:57:36 +0000305/// (N * Scale) where (N in [\p RangeMin, \p RangeMax).
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000306///
307/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000308static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000309 int RangeMin, int RangeMax,
310 int &ScaledConstant) {
Jakob Stoklund Olesen2056d152011-09-23 22:10:33 +0000311 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000312
313 // Check that this is a constant.
314 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
315 if (!C)
316 return false;
317
318 ScaledConstant = (int) C->getZExtValue();
319 if ((ScaledConstant % Scale) != 0)
320 return false;
321
322 ScaledConstant /= Scale;
323 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
324}
325
Evan Chengeae6d2c2012-12-19 20:16:09 +0000326void ARMDAGToDAGISel::PreprocessISelDAG() {
327 if (!Subtarget->hasV6T2Ops())
328 return;
329
330 bool isThumb2 = Subtarget->isThumb();
331 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
332 E = CurDAG->allnodes_end(); I != E; ) {
333 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
334
335 if (N->getOpcode() != ISD::ADD)
336 continue;
337
338 // Look for (add X1, (and (srl X2, c1), c2)) where c2 is constant with
339 // leading zeros, followed by consecutive set bits, followed by 1 or 2
340 // trailing zeros, e.g. 1020.
341 // Transform the expression to
342 // (add X1, (shl (and (srl X2, c1), (c2>>tz)), tz)) where tz is the number
343 // of trailing zeros of c2. The left shift would be folded as an shifter
344 // operand of 'add' and the 'and' and 'srl' would become a bits extraction
345 // node (UBFX).
346
347 SDValue N0 = N->getOperand(0);
348 SDValue N1 = N->getOperand(1);
349 unsigned And_imm = 0;
350 if (!isOpcWithIntImmediate(N1.getNode(), ISD::AND, And_imm)) {
351 if (isOpcWithIntImmediate(N0.getNode(), ISD::AND, And_imm))
352 std::swap(N0, N1);
353 }
354 if (!And_imm)
355 continue;
356
357 // Check if the AND mask is an immediate of the form: 000.....1111111100
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000358 unsigned TZ = countTrailingZeros(And_imm);
Evan Chengeae6d2c2012-12-19 20:16:09 +0000359 if (TZ != 1 && TZ != 2)
360 // Be conservative here. Shifter operands aren't always free. e.g. On
361 // Swift, left shifter operand of 1 / 2 for free but others are not.
362 // e.g.
363 // ubfx r3, r1, #16, #8
364 // ldr.w r3, [r0, r3, lsl #2]
365 // vs.
366 // mov.w r9, #1020
367 // and.w r2, r9, r1, lsr #14
368 // ldr r2, [r0, r2]
369 continue;
370 And_imm >>= TZ;
371 if (And_imm & (And_imm + 1))
372 continue;
373
374 // Look for (and (srl X, c1), c2).
375 SDValue Srl = N1.getOperand(0);
376 unsigned Srl_imm = 0;
377 if (!isOpcWithIntImmediate(Srl.getNode(), ISD::SRL, Srl_imm) ||
378 (Srl_imm <= 2))
379 continue;
380
381 // Make sure first operand is not a shifter operand which would prevent
382 // folding of the left shift.
383 SDValue CPTmp0;
384 SDValue CPTmp1;
385 SDValue CPTmp2;
386 if (isThumb2) {
387 if (SelectT2ShifterOperandReg(N0, CPTmp0, CPTmp1))
388 continue;
389 } else {
390 if (SelectImmShifterOperand(N0, CPTmp0, CPTmp1) ||
391 SelectRegShifterOperand(N0, CPTmp0, CPTmp1, CPTmp2))
392 continue;
393 }
394
395 // Now make the transformation.
Andrew Trickef9de2a2013-05-25 02:42:55 +0000396 Srl = CurDAG->getNode(ISD::SRL, SDLoc(Srl), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000397 Srl.getOperand(0),
398 CurDAG->getConstant(Srl_imm+TZ, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000399 N1 = CurDAG->getNode(ISD::AND, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000400 Srl, CurDAG->getConstant(And_imm, MVT::i32));
Andrew Trickef9de2a2013-05-25 02:42:55 +0000401 N1 = CurDAG->getNode(ISD::SHL, SDLoc(N1), MVT::i32,
Evan Chengeae6d2c2012-12-19 20:16:09 +0000402 N1, CurDAG->getConstant(TZ, MVT::i32));
403 CurDAG->UpdateNodeOperands(N, N0, N1);
404 }
405}
406
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000407/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
408/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
409/// least on current ARM implementations) which should be avoidded.
410bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
411 if (OptLevel == CodeGenOpt::None)
412 return true;
413
414 if (!CheckVMLxHazard)
415 return true;
Bob Wilsone8a549c2012-09-29 21:43:49 +0000416
Silviu Baranga91ddaa12013-07-29 09:25:50 +0000417 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9() &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000418 !Subtarget->isSwift())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000419 return true;
420
421 if (!N->hasOneUse())
422 return false;
423
424 SDNode *Use = *N->use_begin();
425 if (Use->getOpcode() == ISD::CopyToReg)
426 return true;
427 if (Use->isMachineOpcode()) {
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000428 const ARMBaseInstrInfo *TII =
429 static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
430
Evan Cheng6cc775f2011-06-28 19:10:37 +0000431 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
432 if (MCID.mayStore())
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000433 return true;
Evan Cheng6cc775f2011-06-28 19:10:37 +0000434 unsigned Opcode = MCID.getOpcode();
Evan Cheng62c7b5b2010-12-05 22:04:16 +0000435 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
436 return true;
437 // vmlx feeding into another vmlx. We actually want to unfold
438 // the use later in the MLxExpansion pass. e.g.
439 // vmla
440 // vmla (stall 8 cycles)
441 //
442 // vmul (5 cycles)
443 // vadd (5 cycles)
444 // vmla
445 // This adds up to about 18 - 19 cycles.
446 //
447 // vmla
448 // vmul (stall 4 cycles)
449 // vadd adds up to about 14 cycles.
450 return TII->isFpMLxInstruction(Opcode);
451 }
452
453 return false;
454}
Sandeep Patel423e42b2009-10-13 18:59:48 +0000455
Evan Cheng59bbc542010-10-27 23:41:30 +0000456bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
457 ARM_AM::ShiftOpc ShOpcVal,
458 unsigned ShAmt) {
Bob Wilsone8a549c2012-09-29 21:43:49 +0000459 if (!Subtarget->isLikeA9() && !Subtarget->isSwift())
Evan Cheng59bbc542010-10-27 23:41:30 +0000460 return true;
461 if (Shift.hasOneUse())
462 return true;
463 // R << 2 is free.
Bob Wilsone8a549c2012-09-29 21:43:49 +0000464 return ShOpcVal == ARM_AM::lsl &&
465 (ShAmt == 2 || (Subtarget->isSwift() && ShAmt == 1));
Evan Cheng59bbc542010-10-27 23:41:30 +0000466}
467
Owen Andersonb595ed02011-07-21 18:54:16 +0000468bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +0000469 SDValue &BaseReg,
Owen Anderson6d557452011-03-18 19:46:58 +0000470 SDValue &Opc,
471 bool CheckProfitability) {
Evan Cheng59069ec2010-07-30 23:33:54 +0000472 if (DisableShifterOp)
473 return false;
474
Evan Chenga20cde32011-07-20 23:34:39 +0000475 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +0000476
477 // Don't match base register only case. That is matched to a separate
478 // lower complexity pattern with explicit register operand.
479 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000480
Evan Chengb23b50d2009-06-29 07:51:04 +0000481 BaseReg = N.getOperand(0);
482 unsigned ShImmVal = 0;
Owen Andersonb595ed02011-07-21 18:54:16 +0000483 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
484 if (!RHS) return false;
Owen Andersonb595ed02011-07-21 18:54:16 +0000485 ShImmVal = RHS->getZExtValue() & 31;
Evan Cheng59bbc542010-10-27 23:41:30 +0000486 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
487 MVT::i32);
488 return true;
489}
490
Owen Andersonb595ed02011-07-21 18:54:16 +0000491bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
492 SDValue &BaseReg,
493 SDValue &ShReg,
494 SDValue &Opc,
495 bool CheckProfitability) {
496 if (DisableShifterOp)
497 return false;
498
499 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
500
501 // Don't match base register only case. That is matched to a separate
502 // lower complexity pattern with explicit register operand.
503 if (ShOpcVal == ARM_AM::no_shift) return false;
504
505 BaseReg = N.getOperand(0);
506 unsigned ShImmVal = 0;
507 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
508 if (RHS) return false;
509
510 ShReg = N.getOperand(1);
511 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
512 return false;
513 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
514 MVT::i32);
515 return true;
516}
517
518
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000519bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
520 SDValue &Base,
521 SDValue &OffImm) {
522 // Match simple R + imm12 operands.
523
524 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +0000525 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
526 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000527 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000528 // Match frame index.
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000529 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000530 Base = CurDAG->getTargetFrameIndex(FI,
531 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000532 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
533 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +0000534 }
Owen Anderson6d557452011-03-18 19:46:58 +0000535
Chris Lattner46c01a32011-02-13 22:25:43 +0000536 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000537 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000538 Base = N.getOperand(0);
539 } else
540 Base = N;
541 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
542 return true;
543 }
544
545 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
546 int RHSC = (int)RHS->getZExtValue();
547 if (N.getOpcode() == ISD::SUB)
548 RHSC = -RHSC;
549
550 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
551 Base = N.getOperand(0);
552 if (Base.getOpcode() == ISD::FrameIndex) {
553 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000554 Base = CurDAG->getTargetFrameIndex(FI,
555 getTargetLowering()->getPointerTy());
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000556 }
557 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
558 return true;
559 }
560 }
561
562 // Base only.
563 Base = N;
564 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
565 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),
589 MVT::i32);
590 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),
660 MVT::i32);
661 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),
Owen Anderson9f944592009-08-11 20:47:22 +0000688 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();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000701 Base = CurDAG->getTargetFrameIndex(FI,
702 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000703 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000704 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000705 Base = N.getOperand(0);
706 }
Owen Anderson9f944592009-08-11 20:47:22 +0000707 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000708 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
709 ARM_AM::no_shift),
Owen Anderson9f944592009-08-11 20:47:22 +0000710 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000711 return AM2_BASE;
Rafael Espindola708cb602006-11-08 17:07:32 +0000712 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000713
Evan Cheng10043e22007-01-19 07:51:42 +0000714 // Match simple R +/- imm12 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +0000715 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000716 int RHSC;
717 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
718 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
719 Base = N.getOperand(0);
720 if (Base.getOpcode() == ISD::FrameIndex) {
721 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000722 Base = CurDAG->getTargetFrameIndex(FI,
723 getTargetLowering()->getPointerTy());
Rafael Espindola708cb602006-11-08 17:07:32 +0000724 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000725 Offset = CurDAG->getRegister(0, MVT::i32);
726
727 ARM_AM::AddrOpc AddSub = ARM_AM::add;
728 if (RHSC < 0) {
729 AddSub = ARM_AM::sub;
730 RHSC = - RHSC;
731 }
732 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
733 ARM_AM::no_shift),
734 MVT::i32);
735 return AM2_BASE;
Evan Cheng10043e22007-01-19 07:51:42 +0000736 }
Jim Grosbachc7b10f32010-09-29 17:32:29 +0000737 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000738
Bob Wilsone8a549c2012-09-29 21:43:49 +0000739 if ((Subtarget->isLikeA9() || Subtarget->isSwift()) && !N.hasOneUse()) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000740 // Compute R +/- (R << N) and reuse it.
741 Base = N;
742 Offset = CurDAG->getRegister(0, MVT::i32);
743 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
744 ARM_AM::no_shift),
745 MVT::i32);
746 return AM2_BASE;
747 }
748
Johnny Chenb678a562009-10-27 17:25:15 +0000749 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner46c01a32011-02-13 22:25:43 +0000750 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chenga20cde32011-07-20 23:34:39 +0000751 ARM_AM::ShiftOpc ShOpcVal =
752 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000753 unsigned ShAmt = 0;
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000754
Evan Cheng10043e22007-01-19 07:51:42 +0000755 Base = N.getOperand(0);
756 Offset = N.getOperand(1);
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000757
Evan Cheng10043e22007-01-19 07:51:42 +0000758 if (ShOpcVal != ARM_AM::no_shift) {
759 // Check to see if the RHS of the shift is a constant, if not, we can't fold
760 // it.
761 if (ConstantSDNode *Sh =
762 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000763 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000764 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
765 Offset = N.getOperand(1).getOperand(0);
766 else {
767 ShAmt = 0;
768 ShOpcVal = ARM_AM::no_shift;
769 }
Evan Cheng10043e22007-01-19 07:51:42 +0000770 } else {
771 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola708cb602006-11-08 17:07:32 +0000772 }
773 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000774
Evan Cheng10043e22007-01-19 07:51:42 +0000775 // Try matching (R shl C) + (R).
Chris Lattner46c01a32011-02-13 22:25:43 +0000776 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Bob Wilsone8a549c2012-09-29 21:43:49 +0000777 !(Subtarget->isLikeA9() || Subtarget->isSwift() ||
778 N.getOperand(0).hasOneUse())) {
Evan Chenga20cde32011-07-20 23:34:39 +0000779 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000780 if (ShOpcVal != ARM_AM::no_shift) {
781 // Check to see if the RHS of the shift is a constant, if not, we can't
782 // fold it.
783 if (ConstantSDNode *Sh =
784 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000785 ShAmt = Sh->getZExtValue();
Cameron Zwarich842f99a2011-10-05 23:39:02 +0000786 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Cheng59bbc542010-10-27 23:41:30 +0000787 Offset = N.getOperand(0).getOperand(0);
788 Base = N.getOperand(1);
789 } else {
790 ShAmt = 0;
791 ShOpcVal = ARM_AM::no_shift;
792 }
Evan Cheng10043e22007-01-19 07:51:42 +0000793 } else {
794 ShOpcVal = ARM_AM::no_shift;
795 }
796 }
797 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000798
Evan Cheng10043e22007-01-19 07:51:42 +0000799 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000800 MVT::i32);
Jim Grosbach08605202010-09-29 19:03:54 +0000801 return AM2_SHOP;
Rafael Espindola708cb602006-11-08 17:07:32 +0000802}
803
Owen Anderson2aedba62011-07-26 20:54:26 +0000804bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000805 SDValue &Offset, SDValue &Opc) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +0000806 unsigned Opcode = Op->getOpcode();
Evan Cheng10043e22007-01-19 07:51:42 +0000807 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
808 ? cast<LoadSDNode>(Op)->getAddressingMode()
809 : cast<StoreSDNode>(Op)->getAddressingMode();
810 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
811 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000812 int Val;
Owen Anderson2aedba62011-07-26 20:54:26 +0000813 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
814 return false;
Evan Cheng10043e22007-01-19 07:51:42 +0000815
816 Offset = N;
Evan Chenga20cde32011-07-20 23:34:39 +0000817 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng10043e22007-01-19 07:51:42 +0000818 unsigned ShAmt = 0;
819 if (ShOpcVal != ARM_AM::no_shift) {
820 // Check to see if the RHS of the shift is a constant, if not, we can't fold
821 // it.
822 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +0000823 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +0000824 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
825 Offset = N.getOperand(0);
826 else {
827 ShAmt = 0;
828 ShOpcVal = ARM_AM::no_shift;
829 }
Evan Cheng10043e22007-01-19 07:51:42 +0000830 } else {
831 ShOpcVal = ARM_AM::no_shift;
832 }
833 }
834
835 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson9f944592009-08-11 20:47:22 +0000836 MVT::i32);
Rafael Espindola19398ec2006-10-17 18:04:53 +0000837 return true;
838}
839
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000840bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
841 SDValue &Offset, SDValue &Opc) {
Owen Anderson939cd212011-08-31 20:00:11 +0000842 unsigned Opcode = Op->getOpcode();
843 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
844 ? cast<LoadSDNode>(Op)->getAddressingMode()
845 : cast<StoreSDNode>(Op)->getAddressingMode();
846 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
847 ? ARM_AM::add : ARM_AM::sub;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000848 int Val;
849 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Anderson939cd212011-08-31 20:00:11 +0000850 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Anderson4d5c8f82011-08-29 20:16:50 +0000851 Offset = CurDAG->getRegister(0, MVT::i32);
852 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
853 return true;
854 }
855
856 return false;
857}
858
859
Owen Anderson2aedba62011-07-26 20:54:26 +0000860bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
861 SDValue &Offset, SDValue &Opc) {
862 unsigned Opcode = Op->getOpcode();
863 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
864 ? cast<LoadSDNode>(Op)->getAddressingMode()
865 : cast<StoreSDNode>(Op)->getAddressingMode();
866 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
867 ? ARM_AM::add : ARM_AM::sub;
868 int Val;
869 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
870 Offset = CurDAG->getRegister(0, MVT::i32);
871 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
872 ARM_AM::no_shift),
873 MVT::i32);
874 return true;
875 }
876
877 return false;
878}
879
Jim Grosbachf0c95ca2011-08-05 20:35:44 +0000880bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
881 Base = N;
882 return true;
883}
Evan Cheng10043e22007-01-19 07:51:42 +0000884
Chris Lattner0e023ea2010-09-21 20:31:19 +0000885bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000886 SDValue &Base, SDValue &Offset,
887 SDValue &Opc) {
Evan Cheng10043e22007-01-19 07:51:42 +0000888 if (N.getOpcode() == ISD::SUB) {
889 // X - C is canonicalize to X + -C, no need to handle it here.
890 Base = N.getOperand(0);
891 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000892 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000893 return true;
894 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000895
Chris Lattner46c01a32011-02-13 22:25:43 +0000896 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000897 Base = N;
898 if (N.getOpcode() == ISD::FrameIndex) {
899 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000900 Base = CurDAG->getTargetFrameIndex(FI,
901 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000902 }
Owen Anderson9f944592009-08-11 20:47:22 +0000903 Offset = CurDAG->getRegister(0, MVT::i32);
904 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000905 return true;
906 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000907
Evan Cheng10043e22007-01-19 07:51:42 +0000908 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000909 int RHSC;
910 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
911 -256 + 1, 256, RHSC)) { // 8 bits.
912 Base = N.getOperand(0);
913 if (Base.getOpcode() == ISD::FrameIndex) {
914 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000915 Base = CurDAG->getTargetFrameIndex(FI,
916 getTargetLowering()->getPointerTy());
Evan Cheng10043e22007-01-19 07:51:42 +0000917 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000918 Offset = CurDAG->getRegister(0, MVT::i32);
919
920 ARM_AM::AddrOpc AddSub = ARM_AM::add;
921 if (RHSC < 0) {
922 AddSub = ARM_AM::sub;
Chris Lattner46c01a32011-02-13 22:25:43 +0000923 RHSC = -RHSC;
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000924 }
925 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
926 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000927 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000928
Evan Cheng10043e22007-01-19 07:51:42 +0000929 Base = N.getOperand(0);
930 Offset = N.getOperand(1);
Owen Anderson9f944592009-08-11 20:47:22 +0000931 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), 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);
946 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
947 return true;
Evan Cheng10043e22007-01-19 07:51:42 +0000948 }
949
950 Offset = N;
Owen Anderson9f944592009-08-11 20:47:22 +0000951 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000952 return true;
953}
954
Jim Grosbachd37f0712010-10-21 19:38:40 +0000955bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000956 SDValue &Base, SDValue &Offset) {
Chris Lattner46c01a32011-02-13 22:25:43 +0000957 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng10043e22007-01-19 07:51:42 +0000958 Base = N;
959 if (N.getOpcode() == ISD::FrameIndex) {
960 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000961 Base = CurDAG->getTargetFrameIndex(FI,
962 getTargetLowering()->getPointerTy());
Anton Korobeynikov25229082009-11-24 00:44:37 +0000963 } else if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +0000964 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng10043e22007-01-19 07:51:42 +0000965 Base = N.getOperand(0);
966 }
967 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson9f944592009-08-11 20:47:22 +0000968 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +0000969 return true;
970 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000971
Evan Cheng10043e22007-01-19 07:51:42 +0000972 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +0000973 int RHSC;
974 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
975 -256 + 1, 256, RHSC)) {
976 Base = N.getOperand(0);
977 if (Base.getOpcode() == ISD::FrameIndex) {
978 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000979 Base = CurDAG->getTargetFrameIndex(FI,
980 getTargetLowering()->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),
989 MVT::i32);
990 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),
Owen Anderson9f944592009-08-11 20:47:22 +0000995 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;
1004 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
1005 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
1006 // The maximum alignment is equal to the memory size being referenced.
1007 unsigned LSNAlign = LSN->getAlignment();
1008 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesene5a6adc2011-10-27 22:39:16 +00001009 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001010 Alignment = MemSize;
1011 } else {
1012 // All other uses of addrmode6 are for intrinsics. For now just record
1013 // the raw alignment value; it will be refined later based on the legal
1014 // alignment operands for the intrinsic.
1015 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
1016 }
1017
1018 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsondeb35af2009-07-01 23:16:05 +00001019 return true;
1020}
1021
Bob Wilsone3ecd5f2011-02-25 06:42:42 +00001022bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
1023 SDValue &Offset) {
1024 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
1025 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
1026 if (AM != ISD::POST_INC)
1027 return false;
1028 Offset = N;
1029 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
1030 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
1031 Offset = CurDAG->getRegister(0, MVT::i32);
1032 }
1033 return true;
1034}
1035
Chris Lattner0e023ea2010-09-21 20:31:19 +00001036bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Cheng9a58aff2009-08-14 19:01:37 +00001037 SDValue &Offset, SDValue &Label) {
Evan Cheng10043e22007-01-19 07:51:42 +00001038 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
1039 Offset = N.getOperand(0);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001040 SDValue N1 = N.getOperand(1);
Evan Chengb8b0ad82011-01-20 08:34:58 +00001041 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
1042 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001043 return true;
1044 }
Bill Wendling092a7bd2010-12-14 03:36:38 +00001045
Evan Cheng10043e22007-01-19 07:51:42 +00001046 return false;
1047}
1048
Bill Wendling092a7bd2010-12-14 03:36:38 +00001049
1050//===----------------------------------------------------------------------===//
1051// Thumb Addressing Modes
1052//===----------------------------------------------------------------------===//
1053
Chris Lattner0e023ea2010-09-21 20:31:19 +00001054bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001055 SDValue &Base, SDValue &Offset){
Chris Lattner46c01a32011-02-13 22:25:43 +00001056 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng0794c6a2009-07-11 07:08:13 +00001057 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmanf1d83042010-06-18 14:22:04 +00001058 if (!NC || !NC->isNullValue())
Evan Cheng0794c6a2009-07-11 07:08:13 +00001059 return false;
1060
1061 Base = Offset = N;
Evan Chengc0b73662007-01-23 22:59:13 +00001062 return true;
1063 }
1064
Evan Cheng10043e22007-01-19 07:51:42 +00001065 Base = N.getOperand(0);
1066 Offset = N.getOperand(1);
1067 return true;
1068}
1069
Evan Cheng139edae2007-01-24 02:21:22 +00001070bool
Bill Wendling092a7bd2010-12-14 03:36:38 +00001071ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
1072 SDValue &Offset, unsigned Scale) {
Evan Cheng139edae2007-01-24 02:21:22 +00001073 if (Scale == 4) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001074 SDValue TmpBase, TmpOffImm;
Chris Lattner0e023ea2010-09-21 20:31:19 +00001075 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng139edae2007-01-24 02:21:22 +00001076 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendling092a7bd2010-12-14 03:36:38 +00001077
Evan Cheng1526ba52007-01-24 08:53:17 +00001078 if (N.getOpcode() == ARMISD::Wrapper &&
1079 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1080 return false; // We want to select tLDRpci instead.
Evan Cheng139edae2007-01-24 02:21:22 +00001081 }
1082
Chris Lattner46c01a32011-02-13 22:25:43 +00001083 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendling832a5da2010-12-15 01:03:19 +00001084 return false;
Evan Cheng10043e22007-01-19 07:51:42 +00001085
Evan Cheng650d0672007-02-06 00:22:06 +00001086 // Thumb does not have [sp, r] address mode.
1087 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1088 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1089 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling832a5da2010-12-15 01:03:19 +00001090 (RHSR && RHSR->getReg() == ARM::SP))
1091 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001092
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001093 // FIXME: Why do we explicitly check for a match here and then return false?
1094 // Presumably to allow something else to match, but shouldn't this be
1095 // documented?
1096 int RHSC;
1097 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1098 return false;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001099
1100 Base = N.getOperand(0);
1101 Offset = N.getOperand(1);
1102 return true;
1103}
1104
1105bool
1106ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1107 SDValue &Base,
1108 SDValue &Offset) {
1109 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1110}
1111
1112bool
1113ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1114 SDValue &Base,
1115 SDValue &Offset) {
1116 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1117}
1118
1119bool
1120ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1121 SDValue &Base,
1122 SDValue &Offset) {
1123 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1124}
1125
1126bool
1127ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1128 SDValue &Base, SDValue &OffImm) {
1129 if (Scale == 4) {
1130 SDValue TmpBase, TmpOffImm;
1131 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1132 return false; // We want to select tLDRspi / tSTRspi instead.
1133
1134 if (N.getOpcode() == ARMISD::Wrapper &&
1135 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1136 return false; // We want to select tLDRpci instead.
1137 }
1138
Chris Lattner46c01a32011-02-13 22:25:43 +00001139 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001140 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001141 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Bill Wendling092a7bd2010-12-14 03:36:38 +00001142 Base = N.getOperand(0);
1143 } else {
1144 Base = N;
1145 }
1146
Owen Anderson9f944592009-08-11 20:47:22 +00001147 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng650d0672007-02-06 00:22:06 +00001148 return true;
1149 }
1150
Bill Wendling832a5da2010-12-15 01:03:19 +00001151 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1152 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1153 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1154 (RHSR && RHSR->getReg() == ARM::SP)) {
1155 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1156 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1157 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1158 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1159
1160 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1161 if (LHSC != 0 || RHSC != 0) return false;
1162
1163 Base = N;
1164 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1165 return true;
1166 }
1167
Evan Cheng10043e22007-01-19 07:51:42 +00001168 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001169 int RHSC;
1170 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1171 Base = N.getOperand(0);
1172 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1173 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001174 }
1175
Evan Chengc0b73662007-01-23 22:59:13 +00001176 Base = N.getOperand(0);
Owen Anderson9f944592009-08-11 20:47:22 +00001177 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc0b73662007-01-23 22:59:13 +00001178 return true;
Evan Cheng10043e22007-01-19 07:51:42 +00001179}
1180
Bill Wendling092a7bd2010-12-14 03:36:38 +00001181bool
1182ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1183 SDValue &OffImm) {
1184 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001185}
1186
Bill Wendling092a7bd2010-12-14 03:36:38 +00001187bool
1188ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1189 SDValue &OffImm) {
1190 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001191}
1192
Bill Wendling092a7bd2010-12-14 03:36:38 +00001193bool
1194ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1195 SDValue &OffImm) {
1196 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Cheng10043e22007-01-19 07:51:42 +00001197}
1198
Chris Lattner0e023ea2010-09-21 20:31:19 +00001199bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1200 SDValue &Base, SDValue &OffImm) {
Evan Cheng10043e22007-01-19 07:51:42 +00001201 if (N.getOpcode() == ISD::FrameIndex) {
1202 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001203 Base = CurDAG->getTargetFrameIndex(FI,
1204 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001205 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +00001206 return true;
1207 }
Evan Cheng139edae2007-01-24 02:21:22 +00001208
Chris Lattner46c01a32011-02-13 22:25:43 +00001209 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Cheng650d0672007-02-06 00:22:06 +00001210 return false;
1211
1212 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Chenga9740312007-02-06 09:11:20 +00001213 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1214 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng139edae2007-01-24 02:21:22 +00001215 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001216 int RHSC;
1217 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1218 Base = N.getOperand(0);
1219 if (Base.getOpcode() == ISD::FrameIndex) {
1220 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001221 Base = CurDAG->getTargetFrameIndex(FI,
1222 getTargetLowering()->getPointerTy());
Evan Cheng139edae2007-01-24 02:21:22 +00001223 }
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001224 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1225 return true;
Evan Cheng139edae2007-01-24 02:21:22 +00001226 }
1227 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001228
Evan Cheng10043e22007-01-19 07:51:42 +00001229 return false;
1230}
1231
Bill Wendling092a7bd2010-12-14 03:36:38 +00001232
1233//===----------------------------------------------------------------------===//
1234// Thumb 2 Addressing Modes
1235//===----------------------------------------------------------------------===//
1236
1237
Chris Lattner0e023ea2010-09-21 20:31:19 +00001238bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Chengeab9ca72009-06-27 02:26:13 +00001239 SDValue &Opc) {
Evan Cheng59069ec2010-07-30 23:33:54 +00001240 if (DisableShifterOp)
1241 return false;
1242
Evan Chenga20cde32011-07-20 23:34:39 +00001243 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chengeab9ca72009-06-27 02:26:13 +00001244
1245 // Don't match base register only case. That is matched to a separate
1246 // lower complexity pattern with explicit register operand.
1247 if (ShOpcVal == ARM_AM::no_shift) return false;
1248
1249 BaseReg = N.getOperand(0);
1250 unsigned ShImmVal = 0;
1251 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1252 ShImmVal = RHS->getZExtValue() & 31;
1253 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1254 return true;
1255 }
1256
1257 return false;
1258}
1259
Chris Lattner0e023ea2010-09-21 20:31:19 +00001260bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001261 SDValue &Base, SDValue &OffImm) {
1262 // Match simple R + imm12 operands.
David Goodwin802a0b52009-07-20 15:55:39 +00001263
Evan Cheng36064672009-08-11 08:52:18 +00001264 // Base only.
Chris Lattner46c01a32011-02-13 22:25:43 +00001265 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1266 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin802a0b52009-07-20 15:55:39 +00001267 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner46c01a32011-02-13 22:25:43 +00001268 // Match frame index.
David Goodwin802a0b52009-07-20 15:55:39 +00001269 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001270 Base = CurDAG->getTargetFrameIndex(FI,
1271 getTargetLowering()->getPointerTy());
Owen Anderson9f944592009-08-11 20:47:22 +00001272 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin802a0b52009-07-20 15:55:39 +00001273 return true;
Chris Lattner46c01a32011-02-13 22:25:43 +00001274 }
Owen Anderson6d557452011-03-18 19:46:58 +00001275
Chris Lattner46c01a32011-02-13 22:25:43 +00001276 if (N.getOpcode() == ARMISD::Wrapper &&
Tim Northover72360d22013-12-02 10:35:41 +00001277 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress) {
Evan Cheng36064672009-08-11 08:52:18 +00001278 Base = N.getOperand(0);
1279 if (Base.getOpcode() == ISD::TargetConstantPool)
1280 return false; // We want to select t2LDRpci instead.
1281 } else
1282 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001283 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001284 return true;
David Goodwin802a0b52009-07-20 15:55:39 +00001285 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001286
1287 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner0e023ea2010-09-21 20:31:19 +00001288 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng36064672009-08-11 08:52:18 +00001289 // Let t2LDRi8 handle (R - imm8).
1290 return false;
1291
Evan Chengb23b50d2009-06-29 07:51:04 +00001292 int RHSC = (int)RHS->getZExtValue();
David Goodwin79c079b2009-07-30 18:56:48 +00001293 if (N.getOpcode() == ISD::SUB)
1294 RHSC = -RHSC;
1295
1296 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Chengb23b50d2009-06-29 07:51:04 +00001297 Base = N.getOperand(0);
David Goodwin79c079b2009-07-30 18:56:48 +00001298 if (Base.getOpcode() == ISD::FrameIndex) {
1299 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001300 Base = CurDAG->getTargetFrameIndex(FI,
1301 getTargetLowering()->getPointerTy());
David Goodwin79c079b2009-07-30 18:56:48 +00001302 }
Owen Anderson9f944592009-08-11 20:47:22 +00001303 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001304 return true;
1305 }
1306 }
1307
Evan Cheng36064672009-08-11 08:52:18 +00001308 // Base only.
1309 Base = N;
Owen Anderson9f944592009-08-11 20:47:22 +00001310 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng36064672009-08-11 08:52:18 +00001311 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001312}
1313
Chris Lattner0e023ea2010-09-21 20:31:19 +00001314bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001315 SDValue &Base, SDValue &OffImm) {
David Goodwin79c079b2009-07-30 18:56:48 +00001316 // Match simple R - imm8 operands.
Chris Lattner46c01a32011-02-13 22:25:43 +00001317 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1318 !CurDAG->isBaseWithConstantOffset(N))
1319 return false;
Owen Anderson6d557452011-03-18 19:46:58 +00001320
Chris Lattner46c01a32011-02-13 22:25:43 +00001321 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1322 int RHSC = (int)RHS->getSExtValue();
1323 if (N.getOpcode() == ISD::SUB)
1324 RHSC = -RHSC;
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001325
Chris Lattner46c01a32011-02-13 22:25:43 +00001326 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1327 Base = N.getOperand(0);
1328 if (Base.getOpcode() == ISD::FrameIndex) {
1329 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00001330 Base = CurDAG->getTargetFrameIndex(FI,
1331 getTargetLowering()->getPointerTy());
Evan Chengb23b50d2009-06-29 07:51:04 +00001332 }
Chris Lattner46c01a32011-02-13 22:25:43 +00001333 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1334 return true;
Evan Chengb23b50d2009-06-29 07:51:04 +00001335 }
1336 }
1337
1338 return false;
1339}
1340
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001341bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Cheng84c6cda2009-07-02 07:28:31 +00001342 SDValue &OffImm){
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001343 unsigned Opcode = Op->getOpcode();
Evan Cheng84c6cda2009-07-02 07:28:31 +00001344 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1345 ? cast<LoadSDNode>(Op)->getAddressingMode()
1346 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbare0cd9ac2011-01-19 15:12:16 +00001347 int RHSC;
1348 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1349 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1350 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1351 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1352 return true;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001353 }
1354
1355 return false;
1356}
1357
Chris Lattner0e023ea2010-09-21 20:31:19 +00001358bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Chengb23b50d2009-06-29 07:51:04 +00001359 SDValue &Base,
1360 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng36064672009-08-11 08:52:18 +00001361 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner46c01a32011-02-13 22:25:43 +00001362 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng36064672009-08-11 08:52:18 +00001363 return false;
Evan Chengb23b50d2009-06-29 07:51:04 +00001364
Evan Cheng36064672009-08-11 08:52:18 +00001365 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1366 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1367 int RHSC = (int)RHS->getZExtValue();
1368 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1369 return false;
1370 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwin79c079b2009-07-30 18:56:48 +00001371 return false;
1372 }
1373
Evan Chengb23b50d2009-06-29 07:51:04 +00001374 // Look for (R + R) or (R + (R << [1,2,3])).
1375 unsigned ShAmt = 0;
1376 Base = N.getOperand(0);
1377 OffReg = N.getOperand(1);
1378
1379 // Swap if it is ((R << c) + R).
Evan Chenga20cde32011-07-20 23:34:39 +00001380 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001381 if (ShOpcVal != ARM_AM::lsl) {
Evan Chenga20cde32011-07-20 23:34:39 +00001382 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Chengb23b50d2009-06-29 07:51:04 +00001383 if (ShOpcVal == ARM_AM::lsl)
1384 std::swap(Base, OffReg);
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001385 }
1386
Evan Chengb23b50d2009-06-29 07:51:04 +00001387 if (ShOpcVal == ARM_AM::lsl) {
1388 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1389 // it.
1390 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1391 ShAmt = Sh->getZExtValue();
Evan Cheng59bbc542010-10-27 23:41:30 +00001392 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1393 OffReg = OffReg.getOperand(0);
1394 else {
Evan Chengb23b50d2009-06-29 07:51:04 +00001395 ShAmt = 0;
1396 ShOpcVal = ARM_AM::no_shift;
Evan Cheng59bbc542010-10-27 23:41:30 +00001397 }
Evan Chengb23b50d2009-06-29 07:51:04 +00001398 } else {
1399 ShOpcVal = ARM_AM::no_shift;
1400 }
David Goodwinf3912052009-07-15 15:50:19 +00001401 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00001402
Owen Anderson9f944592009-08-11 20:47:22 +00001403 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Chengb23b50d2009-06-29 07:51:04 +00001404
1405 return true;
1406}
1407
Tim Northovera7ecd242013-07-16 09:46:55 +00001408bool ARMDAGToDAGISel::SelectT2AddrModeExclusive(SDValue N, SDValue &Base,
1409 SDValue &OffImm) {
1410 // This *must* succeed since it's used for the irreplacable ldrex and strex
1411 // instructions.
1412 Base = N;
1413 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1414
1415 if (N.getOpcode() != ISD::ADD || !CurDAG->isBaseWithConstantOffset(N))
1416 return true;
1417
1418 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1419 if (!RHS)
1420 return true;
1421
1422 uint32_t RHSC = (int)RHS->getZExtValue();
1423 if (RHSC > 1020 || RHSC % 4 != 0)
1424 return true;
1425
1426 Base = N.getOperand(0);
1427 if (Base.getOpcode() == ISD::FrameIndex) {
1428 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1429 Base = CurDAG->getTargetFrameIndex(FI, getTargetLowering()->getPointerTy());
1430 }
1431
1432 OffImm = CurDAG->getTargetConstant(RHSC / 4, MVT::i32);
1433 return true;
1434}
1435
Evan Chengb23b50d2009-06-29 07:51:04 +00001436//===--------------------------------------------------------------------===//
1437
Evan Cheng7e90b112007-07-05 07:15:27 +00001438/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00001439static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson9f944592009-08-11 20:47:22 +00001440 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng0f7cbe82007-05-15 01:29:07 +00001441}
1442
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001443SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1444 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengd9c55362009-07-02 01:23:32 +00001445 ISD::MemIndexedMode AM = LD->getAddressingMode();
1446 if (AM == ISD::UNINDEXED)
1447 return NULL;
1448
Owen Anderson53aa7a92009-08-10 22:56:29 +00001449 EVT LoadedVT = LD->getMemoryVT();
Evan Chengd9c55362009-07-02 01:23:32 +00001450 SDValue Offset, AMOpc;
1451 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1452 unsigned Opcode = 0;
1453 bool Match = false;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001454 if (LoadedVT == MVT::i32 && isPre &&
1455 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1456 Opcode = ARM::LDR_PRE_IMM;
1457 Match = true;
1458 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson2aedba62011-07-26 20:54:26 +00001459 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001460 Opcode = ARM::LDR_POST_IMM;
Evan Chengd9c55362009-07-02 01:23:32 +00001461 Match = true;
Owen Anderson2aedba62011-07-26 20:54:26 +00001462 } else if (LoadedVT == MVT::i32 &&
1463 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson16d33f32011-08-26 20:43:14 +00001464 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson2aedba62011-07-26 20:54:26 +00001465 Match = true;
1466
Owen Anderson9f944592009-08-11 20:47:22 +00001467 } else if (LoadedVT == MVT::i16 &&
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001468 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001469 Match = true;
1470 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1471 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1472 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson9f944592009-08-11 20:47:22 +00001473 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengd9c55362009-07-02 01:23:32 +00001474 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001475 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001476 Match = true;
1477 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1478 }
1479 } else {
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001480 if (isPre &&
1481 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengd9c55362009-07-02 01:23:32 +00001482 Match = true;
Owen Anderson4d5c8f82011-08-29 20:16:50 +00001483 Opcode = ARM::LDRB_PRE_IMM;
1484 } else if (!isPre &&
1485 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1486 Match = true;
1487 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson2aedba62011-07-26 20:54:26 +00001488 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1489 Match = true;
Owen Anderson16d33f32011-08-26 20:43:14 +00001490 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengd9c55362009-07-02 01:23:32 +00001491 }
1492 }
1493 }
1494
1495 if (Match) {
Owen Andersonfd60f602011-08-26 21:12:37 +00001496 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1497 SDValue Chain = LD->getChain();
1498 SDValue Base = LD->getBasePtr();
1499 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1500 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001501 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001502 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001503 } else {
1504 SDValue Chain = LD->getChain();
1505 SDValue Base = LD->getBasePtr();
1506 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1507 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001508 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001509 MVT::i32, MVT::Other, Ops);
Owen Andersonfd60f602011-08-26 21:12:37 +00001510 }
Evan Chengd9c55362009-07-02 01:23:32 +00001511 }
1512
1513 return NULL;
1514}
1515
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001516SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1517 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001518 ISD::MemIndexedMode AM = LD->getAddressingMode();
1519 if (AM == ISD::UNINDEXED)
1520 return NULL;
1521
Owen Anderson53aa7a92009-08-10 22:56:29 +00001522 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001523 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001524 SDValue Offset;
1525 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1526 unsigned Opcode = 0;
1527 bool Match = false;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001528 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson9f944592009-08-11 20:47:22 +00001529 switch (LoadedVT.getSimpleVT().SimpleTy) {
1530 case MVT::i32:
Evan Cheng84c6cda2009-07-02 07:28:31 +00001531 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1532 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001533 case MVT::i16:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001534 if (isSExtLd)
1535 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1536 else
1537 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001538 break;
Owen Anderson9f944592009-08-11 20:47:22 +00001539 case MVT::i8:
1540 case MVT::i1:
Evan Cheng8ecd7eb2009-07-02 23:16:11 +00001541 if (isSExtLd)
1542 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1543 else
1544 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Cheng84c6cda2009-07-02 07:28:31 +00001545 break;
1546 default:
1547 return NULL;
1548 }
1549 Match = true;
1550 }
1551
1552 if (Match) {
1553 SDValue Chain = LD->getChain();
1554 SDValue Base = LD->getBasePtr();
1555 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00001556 CurDAG->getRegister(0, MVT::i32), Chain };
Andrew Trickef9de2a2013-05-25 02:42:55 +00001557 return CurDAG->getMachineNode(Opcode, SDLoc(N), MVT::i32, MVT::i32,
Michael Liaob53d8962013-04-19 22:22:57 +00001558 MVT::Other, Ops);
Evan Cheng84c6cda2009-07-02 07:28:31 +00001559 }
1560
1561 return NULL;
1562}
1563
Weiming Zhao8f56f882012-11-16 21:55:34 +00001564/// \brief Form a GPRPair pseudo register from a pair of GPR regs.
1565SDNode *ARMDAGToDAGISel::createGPRPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001566 SDLoc dl(V0.getNode());
Weiming Zhao8f56f882012-11-16 21:55:34 +00001567 SDValue RegClass =
1568 CurDAG->getTargetConstant(ARM::GPRPairRegClassID, MVT::i32);
1569 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
1570 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
1571 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001572 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Weiming Zhao8f56f882012-11-16 21:55:34 +00001573}
1574
Weiming Zhao95782222012-11-17 00:23:35 +00001575/// \brief Form a D register from a pair of S registers.
1576SDNode *ARMDAGToDAGISel::createSRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001577 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001578 SDValue RegClass =
1579 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001580 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1581 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001582 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001583 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001584}
1585
Weiming Zhao95782222012-11-17 00:23:35 +00001586/// \brief Form a quad register from a pair of D registers.
1587SDNode *ARMDAGToDAGISel::createDRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001588 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001589 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001590 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1591 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001592 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001593 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsone6b778d2009-10-06 22:01:59 +00001594}
1595
Weiming Zhao95782222012-11-17 00:23:35 +00001596/// \brief Form 4 consecutive D registers from a pair of Q registers.
1597SDNode *ARMDAGToDAGISel::createQRegPairNode(EVT VT, SDValue V0, SDValue V1) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001598 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001599 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001600 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1601 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001602 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
Michael Liaob53d8962013-04-19 22:22:57 +00001603 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001604}
1605
Weiming Zhao95782222012-11-17 00:23:35 +00001606/// \brief Form 4 consecutive S registers.
1607SDNode *ARMDAGToDAGISel::createQuadSRegsNode(EVT VT, SDValue V0, SDValue V1,
Bob Wilsond8a9a042010-06-04 00:04:02 +00001608 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001609 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001610 SDValue RegClass =
1611 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001612 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1613 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1614 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1615 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001616 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1617 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001618 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Bob Wilsond8a9a042010-06-04 00:04:02 +00001619}
1620
Weiming Zhao95782222012-11-17 00:23:35 +00001621/// \brief Form 4 consecutive D registers.
1622SDNode *ARMDAGToDAGISel::createQuadDRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Chengc2ae5f52010-05-10 17:34:18 +00001623 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001624 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001625 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001626 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1627 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1628 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1629 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001630 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1631 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001632 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Chengc2ae5f52010-05-10 17:34:18 +00001633}
1634
Weiming Zhao95782222012-11-17 00:23:35 +00001635/// \brief Form 4 consecutive Q registers.
1636SDNode *ARMDAGToDAGISel::createQuadQRegsNode(EVT VT, SDValue V0, SDValue V1,
Evan Cheng298e6b82010-05-16 03:27:48 +00001637 SDValue V2, SDValue V3) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00001638 SDLoc dl(V0.getNode());
Owen Anderson5fc8b772011-06-16 18:17:13 +00001639 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen6c47d642010-05-24 16:54:32 +00001640 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1641 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1642 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1643 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson5fc8b772011-06-16 18:17:13 +00001644 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1645 V2, SubReg2, V3, SubReg3 };
Michael Liaob53d8962013-04-19 22:22:57 +00001646 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops);
Evan Cheng298e6b82010-05-16 03:27:48 +00001647}
1648
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001649/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1650/// of a NEON VLD or VST instruction. The supported values depend on the
1651/// number of registers being loaded.
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001652SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1653 bool is64BitVector) {
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001654 unsigned NumRegs = NumVecs;
1655 if (!is64BitVector && NumVecs < 3)
1656 NumRegs *= 2;
1657
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001658 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001659 if (Alignment >= 32 && NumRegs == 4)
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001660 Alignment = 32;
1661 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1662 Alignment = 16;
1663 else if (Alignment >= 8)
1664 Alignment = 8;
1665 else
1666 Alignment = 0;
1667
1668 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001669}
1670
Jim Grosbach2098cb12011-10-24 21:45:13 +00001671// Get the register stride update opcode of a VLD/VST instruction that
1672// is otherwise equivalent to the given fixed stride updating instruction.
1673static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1674 switch (Opc) {
1675 default: break;
1676 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1677 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1678 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1679 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1680 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1681 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1682 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1683 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach05df4602011-10-31 21:50:31 +00001684
1685 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1686 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1687 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1688 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1689 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1690 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1691 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1692 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbach98d032f2011-11-29 22:38:04 +00001693 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach5ee209c2011-11-29 22:58:48 +00001694 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001695
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001696 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1697 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1698 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbachd146a022011-12-09 21:28:25 +00001699 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1700 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1701 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1702
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001703 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1704 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1705 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbach88ac7612011-12-14 21:32:11 +00001706 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1707 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1708 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbachc80a2642011-12-21 19:40:55 +00001709
Jim Grosbach13a292c2012-03-06 22:01:44 +00001710 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1711 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1712 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach2098cb12011-10-24 21:45:13 +00001713 }
1714 return Opc; // If not one we handle, return it unchanged.
1715}
1716
Bob Wilson06fce872011-02-07 17:43:21 +00001717SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001718 const uint16_t *DOpcodes,
1719 const uint16_t *QOpcodes0,
1720 const uint16_t *QOpcodes1) {
Bob Wilson340861d2010-03-23 05:25:43 +00001721 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001722 SDLoc dl(N);
Bob Wilson12b47992009-10-14 17:28:52 +00001723
Bob Wilsonae08a732010-03-20 22:13:40 +00001724 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001725 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1726 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson12b47992009-10-14 17:28:52 +00001727 return NULL;
1728
1729 SDValue Chain = N->getOperand(0);
1730 EVT VT = N->getValueType(0);
1731 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001732 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson9eeb8902010-09-23 21:43:54 +00001733
Bob Wilson12b47992009-10-14 17:28:52 +00001734 unsigned OpcodeIndex;
1735 switch (VT.getSimpleVT().SimpleTy) {
1736 default: llvm_unreachable("unhandled vld type");
1737 // Double-register operations:
1738 case MVT::v8i8: OpcodeIndex = 0; break;
1739 case MVT::v4i16: OpcodeIndex = 1; break;
1740 case MVT::v2f32:
1741 case MVT::v2i32: OpcodeIndex = 2; break;
1742 case MVT::v1i64: OpcodeIndex = 3; break;
1743 // Quad-register operations:
1744 case MVT::v16i8: OpcodeIndex = 0; break;
1745 case MVT::v8i16: OpcodeIndex = 1; break;
1746 case MVT::v4f32:
1747 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson340861d2010-03-23 05:25:43 +00001748 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001749 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson340861d2010-03-23 05:25:43 +00001750 break;
Bob Wilson12b47992009-10-14 17:28:52 +00001751 }
1752
Bob Wilson35fafca2010-09-03 18:16:02 +00001753 EVT ResTy;
1754 if (NumVecs == 1)
1755 ResTy = VT;
1756 else {
1757 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1758 if (!is64BitVector)
1759 ResTyElts *= 2;
1760 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1761 }
Bob Wilson06fce872011-02-07 17:43:21 +00001762 std::vector<EVT> ResTys;
1763 ResTys.push_back(ResTy);
1764 if (isUpdating)
1765 ResTys.push_back(MVT::i32);
1766 ResTys.push_back(MVT::Other);
Bob Wilson35fafca2010-09-03 18:16:02 +00001767
Evan Cheng3da64f762010-04-16 05:46:06 +00001768 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001769 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001770 SDNode *VLd;
1771 SmallVector<SDValue, 7> Ops;
Evan Cheng630063a2010-05-10 21:26:24 +00001772
Bob Wilson06fce872011-02-07 17:43:21 +00001773 // Double registers and VLD1/VLD2 quad registers are directly supported.
1774 if (is64BitVector || NumVecs <= 2) {
1775 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1776 QOpcodes0[OpcodeIndex]);
1777 Ops.push_back(MemAddr);
1778 Ops.push_back(Align);
1779 if (isUpdating) {
1780 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachd146a022011-12-09 21:28:25 +00001781 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach2098cb12011-10-24 21:45:13 +00001782 // case entirely when the rest are updated to that form, too.
Jim Grosbachd146a022011-12-09 21:28:25 +00001783 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001784 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbachd146a022011-12-09 21:28:25 +00001785 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach05df4602011-10-31 21:50:31 +00001786 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001787 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001788 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach2098cb12011-10-24 21:45:13 +00001789 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Cheng630063a2010-05-10 21:26:24 +00001790 }
Bob Wilson06fce872011-02-07 17:43:21 +00001791 Ops.push_back(Pred);
1792 Ops.push_back(Reg0);
1793 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001794 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Bob Wilson75a64082010-09-02 16:00:54 +00001795
Bob Wilson12b47992009-10-14 17:28:52 +00001796 } else {
1797 // Otherwise, quad registers are loaded with two separate instructions,
1798 // where one loads the even registers and the other loads the odd registers.
Bob Wilson35fafca2010-09-03 18:16:02 +00001799 EVT AddrTy = MemAddr.getValueType();
Bob Wilson12b47992009-10-14 17:28:52 +00001800
Bob Wilson06fce872011-02-07 17:43:21 +00001801 // Load the even subregs. This is always an updating load, so that it
1802 // provides the address to the second load for the odd subregs.
Bob Wilson35fafca2010-09-03 18:16:02 +00001803 SDValue ImplDef =
1804 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1805 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilsona609b892011-02-07 17:43:15 +00001806 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
Michael Liaob53d8962013-04-19 22:22:57 +00001807 ResTy, AddrTy, MVT::Other, OpsA);
Bob Wilson35fafca2010-09-03 18:16:02 +00001808 Chain = SDValue(VLdA, 2);
Bob Wilson12b47992009-10-14 17:28:52 +00001809
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001810 // Load the odd subregs.
Bob Wilson06fce872011-02-07 17:43:21 +00001811 Ops.push_back(SDValue(VLdA, 1));
1812 Ops.push_back(Align);
1813 if (isUpdating) {
1814 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1815 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1816 "only constant post-increment update allowed for VLD3/4");
1817 (void)Inc;
1818 Ops.push_back(Reg0);
1819 }
1820 Ops.push_back(SDValue(VLdA, 0));
1821 Ops.push_back(Pred);
1822 Ops.push_back(Reg0);
1823 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001824 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys, Ops);
Bob Wilson35fafca2010-09-03 18:16:02 +00001825 }
Bob Wilson12b47992009-10-14 17:28:52 +00001826
Evan Cheng40791332011-04-19 00:04:03 +00001827 // Transfer memoperands.
1828 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1829 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1830 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1831
Bob Wilson06fce872011-02-07 17:43:21 +00001832 if (NumVecs == 1)
1833 return VLd;
1834
1835 // Extract out the subregisters.
1836 SDValue SuperReg = SDValue(VLd, 0);
1837 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1838 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1839 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1840 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1841 ReplaceUses(SDValue(N, Vec),
1842 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1843 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1844 if (isUpdating)
1845 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson12b47992009-10-14 17:28:52 +00001846 return NULL;
1847}
1848
Bob Wilson06fce872011-02-07 17:43:21 +00001849SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001850 const uint16_t *DOpcodes,
1851 const uint16_t *QOpcodes0,
1852 const uint16_t *QOpcodes1) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00001853 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001854 SDLoc dl(N);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001855
Bob Wilsonae08a732010-03-20 22:13:40 +00001856 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00001857 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1858 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1859 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001860 return NULL;
1861
Evan Cheng40791332011-04-19 00:04:03 +00001862 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1863 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1864
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001865 SDValue Chain = N->getOperand(0);
Bob Wilson06fce872011-02-07 17:43:21 +00001866 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001867 bool is64BitVector = VT.is64BitVector();
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00001868 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson7fbbe9a2010-09-23 23:42:37 +00001869
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001870 unsigned OpcodeIndex;
1871 switch (VT.getSimpleVT().SimpleTy) {
1872 default: llvm_unreachable("unhandled vst type");
1873 // Double-register operations:
1874 case MVT::v8i8: OpcodeIndex = 0; break;
1875 case MVT::v4i16: OpcodeIndex = 1; break;
1876 case MVT::v2f32:
1877 case MVT::v2i32: OpcodeIndex = 2; break;
1878 case MVT::v1i64: OpcodeIndex = 3; break;
1879 // Quad-register operations:
1880 case MVT::v16i8: OpcodeIndex = 0; break;
1881 case MVT::v8i16: OpcodeIndex = 1; break;
1882 case MVT::v4f32:
1883 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00001884 case MVT::v2i64: OpcodeIndex = 3;
1885 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1886 break;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001887 }
1888
Bob Wilson06fce872011-02-07 17:43:21 +00001889 std::vector<EVT> ResTys;
1890 if (isUpdating)
1891 ResTys.push_back(MVT::i32);
1892 ResTys.push_back(MVT::Other);
1893
Evan Cheng3da64f762010-04-16 05:46:06 +00001894 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00001895 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson06fce872011-02-07 17:43:21 +00001896 SmallVector<SDValue, 7> Ops;
Evan Chenga33fc862009-11-21 06:21:52 +00001897
Bob Wilson06fce872011-02-07 17:43:21 +00001898 // Double registers and VST1/VST2 quad registers are directly supported.
1899 if (is64BitVector || NumVecs <= 2) {
Bob Wilsona609b892011-02-07 17:43:15 +00001900 SDValue SrcReg;
Bob Wilson950882b2010-08-28 05:12:57 +00001901 if (NumVecs == 1) {
Bob Wilson06fce872011-02-07 17:43:21 +00001902 SrcReg = N->getOperand(Vec0Idx);
1903 } else if (is64BitVector) {
Evan Chenge276c182010-05-11 01:19:40 +00001904 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson06fce872011-02-07 17:43:21 +00001905 SDValue V0 = N->getOperand(Vec0Idx + 0);
1906 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Chenge276c182010-05-11 01:19:40 +00001907 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00001908 SrcReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001909 else {
Bob Wilson06fce872011-02-07 17:43:21 +00001910 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsona609b892011-02-07 17:43:15 +00001911 // If it's a vst3, form a quad D-register and leave the last part as
Evan Chenge276c182010-05-11 01:19:40 +00001912 // an undef.
1913 SDValue V3 = (NumVecs == 3)
1914 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001915 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001916 SrcReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Chenge276c182010-05-11 01:19:40 +00001917 }
Bob Wilson950882b2010-08-28 05:12:57 +00001918 } else {
1919 // Form a QQ register.
Bob Wilson06fce872011-02-07 17:43:21 +00001920 SDValue Q0 = N->getOperand(Vec0Idx);
1921 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Weiming Zhao95782222012-11-17 00:23:35 +00001922 SrcReg = SDValue(createQRegPairNode(MVT::v4i64, Q0, Q1), 0);
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001923 }
Bob Wilson06fce872011-02-07 17:43:21 +00001924
1925 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1926 QOpcodes0[OpcodeIndex]);
1927 Ops.push_back(MemAddr);
1928 Ops.push_back(Align);
1929 if (isUpdating) {
1930 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbach88ac7612011-12-14 21:32:11 +00001931 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach05df4602011-10-31 21:50:31 +00001932 // case entirely when the rest are updated to that form, too.
Jim Grosbach88ac7612011-12-14 21:32:11 +00001933 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach05df4602011-10-31 21:50:31 +00001934 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1935 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1936 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001937 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach05df4602011-10-31 21:50:31 +00001938 !isa<ConstantSDNode>(Inc.getNode()))
1939 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson06fce872011-02-07 17:43:21 +00001940 }
1941 Ops.push_back(SrcReg);
1942 Ops.push_back(Pred);
1943 Ops.push_back(Reg0);
1944 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00001945 SDNode *VSt = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001946
1947 // Transfer memoperands.
1948 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1949
1950 return VSt;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001951 }
1952
1953 // Otherwise, quad registers are stored with two separate instructions,
1954 // where one stores the even registers and the other stores the odd registers.
Evan Cheng9e688cb2010-05-15 07:53:37 +00001955
Bob Wilson01ac8f92010-06-16 21:34:01 +00001956 // Form the QQQQ REG_SEQUENCE.
Bob Wilson06fce872011-02-07 17:43:21 +00001957 SDValue V0 = N->getOperand(Vec0Idx + 0);
1958 SDValue V1 = N->getOperand(Vec0Idx + 1);
1959 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson950882b2010-08-28 05:12:57 +00001960 SDValue V3 = (NumVecs == 3)
1961 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson06fce872011-02-07 17:43:21 +00001962 : N->getOperand(Vec0Idx + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00001963 SDValue RegSeq = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001964
Bob Wilson06fce872011-02-07 17:43:21 +00001965 // Store the even D registers. This is always an updating store, so that it
1966 // provides the address to the second store for the odd subregs.
Bob Wilsona609b892011-02-07 17:43:15 +00001967 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1968 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1969 MemAddr.getValueType(),
Michael Liaob53d8962013-04-19 22:22:57 +00001970 MVT::Other, OpsA);
Evan Cheng40791332011-04-19 00:04:03 +00001971 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson01ac8f92010-06-16 21:34:01 +00001972 Chain = SDValue(VStA, 1);
1973
1974 // Store the odd D registers.
Bob Wilson06fce872011-02-07 17:43:21 +00001975 Ops.push_back(SDValue(VStA, 0));
1976 Ops.push_back(Align);
1977 if (isUpdating) {
1978 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1979 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1980 "only constant post-increment update allowed for VST3/4");
1981 (void)Inc;
1982 Ops.push_back(Reg0);
1983 }
1984 Ops.push_back(RegSeq);
1985 Ops.push_back(Pred);
1986 Ops.push_back(Reg0);
1987 Ops.push_back(Chain);
Evan Cheng40791332011-04-19 00:04:03 +00001988 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
Michael Liaob53d8962013-04-19 22:22:57 +00001989 Ops);
Evan Cheng40791332011-04-19 00:04:03 +00001990 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1991 return VStB;
Bob Wilsonc350cdf2009-10-14 18:32:29 +00001992}
1993
Dan Gohmanea6f91f2010-01-05 01:24:18 +00001994SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson06fce872011-02-07 17:43:21 +00001995 bool isUpdating, unsigned NumVecs,
Craig Topper01736f82012-05-24 05:17:00 +00001996 const uint16_t *DOpcodes,
1997 const uint16_t *QOpcodes) {
Bob Wilson93117bc2009-10-14 16:46:45 +00001998 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00001999 SDLoc dl(N);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002000
Bob Wilsonae08a732010-03-20 22:13:40 +00002001 SDValue MemAddr, Align;
Bob Wilson06fce872011-02-07 17:43:21 +00002002 unsigned AddrOpIdx = isUpdating ? 1 : 2;
2003 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
2004 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson4145e3a2009-10-14 16:19:03 +00002005 return NULL;
2006
Evan Cheng40791332011-04-19 00:04:03 +00002007 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2008 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2009
Bob Wilson4145e3a2009-10-14 16:19:03 +00002010 SDValue Chain = N->getOperand(0);
2011 unsigned Lane =
Bob Wilson06fce872011-02-07 17:43:21 +00002012 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
2013 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson4145e3a2009-10-14 16:19:03 +00002014 bool is64BitVector = VT.is64BitVector();
2015
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002016 unsigned Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002017 if (NumVecs != 3) {
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002018 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002019 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2020 if (Alignment > NumBytes)
2021 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002022 if (Alignment < 8 && Alignment < NumBytes)
2023 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002024 // Alignment must be a power of two; make sure of that.
2025 Alignment = (Alignment & -Alignment);
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002026 if (Alignment == 1)
2027 Alignment = 0;
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002028 }
Bob Wilsondd9fbaa2010-11-01 23:40:51 +00002029 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilsonb6d61dc2010-10-19 00:16:32 +00002030
Bob Wilson4145e3a2009-10-14 16:19:03 +00002031 unsigned OpcodeIndex;
2032 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson93117bc2009-10-14 16:46:45 +00002033 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilson4145e3a2009-10-14 16:19:03 +00002034 // Double-register operations:
2035 case MVT::v8i8: OpcodeIndex = 0; break;
2036 case MVT::v4i16: OpcodeIndex = 1; break;
2037 case MVT::v2f32:
2038 case MVT::v2i32: OpcodeIndex = 2; break;
2039 // Quad-register operations:
2040 case MVT::v8i16: OpcodeIndex = 0; break;
2041 case MVT::v4f32:
2042 case MVT::v4i32: OpcodeIndex = 1; break;
2043 }
2044
Bob Wilson06fce872011-02-07 17:43:21 +00002045 std::vector<EVT> ResTys;
2046 if (IsLoad) {
2047 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
2048 if (!is64BitVector)
2049 ResTyElts *= 2;
2050 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
2051 MVT::i64, ResTyElts));
2052 }
2053 if (isUpdating)
2054 ResTys.push_back(MVT::i32);
2055 ResTys.push_back(MVT::Other);
2056
Evan Cheng3da64f762010-04-16 05:46:06 +00002057 SDValue Pred = getAL(CurDAG);
Bob Wilsonae08a732010-03-20 22:13:40 +00002058 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chenga33fc862009-11-21 06:21:52 +00002059
Bob Wilson06fce872011-02-07 17:43:21 +00002060 SmallVector<SDValue, 8> Ops;
Bob Wilson4145e3a2009-10-14 16:19:03 +00002061 Ops.push_back(MemAddr);
Jim Grosbachd1d002a2009-11-07 21:25:39 +00002062 Ops.push_back(Align);
Bob Wilson06fce872011-02-07 17:43:21 +00002063 if (isUpdating) {
2064 SDValue Inc = N->getOperand(AddrOpIdx + 1);
2065 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
2066 }
Bob Wilson01ac8f92010-06-16 21:34:01 +00002067
Bob Wilsond5c57a52010-09-13 23:01:35 +00002068 SDValue SuperReg;
Bob Wilson06fce872011-02-07 17:43:21 +00002069 SDValue V0 = N->getOperand(Vec0Idx + 0);
2070 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002071 if (NumVecs == 2) {
2072 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002073 SuperReg = SDValue(createDRegPairNode(MVT::v2i64, V0, V1), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002074 else
Weiming Zhao95782222012-11-17 00:23:35 +00002075 SuperReg = SDValue(createQRegPairNode(MVT::v4i64, V0, V1), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002076 } else {
Bob Wilson06fce872011-02-07 17:43:21 +00002077 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002078 SDValue V3 = (NumVecs == 3)
Bob Wilson06fce872011-02-07 17:43:21 +00002079 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
2080 : N->getOperand(Vec0Idx + 3);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002081 if (is64BitVector)
Weiming Zhao95782222012-11-17 00:23:35 +00002082 SuperReg = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilsond5c57a52010-09-13 23:01:35 +00002083 else
Weiming Zhao95782222012-11-17 00:23:35 +00002084 SuperReg = SDValue(createQuadQRegsNode(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002085 }
Bob Wilsond5c57a52010-09-13 23:01:35 +00002086 Ops.push_back(SuperReg);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002087 Ops.push_back(getI32Imm(Lane));
Evan Chenga33fc862009-11-21 06:21:52 +00002088 Ops.push_back(Pred);
Bob Wilsonae08a732010-03-20 22:13:40 +00002089 Ops.push_back(Reg0);
Bob Wilson4145e3a2009-10-14 16:19:03 +00002090 Ops.push_back(Chain);
2091
Bob Wilson06fce872011-02-07 17:43:21 +00002092 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
2093 QOpcodes[OpcodeIndex]);
Michael Liaob53d8962013-04-19 22:22:57 +00002094 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002095 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson93117bc2009-10-14 16:46:45 +00002096 if (!IsLoad)
Bob Wilson06fce872011-02-07 17:43:21 +00002097 return VLdLn;
Evan Cheng0cbd11d2010-05-15 01:36:29 +00002098
Bob Wilsond5c57a52010-09-13 23:01:35 +00002099 // Extract the subregisters.
Bob Wilson06fce872011-02-07 17:43:21 +00002100 SuperReg = SDValue(VLdLn, 0);
2101 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
2102 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
2103 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson01ac8f92010-06-16 21:34:01 +00002104 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2105 ReplaceUses(SDValue(N, Vec),
Bob Wilson06fce872011-02-07 17:43:21 +00002106 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
2107 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
2108 if (isUpdating)
2109 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilson4145e3a2009-10-14 16:19:03 +00002110 return NULL;
2111}
2112
Bob Wilson06fce872011-02-07 17:43:21 +00002113SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper01736f82012-05-24 05:17:00 +00002114 unsigned NumVecs,
2115 const uint16_t *Opcodes) {
Bob Wilson2d790df2010-11-28 06:51:26 +00002116 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002117 SDLoc dl(N);
Bob Wilson2d790df2010-11-28 06:51:26 +00002118
2119 SDValue MemAddr, Align;
2120 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2121 return NULL;
2122
Evan Cheng40791332011-04-19 00:04:03 +00002123 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2124 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2125
Bob Wilson2d790df2010-11-28 06:51:26 +00002126 SDValue Chain = N->getOperand(0);
2127 EVT VT = N->getValueType(0);
2128
2129 unsigned Alignment = 0;
2130 if (NumVecs != 3) {
2131 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2132 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2133 if (Alignment > NumBytes)
2134 Alignment = NumBytes;
Bob Wilsond29b38c2010-12-10 19:37:42 +00002135 if (Alignment < 8 && Alignment < NumBytes)
2136 Alignment = 0;
Bob Wilson2d790df2010-11-28 06:51:26 +00002137 // Alignment must be a power of two; make sure of that.
2138 Alignment = (Alignment & -Alignment);
2139 if (Alignment == 1)
2140 Alignment = 0;
2141 }
2142 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2143
2144 unsigned OpcodeIndex;
2145 switch (VT.getSimpleVT().SimpleTy) {
2146 default: llvm_unreachable("unhandled vld-dup type");
2147 case MVT::v8i8: OpcodeIndex = 0; break;
2148 case MVT::v4i16: OpcodeIndex = 1; break;
2149 case MVT::v2f32:
2150 case MVT::v2i32: OpcodeIndex = 2; break;
2151 }
2152
2153 SDValue Pred = getAL(CurDAG);
2154 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2155 SDValue SuperReg;
2156 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson06fce872011-02-07 17:43:21 +00002157 SmallVector<SDValue, 6> Ops;
2158 Ops.push_back(MemAddr);
2159 Ops.push_back(Align);
2160 if (isUpdating) {
Jim Grosbachc80a2642011-12-21 19:40:55 +00002161 // fixed-stride update instructions don't have an explicit writeback
2162 // operand. It's implicit in the opcode itself.
Bob Wilson06fce872011-02-07 17:43:21 +00002163 SDValue Inc = N->getOperand(2);
Jim Grosbachc80a2642011-12-21 19:40:55 +00002164 if (!isa<ConstantSDNode>(Inc.getNode()))
2165 Ops.push_back(Inc);
2166 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2167 else if (NumVecs > 2)
2168 Ops.push_back(Reg0);
Bob Wilson06fce872011-02-07 17:43:21 +00002169 }
2170 Ops.push_back(Pred);
2171 Ops.push_back(Reg0);
2172 Ops.push_back(Chain);
Bob Wilson2d790df2010-11-28 06:51:26 +00002173
2174 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson06fce872011-02-07 17:43:21 +00002175 std::vector<EVT> ResTys;
Evan Cheng40791332011-04-19 00:04:03 +00002176 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson06fce872011-02-07 17:43:21 +00002177 if (isUpdating)
2178 ResTys.push_back(MVT::i32);
2179 ResTys.push_back(MVT::Other);
Michael Liaob53d8962013-04-19 22:22:57 +00002180 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTys, Ops);
Evan Cheng40791332011-04-19 00:04:03 +00002181 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson2d790df2010-11-28 06:51:26 +00002182 SuperReg = SDValue(VLdDup, 0);
Bob Wilson2d790df2010-11-28 06:51:26 +00002183
2184 // Extract the subregisters.
2185 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2186 unsigned SubIdx = ARM::dsub_0;
2187 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2188 ReplaceUses(SDValue(N, Vec),
2189 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson06fce872011-02-07 17:43:21 +00002190 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2191 if (isUpdating)
2192 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilson2d790df2010-11-28 06:51:26 +00002193 return NULL;
2194}
2195
Bob Wilson5bc8a792010-07-07 00:08:54 +00002196SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2197 unsigned Opc) {
Bob Wilson3ed511b2010-07-06 23:36:25 +00002198 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
Andrew Trickef9de2a2013-05-25 02:42:55 +00002199 SDLoc dl(N);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002200 EVT VT = N->getValueType(0);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002201 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilson3ed511b2010-07-06 23:36:25 +00002202
2203 // Form a REG_SEQUENCE to force register allocation.
2204 SDValue RegSeq;
Bob Wilson5bc8a792010-07-07 00:08:54 +00002205 SDValue V0 = N->getOperand(FirstTblReg + 0);
2206 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002207 if (NumVecs == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002208 RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002209 else {
Bob Wilson5bc8a792010-07-07 00:08:54 +00002210 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbachd37f0712010-10-21 19:38:40 +00002211 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilson3ed511b2010-07-06 23:36:25 +00002212 // an undef.
2213 SDValue V3 = (NumVecs == 3)
2214 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson5bc8a792010-07-07 00:08:54 +00002215 : N->getOperand(FirstTblReg + 3);
Weiming Zhao95782222012-11-17 00:23:35 +00002216 RegSeq = SDValue(createQuadDRegsNode(MVT::v4i64, V0, V1, V2, V3), 0);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002217 }
2218
Bob Wilson5bc8a792010-07-07 00:08:54 +00002219 SmallVector<SDValue, 6> Ops;
2220 if (IsExt)
2221 Ops.push_back(N->getOperand(1));
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00002222 Ops.push_back(RegSeq);
Bob Wilson5bc8a792010-07-07 00:08:54 +00002223 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilson3ed511b2010-07-06 23:36:25 +00002224 Ops.push_back(getAL(CurDAG)); // predicate
2225 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Michael Liaob53d8962013-04-19 22:22:57 +00002226 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Bob Wilson3ed511b2010-07-06 23:36:25 +00002227}
2228
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002229SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach825cb292010-04-22 23:24:18 +00002230 bool isSigned) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002231 if (!Subtarget->hasV6T2Ops())
2232 return NULL;
Bob Wilson93117bc2009-10-14 16:46:45 +00002233
Evan Chengeae6d2c2012-12-19 20:16:09 +00002234 unsigned Opc = isSigned
2235 ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
Jim Grosbach825cb292010-04-22 23:24:18 +00002236 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2237
Jim Grosbach825cb292010-04-22 23:24:18 +00002238 // For unsigned extracts, check for a shift right and mask
2239 unsigned And_imm = 0;
2240 if (N->getOpcode() == ISD::AND) {
2241 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2242
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00002243 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
Jim Grosbach825cb292010-04-22 23:24:18 +00002244 if (And_imm & (And_imm + 1))
2245 return NULL;
2246
2247 unsigned Srl_imm = 0;
2248 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2249 Srl_imm)) {
2250 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2251
Jim Grosbach03f56d92011-07-27 21:09:25 +00002252 // Note: The width operand is encoded as width-1.
2253 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach825cb292010-04-22 23:24:18 +00002254 unsigned LSB = Srl_imm;
Evan Chengeae6d2c2012-12-19 20:16:09 +00002255
Jim Grosbach825cb292010-04-22 23:24:18 +00002256 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengeae6d2c2012-12-19 20:16:09 +00002257
2258 if ((LSB + Width + 1) == N->getValueType(0).getSizeInBits()) {
2259 // It's cheaper to use a right shift to extract the top bits.
2260 if (Subtarget->isThumb()) {
2261 Opc = isSigned ? ARM::t2ASRri : ARM::t2LSRri;
2262 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2263 CurDAG->getTargetConstant(LSB, MVT::i32),
2264 getAL(CurDAG), Reg0, Reg0 };
2265 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2266 }
2267
2268 // ARM models shift instructions as MOVsi with shifter operand.
2269 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(ISD::SRL);
2270 SDValue ShOpc =
2271 CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, LSB),
2272 MVT::i32);
2273 SDValue Ops[] = { N->getOperand(0).getOperand(0), ShOpc,
2274 getAL(CurDAG), Reg0, Reg0 };
2275 return CurDAG->SelectNodeTo(N, ARM::MOVsi, MVT::i32, Ops, 5);
2276 }
2277
Jim Grosbach825cb292010-04-22 23:24:18 +00002278 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2279 CurDAG->getTargetConstant(LSB, MVT::i32),
2280 CurDAG->getTargetConstant(Width, MVT::i32),
2281 getAL(CurDAG), Reg0 };
2282 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2283 }
2284 }
2285 return NULL;
2286 }
2287
2288 // Otherwise, we're looking for a shift of a shift
Sandeep Patel423e42b2009-10-13 18:59:48 +00002289 unsigned Shl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002290 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002291 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2292 unsigned Srl_imm = 0;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002293 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel423e42b2009-10-13 18:59:48 +00002294 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbach03f56d92011-07-27 21:09:25 +00002295 // Note: The width operand is encoded as width-1.
2296 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel423e42b2009-10-13 18:59:48 +00002297 int LSB = Srl_imm - Shl_imm;
Evan Cheng0f55e9c2009-10-22 00:40:00 +00002298 if (LSB < 0)
Sandeep Patel423e42b2009-10-13 18:59:48 +00002299 return NULL;
2300 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002301 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel423e42b2009-10-13 18:59:48 +00002302 CurDAG->getTargetConstant(LSB, MVT::i32),
2303 CurDAG->getTargetConstant(Width, MVT::i32),
2304 getAL(CurDAG), Reg0 };
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002305 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel423e42b2009-10-13 18:59:48 +00002306 }
2307 }
2308 return NULL;
2309}
2310
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002311/// Target-specific DAG combining for ISD::XOR.
2312/// Target-independent combining lowers SELECT_CC nodes of the form
2313/// select_cc setg[ge] X, 0, X, -X
2314/// select_cc setgt X, -1, X, -X
2315/// select_cc setl[te] X, 0, -X, X
2316/// select_cc setlt X, 1, -X, X
2317/// which represent Integer ABS into:
2318/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2319/// ARM instruction selection detects the latter and matches it to
2320/// ARM::ABS or ARM::t2ABS machine node.
2321SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2322 SDValue XORSrc0 = N->getOperand(0);
2323 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002324 EVT VT = N->getValueType(0);
2325
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002326 if (Subtarget->isThumb1Only())
2327 return NULL;
2328
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002329 if (XORSrc0.getOpcode() != ISD::ADD || XORSrc1.getOpcode() != ISD::SRA)
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002330 return NULL;
2331
2332 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2333 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2334 SDValue SRASrc0 = XORSrc1.getOperand(0);
2335 SDValue SRASrc1 = XORSrc1.getOperand(1);
2336 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2337 EVT XType = SRASrc0.getValueType();
2338 unsigned Size = XType.getSizeInBits() - 1;
2339
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002340 if (ADDSrc1 == XORSrc1 && ADDSrc0 == SRASrc0 &&
2341 XType.isInteger() && SRAConstant != NULL &&
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002342 Size == SRAConstant->getZExtValue()) {
Jim Grosbachb437a8c2012-08-01 20:33:00 +00002343 unsigned Opcode = Subtarget->isThumb2() ? ARM::t2ABS : ARM::ABS;
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002344 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2345 }
2346
2347 return NULL;
2348}
2349
Evan Chengd85631e2010-05-05 18:28:36 +00002350SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2351 // The only time a CONCAT_VECTORS operation can have legal types is when
2352 // two 64-bit vectors are concatenated to a 128-bit vector.
2353 EVT VT = N->getValueType(0);
2354 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2355 llvm_unreachable("unexpected CONCAT_VECTORS");
Weiming Zhao95782222012-11-17 00:23:35 +00002356 return createDRegPairNode(VT, N->getOperand(0), N->getOperand(1));
Evan Chengd85631e2010-05-05 18:28:36 +00002357}
2358
Amara Emersonb4ad2f32013-09-26 12:22:36 +00002359SDNode *ARMDAGToDAGISel::SelectAtomic(SDNode *Node, unsigned Op8,
2360 unsigned Op16,unsigned Op32,
2361 unsigned Op64) {
2362 // Mostly direct translation to the given operations, except that we preserve
2363 // the AtomicOrdering for use later on.
2364 AtomicSDNode *AN = cast<AtomicSDNode>(Node);
2365 EVT VT = AN->getMemoryVT();
2366
2367 unsigned Op;
2368 SDVTList VTs = CurDAG->getVTList(AN->getValueType(0), MVT::Other);
2369 if (VT == MVT::i8)
2370 Op = Op8;
2371 else if (VT == MVT::i16)
2372 Op = Op16;
2373 else if (VT == MVT::i32)
2374 Op = Op32;
2375 else if (VT == MVT::i64) {
2376 Op = Op64;
2377 VTs = CurDAG->getVTList(MVT::i32, MVT::i32, MVT::Other);
2378 } else
2379 llvm_unreachable("Unexpected atomic operation");
2380
Eli Friedman1ccecbb2011-08-31 17:52:22 +00002381 SmallVector<SDValue, 6> Ops;
Amara Emersonb4ad2f32013-09-26 12:22:36 +00002382 for (unsigned i = 1; i < AN->getNumOperands(); ++i)
2383 Ops.push_back(AN->getOperand(i));
2384
2385 Ops.push_back(CurDAG->getTargetConstant(AN->getOrdering(), MVT::i32));
2386 Ops.push_back(AN->getOperand(0)); // Chain moves to the end
2387
2388 return CurDAG->SelectNodeTo(Node, Op, VTs, &Ops[0], Ops.size());
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00002389}
2390
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002391SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Andrew Trickef9de2a2013-05-25 02:42:55 +00002392 SDLoc dl(N);
Evan Cheng10043e22007-01-19 07:51:42 +00002393
Tim Northover31d093c2013-09-22 08:21:56 +00002394 if (N->isMachineOpcode()) {
2395 N->setNodeId(-1);
Evan Cheng10043e22007-01-19 07:51:42 +00002396 return NULL; // Already selected.
Tim Northover31d093c2013-09-22 08:21:56 +00002397 }
Rafael Espindola4e760152006-06-12 12:28:08 +00002398
2399 switch (N->getOpcode()) {
Evan Cheng10043e22007-01-19 07:51:42 +00002400 default: break;
Weiming Zhaoc5987002013-02-14 18:10:21 +00002401 case ISD::INLINEASM: {
2402 SDNode *ResNode = SelectInlineAsm(N);
2403 if (ResNode)
2404 return ResNode;
2405 break;
2406 }
Bill Wendlinga7d697e2011-10-10 22:59:55 +00002407 case ISD::XOR: {
2408 // Select special operations if XOR node forms integer ABS pattern
2409 SDNode *ResNode = SelectABSOp(N);
2410 if (ResNode)
2411 return ResNode;
2412 // Other cases are autogenerated.
2413 break;
2414 }
Evan Cheng10043e22007-01-19 07:51:42 +00002415 case ISD::Constant: {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002416 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002417 bool UseCP = true;
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002418 if (Subtarget->hasThumb2())
2419 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2420 // be done with MOV + MOVT, at worst.
2421 UseCP = 0;
2422 else {
2423 if (Subtarget->isThumb()) {
Bob Wilson360eef02009-06-22 17:29:13 +00002424 UseCP = (Val > 255 && // MOV
2425 ~Val > 255 && // MOV + MVN
2426 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov7c2b1e72009-09-27 23:52:58 +00002427 } else
2428 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2429 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2430 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2431 }
2432
Evan Cheng10043e22007-01-19 07:51:42 +00002433 if (UseCP) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002434 SDValue CPIdx =
Owen Anderson55f1c092009-08-13 21:58:54 +00002435 CurDAG->getTargetConstantPool(ConstantInt::get(
2436 Type::getInt32Ty(*CurDAG->getContext()), Val),
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002437 getTargetLowering()->getPointerTy());
Evan Cheng1526ba52007-01-24 08:53:17 +00002438
2439 SDNode *ResNode;
Evan Chengcd4cdd12009-07-11 06:43:01 +00002440 if (Subtarget->isThumb1Only()) {
Evan Cheng3da64f762010-04-16 05:46:06 +00002441 SDValue Pred = getAL(CurDAG);
Owen Anderson9f944592009-08-11 20:47:22 +00002442 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002443 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbachbfef3092010-12-15 23:52:36 +00002444 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002445 Ops);
Evan Chengcd4cdd12009-07-11 06:43:01 +00002446 } else {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002447 SDValue Ops[] = {
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002448 CPIdx,
Owen Anderson9f944592009-08-11 20:47:22 +00002449 CurDAG->getTargetConstant(0, MVT::i32),
Evan Cheng7e90b112007-07-05 07:15:27 +00002450 getAL(CurDAG),
Owen Anderson9f944592009-08-11 20:47:22 +00002451 CurDAG->getRegister(0, MVT::i32),
Evan Cheng1526ba52007-01-24 08:53:17 +00002452 CurDAG->getEntryNode()
2453 };
Dan Gohman32f71d72009-09-25 18:54:59 +00002454 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002455 Ops);
Evan Cheng1526ba52007-01-24 08:53:17 +00002456 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002457 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Cheng10043e22007-01-19 07:51:42 +00002458 return NULL;
2459 }
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002460
Evan Cheng10043e22007-01-19 07:51:42 +00002461 // Other cases are autogenerated.
Rafael Espindola4e760152006-06-12 12:28:08 +00002462 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002463 }
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002464 case ISD::FrameIndex: {
Evan Cheng10043e22007-01-19 07:51:42 +00002465 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002466 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Bill Wendlinga3cd3502013-06-19 21:36:55 +00002467 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
2468 getTargetLowering()->getPointerTy());
David Goodwin22c2fba2009-07-08 23:10:31 +00002469 if (Subtarget->isThumb1Only()) {
Jim Grosbach1b8457a2011-08-24 17:46:13 +00002470 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2471 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2472 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbachfde21102009-04-07 20:34:09 +00002473 } else {
David Goodwin4ad77972009-07-14 18:48:51 +00002474 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2475 ARM::t2ADDri : ARM::ADDri);
Owen Anderson9f944592009-08-11 20:47:22 +00002476 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2477 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2478 CurDAG->getRegister(0, MVT::i32) };
2479 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng7e90b112007-07-05 07:15:27 +00002480 }
Evan Cheng10043e22007-01-19 07:51:42 +00002481 }
Sandeep Patel423e42b2009-10-13 18:59:48 +00002482 case ISD::SRL:
Jim Grosbach825cb292010-04-22 23:24:18 +00002483 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002484 return I;
2485 break;
2486 case ISD::SRA:
Jim Grosbach825cb292010-04-22 23:24:18 +00002487 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel423e42b2009-10-13 18:59:48 +00002488 return I;
2489 break;
Evan Cheng10043e22007-01-19 07:51:42 +00002490 case ISD::MUL:
Evan Chengb24e51e2009-07-07 01:17:28 +00002491 if (Subtarget->isThumb1Only())
Evan Cheng139edae2007-01-24 02:21:22 +00002492 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002493 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmaneffb8942008-09-12 16:56:44 +00002494 unsigned RHSV = C->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +00002495 if (!RHSV) break;
2496 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002497 unsigned ShImm = Log2_32(RHSV-1);
2498 if (ShImm >= 32)
2499 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002500 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002501 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002502 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2503 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002504 if (Subtarget->isThumb()) {
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002505 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson9f944592009-08-11 20:47:22 +00002506 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002507 } else {
2508 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002509 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002510 }
Evan Cheng10043e22007-01-19 07:51:42 +00002511 }
2512 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002513 unsigned ShImm = Log2_32(RHSV+1);
2514 if (ShImm >= 32)
2515 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002516 SDValue V = N->getOperand(0);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002517 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson9f944592009-08-11 20:47:22 +00002518 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2519 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng1ec43962009-07-22 18:08:05 +00002520 if (Subtarget->isThumb()) {
Bob Wilsonb6112e82010-05-28 00:27:15 +00002521 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2522 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002523 } else {
2524 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Andersonb595ed02011-07-21 18:54:16 +00002525 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Cheng0d8b0cf2009-07-21 00:31:12 +00002526 }
Evan Cheng10043e22007-01-19 07:51:42 +00002527 }
2528 }
2529 break;
Evan Cheng786b15f2009-10-21 08:15:52 +00002530 case ISD::AND: {
Jim Grosbach825cb292010-04-22 23:24:18 +00002531 // Check for unsigned bitfield extract
2532 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2533 return I;
2534
Evan Cheng786b15f2009-10-21 08:15:52 +00002535 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2536 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2537 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2538 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2539 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002540 EVT VT = N->getValueType(0);
Evan Cheng786b15f2009-10-21 08:15:52 +00002541 if (VT != MVT::i32)
2542 break;
2543 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2544 ? ARM::t2MOVTi16
2545 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2546 if (!Opc)
2547 break;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002548 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng786b15f2009-10-21 08:15:52 +00002549 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2550 if (!N1C)
2551 break;
2552 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2553 SDValue N2 = N0.getOperand(1);
2554 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2555 if (!N2C)
2556 break;
2557 unsigned N1CVal = N1C->getZExtValue();
2558 unsigned N2CVal = N2C->getZExtValue();
2559 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2560 (N1CVal & 0xffffU) == 0xffffU &&
2561 (N2CVal & 0xffffU) == 0x0U) {
2562 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2563 MVT::i32);
2564 SDValue Ops[] = { N0.getOperand(0), Imm16,
2565 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002566 return CurDAG->getMachineNode(Opc, dl, VT, Ops);
Evan Cheng786b15f2009-10-21 08:15:52 +00002567 }
2568 }
2569 break;
2570 }
Jim Grosbachd7cf55c2009-11-09 00:11:35 +00002571 case ARMISD::VMOVRRD:
2572 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002573 N->getOperand(0), getAL(CurDAG),
Dan Gohman32f71d72009-09-25 18:54:59 +00002574 CurDAG->getRegister(0, MVT::i32));
Dan Gohmana1603612007-10-08 18:33:35 +00002575 case ISD::UMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002576 if (Subtarget->isThumb1Only())
2577 break;
2578 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002579 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Michael Liaob53d8962013-04-19 22:22:57 +00002580 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2581 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002582 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002583 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002584 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2585 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002586 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2587 ARM::UMULL : ARM::UMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002588 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002589 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002590 }
Dan Gohmana1603612007-10-08 18:33:35 +00002591 case ISD::SMUL_LOHI: {
Evan Chengb24e51e2009-07-07 01:17:28 +00002592 if (Subtarget->isThumb1Only())
2593 break;
2594 if (Subtarget->isThumb()) {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002595 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002596 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Michael Liaob53d8962013-04-19 22:22:57 +00002597 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002598 } else {
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002599 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson9f944592009-08-11 20:47:22 +00002600 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2601 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov62acecd2011-01-01 20:38:38 +00002602 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2603 ARM::SMULL : ARM::SMULLv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002604 dl, MVT::i32, MVT::i32, Ops);
Evan Chengb24e51e2009-07-07 01:17:28 +00002605 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002606 }
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002607 case ARMISD::UMLAL:{
2608 if (Subtarget->isThumb()) {
2609 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2610 N->getOperand(3), getAL(CurDAG),
2611 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002612 return CurDAG->getMachineNode(ARM::t2UMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002613 }else{
2614 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2615 N->getOperand(3), getAL(CurDAG),
2616 CurDAG->getRegister(0, MVT::i32),
2617 CurDAG->getRegister(0, MVT::i32) };
2618 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2619 ARM::UMLAL : ARM::UMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002620 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002621 }
2622 }
2623 case ARMISD::SMLAL:{
2624 if (Subtarget->isThumb()) {
2625 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2626 N->getOperand(3), getAL(CurDAG),
2627 CurDAG->getRegister(0, MVT::i32)};
Michael Liaob53d8962013-04-19 22:22:57 +00002628 return CurDAG->getMachineNode(ARM::t2SMLAL, dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002629 }else{
2630 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), N->getOperand(2),
2631 N->getOperand(3), getAL(CurDAG),
2632 CurDAG->getRegister(0, MVT::i32),
2633 CurDAG->getRegister(0, MVT::i32) };
2634 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2635 ARM::SMLAL : ARM::SMLALv5,
Michael Liaob53d8962013-04-19 22:22:57 +00002636 dl, MVT::i32, MVT::i32, Ops);
Arnold Schwaighoferf00fb1c2012-09-04 14:37:49 +00002637 }
2638 }
Evan Cheng10043e22007-01-19 07:51:42 +00002639 case ISD::LOAD: {
Evan Cheng84c6cda2009-07-02 07:28:31 +00002640 SDNode *ResNode = 0;
Evan Chengb24e51e2009-07-07 01:17:28 +00002641 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002642 ResNode = SelectT2IndexedLoad(N);
Evan Cheng84c6cda2009-07-02 07:28:31 +00002643 else
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002644 ResNode = SelectARMIndexedLoad(N);
Evan Chengd9c55362009-07-02 01:23:32 +00002645 if (ResNode)
2646 return ResNode;
Evan Cheng10043e22007-01-19 07:51:42 +00002647 // Other cases are autogenerated.
Rafael Espindola5f7ab1b2006-11-09 13:58:55 +00002648 break;
Rafael Espindola4e760152006-06-12 12:28:08 +00002649 }
Evan Cheng7e90b112007-07-05 07:15:27 +00002650 case ARMISD::BRCOND: {
2651 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2652 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2653 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00002654
Evan Cheng7e90b112007-07-05 07:15:27 +00002655 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2656 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2657 // Pattern complexity = 6 cost = 1 size = 0
2658
David Goodwin27303cd2009-06-30 18:04:13 +00002659 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2660 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2661 // Pattern complexity = 6 cost = 1 size = 0
2662
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002663 unsigned Opc = Subtarget->isThumb() ?
David Goodwin27303cd2009-06-30 18:04:13 +00002664 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002665 SDValue Chain = N->getOperand(0);
2666 SDValue N1 = N->getOperand(1);
2667 SDValue N2 = N->getOperand(2);
2668 SDValue N3 = N->getOperand(3);
2669 SDValue InFlag = N->getOperand(4);
Evan Cheng7e90b112007-07-05 07:15:27 +00002670 assert(N1.getOpcode() == ISD::BasicBlock);
2671 assert(N2.getOpcode() == ISD::Constant);
2672 assert(N3.getOpcode() == ISD::Register);
2673
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002674 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmaneffb8942008-09-12 16:56:44 +00002675 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson9f944592009-08-11 20:47:22 +00002676 MVT::i32);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002677 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman32f71d72009-09-25 18:54:59 +00002678 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Michael Liaob53d8962013-04-19 22:22:57 +00002679 MVT::Glue, Ops);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002680 Chain = SDValue(ResNode, 0);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002681 if (N->getNumValues() == 2) {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +00002682 InFlag = SDValue(ResNode, 1);
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002683 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnere99faac2008-02-03 03:20:59 +00002684 }
Dan Gohmanea6f91f2010-01-05 01:24:18 +00002685 ReplaceUses(SDValue(N, 0),
Evan Cheng82adca82009-11-19 08:16:50 +00002686 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Cheng7e90b112007-07-05 07:15:27 +00002687 return NULL;
2688 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002689 case ARMISD::VZIP: {
2690 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002691 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002692 switch (VT.getSimpleVT().SimpleTy) {
2693 default: return NULL;
2694 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2695 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2696 case MVT::v2f32:
Jim Grosbach4640c812012-04-11 16:53:25 +00002697 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2698 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002699 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2700 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2701 case MVT::v4f32:
2702 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2703 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002704 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002705 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2706 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002707 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002708 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002709 case ARMISD::VUZP: {
2710 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002711 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002712 switch (VT.getSimpleVT().SimpleTy) {
2713 default: return NULL;
2714 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2715 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2716 case MVT::v2f32:
Jim Grosbach6e536de2012-04-11 17:40:18 +00002717 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2718 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002719 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2720 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2721 case MVT::v4f32:
2722 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2723 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002724 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002725 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2726 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002727 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002728 }
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002729 case ARMISD::VTRN: {
2730 unsigned Opc = 0;
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002731 EVT VT = N->getValueType(0);
Anton Korobeynikov232b19c2009-08-21 12:41:42 +00002732 switch (VT.getSimpleVT().SimpleTy) {
2733 default: return NULL;
2734 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2735 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2736 case MVT::v2f32:
2737 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2738 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2739 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2740 case MVT::v4f32:
2741 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2742 }
Evan Cheng3da64f762010-04-16 05:46:06 +00002743 SDValue Pred = getAL(CurDAG);
Evan Chenga33fc862009-11-21 06:21:52 +00002744 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2745 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
Michael Liaob53d8962013-04-19 22:22:57 +00002746 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops);
Anton Korobeynikovce3ff1b2009-08-21 12:40:50 +00002747 }
Bob Wilsond8a9a042010-06-04 00:04:02 +00002748 case ARMISD::BUILD_VECTOR: {
2749 EVT VecVT = N->getValueType(0);
2750 EVT EltVT = VecVT.getVectorElementType();
2751 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sands14627772010-11-03 12:17:33 +00002752 if (EltVT == MVT::f64) {
Bob Wilsond8a9a042010-06-04 00:04:02 +00002753 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002754 return createDRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002755 }
Duncan Sands14627772010-11-03 12:17:33 +00002756 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilsond8a9a042010-06-04 00:04:02 +00002757 if (NumElts == 2)
Weiming Zhao95782222012-11-17 00:23:35 +00002758 return createSRegPairNode(VecVT, N->getOperand(0), N->getOperand(1));
Bob Wilsond8a9a042010-06-04 00:04:02 +00002759 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
Weiming Zhao95782222012-11-17 00:23:35 +00002760 return createQuadSRegsNode(VecVT, N->getOperand(0), N->getOperand(1),
Bob Wilsond8a9a042010-06-04 00:04:02 +00002761 N->getOperand(2), N->getOperand(3));
2762 }
Bob Wilsone0636a72009-08-26 17:39:53 +00002763
Bob Wilson2d790df2010-11-28 06:51:26 +00002764 case ARMISD::VLD2DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002765 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2766 ARM::VLD2DUPd32 };
Bob Wilson06fce872011-02-07 17:43:21 +00002767 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilson2d790df2010-11-28 06:51:26 +00002768 }
2769
Bob Wilson77ab1652010-11-29 19:35:29 +00002770 case ARMISD::VLD3DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002771 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2772 ARM::VLD3DUPd16Pseudo,
2773 ARM::VLD3DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002774 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson77ab1652010-11-29 19:35:29 +00002775 }
2776
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002777 case ARMISD::VLD4DUP: {
Craig Topper01736f82012-05-24 05:17:00 +00002778 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2779 ARM::VLD4DUPd16Pseudo,
2780 ARM::VLD4DUPd32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00002781 return SelectVLDDup(N, false, 4, Opcodes);
2782 }
2783
2784 case ARMISD::VLD2DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002785 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2786 ARM::VLD2DUPd16wb_fixed,
2787 ARM::VLD2DUPd32wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002788 return SelectVLDDup(N, true, 2, Opcodes);
2789 }
2790
2791 case ARMISD::VLD3DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002792 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2793 ARM::VLD3DUPd16Pseudo_UPD,
2794 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002795 return SelectVLDDup(N, true, 3, Opcodes);
2796 }
2797
2798 case ARMISD::VLD4DUP_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002799 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2800 ARM::VLD4DUPd16Pseudo_UPD,
2801 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002802 return SelectVLDDup(N, true, 4, Opcodes);
2803 }
2804
2805 case ARMISD::VLD1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002806 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2807 ARM::VLD1d16wb_fixed,
2808 ARM::VLD1d32wb_fixed,
2809 ARM::VLD1d64wb_fixed };
2810 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2811 ARM::VLD1q16wb_fixed,
2812 ARM::VLD1q32wb_fixed,
2813 ARM::VLD1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002814 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2815 }
2816
2817 case ARMISD::VLD2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002818 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2819 ARM::VLD2d16wb_fixed,
2820 ARM::VLD2d32wb_fixed,
2821 ARM::VLD1q64wb_fixed};
2822 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2823 ARM::VLD2q16PseudoWB_fixed,
2824 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002825 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2826 }
2827
2828 case ARMISD::VLD3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002829 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2830 ARM::VLD3d16Pseudo_UPD,
2831 ARM::VLD3d32Pseudo_UPD,
2832 ARM::VLD1q64wb_fixed};
2833 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2834 ARM::VLD3q16Pseudo_UPD,
2835 ARM::VLD3q32Pseudo_UPD };
2836 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2837 ARM::VLD3q16oddPseudo_UPD,
2838 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002839 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2840 }
2841
2842 case ARMISD::VLD4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002843 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2844 ARM::VLD4d16Pseudo_UPD,
2845 ARM::VLD4d32Pseudo_UPD,
2846 ARM::VLD1q64wb_fixed};
2847 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2848 ARM::VLD4q16Pseudo_UPD,
2849 ARM::VLD4q32Pseudo_UPD };
2850 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2851 ARM::VLD4q16oddPseudo_UPD,
2852 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002853 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2854 }
2855
2856 case ARMISD::VLD2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002857 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2858 ARM::VLD2LNd16Pseudo_UPD,
2859 ARM::VLD2LNd32Pseudo_UPD };
2860 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2861 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002862 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2863 }
2864
2865 case ARMISD::VLD3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002866 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2867 ARM::VLD3LNd16Pseudo_UPD,
2868 ARM::VLD3LNd32Pseudo_UPD };
2869 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2870 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002871 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2872 }
2873
2874 case ARMISD::VLD4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002875 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
2876 ARM::VLD4LNd16Pseudo_UPD,
2877 ARM::VLD4LNd32Pseudo_UPD };
2878 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
2879 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002880 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
2881 }
2882
2883 case ARMISD::VST1_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002884 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
2885 ARM::VST1d16wb_fixed,
2886 ARM::VST1d32wb_fixed,
2887 ARM::VST1d64wb_fixed };
2888 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
2889 ARM::VST1q16wb_fixed,
2890 ARM::VST1q32wb_fixed,
2891 ARM::VST1q64wb_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002892 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
2893 }
2894
2895 case ARMISD::VST2_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002896 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
2897 ARM::VST2d16wb_fixed,
2898 ARM::VST2d32wb_fixed,
2899 ARM::VST1q64wb_fixed};
2900 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
2901 ARM::VST2q16PseudoWB_fixed,
2902 ARM::VST2q32PseudoWB_fixed };
Bob Wilson06fce872011-02-07 17:43:21 +00002903 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
2904 }
2905
2906 case ARMISD::VST3_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002907 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
2908 ARM::VST3d16Pseudo_UPD,
2909 ARM::VST3d32Pseudo_UPD,
2910 ARM::VST1d64TPseudoWB_fixed};
2911 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2912 ARM::VST3q16Pseudo_UPD,
2913 ARM::VST3q32Pseudo_UPD };
2914 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2915 ARM::VST3q16oddPseudo_UPD,
2916 ARM::VST3q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002917 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2918 }
2919
2920 case ARMISD::VST4_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002921 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
2922 ARM::VST4d16Pseudo_UPD,
2923 ARM::VST4d32Pseudo_UPD,
2924 ARM::VST1d64QPseudoWB_fixed};
2925 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2926 ARM::VST4q16Pseudo_UPD,
2927 ARM::VST4q32Pseudo_UPD };
2928 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2929 ARM::VST4q16oddPseudo_UPD,
2930 ARM::VST4q32oddPseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002931 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2932 }
2933
2934 case ARMISD::VST2LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002935 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
2936 ARM::VST2LNd16Pseudo_UPD,
2937 ARM::VST2LNd32Pseudo_UPD };
2938 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
2939 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002940 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
2941 }
2942
2943 case ARMISD::VST3LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002944 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
2945 ARM::VST3LNd16Pseudo_UPD,
2946 ARM::VST3LNd32Pseudo_UPD };
2947 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
2948 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002949 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
2950 }
2951
2952 case ARMISD::VST4LN_UPD: {
Craig Topper01736f82012-05-24 05:17:00 +00002953 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
2954 ARM::VST4LNd16Pseudo_UPD,
2955 ARM::VST4LNd32Pseudo_UPD };
2956 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
2957 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson06fce872011-02-07 17:43:21 +00002958 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson431ac4ef2010-11-30 00:00:35 +00002959 }
2960
Bob Wilsone0636a72009-08-26 17:39:53 +00002961 case ISD::INTRINSIC_VOID:
2962 case ISD::INTRINSIC_W_CHAIN: {
2963 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilsone0636a72009-08-26 17:39:53 +00002964 switch (IntNo) {
2965 default:
Bob Wilsonf765e1f2010-05-06 16:05:26 +00002966 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00002967
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002968 case Intrinsic::arm_ldrexd: {
2969 SDValue MemAddr = N->getOperand(2);
Andrew Trickef9de2a2013-05-25 02:42:55 +00002970 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002971 SDValue Chain = N->getOperand(0);
2972
Weiming Zhao8f56f882012-11-16 21:55:34 +00002973 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
2974 unsigned NewOpc = isThumb ? ARM::t2LDREXD :ARM::LDREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002975
2976 // arm_ldrexd returns a i64 value in {i32, i32}
2977 std::vector<EVT> ResTys;
Weiming Zhao8f56f882012-11-16 21:55:34 +00002978 if (isThumb) {
2979 ResTys.push_back(MVT::i32);
2980 ResTys.push_back(MVT::i32);
2981 } else
2982 ResTys.push_back(MVT::Untyped);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002983 ResTys.push_back(MVT::Other);
2984
Weiming Zhao8f56f882012-11-16 21:55:34 +00002985 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002986 SmallVector<SDValue, 7> Ops;
2987 Ops.push_back(MemAddr);
2988 Ops.push_back(getAL(CurDAG));
2989 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
2990 Ops.push_back(Chain);
Michael Liaob53d8962013-04-19 22:22:57 +00002991 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002992 // Transfer memoperands.
2993 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2994 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2995 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
2996
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002997 // Remap uses.
Lang Hamesbe3d9712013-03-09 22:56:09 +00002998 SDValue OutChain = isThumb ? SDValue(Ld, 2) : SDValue(Ld, 1);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00002999 if (!SDValue(N, 0).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003000 SDValue Result;
3001 if (isThumb)
3002 Result = SDValue(Ld, 0);
3003 else {
3004 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_0, MVT::i32);
3005 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003006 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003007 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003008 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003009 ReplaceUses(SDValue(N, 0), Result);
3010 }
3011 if (!SDValue(N, 1).use_empty()) {
Weiming Zhao8f56f882012-11-16 21:55:34 +00003012 SDValue Result;
3013 if (isThumb)
3014 Result = SDValue(Ld, 1);
3015 else {
3016 SDValue SubRegIdx = CurDAG->getTargetConstant(ARM::gsub_1, MVT::i32);
3017 SDNode *ResNode = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Lang Hamesbe3d9712013-03-09 22:56:09 +00003018 dl, MVT::i32, SDValue(Ld, 0), SubRegIdx);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003019 Result = SDValue(ResNode,0);
Weiming Zhao8f56f882012-11-16 21:55:34 +00003020 }
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003021 ReplaceUses(SDValue(N, 1), Result);
3022 }
Lang Hamesbe3d9712013-03-09 22:56:09 +00003023 ReplaceUses(SDValue(N, 2), OutChain);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003024 return NULL;
3025 }
3026
3027 case Intrinsic::arm_strexd: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003028 SDLoc dl(N);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003029 SDValue Chain = N->getOperand(0);
3030 SDValue Val0 = N->getOperand(2);
3031 SDValue Val1 = N->getOperand(3);
3032 SDValue MemAddr = N->getOperand(4);
3033
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003034 // Store exclusive double return a i32 value which is the return status
3035 // of the issued store.
Benjamin Kramerfdf362b2013-03-07 20:33:29 +00003036 EVT ResTys[] = { MVT::i32, MVT::Other };
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003037
Weiming Zhao8f56f882012-11-16 21:55:34 +00003038 bool isThumb = Subtarget->isThumb() && Subtarget->hasThumb2();
3039 // Place arguments in the right order.
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003040 SmallVector<SDValue, 7> Ops;
Weiming Zhao8f56f882012-11-16 21:55:34 +00003041 if (isThumb) {
3042 Ops.push_back(Val0);
3043 Ops.push_back(Val1);
3044 } else
3045 // arm_strexd uses GPRPair.
3046 Ops.push_back(SDValue(createGPRPairNode(MVT::Untyped, Val0, Val1), 0));
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003047 Ops.push_back(MemAddr);
3048 Ops.push_back(getAL(CurDAG));
3049 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3050 Ops.push_back(Chain);
3051
Weiming Zhao8f56f882012-11-16 21:55:34 +00003052 unsigned NewOpc = isThumb ? ARM::t2STREXD : ARM::STREXD;
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003053
Michael Liaob53d8962013-04-19 22:22:57 +00003054 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops);
Bruno Cardoso Lopes325110f2011-05-28 04:07:29 +00003055 // Transfer memoperands.
3056 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3057 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3058 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3059
3060 return St;
3061 }
3062
Bob Wilson340861d2010-03-23 05:25:43 +00003063 case Intrinsic::arm_neon_vld1: {
Craig Topper01736f82012-05-24 05:17:00 +00003064 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3065 ARM::VLD1d32, ARM::VLD1d64 };
3066 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3067 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson06fce872011-02-07 17:43:21 +00003068 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson340861d2010-03-23 05:25:43 +00003069 }
3070
Bob Wilsone0636a72009-08-26 17:39:53 +00003071 case Intrinsic::arm_neon_vld2: {
Craig Topper01736f82012-05-24 05:17:00 +00003072 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3073 ARM::VLD2d32, ARM::VLD1q64 };
3074 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3075 ARM::VLD2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003076 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003077 }
3078
3079 case Intrinsic::arm_neon_vld3: {
Craig Topper01736f82012-05-24 05:17:00 +00003080 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3081 ARM::VLD3d16Pseudo,
3082 ARM::VLD3d32Pseudo,
3083 ARM::VLD1d64TPseudo };
3084 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3085 ARM::VLD3q16Pseudo_UPD,
3086 ARM::VLD3q32Pseudo_UPD };
3087 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3088 ARM::VLD3q16oddPseudo,
3089 ARM::VLD3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003090 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003091 }
3092
3093 case Intrinsic::arm_neon_vld4: {
Craig Topper01736f82012-05-24 05:17:00 +00003094 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3095 ARM::VLD4d16Pseudo,
3096 ARM::VLD4d32Pseudo,
3097 ARM::VLD1d64QPseudo };
3098 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3099 ARM::VLD4q16Pseudo_UPD,
3100 ARM::VLD4q32Pseudo_UPD };
3101 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3102 ARM::VLD4q16oddPseudo,
3103 ARM::VLD4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003104 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003105 }
3106
Bob Wilsonda9817c2009-09-01 04:26:28 +00003107 case Intrinsic::arm_neon_vld2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003108 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3109 ARM::VLD2LNd16Pseudo,
3110 ARM::VLD2LNd32Pseudo };
3111 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3112 ARM::VLD2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003113 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003114 }
3115
3116 case Intrinsic::arm_neon_vld3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003117 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3118 ARM::VLD3LNd16Pseudo,
3119 ARM::VLD3LNd32Pseudo };
3120 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3121 ARM::VLD3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003122 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003123 }
3124
3125 case Intrinsic::arm_neon_vld4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003126 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3127 ARM::VLD4LNd16Pseudo,
3128 ARM::VLD4LNd32Pseudo };
3129 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3130 ARM::VLD4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003131 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilsonda9817c2009-09-01 04:26:28 +00003132 }
3133
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003134 case Intrinsic::arm_neon_vst1: {
Craig Topper01736f82012-05-24 05:17:00 +00003135 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3136 ARM::VST1d32, ARM::VST1d64 };
3137 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3138 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson06fce872011-02-07 17:43:21 +00003139 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilsoncc0a2a72010-03-23 06:20:33 +00003140 }
3141
Bob Wilsone0636a72009-08-26 17:39:53 +00003142 case Intrinsic::arm_neon_vst2: {
Craig Topper01736f82012-05-24 05:17:00 +00003143 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3144 ARM::VST2d32, ARM::VST1q64 };
3145 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3146 ARM::VST2q32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003147 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilsone0636a72009-08-26 17:39:53 +00003148 }
3149
3150 case Intrinsic::arm_neon_vst3: {
Craig Topper01736f82012-05-24 05:17:00 +00003151 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3152 ARM::VST3d16Pseudo,
3153 ARM::VST3d32Pseudo,
3154 ARM::VST1d64TPseudo };
3155 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3156 ARM::VST3q16Pseudo_UPD,
3157 ARM::VST3q32Pseudo_UPD };
3158 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3159 ARM::VST3q16oddPseudo,
3160 ARM::VST3q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003161 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003162 }
3163
3164 case Intrinsic::arm_neon_vst4: {
Craig Topper01736f82012-05-24 05:17:00 +00003165 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3166 ARM::VST4d16Pseudo,
3167 ARM::VST4d32Pseudo,
3168 ARM::VST1d64QPseudo };
3169 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3170 ARM::VST4q16Pseudo_UPD,
3171 ARM::VST4q32Pseudo_UPD };
3172 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3173 ARM::VST4q16oddPseudo,
3174 ARM::VST4q32oddPseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003175 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilsone0636a72009-08-26 17:39:53 +00003176 }
Bob Wilsond7797752009-09-01 18:51:56 +00003177
3178 case Intrinsic::arm_neon_vst2lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003179 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3180 ARM::VST2LNd16Pseudo,
3181 ARM::VST2LNd32Pseudo };
3182 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3183 ARM::VST2LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003184 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003185 }
3186
3187 case Intrinsic::arm_neon_vst3lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003188 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3189 ARM::VST3LNd16Pseudo,
3190 ARM::VST3LNd32Pseudo };
3191 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3192 ARM::VST3LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003193 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003194 }
3195
3196 case Intrinsic::arm_neon_vst4lane: {
Craig Topper01736f82012-05-24 05:17:00 +00003197 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3198 ARM::VST4LNd16Pseudo,
3199 ARM::VST4LNd32Pseudo };
3200 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3201 ARM::VST4LNq32Pseudo };
Bob Wilson06fce872011-02-07 17:43:21 +00003202 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilsond7797752009-09-01 18:51:56 +00003203 }
Bob Wilsone0636a72009-08-26 17:39:53 +00003204 }
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003205 break;
Bob Wilsone0636a72009-08-26 17:39:53 +00003206 }
Evan Chengd85631e2010-05-05 18:28:36 +00003207
Bob Wilson3ed511b2010-07-06 23:36:25 +00003208 case ISD::INTRINSIC_WO_CHAIN: {
3209 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3210 switch (IntNo) {
3211 default:
3212 break;
3213
3214 case Intrinsic::arm_neon_vtbl2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003215 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003216 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003217 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003218 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003219 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003220
3221 case Intrinsic::arm_neon_vtbx2:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003222 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003223 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003224 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson5bc8a792010-07-07 00:08:54 +00003225 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonc597fd3b2010-09-13 23:55:10 +00003226 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilson3ed511b2010-07-06 23:36:25 +00003227 }
3228 break;
3229 }
3230
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003231 case ARMISD::VTBL1: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003232 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003233 EVT VT = N->getValueType(0);
3234 SmallVector<SDValue, 6> Ops;
3235
3236 Ops.push_back(N->getOperand(0));
3237 Ops.push_back(N->getOperand(1));
3238 Ops.push_back(getAL(CurDAG)); // Predicate
3239 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003240 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003241 }
3242 case ARMISD::VTBL2: {
Andrew Trickef9de2a2013-05-25 02:42:55 +00003243 SDLoc dl(N);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003244 EVT VT = N->getValueType(0);
3245
3246 // Form a REG_SEQUENCE to force register allocation.
3247 SDValue V0 = N->getOperand(0);
3248 SDValue V1 = N->getOperand(1);
Weiming Zhao95782222012-11-17 00:23:35 +00003249 SDValue RegSeq = SDValue(createDRegPairNode(MVT::v16i8, V0, V1), 0);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003250
3251 SmallVector<SDValue, 6> Ops;
3252 Ops.push_back(RegSeq);
3253 Ops.push_back(N->getOperand(2));
3254 Ops.push_back(getAL(CurDAG)); // Predicate
3255 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Michael Liaob53d8962013-04-19 22:22:57 +00003256 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT, Ops);
Bill Wendlinge1fd78f2011-03-14 23:02:38 +00003257 }
3258
Bob Wilsonf765e1f2010-05-06 16:05:26 +00003259 case ISD::CONCAT_VECTORS:
Evan Chengd85631e2010-05-05 18:28:36 +00003260 return SelectConcatVector(N);
Eli Friedmanc3f9c4a2011-08-31 00:31:29 +00003261
Amara Emersonb4ad2f32013-09-26 12:22:36 +00003262 case ISD::ATOMIC_LOAD:
3263 if (cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64)
3264 return SelectAtomic(N, 0, 0, 0, ARM::ATOMIC_LOAD_I64);
3265 else
3266 break;
Silviu Baranga93aefa52012-11-29 14:41:25 +00003267
Amara Emersonb4ad2f32013-09-26 12:22:36 +00003268 case ISD::ATOMIC_STORE:
3269 if (cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64)
3270 return SelectAtomic(N, 0, 0, 0, ARM::ATOMIC_STORE_I64);
3271 else
3272 break;
3273
3274 case ISD::ATOMIC_LOAD_ADD:
3275 return SelectAtomic(N,
3276 ARM::ATOMIC_LOAD_ADD_I8,
3277 ARM::ATOMIC_LOAD_ADD_I16,
3278 ARM::ATOMIC_LOAD_ADD_I32,
3279 ARM::ATOMIC_LOAD_ADD_I64);
3280 case ISD::ATOMIC_LOAD_SUB:
3281 return SelectAtomic(N,
3282 ARM::ATOMIC_LOAD_SUB_I8,
3283 ARM::ATOMIC_LOAD_SUB_I16,
3284 ARM::ATOMIC_LOAD_SUB_I32,
3285 ARM::ATOMIC_LOAD_SUB_I64);
3286 case ISD::ATOMIC_LOAD_AND:
3287 return SelectAtomic(N,
3288 ARM::ATOMIC_LOAD_AND_I8,
3289 ARM::ATOMIC_LOAD_AND_I16,
3290 ARM::ATOMIC_LOAD_AND_I32,
3291 ARM::ATOMIC_LOAD_AND_I64);
3292 case ISD::ATOMIC_LOAD_OR:
3293 return SelectAtomic(N,
3294 ARM::ATOMIC_LOAD_OR_I8,
3295 ARM::ATOMIC_LOAD_OR_I16,
3296 ARM::ATOMIC_LOAD_OR_I32,
3297 ARM::ATOMIC_LOAD_OR_I64);
3298 case ISD::ATOMIC_LOAD_XOR:
3299 return SelectAtomic(N,
3300 ARM::ATOMIC_LOAD_XOR_I8,
3301 ARM::ATOMIC_LOAD_XOR_I16,
3302 ARM::ATOMIC_LOAD_XOR_I32,
3303 ARM::ATOMIC_LOAD_XOR_I64);
3304 case ISD::ATOMIC_LOAD_NAND:
3305 return SelectAtomic(N,
3306 ARM::ATOMIC_LOAD_NAND_I8,
3307 ARM::ATOMIC_LOAD_NAND_I16,
3308 ARM::ATOMIC_LOAD_NAND_I32,
3309 ARM::ATOMIC_LOAD_NAND_I64);
3310 case ISD::ATOMIC_LOAD_MIN:
3311 return SelectAtomic(N,
3312 ARM::ATOMIC_LOAD_MIN_I8,
3313 ARM::ATOMIC_LOAD_MIN_I16,
3314 ARM::ATOMIC_LOAD_MIN_I32,
3315 ARM::ATOMIC_LOAD_MIN_I64);
3316 case ISD::ATOMIC_LOAD_MAX:
3317 return SelectAtomic(N,
3318 ARM::ATOMIC_LOAD_MAX_I8,
3319 ARM::ATOMIC_LOAD_MAX_I16,
3320 ARM::ATOMIC_LOAD_MAX_I32,
3321 ARM::ATOMIC_LOAD_MAX_I64);
3322 case ISD::ATOMIC_LOAD_UMIN:
3323 return SelectAtomic(N,
3324 ARM::ATOMIC_LOAD_UMIN_I8,
3325 ARM::ATOMIC_LOAD_UMIN_I16,
3326 ARM::ATOMIC_LOAD_UMIN_I32,
3327 ARM::ATOMIC_LOAD_UMIN_I64);
3328 case ISD::ATOMIC_LOAD_UMAX:
3329 return SelectAtomic(N,
3330 ARM::ATOMIC_LOAD_UMAX_I8,
3331 ARM::ATOMIC_LOAD_UMAX_I16,
3332 ARM::ATOMIC_LOAD_UMAX_I32,
3333 ARM::ATOMIC_LOAD_UMAX_I64);
3334 case ISD::ATOMIC_SWAP:
3335 return SelectAtomic(N,
3336 ARM::ATOMIC_SWAP_I8,
3337 ARM::ATOMIC_SWAP_I16,
3338 ARM::ATOMIC_SWAP_I32,
3339 ARM::ATOMIC_SWAP_I64);
3340 case ISD::ATOMIC_CMP_SWAP:
3341 return SelectAtomic(N,
3342 ARM::ATOMIC_CMP_SWAP_I8,
3343 ARM::ATOMIC_CMP_SWAP_I16,
3344 ARM::ATOMIC_CMP_SWAP_I32,
3345 ARM::ATOMIC_CMP_SWAP_I64);
Evan Chengd85631e2010-05-05 18:28:36 +00003346 }
Evan Chengd5021732008-12-10 21:54:21 +00003347
Dan Gohmanea6f91f2010-01-05 01:24:18 +00003348 return SelectCode(N);
Evan Cheng10043e22007-01-19 07:51:42 +00003349}
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003350
Weiming Zhaoc5987002013-02-14 18:10:21 +00003351SDNode *ARMDAGToDAGISel::SelectInlineAsm(SDNode *N){
3352 std::vector<SDValue> AsmNodeOperands;
3353 unsigned Flag, Kind;
3354 bool Changed = false;
3355 unsigned NumOps = N->getNumOperands();
3356
Weiming Zhaoc5987002013-02-14 18:10:21 +00003357 // Normally, i64 data is bounded to two arbitrary GRPs for "%r" constraint.
3358 // However, some instrstions (e.g. ldrexd/strexd in ARM mode) require
3359 // (even/even+1) GPRs and use %n and %Hn to refer to the individual regs
3360 // respectively. Since there is no constraint to explicitly specify a
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003361 // reg pair, we use GPRPair reg class for "%r" for 64-bit data. For Thumb,
3362 // the 64-bit data may be referred by H, Q, R modifiers, so we still pack
3363 // them into a GPRPair.
Weiming Zhaoc5987002013-02-14 18:10:21 +00003364
Andrew Trickef9de2a2013-05-25 02:42:55 +00003365 SDLoc dl(N);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003366 SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1) : SDValue(0,0);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003367
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003368 SmallVector<bool, 8> OpChanged;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003369 // Glue node will be appended late.
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003370 for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
Weiming Zhaoc5987002013-02-14 18:10:21 +00003371 SDValue op = N->getOperand(i);
3372 AsmNodeOperands.push_back(op);
3373
3374 if (i < InlineAsm::Op_FirstOperand)
3375 continue;
3376
3377 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
3378 Flag = C->getZExtValue();
3379 Kind = InlineAsm::getKind(Flag);
3380 }
3381 else
3382 continue;
3383
Joey Gouly392cdad2013-07-08 19:52:51 +00003384 // Immediate operands to inline asm in the SelectionDAG are modeled with
3385 // two operands. The first is a constant of value InlineAsm::Kind_Imm, and
3386 // the second is a constant with the value of the immediate. If we get here
3387 // and we have a Kind_Imm, skip the next operand, and continue.
Joey Gouly606f3fb2013-07-05 10:19:40 +00003388 if (Kind == InlineAsm::Kind_Imm) {
3389 SDValue op = N->getOperand(++i);
3390 AsmNodeOperands.push_back(op);
3391 continue;
3392 }
3393
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003394 unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
3395 if (NumRegs)
3396 OpChanged.push_back(false);
3397
3398 unsigned DefIdx = 0;
3399 bool IsTiedToChangedOp = false;
3400 // If it's a use that is tied with a previous def, it has no
3401 // reg class constraint.
3402 if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
3403 IsTiedToChangedOp = OpChanged[DefIdx];
3404
Weiming Zhaoc5987002013-02-14 18:10:21 +00003405 if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
3406 && Kind != InlineAsm::Kind_RegDefEarlyClobber)
3407 continue;
3408
Weiming Zhaoc5987002013-02-14 18:10:21 +00003409 unsigned RC;
3410 bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003411 if ((!IsTiedToChangedOp && (!HasRC || RC != ARM::GPRRegClassID))
3412 || NumRegs != 2)
Weiming Zhaoc5987002013-02-14 18:10:21 +00003413 continue;
3414
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003415 assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
Weiming Zhaoc5987002013-02-14 18:10:21 +00003416 SDValue V0 = N->getOperand(i+1);
3417 SDValue V1 = N->getOperand(i+2);
3418 unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
3419 unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
3420 SDValue PairedReg;
3421 MachineRegisterInfo &MRI = MF->getRegInfo();
3422
3423 if (Kind == InlineAsm::Kind_RegDef ||
3424 Kind == InlineAsm::Kind_RegDefEarlyClobber) {
3425 // Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
3426 // the original GPRs.
3427
3428 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3429 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3430 SDValue Chain = SDValue(N,0);
3431
3432 SDNode *GU = N->getGluedUser();
3433 SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::Untyped,
3434 Chain.getValue(1));
3435
3436 // Extract values from a GPRPair reg and copy to the original GPR reg.
3437 SDValue Sub0 = CurDAG->getTargetExtractSubreg(ARM::gsub_0, dl, MVT::i32,
3438 RegCopy);
3439 SDValue Sub1 = CurDAG->getTargetExtractSubreg(ARM::gsub_1, dl, MVT::i32,
3440 RegCopy);
3441 SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
3442 RegCopy.getValue(1));
3443 SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
3444
3445 // Update the original glue user.
3446 std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
3447 Ops.push_back(T1.getValue(1));
3448 CurDAG->UpdateNodeOperands(GU, &Ops[0], Ops.size());
3449 GU = T1.getNode();
3450 }
3451 else {
3452 // For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
3453 // GPRPair and then pass the GPRPair to the inline asm.
3454 SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
3455
3456 // As REG_SEQ doesn't take RegisterSDNode, we copy them first.
3457 SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
3458 Chain.getValue(1));
3459 SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
3460 T0.getValue(1));
3461 SDValue Pair = SDValue(createGPRPairNode(MVT::Untyped, T0, T1), 0);
3462
3463 // Copy REG_SEQ into a GPRPair-typed VR and replace the original two
3464 // i32 VRs of inline asm with it.
3465 unsigned GPVR = MRI.createVirtualRegister(&ARM::GPRPairRegClass);
3466 PairedReg = CurDAG->getRegister(GPVR, MVT::Untyped);
3467 Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
3468
3469 AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
3470 Glue = Chain.getValue(1);
3471 }
3472
3473 Changed = true;
3474
3475 if(PairedReg.getNode()) {
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003476 OpChanged[OpChanged.size() -1 ] = true;
Weiming Zhaoc5987002013-02-14 18:10:21 +00003477 Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
Tim Northover55349a22013-08-18 18:06:03 +00003478 if (IsTiedToChangedOp)
3479 Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
3480 else
3481 Flag = InlineAsm::getFlagWordForRegClass(Flag, ARM::GPRPairRegClassID);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003482 // Replace the current flag.
3483 AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
3484 Flag, MVT::i32);
3485 // Add the new register node and skip the original two GPRs.
3486 AsmNodeOperands.push_back(PairedReg);
3487 // Skip the next two GPRs.
3488 i += 2;
3489 }
3490 }
3491
Weiming Zhaoa3d87a12013-06-28 17:26:02 +00003492 if (Glue.getNode())
3493 AsmNodeOperands.push_back(Glue);
Weiming Zhaoc5987002013-02-14 18:10:21 +00003494 if (!Changed)
3495 return NULL;
3496
Andrew Trickef9de2a2013-05-25 02:42:55 +00003497 SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
Weiming Zhaoc5987002013-02-14 18:10:21 +00003498 CurDAG->getVTList(MVT::Other, MVT::Glue), &AsmNodeOperands[0],
3499 AsmNodeOperands.size());
3500 New->setNodeId(-1);
3501 return New.getNode();
3502}
3503
3504
Bob Wilsona2c462b2009-05-19 05:53:42 +00003505bool ARMDAGToDAGISel::
3506SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3507 std::vector<SDValue> &OutOps) {
3508 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson3b515602009-10-13 20:50:28 +00003509 // Require the address to be in a register. That is safe for all ARM
3510 // variants and it is hard to do anything much smarter without knowing
3511 // how the operand is used.
3512 OutOps.push_back(Op);
Bob Wilsona2c462b2009-05-19 05:53:42 +00003513 return false;
3514}
3515
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003516/// createARMISelDag - This pass converts a legalized DAG into a
3517/// ARM-specific DAG, ready for instruction scheduling.
3518///
Bob Wilson2dd957f2009-09-28 14:30:20 +00003519FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3520 CodeGenOpt::Level OptLevel) {
3521 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindolaffdc24b2006-05-14 22:18:28 +00003522}